这名比较叼 发表于 2016-12-20 17:09:47

STM32F429+LAN8720网口调试

第一次调网口相关的程序,相关文件太多,完全看不懂,那就先不管了,先把功能实现,在后面慢慢消化,买的是fire的F429系列的一个核心板,拿到了相关的程序源码,于是选择了一个UDP协议的程序,原程序里是通过按键控制udp的连接与断开,由于核心板里只有一个复位按键,于是将按键部分程序删掉,改成直接进入主循环后,直接开启udp连接,ip啥的都改好,ping通之后,下载程序,复位后通过串口打印情况发现出问题了,在连接udp函数里出现了“can not create udp pcb”,原因是由一个upcb变量不为零,其他的程序部分我也看不懂,请问论坛里面有大神指导什么原因吗?以下是main部分程序和udp连接部分程序:
int main(void)
{
      /* ³õʼ»¯µ÷ÊÔ´®¿Ú£¬Ò»°ãΪ´®¿Ú1 */
      Debug_USART_Config();
      
      /* ³õʼ»¯ÏµÍ³µÎ´ð¶¨Ê±Æ÷ */      
      SysTick_Init();
      
      TIM3_Config(999,899);//10ms¶¨Ê±Æ÷
      printf("LAN8720A Ethernet Demo\n");

      /* Configure ethernet (GPIOs, clocks, MAC, DMA) */
ETH_BSP_Config();      
printf("LAN8720A BSP INIT AND COMFIGURE SUCCESS\n");
      
/* Initilaize the LwIP stack */
LwIP_Init();      

printf("    KEY1: Æô¶¯UDPÁ¬½Ó\n");
printf("    KEY2: ¶Ï¿ªUDPÁ¬½Ó\n");

//IPµØÖ·ºÍ¶Ë¿Ú¿ÉÔÚnetconf.hÎļþÐ޸쬻òÕßʹÓÃDHCP·þÎñ×Ô¶¯»ñÈ¡IP(ÐèҪ·ÓÉÆ÷Ö§³Ö)
printf("±¾µØIPºÍ¶Ë¿Ú: %d.%d.%d.%d:%d\n",IP_ADDR0,IP_ADDR1,IP_ADDR2,IP_ADDR3,UDP_SERVER_PORT);
printf("Ô¶¶ËIPºÍ¶Ë¿Ú: %d.%d.%d.%d:%d\n",DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3,DEST_PORT);
      while(1)
      {

                        if (EthLinkStatus == 0)
                        {
                              printf("Connect to udp server\n");
                              /* Connect to udp server */
                              udp_echoclient_connect();
                        }

                        /* check if any packet received */
                        if (ETH_CheckFrameReceived())
                        {
                              /* process received ethernet packet */
                              LwIP_Pkt_Handle();
                        }
                        /* handle periodic timers for LwIP */
                        LwIP_Periodic_Handle(LocalTime);
      }
}

void udp_echoclient_connect(void)
{

struct pbuf *p;
struct ip_addr DestIPaddr;
err_t err;

/* Create a new UDP control block*/
upcb = udp_new();

if (upcb!=NULL)
{
    /*assign destination IP address */
    IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3 );

    /* configure destination IP address and port */
    err= udp_connect(upcb, &DestIPaddr, DEST_PORT);

    if (err == ERR_OK)
    {
      /* Set a receive callback for the upcb */
      udp_recv(upcb, udp_receive_callback, NULL);

      sprintf((char*)data, "sending udp client message %d\n",message_count);

      /* allocate pbuf from pool*/
      p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)data), PBUF_POOL);

      if (p != NULL)
      {
      /* copy data to pbuf */
      pbuf_take(p, (char*)data, strlen((char*)data));

      /* send udp data */
      udp_send(upcb, p);

      /* free pbuf */
      pbuf_free(p);
      }
      else
      {
      /* free the UDP connection, so we can accept new clients */
      udp_remove(upcb);
      #ifdef SERIAL_DEBUG
      printf("\n\r can not allocate pbuf ");
      #endif
      }
    }
    else
    {
      /* free the UDP connection, so we can accept new clients */
      udp_remove(upcb);
      #ifdef SERIAL_DEBUG
       printf("\n\r can not connect udp pcb");
      #endif
    }
}
else
{
    #ifdef SERIAL_DEBUG
   printf("\n\r can not create udp pcb");
    #endif
}
}




5265325 发表于 2016-12-21 10:02:41

:lol:lol:lol:lol

这名比较叼 发表于 2016-12-21 13:30:19

5265325 发表于 2016-12-21 10:02


大神,求指导:P

5265325 发表于 2016-12-23 08:40:41

:lol:lol:lol:lol

斜阳__ 发表于 2016-12-23 08:54:37

凑热闹         

damiaa 发表于 2016-12-23 09:34:32

:):):):):):):)

zero99 发表于 2017-1-11 10:00:11

部分乱码了

zhangxu56726 发表于 2017-1-11 10:31:53

裸奔,基本没人这么用了,建议直接上系统

无薪税绵 发表于 2017-3-10 08:21:35

楼主是使用了LwIP,应该是使用了DHCP吧。
你提供的程序是看不出问题的。
只有提供LWIP的 创建UDP 的那段程序才知道是什么问题。

估计是 DHCP 未能获取IP地址。因为DHCP是要经过适量的延时,才能获取到IP的。

boboo-23776 发表于 2017-3-10 10:28:37


凑热闹
页: [1] 2
查看完整版本: STM32F429+LAN8720网口调试