Skip to main content
Visitor II
November 8, 2022
Solved

STM32F107+LWIP(2.0.3)+freeRTOS not work

  • November 8, 2022
  • 10 replies
  • 5350 views

i use STM32F107+LWIP(2.0.3)+freeRTOS

I wrote the program with the help of the following document :

https://www.st.com/resource/en/user_manual/um1713-developing-applications-on-stm32cube-with-lwip-tcpip-stack-stmicroelectronics.pdf

After connecting the computer with the micro a few times, the information is correctly received by the micro.

But I don't send a reply to the computer. The tcp_server_recv callback function only turns one LED on and off for one second.

After sending information a few times, it stops receiving and I don't have ping anymore.

What advice can you give?

    This topic has been closed for replies.
    Best answer by Piranha

    You have to be kidding... You are not freeing the PBUF! All examples, including the one from ST, does free the PBUF. And as LCE said, you have to close your the connection, when the other end closes it.

    static err_t TCPRecv_(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
    {
    	if (!p) {
    		tcp_close(tpcb);
    		return ERR_OK;
    	}
     
    	// Process the received data
     
    	tcp_recved(tpcb, p->tot_len);
    	pbuf_free(p);
    	return ERR_OK;
    }

    Read the documentation and this:

    https://lwip.fandom.com/wiki/Raw/TCP

    Also, when using the lwIP core API with RTOS, the lwIP core locking must be used. You can find more information and examples in the following topic:

    https://community.st.com/s/question/0D53W00001sGiChSAK/cubemx-lwip-ethernetlinkthread-bug

    10 replies

    HKabi.1Author
    Visitor II
    November 9, 2022

    My receive callback is :

    static err_t tcp_server_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,err_t err) {
     
    	if (p != NULL){
     
     tcp_recved(tpcb,p->tot_len);
     
     HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
     
     osDelay(1000);
     
     HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
     
    	}
     
    	return ERR_OK;
     
    }

    Many times the receive callback function is executed twice.

    It stops after a few pings.

    The result can be seen in the photo.

    0693W00000WHs3pQAD.png 

    This device works well with another program written with lwip-1.3.1 and Kiel.

    Graduate II
    November 9, 2022

    So you don't handle pbuf == NULL, or err != ERR_OK.

    Check some examples and why that might be necessary (e.g., closing connection).

    HKabi.1Author
    Visitor II
    November 9, 2022

    pbuf is structure and define p

    struct pbuf *p (line 1 break)

    I added the error check but it didn't make any difference

    static err_t tcp_server_recv(void *arg,struct tcp_pcb *tpcb,struct pbuf *p, err_t err) {
    	if ((p != NULL) && (err==ERR_OK)){
    	 tcp_recved(tpcb,p->tot_len);
    	 Beep();
    	}
    	return ERR_OK;
    }

    i can not test my program with keil becuse when i export to keil and comple get this err :

    ../Middlewares/Third_Party/FreeRTOS/Source/include/FreeRTOS.h(71): error: #5: cannot open source input file "reent.h": No such file or directory 

    HKabi.1Author
    Visitor II
    November 15, 2022

    I created the project without FreeRTOS but the problem still exists and it crashes after receiving the network a few times.

    HKabi.1Author
    Visitor II
    November 15, 2022

    Has anyone used lwip and tcpserver in cube?

    I have a very hard problem with this on my stm32f107vct6 micro and no one can help.

    I used Cube's LWIP TCP ECHO SERVER example in stm32f107, but the same problem exists.

    I think this problem is from ST side. @st

    Graduate II
    November 15, 2022

    I started with the Cube stuff and the HAL ethernet drivers with a STM32F767.

    I had a HTTP server (http is based on TCP) up quite quickly, TCP echo working too.

    The problems were rather on my lwIP's "opt.h" side, and the HAL ethernet drivers.

    It was not "plug and play".

    Check your code, use the CubeIDE debugging tools and work through it.

    If you want to use STM32 and lwIP for some serious stuff = work / job, then you have to understand more than using CubeMX.

    HKabi.1Author
    Visitor II
    November 15, 2022

    I use the CubeIDE debugger. No errors or exceptions occur, only the ping is interrupted and the network connection is interrupted. But the main loop is still running.

    This happens almost after sending 8 data packets.

    PiranhaAnswer
    Graduate II
    November 27, 2022

    You have to be kidding... You are not freeing the PBUF! All examples, including the one from ST, does free the PBUF. And as LCE said, you have to close your the connection, when the other end closes it.

    static err_t TCPRecv_(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
    {
    	if (!p) {
    		tcp_close(tpcb);
    		return ERR_OK;
    	}
     
    	// Process the received data
     
    	tcp_recved(tpcb, p->tot_len);
    	pbuf_free(p);
    	return ERR_OK;
    }

    Read the documentation and this:

    https://lwip.fandom.com/wiki/Raw/TCP

    Also, when using the lwIP core API with RTOS, the lwIP core locking must be used. You can find more information and examples in the following topic:

    https://community.st.com/s/question/0D53W00001sGiChSAK/cubemx-lwip-ethernetlinkthread-bug

    Visitor II
    March 3, 2024

    Does anyone know what is causing this error and how to fix it in STMCubeIDE?

     

    spoatech_0-1709480785790.png

     

    Thanks!

     

    Explorer
    March 21, 2024

    @spoatech 

    GO to freeRTOS-> Advanced Settings and Enable USE_NEWLIB_REENTRANT

    srdas_0-1711028897728.png

    This will fix the issue

     

    Visitor II
    March 22, 2024

    @srdas,

    Thanks for your reply. However, I already had this setting in FreeRTOS (Enable USE_NEWLIB_REENTRANT) and it was not the solution. A representative from ST helped out with this and the picture below explains the proper setup. The setting below in LWIP General Settings, must be set to "1" and this fixed the problem.

     

    LWIP_FreeRTOS.png

    Explorer
    March 25, 2024

    @spoatechThanks for the Update.

    I'd like to like to know if you can ping the STM32F107. If possible, I'd appreciate guidance on configuring it for Ethernet functionality. In my case, I'm unable to ping the STM32F107 when using FreeRTOS and LWIP together, but I can ping it when using LWIP alone without FreeRTOS.

    Hardware used : HAOYU Electronics STM107 Board

    IDE: STMCubeIDE