初级会员
- 积分
- 69
- 金钱
- 69
- 注册时间
- 2018-12-7
- 在线时间
- 45 小时
|
10金钱
H743开发板,HAL库的例程中用的是LAN8720,
由于我们硬件要使用DP83848,
所以对原子例程做了修改,对应DP83848的管脚定义和寄存器配置,
可是修改后,寄存器读出来的值始终是0XFFFF,这可能会是什么情况。
以下均是在原子例程上做的修改,
#define DP83848_PHY_ADDRESS 0x01 /* Relative to STM322xG-EVAL Board */
void HAL_ETH_MspInit_dp83848(ETH_HandleTypeDef *heth)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_GPIOA_CLK_ENABLE(); //开启GPIOA时钟
__HAL_RCC_GPIOB_CLK_ENABLE(); //开启GPIOB时钟
__HAL_RCC_GPIOC_CLK_ENABLE(); //开启GPIOC时钟
__HAL_RCC_GPIOG_CLK_ENABLE(); //开启GPIOG时钟
__HAL_RCC_ETH1MAC_CLK_ENABLE(); //使能ETH1 MAC时钟
__HAL_RCC_ETH1TX_CLK_ENABLE(); //使能ETH1发送时钟
__HAL_RCC_ETH1RX_CLK_ENABLE(); //使能ETH1接收时钟
GPIO_Initure.Pin = GPIO_PIN_8;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
//PA1,2,7
GPIO_Initure.Pin=GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_7;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Alternate = GPIO_AF11_ETH;
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
//PC1,4,5
GPIO_Initure.Pin=GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Alternate = GPIO_AF11_ETH;
HAL_GPIO_Init(GPIOC,&GPIO_Initure);
//PB11,12,13
GPIO_Initure.Pin=GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13;
GPIO_Initure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_Initure.Mode = GPIO_MODE_AF_PP;
GPIO_Initure.Pull = GPIO_NOPULL;
GPIO_Initure.Alternate = GPIO_AF11_ETH;
HAL_GPIO_Init(GPIOB,&GPIO_Initure);
HAL_NVIC_SetPriority(ETH_IRQn,1,0); //网络中断优先级应该高一点
HAL_NVIC_EnableIRQ(ETH_IRQn);
}
int32_t DP83848_Init(void)
{
u8 macaddress[6];
u32 timeout=0;
u32 regval=0;
u32 phylink=0;
int32_t status=DP83848_STATUS_OK;
//硬件复位
INTX_DISABLE(); //关闭所有中断,复位过程不能被打断!
DP83848_Phy_Rest();
INTX_ENABLE(); //开启所有中断
NETMPU_Config(); //MPU保护设置
macaddress[0]=lwipdev.mac[0];
macaddress[1]=lwipdev.mac[1];
macaddress[2]=lwipdev.mac[2];
macaddress[3]=lwipdev.mac[3];
macaddress[4]=lwipdev.mac[4];
macaddress[5]=lwipdev.mac[5];
DP83848_ETHHandle.Instance=ETH; //ETH
DP83848_ETHHandle.Init.MACAddr=macaddress; //mac地址
DP83848_ETHHandle.Init.MediaInterface=HAL_ETH_RMII_MODE; //RMII接口
DP83848_ETHHandle.Init.RxDesc=DMARxDscrTab; //发送描述符
DP83848_ETHHandle.Init.TxDesc=DMATxDscrTab; //接收描述如
DP83848_ETHHandle.Init.RxBuffLen=ETH_MAX_PACKET_SIZE; //接收长度
HAL_ETH_Init(&DP83848_ETHHandle); //初始化ETH
HAL_ETH_SetMDIOClockRange(&DP83848_ETHHandle);
if(DP83848_WritePHY(DP83848_PHY_BCR,DP83848_PHY_Reset)>=0) //DP83848软件复位
{
//等待软件复位完成
if(DP83848_ReadPHY(DP83848_PHY_BCR,®val)>=0)
{
while(regval & DP83848_PHY_Reset)
{
if(DP83848_ReadPHY(DP83848_PHY_BCR,®val)<0)
{
status=DP83848_STATUS_READ_ERROR;
break;
}
delay_ms(10);
timeout++;
if(timeout>=DP83848_TIMEOUT) break; //超时跳出,5S
}
}
else
{
status=DP83848_STATUS_READ_ERROR;
}
}
else
{
status=DP83848_STATUS_WRITE_ERROR;
}
DP83848_StartAutoNego(); //开启自动协商功能
if(status== DP83848_STATUS_OK) //如果前面运行正常就延时1s
delay_ms(1000); //等待1s
//等待网络连接成功
timeout=0;
while(DP83848_GetLinkState()<= DP83848_STATUS_LINK_DOWN)
{
delay_ms(10);
timeout++;
if(timeout>= DP83848_TIMEOUT)
{
status= DP83848_STATUS_LINK_DOWN;
break; //超时跳出,5S
}
}
phylink=LAN8720_GetLinkState();
if(phylink==DP83848_STATUS_100MBITS_FULLDUPLEX)
printf("DP83848:100Mb/s FullDuplex\r\n");
else if(phylink==DP83848_STATUS_100MBITS_HALFDUPLEX)
printf("DP83848:100Mb/s HalfDuplex\r\n");
else if(phylink==DP83848_STATUS_10MBITS_FULLDUPLEX)
printf("DP83848:10Mb/s FullDuplex\r\n");
else if(phylink==DP83848_STATUS_10MBITS_HALFDUPLEX)
printf("DP83848:10Mb/s HalfDuplex\r\n");
return status;
}
|
|