From afd90d357ca8c44459099280597bbf5f862a09ad Mon Sep 17 00:00:00 2001 From: xiao Date: Wed, 22 Apr 2026 23:59:19 +0800 Subject: [PATCH] fix: add bounded lwip connect waits and link status helper --- Drivers/LwIP/src/api/api_msg.c | 8 +- Drivers/LwIP/src/include/netif/ethernetif.h | 1 + Drivers/LwIP/src/netif/ethernetif.c | 11 +- Drivers/LwIP/src/netif/ethernetif.h | 6 + MDK-ARM/TCP2UART.uvoptx | 1381 ------------------- MDK-ARM/build_capture.txt | 8 - 6 files changed, 23 insertions(+), 1392 deletions(-) delete mode 100644 MDK-ARM/TCP2UART.uvoptx delete mode 100644 MDK-ARM/build_capture.txt diff --git a/Drivers/LwIP/src/api/api_msg.c b/Drivers/LwIP/src/api/api_msg.c index 8092be9..bc0ddab 100644 --- a/Drivers/LwIP/src/api/api_msg.c +++ b/Drivers/LwIP/src/api/api_msg.c @@ -1395,7 +1395,13 @@ lwip_netconn_do_connect(void *m) #if LWIP_TCPIP_CORE_LOCKING LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT); UNLOCK_TCPIP_CORE(); - sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); + if (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), msg->conn->recv_timeout) == SYS_ARCH_TIMEOUT) { + if (msg->conn->state == NETCONN_CONNECT) { + msg->conn->current_msg = NULL; + msg->conn->state = NETCONN_NONE; + msg->err = ERR_TIMEOUT; + } + } LOCK_TCPIP_CORE(); LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT); #endif /* LWIP_TCPIP_CORE_LOCKING */ diff --git a/Drivers/LwIP/src/include/netif/ethernetif.h b/Drivers/LwIP/src/include/netif/ethernetif.h index 8350495..aec39e2 100644 --- a/Drivers/LwIP/src/include/netif/ethernetif.h +++ b/Drivers/LwIP/src/include/netif/ethernetif.h @@ -24,6 +24,7 @@ err_t ethernetif_init(struct netif *netif); void ethernetif_input(struct netif *netif); void lwip_netif_init(const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw); void ethernetif_check_link(void); +uint8_t ethernetif_link_is_up(void); void ethernetif_poll(void); void print_netif(struct netif *netif); diff --git a/Drivers/LwIP/src/netif/ethernetif.c b/Drivers/LwIP/src/netif/ethernetif.c index fd1d4b2..7f49391 100644 --- a/Drivers/LwIP/src/netif/ethernetif.c +++ b/Drivers/LwIP/src/netif/ethernetif.c @@ -457,6 +457,8 @@ void ethernetif_diag_poll_status(void) */ static void ethernetif_update_link(uint8_t link_status) { + LOCK_TCPIP_CORE(); + if (link_status) { if (!netif_is_link_up(&ch390_netif)) @@ -464,9 +466,7 @@ static void ethernetif_update_link(uint8_t link_status) netif_set_link_up(&ch390_netif); if ((s_garp_sent == 0u) && netif_is_up(&ch390_netif)) { - LOCK_TCPIP_CORE(); etharp_gratuitous(&ch390_netif); - UNLOCK_TCPIP_CORE(); s_garp_sent = 1u; } } @@ -479,6 +479,8 @@ static void ethernetif_update_link(uint8_t link_status) s_garp_sent = 0u; } } + + UNLOCK_TCPIP_CORE(); } /** @@ -561,3 +563,8 @@ void ethernetif_check_link(void) ethernetif_update_link(link_status); } + +uint8_t ethernetif_link_is_up(void) +{ + return netif_is_link_up(&ch390_netif) ? 1u : 0u; +} diff --git a/Drivers/LwIP/src/netif/ethernetif.h b/Drivers/LwIP/src/netif/ethernetif.h index b806184..0886a49 100644 --- a/Drivers/LwIP/src/netif/ethernetif.h +++ b/Drivers/LwIP/src/netif/ethernetif.h @@ -63,6 +63,12 @@ void ethernetif_diag_poll_status(void); */ void ethernetif_check_link(void); +/** + * @brief Query whether physical Ethernet link is currently up + * @return 1 if link is up, 0 otherwise + */ +uint8_t ethernetif_link_is_up(void); + /** * @brief Process all pending RX packets * @note Call this from the LwIP task when RX interrupt occurs diff --git a/MDK-ARM/TCP2UART.uvoptx b/MDK-ARM/TCP2UART.uvoptx deleted file mode 100644 index d212b2e..0000000 --- a/MDK-ARM/TCP2UART.uvoptx +++ /dev/null @@ -1,1381 +0,0 @@ - - - - 1.0 - -
### uVision Project, (C) Keil Software
- - - *.c - *.s*; *.src; *.a* - *.obj; *.o - *.lib - *.txt; *.h; *.inc; *.md - *.plm - *.cpp - 0 - - - - 0 - 0 - - - - TCP2UART - 0x4 - ARM-ADS - - 8000000 - - 1 - 1 - 0 - 1 - 0 - - - 1 - 65535 - 0 - 0 - 0 - - - 79 - 66 - 8 - .\TCP2UART\ - - - 1 - 1 - 1 - 0 - 1 - 1 - 0 - 1 - 0 - 0 - 0 - 0 - - - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - - - 1 - 0 - 1 - - 18 - - 0 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 0 - 0 - 1 - 0 - 0 - 3 - - - - - - - - - - - BIN\CMSIS_AGDI.dll - - - - 0 - ARMRTXEVENTFLAGS - -L70 -Z18 -C0 -M0 -T1 - - - 0 - DLGTARM - (1010=-1,-1,-1,-1,0)(1007=-1,-1,-1,-1,0)(1008=-1,-1,-1,-1,0)(1009=-1,-1,-1,-1,0) - - - 0 - ARMDBGFLAGS - - - - 0 - DLGUARM - - - - 0 - CMSIS_AGDI - -X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103R8$Flash\STM32F10x_128.FLM) - - - 0 - UL2CM3 - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32F10x_128 -FL020000 -FS08000000 -FP0($$Device:STM32F103R8$Flash\STM32F10x_128.FLM) - - - 0 - ST-LINKIII-KEIL_SWO - UL2CM3(-S0 -C0 -P0 ) -FN1 -FC1000 -FD20000000 -FF0STM32F10x_128 -FL020000 -FS08000000 -FP0($$Device:STM32F103R8$Flash\STM32F10x_128.FLM) - - - - - 0 - - - 0 - 1 - 1 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - - - - 0 - 0 - 0 - - - - - - - - - - 1 - 0 - 0 - 2 - 10000000 - - - - - - Application/MDK-ARM - 0 - 0 - 0 - 0 - - 1 - 1 - 2 - 0 - 0 - 0 - startup_stm32f103xe.s - startup_stm32f103xe.s - 0 - 0 - - - - - Application/User/Core - 0 - 0 - 0 - 0 - - 2 - 2 - 1 - 0 - 0 - 0 - ../Core/Src/main.c - main.c - 0 - 0 - - - 2 - 3 - 1 - 0 - 0 - 0 - ../Core/Src/gpio.c - gpio.c - 0 - 0 - - - 2 - 4 - 1 - 0 - 0 - 0 - ../Core/Src/freertos.c - freertos.c - 0 - 0 - - - 2 - 5 - 1 - 0 - 0 - 0 - ../Core/Src/dma.c - dma.c - 0 - 0 - - - 2 - 6 - 1 - 0 - 0 - 0 - ../Core/Src/iwdg.c - iwdg.c - 0 - 0 - - - 2 - 7 - 1 - 0 - 0 - 0 - ../Core/Src/spi.c - spi.c - 0 - 0 - - - 2 - 8 - 1 - 0 - 0 - 0 - ../Core/Src/usart.c - usart.c - 0 - 0 - - - 2 - 9 - 1 - 0 - 0 - 0 - ../Core/Src/stm32f1xx_it.c - stm32f1xx_it.c - 0 - 0 - - - 2 - 10 - 1 - 0 - 0 - 0 - ../Core/Src/stm32f1xx_hal_timebase_tim.c - stm32f1xx_hal_timebase_tim.c - 0 - 0 - - - 2 - 11 - 1 - 0 - 0 - 0 - ../Core/Src/stm32f1xx_hal_msp.c - stm32f1xx_hal_msp.c - 0 - 0 - - - 2 - 12 - 1 - 0 - 0 - 0 - ../Core/Src/debug_log.c - debug_log.c - 0 - 0 - - - 2 - 13 - 1 - 0 - 0 - 0 - ../Core/Src/retarget_rtt.c - retarget_rtt.c - 0 - 0 - - - - - Drivers/STM32F1xx_HAL_Driver - 0 - 0 - 0 - 0 - - 3 - 14 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c - stm32f1xx_hal_gpio_ex.c - 0 - 0 - - - 3 - 15 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c - stm32f1xx_hal.c - 0 - 0 - - - 3 - 16 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c - stm32f1xx_hal_rcc.c - 0 - 0 - - - 3 - 17 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c - stm32f1xx_hal_rcc_ex.c - 0 - 0 - - - 3 - 18 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c - stm32f1xx_hal_gpio.c - 0 - 0 - - - 3 - 19 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c - stm32f1xx_hal_dma.c - 0 - 0 - - - 3 - 20 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c - stm32f1xx_hal_cortex.c - 0 - 0 - - - 3 - 21 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c - stm32f1xx_hal_pwr.c - 0 - 0 - - - 3 - 22 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c - stm32f1xx_hal_flash.c - 0 - 0 - - - 3 - 23 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c - stm32f1xx_hal_flash_ex.c - 0 - 0 - - - 3 - 24 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c - stm32f1xx_hal_exti.c - 0 - 0 - - - 3 - 25 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_iwdg.c - stm32f1xx_hal_iwdg.c - 0 - 0 - - - 3 - 26 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c - stm32f1xx_hal_spi.c - 0 - 0 - - - 3 - 27 - 1 - 0 - 0 - 0 - ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c - stm32f1xx_hal_uart.c - 0 - 0 - - - - - Drivers/CMSIS - 0 - 0 - 0 - 0 - - 4 - 28 - 1 - 0 - 0 - 0 - ../Core/Src/system_stm32f1xx.c - system_stm32f1xx.c - 0 - 0 - - - - - Middlewares/FreeRTOS - 0 - 0 - 0 - 0 - - 5 - 29 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/croutine.c - croutine.c - 0 - 0 - - - 5 - 30 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/event_groups.c - event_groups.c - 0 - 0 - - - 5 - 31 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/list.c - list.c - 0 - 0 - - - 5 - 32 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/queue.c - queue.c - 0 - 0 - - - 5 - 33 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c - stream_buffer.c - 0 - 0 - - - 5 - 34 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/tasks.c - tasks.c - 0 - 0 - - - 5 - 35 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/timers.c - timers.c - 0 - 0 - - - 5 - 36 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c - cmsis_os2.c - 0 - 0 - - - 5 - 37 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c - heap_4.c - 0 - 0 - - - 5 - 38 - 1 - 0 - 0 - 0 - ../Middlewares/Third_Party/FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c - port.c - 0 - 0 - - - - - Drivers/CH390 - 0 - 0 - 0 - 0 - - 6 - 39 - 1 - 0 - 0 - 0 - ..\Drivers\CH390\CH390.c - CH390.c - 0 - 0 - - - 6 - 40 - 1 - 0 - 0 - 0 - ..\Drivers\CH390\CH390_Interface.c - CH390_Interface.c - 0 - 0 - - - - - Drivers/LwIP/core - 0 - 0 - 0 - 0 - - 7 - 41 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\altcp.c - altcp.c - 0 - 0 - - - 7 - 42 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\altcp_alloc.c - altcp_alloc.c - 0 - 0 - - - 7 - 43 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\altcp_tcp.c - altcp_tcp.c - 0 - 0 - - - 7 - 44 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\def.c - def.c - 0 - 0 - - - 7 - 45 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\dns.c - dns.c - 0 - 0 - - - 7 - 46 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\inet_chksum.c - inet_chksum.c - 0 - 0 - - - 7 - 47 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\init.c - init.c - 0 - 0 - - - 7 - 48 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ip.c - ip.c - 0 - 0 - - - 7 - 49 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\mem.c - mem.c - 0 - 0 - - - 7 - 50 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\memp.c - memp.c - 0 - 0 - - - 7 - 51 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\netif.c - netif.c - 0 - 0 - - - 7 - 52 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\pbuf.c - pbuf.c - 0 - 0 - - - 7 - 53 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\raw.c - raw.c - 0 - 0 - - - 7 - 54 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\stats.c - stats.c - 0 - 0 - - - 7 - 55 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\sys.c - sys.c - 0 - 0 - - - 7 - 56 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\tcp.c - tcp.c - 0 - 0 - - - 7 - 57 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\tcp_in.c - tcp_in.c - 0 - 0 - - - 7 - 58 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\tcp_out.c - tcp_out.c - 0 - 0 - - - 7 - 59 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\timeouts.c - timeouts.c - 0 - 0 - - - 7 - 60 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\udp.c - udp.c - 0 - 0 - - - 7 - 61 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\acd.c - acd.c - 0 - 0 - - - 7 - 62 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\autoip.c - autoip.c - 0 - 0 - - - 7 - 63 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\dhcp.c - dhcp.c - 0 - 0 - - - 7 - 64 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\etharp.c - etharp.c - 0 - 0 - - - 7 - 65 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\icmp.c - icmp.c - 0 - 0 - - - 7 - 66 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\igmp.c - igmp.c - 0 - 0 - - - 7 - 67 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\ip4.c - ip4.c - 0 - 0 - - - 7 - 68 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\ip4_addr.c - ip4_addr.c - 0 - 0 - - - 7 - 69 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\core\ipv4\ip4_frag.c - ip4_frag.c - 0 - 0 - - - - - Drivers/LwIP/api - 0 - 0 - 0 - 0 - - 8 - 70 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\api_lib.c - api_lib.c - 0 - 0 - - - 8 - 71 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\api_msg.c - api_msg.c - 0 - 0 - - - 8 - 72 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\err.c - err.c - 0 - 0 - - - 8 - 73 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\if_api.c - if_api.c - 0 - 0 - - - 8 - 74 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\netbuf.c - netbuf.c - 0 - 0 - - - 8 - 75 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\netdb.c - netdb.c - 0 - 0 - - - 8 - 76 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\netifapi.c - netifapi.c - 0 - 0 - - - 8 - 77 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\sockets.c - sockets.c - 0 - 0 - - - 8 - 78 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\api\tcpip.c - tcpip.c - 0 - 0 - - - - - Drivers/LwIP/netif - 0 - 0 - 0 - 0 - - 9 - 79 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\netif\ethernet.c - ethernet.c - 0 - 0 - - - 9 - 80 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\src\netif\ethernetif.c - ethernetif.c - 0 - 0 - - - - - Drivers/LwIP/port - 0 - 0 - 0 - 0 - - 10 - 81 - 1 - 0 - 0 - 0 - ..\Drivers\LwIP\port\sys_arch.c - sys_arch.c - 0 - 0 - - - - - Drivers/SEGGER_RTT - 0 - 0 - 0 - 0 - - 11 - 82 - 1 - 0 - 0 - 0 - ..\Drivers\SEGGER\RTT\SEGGER_RTT.c - SEGGER_RTT.c - 0 - 0 - - - - - APP - 0 - 0 - 0 - 0 - - 12 - 83 - 1 - 0 - 0 - 0 - ..\App\config.c - config.c - 0 - 0 - - - 12 - 84 - 1 - 0 - 0 - 0 - ..\App\flash_param.c - flash_param.c - 0 - 0 - - - 12 - 85 - 1 - 0 - 0 - 0 - ..\App\route_msg.c - route_msg.c - 0 - 0 - - - 12 - 86 - 1 - 0 - 0 - 0 - ..\App\task_net_poll.c - task_net_poll.c - 0 - 0 - - - 12 - 87 - 1 - 0 - 0 - 0 - ..\App\tcp_client.c - tcp_client.c - 0 - 0 - - - 12 - 88 - 1 - 0 - 0 - 0 - ..\App\tcp_server.c - tcp_server.c - 0 - 0 - - - 12 - 89 - 1 - 0 - 0 - 0 - ..\App\uart_trans.c - uart_trans.c - 0 - 0 - - - - - ::CMSIS - 0 - 0 - 0 - 1 - - -
diff --git a/MDK-ARM/build_capture.txt b/MDK-ARM/build_capture.txt deleted file mode 100644 index aee44fa..0000000 --- a/MDK-ARM/build_capture.txt +++ /dev/null @@ -1,8 +0,0 @@ -*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' -Build target 'TCP2UART' -compiling tcp_client.c... -linking... -Program Size: Code=84560 RO-data=2496 RW-data=432 ZI-data=47056 -FromELF: creating hex file... -"TCP2UART\TCP2UART.axf" - 0 Error(s), 0 Warning(s). -Build Time Elapsed: 00:00:01