中级会员
- 积分
- 223
- 金钱
- 223
- 注册时间
- 2014-5-2
- 在线时间
- 49 小时
|
本帖最后由 yinshiyouquan 于 2020-11-21 13:29 编辑
使用的是freertos+lwip+hal库,根据调试信息,eth hardware init sucess,sys_sem_new ok,sys_mbox_new ok,netif_set_up OK,lwip dhcp init success,结果就是获取不到ip;
,这段是开启dhcp,然后一直等待获取ip;
if(netif_is_up(&gnetif))
{
err = dhcp_start(&gnetif); //开启dhcp
if(err == ERR_OK)
printf("lwip dhcp init success...\r\n");
else
printf("lwip dhcp init fail...\r\n");
while(ip_addr_cmp(&(gnetif.ip_addr),&ipaddr)) //等待dhcp分配的ip有效
{
vTaskDelay(1);
// printf("等待分配有效ip\r\n");
}
}
后来我用抓包工具,抓的数据如下:Frame 2204: 342 bytes on wire (2736 bits), 342 bytes captured (2736 bits) on interface \Device\NPF_{89A318E3-CC45-4649-9EDC-36C86B8C174E}, id 0
Ethernet II, Src: 88:88:88:88:87:88 (88:88:88:88:87:88), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Internet Protocol Version 4, Src: 0.0.0.0, Dst: 255.255.255.255
User Datagram Protocol, Src Port: 68, Dst Port: 67
Dynamic Host Configuration Protocol (Discover)
Message type: Boot Request (1)
Hardware type: Ethernet (0x01)
Hardware address length: 6
Hops: 0
Transaction ID: 0x14a67052
Seconds elapsed: 0
Bootp flags: 0x8000, Broadcast flag (Broadcast)
Client IP address: 0.0.0.0
Your (client) IP address: 0.0.0.0
Next server IP address: 0.0.0.0
Relay agent IP address: 0.0.0.0
Client MAC address: 88:88:88:88:87:88 (88:88:88:88:87:88)
Client hardware address padding: 00000000000000000000
Server host name not given
Boot file name not given
Magic cookie: DHCP
Option: (53) DHCP Message Type (Discover)
Option: (61) Client identifier
Option: (12) Host Name
Option: (60) Vendor class identifier
Option: (55) Parameter Request List
Option: (255) End
Padding: 0000000000
从抓包中可以看出来,mac这边出现异常,,我设置的默认mac代码如下:
HAL_StatusTypeDef Eth_Init(void)
{
HAL_StatusTypeDef ret;
uint8_t MACAddr[6] ;
HAL_ETH_DeInit(&heth);
Eth_Reset();
ETH->DMABMR |= ETH_DMABMR_SR;
/* Init ETH */
MACAddr[0] = 0x02;
MACAddr[1] = 0x00;
MACAddr[2] = 0x00;
MACAddr[3] = 0x00;
MACAddr[4] = 0x02;
MACAddr[5] = 0x00;
heth.Instance = ETH;
heth.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
heth.Init.PhyAddress = LAN8720_PHY_ADDRESS;
heth.Init.MACAddr = &MACAddr[0];
heth.Init.RxMode = ETH_RXINTERRUPT_MODE; // rx mode
heth.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
heth.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
heth.Init.Speed = ETH_SPEED_100M; //speed
heth.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
/* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */
ret = HAL_ETH_Init(&heth);
if (ret == HAL_OK)
printf("eth hardware init sucess...\r\n");
else
printf("eth hardware init faild...\r\n");
/* Initialize Tx Descriptors list: Chain Mode */
HAL_ETH_DMATxDescListInit(&heth, DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
/* Initialize Rx Descriptors list: Chain Mode */
HAL_ETH_DMARxDescListInit(&heth, DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
/* Enable MAC and DMA transmission and reception */
return ret;
}
因为对lwip研究实在浅薄,所以请教下大家:
1.为何发出去的discovery,mac地址会改变
2.我在接收中断中设置了打印信息,但是调试时候并没有任何中断产生,而从抓包中可以看到,路由器是有收到数据的,那为何客户端收不到数据
3.还有一个信息,关闭dhcp,使用静态测试,同样也是无法ping通
|
-
|