STM32配置配置ETH MAC的参数
时间: 2023-08-02 21:14:12 浏览: 235
在STM32中配置ETH MAC的参数需要以下步骤:
1. 确定ETH MAC的工作模式,可以选择MII或RMII模式。
2. 配置ETH MAC的时钟源,可以选择外部时钟源或者内部PLL时钟源。
3. 配置PHY芯片的地址,使ETH MAC能够与PHY进行通信。
4. 配置ETH MAC的MAC地址,以便其他设备能够识别该设备。
5. 配置ETH MAC的传输参数,如最大传输单元、发送和接收缓冲区大小等。
6. 启动ETH MAC,使其能够开始工作。
以下是一个简单的示例代码,可以帮助你更好地了解如何在STM32中配置ETH MAC的参数:
```
#include "stm32f4xx.h"
#include "stm32f4xx_eth.h"
void ETH_Configuration(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_ETH_MAC | RCC_AHB1Periph_ETH_MAC_Tx | RCC_AHB1Periph_ETH_MAC_Rx, ENABLE);
ETH_DeInit();
ETH_StructInit(Ð_InitStructure);
ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable;
ETH_InitStructure.ETH_Speed = ETH_Speed_100M;
ETH_InitStructure.ETH_Mode = ETH_Mode_FullDuplex;
ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Enable;
ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
ETH_InitStructure.ETH_ReceiveBuffer = ETH_ReceiveBuffer_Ring;
ETH_InitStructure.ETH_TransmitBuffer = ETH_TransmitBuffer_Ring;
ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
ETH_InitStructure.ETH_ReceiveThresholdControl = ETH_ReceiveThresholdControl_64Bytes;
ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
ETH_InitStructure.ETH_RxDescAligned = ETH_RxDescAligned_Enable;
ETH_InitStructure.ETH_TxDescAligned = ETH_TxDescAligned_Enable;
while (ETH_Init(Ð_InitStructure, PHY_ADDRESS) != ETH_SUCCESS);
ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = ETH_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
```
在上面的代码中,我们首先开启了ETH MAC和相关的外设时钟,并使用ETH_DeInit函数将ETH MAC的所有寄存器恢复到默认值。然后,我们使用ETH_StructInit函数初始化了ETH_InitStructure结构体,并设置了各种ETH MAC参数。最后,我们使用ETH_Init函数将ETH MAC初始化,并使用ETH_DMAITConfig函数和NVIC_Init函数配置相关的DMA和中断。
阅读全文