金牌会员
积分 1887
金钱 1887
注册时间 2012-10-28
在线时间 353 小时
5 金钱
lwip 不能够开启自协商模式 ??
static void low_level_init(struct netif *netif)
{
uint32_t regvalue = 0;
HAL_StatusTypeDef hal_eth_init_status;
heth.Instance = ETH;
heth.Init.AutoNegotiation = ETH_AUTONEGOTIATION_DISABLE; // 这个地方不知道为什么,我开启自商协议后,貌似就不行了,如果设置为禁止选项的话 就可以,哪位大神看看是怎么回事啊 ??
heth.Init.Speed = ETH_SPEED_100M; //速度100M,如果开启了自协商模式,此配置就无效
heth.Init.DuplexMode = ETH_MODE_FULLDUPLEX; //全双工模式,如果开启了自协商模式,此配置就无效
heth.Init.PhyAddress = LAN8742A_PHY_ADDRESS;
heth.Init.MACAddr = &lwipdev.mac[0]; // 这个mac地址已经在其他地方设置好的
heth.Init.RxMode = ETH_RXINTERRUPT_MODE; //中断接收模式
heth.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE; //硬件帧校验
heth.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII; //RMII接口
/* USER CODE BEGIN MACADDRESS */
/* USER CODE END MACADDRESS */
hal_eth_init_status = HAL_ETH_Init(&heth);
if (hal_eth_init_status == HAL_OK)
{
/* Set netif link flag */
netif->flags |= NETIF_FLAG_LINK_UP;
}
/* Initialize Tx Descriptors list: Chain Mode */
HAL_ETH_DMATxDescListInit(&heth, DMATxDscrTab, Tx_Buff, ETH_TXBUFNB);
/* Initialize Rx Descriptors list: Chain Mode */
HAL_ETH_DMARxDescListInit(&heth, DMARxDscrTab, Rx_Buff, ETH_RXBUFNB);
#if LWIP_ARP || LWIP_ETHERNET
/* set MAC hardware address length */
netif->hwaddr_len = ETH_HWADDR_LEN;
//初始化MAC地址,设置什么地址由用户自己设置,但是不能与网络中其他设备MAC地址重复
netif->hwaddr[0] = heth.Init.MACAddr[0];
netif->hwaddr[1] = heth.Init.MACAddr[1];
netif->hwaddr[2] = heth.Init.MACAddr[2];
netif->hwaddr[3] = heth.Init.MACAddr[3];
netif->hwaddr[4] = heth.Init.MACAddr[4];
netif->hwaddr[5] = heth.Init.MACAddr[5];
/* maximum transfer unit */
netif->mtu = 1500;//最大允许传输单元,允许该网卡广播和ARP功能
/* Accept broadcast address and ARP traffic */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
/* create a binary semaphore used for informing ethernetif of frame reception */
osSemaphoreDef(SEM); // 定义os_semaphore_def_##name 结构体
s_xSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1 ); ////创建信号量
/* create the task that handles the ETH_MAC */
osThreadDef(EthIf, ethernetif_input, osPriorityRealtime, 0, INTERFACE_THREAD_STACK_SIZE);
osThreadCreate (osThread(EthIf), netif);
/* Enable MAC and DMA transmission and reception */
HAL_ETH_Start(&heth);
/* Read Register Configuration */
HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR, ®value);
regvalue |= (PHY_ISFR_INT4);
/* Enable Interrupt on change of link status */
HAL_ETH_WritePHYRegister(&heth, PHY_ISFR , regvalue );
/* Read Register Configuration */
HAL_ETH_ReadPHYRegister(&heth, PHY_ISFR , ®value);
#endif /* LWIP_ARP || LWIP_ETHERNET */
}
我来回答