0
本帖最后由 lee_st 于 2018-4-3 09:26 编辑
编译正常,然后开始网络的配置
- static void Netif_Config(void)
- {
- ip_addr_t ipaddr;
- ip_addr_t netmask;
- ip_addr_t gw;
- uint8_t iptab[4] = {0};
- uint8_t iptxt[20];
- uint8_t netmasktab[4]={0};
- uint8_t netmasktxt[30];
-
- uint8_t gwtab[4]={0};
- uint8_t gwtxt[30];
-
-
- mem_init(); //3?ê??ˉ?ˉì??ú′???
- memp_init(); //3?ê??ˉ?ú′?3?
-
- #ifdef USE_DHCP
- ipaddr.addr = 0;
- netmask.addr = 0;
- gw.addr = 0;
- #else
- IP4_ADDR(&ipaddr,IP_ADDR0,IP_ADDR1,IP_ADDR2,IP_ADDR3);
- IP4_ADDR(&netmask,NETMASK_ADDR0,NETMASK_ADDR1,NETMASK_ADDR2,NETMASK_ADDR3);
- IP4_ADDR(&gw,GW_ADDR0,GW_ADDR1,GW_ADDR2,GW_ADDR3);
- #endif /* USE_DHCP */
-
- netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, eernetif_init, eernet_input);
-
- /* Registers the default network interface. */
- netif_set_default(&gnetif);
-
- if (netif_is_link_up(&gnetif))
- {
- /* When the netif is fully configured this function must be called.*/
- netif_set_up(&gnetif);
- iptab[0] = IP_ADDR3;
- iptab[1] = IP_ADDR2;
- iptab[2] = IP_ADDR1;
- iptab[3] = IP_ADDR0;
-
- netmasktab[0]=NETMASK_ADDR3;
- netmasktab[1]=NETMASK_ADDR2;
- netmasktab[2]=NETMASK_ADDR1;
- netmasktab[3]=NETMASK_ADDR0;
-
- gwtab[0]=GW_ADDR3;
- gwtab[1]=GW_ADDR2;
- gwtab[2]=GW_ADDR1;
- gwtab[3]=GW_ADDR0;
- //
- sprintf((char*)iptxt, " %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);
-
- sprintf((char*)netmasktxt, "%d.%d.%d.%d",netmasktab[3],netmasktab[2],netmasktab[1],netmasktab[0]);
-
- sprintf((char*)gwtxt,"%d.%d.%d.%d",gwtab[3],gwtab[2],gwtab[1],gwtab[0]);
-
- //
- printf("rn");
- printf("rn");
- printf(" Network Cable is connected rn");
- printf(" This is lwip1.4.1-ping demo test rn");
- printf(" The STM32f769 ip address is: %srn",iptxt);
- printf("The stm32f769 netmask address is: %srn",netmasktxt);
- printf(" The stm32f769 gw address is: %srn",gwtxt);
- printf("rn");
- printf("rn");
- printf("rn");
- }
- else
- {
- /* When the netif link is down this function must be called */
- netif_set_down(&gnetif);
- printf(" Network Cable is not connected rn");
- }
- }
复制代码
完成后,实现网络数据的处理
- void LwIP_Pkt_Handle(void)
- {
- /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */
- ethernetif_input(&gnetif);
- }
- void LwIP_Periodic_Handle(__IO uint32_t localtime)
- {
- #if LWIP_TCP
- /* TCP periodic process every 250 ms */
- if (localtime - TCPTimer >= TCP_TMR_INTERVAL)
- {
- TCPTimer = localtime;
- tcp_tmr();
- }
- #endif
- etharp_tmr();
- }
复制代码
在main函数添加网路初始化,及数据处理
- Netif_Config();
-
- while(1)
- {
- if (ETH_GetReceivedFrame(&EthHandle)) //?ì2éê?·??óê?μ?êy?Y°ü
- {
- LwIP_Pkt_Handle(); //
- }
- /* handle periodic timers for LwIP */
- LwIP_Periodic_Handle(LocalTime);
- led_toggle();
- delay_ms(5000);
- }
复制代码
其他功能目前还在研究
|
评分
-
查看全部评分
|