Skip to main content
Visitor II
March 21, 2021
Question

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

  • March 21, 2021
  • 2 replies
  • 940 views

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())

    This topic has been closed for replies.

    2 replies

    Explorer II
    June 17, 2021

    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.

    Graduate II
    June 20, 2021

    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