cancel
Showing results for 
Search instead for 
Did you mean: 

default application examples of the netconn and socket server because of the random selection of the udp/tcp port

MThom.16
Associate

Hello,

the default application examples of the netconn and socket server based on lwip doens't 

work because the udp and tcp port which are selected randomly (LWIP_RAND() ) could be ouside the autorized ranges (UDP_ENSURE_LOCAL_PORT_RANGE)

hw id: nucleoH723G

fm version :STM32Cube_FW_H7_V1.9.0

app id : LwIP_HTTP_Server_Socket_RTOS & LwIP_HTTP_Server_Netconn_RTOS

The comment of the line #define LWIP_RAND() ((u32_t)rand()) fixes the issue.

/* Define random number generator function */

//#define LWIP_RAND() ((u32_t)rand())

2 REPLIES 2
toroid
Associate III

Very strangely this also happened to my own application after upgrade to CubeIDE to 1.6.1. I had never before had to comment out #define LWIP_RAND() ((u32_t)rand()) for my application to work. But now yes. Thanks for the tip, it solved my boot issue.

Piranha
Chief II

As the name suggests UDP_ENSURE_LOCAL_PORT_RANGE() and other similar macros ensures that the port number is correct regardless of value returned by LWIP_RAND(). The real problems are from calling rand() without a proper initialization and support code.

https://community.st.com/s/question/0D53W00000A34Tg/stm32g071-problem-with-rand-and-random-functions-always-returning-0-in-a-freertos-thread-but-ok-in-main

https://nadler.com/embedded/newlibAndFreeRTOS.html