cancel
Showing results for 
Search instead for 
Did you mean: 

Cortex M4 with FreeRtos httpd hangs when opening page

MRaff.1
Associate III
Hello, 
     I am unable to make httpd server. I am working with the following platform:
 
CPU: STM32F407VET6 (Cortex-M4)
LAN PHY: LAN8720AI
SO: FREERTOS V10.3.1
 
I configured the LWIP and FreeRTOS using CubeMX tool.
The ping command works fine.
 
I defined in fsdata.c a very simple webpage, a sort of "hello world" html. 
 
I checked possible stack overflow and MallocFailed from freertos.
 
When I try to open the webpage I see from debugger that the TCP connection is set ESTABILISHED. But there is no packets sent from the board toward the client.
As soon as I try to open the webpage the whole LWIP stack stop working and also the ping fails until the next reboot.
 
I tried also to increase the MEMP_NUM_PBUF to 64 (from 16).
 
LwIP is initialized calling from DefaultTask():
MX_LWIP_Init()
 
The httpd server is initialized calling from DefaultTask():
httpd_init();
 
Enabling the LWIP_DEBUIG I cannot print everythink since the sprintf and the sent to UART is too slow, but enabling a message ring buffer I see something like this:
 
-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n0dd7c new 0x14 (0)\n chksum)\n)\nx0,
State: \030ù\002\b\003\n   |1056668|    6716   | (id, flags, offset)\nn, fl
TCP connection established 56644 -> 31422
http_accept 0x2000dd34 / 0\n-----+\n(src port, dest port[...]
tcp_receive: ACK for 536927516, unacked->seqno 6511:0\n
tcp_receive: removing 536927468:134412984 from pcb->036934304\n\0, flags (\00x0)\n\00x0)\n\0\0\0\075c)\n"
 
The size in tcp_receive is quite suspect. 
 
The last message I get seems to be "tcp_receive: removing 536927468 etc"
 
It looks a memory allocation issue but I can't figure the cause. 
 
 
Thank you
 
14 REPLIES 14

Hello @MRaff.1 ,

in the example that I sent and that I'm using the data is defined in the fsdata.c

STea_0-1727365110134.png

which I'm excluding from the build as you can see in the screenshot. make sure to use the same file in you project and follow the same process and update me with the status afterwords.
Regards 

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
MRaff.1
Associate III

Thank you STea,

I am trying to change your project settings to make it run on my board. 

I replaced F439 files changing :

- STM32F407VETX_FLASH.ld

- startup startup_stm32f407vetx

- SystemClockConfig()

- MX_GPIO_Init();

but it does not work. It hangs at the first instruction on the StartDefaultTask which is a HAL_GPIO_WritePin(). I suspect the systick is not cofigured properly but I don't find the point where I have to set it.

I don't know if continue to try this approach or try to port the http server part on my code. 

I see you used CMSIS_V2 while my project is configured with CMSIS_V1. Do you think this could make the diference?

 

I was able to make a page work in my previous test project. 

But I am not sure I have fixed the problem. The key change was to reduce the  _Min_Heap_Size and _Min_Stack_Size in the ld file. They were very high (0x4000 and 0x1000 respectively). 

This is a test project with only the webserver enabled. Now I try to port it on the main code. 

 

 

Hello STea,

     even if now I have an example working, when I port the webserver on the full-firmware I get always the same error and the webserver hangs on the netconn_write() function.

It seems a memory issue. Looking at the pointers they don't seems to use much of the ram_heap region with size MEM_SIZE. On the other hand the heap is allocated as in the example (40*1024) and I don't have more space available. 

Some suggestion?

Hello STea,

    taking freeRTos settings from your example make the webserver work. 

In particulare the #define configUSE_COUNTING_SEMAPHORES 1 

Here the settings I have added to FreeRTOSConfig.h

#define configUSE_COUNTING_SEMAPHORES            1

#define configTIMER_TASK_PRIORITY                ( 2 )
#define configTIMER_QUEUE_LENGTH                 10
#define configTIMER_TASK_STACK_DEPTH             600

 Thank you!