我将在STM32f107RCT6和DP83848上设置STM32f107RCT6。我使用CubeMX生成主代码。使用命令ping和arp –a将代码下载到单片机后,结果是:
(MCU IP: 192.168.1.57 *子网: 255.255.255.0 * GW:192.168.1.1 ** MAC: 00-80-e1-00-00)
C:\Users\GmtK>ping 192.168.1.57
Pinging 192.168.1.57 with 32 bytes of data:
Reply from 192.168.1.11: Destination host unreachable.
Reply from 192.168.1.11: Destination host unreachable.
Reply from 192.168.1.11: Destination host unreachable.
Reply from 192.168.1.11: Destination host unreachable.
Ping statistics for 192.168.1.57:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
C:\Users\GmtK>arp -a
Interface: 192.168.1.11 --- 0x16
Internet Address Physical Address Type
192.168.1.1 74-da-da-64-6a-59 dynamic
192.168.1.7 2c-fd-a1-5c-3e-99 dynamic
192.168.1.255 ff-ff-ff-ff-ff-ff static
224.0.0.22 01-00-5e-00-00-16 static
224.0.0.251 01-00-5e-00-00-fb static
224.0.0.252 01-00-5e-00-00-fc static
239.255.255.250 01-00-5e-7f-ff-fa static
255.255.255.255 ff-ff-ff-ff-ff-ff static 然而,通过重新设置单片机,并再次使用arp –a
C:\Users\GmtK>arp -a
Interface: 192.168.1.11 --- 0x16
Internet Address Physical Address Type
192.168.1.1 74-da-da-64-6a-59 dynamic
192.168.1.7 2c-fd-a1-5c-3e-99 dynamic
192.168.1.57 00-80-e1-00-00-00 dynamic //this my MCU
192.168.1.255 ff-ff-ff-ff-ff-ff static
224.0.0.22 01-00-5e-00-00-16 static
224.0.0.251 01-00-5e-00-00-fb static
224.0.0.252 01-00-5e-00-00-fc static
239.255.255.250 01-00-5e-7f-ff-fa static
255.255.255.255 ff-ff-ff-ff-ff-ff static 这个循环是重复的,通过重置MCU,它返回到由arp -a命令提供的列表。我认为ping命令在某种程度上可以理解为什么它不能工作。因为它可能不是由lwIP实现的。所以我用Hercules TCP Client和
Madule IP = 192.168.1.57 and Port = 7 然后按Connect键。其结果是:
Connecting to 192.168.1.57 ...
TCP connection timeout我使用了两个LED来调试它,并且由于打开了RUNNING_LED,所以执行tcp_echoserver_init()。但是,AUX_LED从来没有打开过,这意味着tcp_echoserver_accept()回调函数永远不会被调用!有什么问题吗?为什么不叫呢?
这是我从ST回送服务器示例中采用的代码:
/**
* @brief Initializes the tcp echo server
* @param None
* @retval None
*/
void tcp_echoserver_init(void)
{
/* create new tcp pcb */
tcp_echoserver_pcb = tcp_new();
if (tcp_echoserver_pcb != NULL)
{
err_t err;
/* bind echo_pcb to port 7 (ECHO protocol) */
err = tcp_bind(tcp_echoserver_pcb, IP_ADDR_ANY, 7);
if (err == ERR_OK)
{
/* start tcp listening for echo_pcb */
tcp_echoserver_pcb = tcp_listen(tcp_echoserver_pcb);
/* initialize LwIP tcp_accept callback function */
tcp_accept(tcp_echoserver_pcb, tcp_echoserver_accept);
HAL_GPIO_WritePin(RUNNING_LED, 0); //RUNNING_LED Will be turned on here
}
else
{
/* deallocate the pcb */
memp_free(MEMP_TCP_PCB, tcp_echoserver_pcb);
}
}
}
/**
* @brief This function is the implementation of tcp_accept LwIP callback
* @param arg: not used
* @param newpcb: pointer on tcp_pcb struct for the newly created tcp connection
* @param err: not used
* @retval err_t: error status
*/
static err_t tcp_echoserver_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
{
HAL_GPIO_WritePin(AUx_LED, 0); //AUX_LED will be turned on here
err_t ret_err;
struct tcp_echoserver_struct *es;
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
/* set priority for the newly accepted tcp connection newpcb */
tcp_setprio(newpcb, TCP_PRIO_MIN);
/* allocate structure es to maintain tcp connection informations */
es = (struct tcp_echoserver_struct *)mem_malloc(sizeof(struct tcp_echoserver_struct));
if (es != NULL)
{
es->state = ES_ACCEPTED;
es->pcb = newpcb;
es->retries = 0;
es->p = NULL;
/* pass newly allocated es structure as argument to newpcb */
tcp_arg(newpcb, es);
/* initialize lwip tcp_recv callback function for newpcb */
tcp_recv(newpcb, tcp_echoserver_recv);
/* initialize lwip tcp_err callback function for newpcb */
tcp_err(newpcb, tcp_echoserver_error);
/* initialize lwip tcp_poll callback function for newpcb */
tcp_poll(newpcb, tcp_echoserver_poll, 0);
ret_err = ERR_OK;
}
else
{
/* close tcp connection */
tcp_echoserver_connection_close(newpcb, es);
/* return memory error */
ret_err = ERR_MEM;
}
return ret_err;
}发布于 2021-01-30 05:32:46
正如我在评论中提到的,Raw API实现在轮询模式下工作,因此您必须确保持续的软件轮询是否接收到新数据包。据我所知,我在无限循环体中将这两行代码添加到代码中:
while (1)
{
ethernetif_input(&gnetif);
sys_check_timeouts();
}有关更多细节,请阅读ST,UM1713提供的信息丰富的用户手册。
https://stackoverflow.com/questions/62444261
复制相似问题