cancel
Showing results for 
Search instead for 
Did you mean: 

Assistance Needed with FreeRTOS Application on STM32F407VET6 + LWIP Task Management

ATPL
Associate II

 

Dear Team,

I am using an STM32F407VET6 controller with STM32CubeIDE and FreeRTOS. I’m encountering a problem with thread management in my application. Please find below an overview of my setup:

  • Mutex: Used for UART communication.
  • osTimer: Configured to generate a 1-millisecond periodic interrupt, primarily used to check received frames from the serial/UART. Once a complete frame is received, the data is placed into uartQue.
  • Message Queues:
    • One for UART communication (uartQue) with a message count of 2.
    • One for TCP communication (tcp_messageQue) with a message count of 16.
  • Tasks:
    • http_task: Used for configuring UART settings.
    • tcp_task: Retrieves data from the TCP/IP socket and places it into tcp_messageQue.
    • serial_task: Gets data from tcp_messageQue and sends it over UART. It also retrieves data from uartQue and sends it over the TCP/IP socket.

All tasks are currently running at the same priority (osPriorityNormal). the stack size for all task is 4096  

The http_task works fine when accessing the webpage. However, when I try to connect to my device via TCP( accessing the tcp_task), the issue arises and not able to access tcp_task, the issue arises. Attempting to establish a TCP connection consistently results in a "TCP connection failed" error. After repeated attempts, the device stops responding altogether.

I have been monitoring the ping response on the terminal window during this scenario, and the device fails to respond to pings when the issue occurs.

If I reset the device and connect a TCP client before opening the webpage, the tcp_task works fine. However, if I then try to access the webpage, the TCP client communication fails, and after several failures, the device stops responding altogether.

Only one task (http_task or tcp_task) can run properly at a time, but I need both tasks to function simultaneously.

If anyone has any insights or suggestions on how to resolve this issue, I would greatly appreciate your help. Your feedback would be invaluable to me.

Thank you.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @ASEHST  

Thank you for your valuable input. I already did that, but unfortunately, it didn't resolve the issue in my application.

I’d like to share how I ultimately solved the problem, which might be helpful for others facing a similar issue:

  • Assign different priorities to tasks.
  • Ensure every task has sufficient stack size.

In my case, the http_task had a smaller stack size than required, so I increased the stack size, and this resolved the issue in my application.

How I Handled This:

  1. Go to your application's .ioc file, or you can set it in FreeRTOSConfig.h.
  2. Navigate to FREERTOS Configuration -> Config Parameter -> Hook function related definitions.
  3. Find CHECK_FOR_STACK_OVERFLOW and set it to Option 2.
  4. Enable USE_MALLOC_FAILED_HOOK to help detect heap-related issues during memory allocation for incoming client sockets.

When a stack overflows, the void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); function is called, allowing you to check which task's stack overflowed.

When malloc fails, the void vApplicationMallocFailedHook(void); function is triggered.

By following these steps, I was able to solve my application's problem.

 

View solution in original post

2 REPLIES 2
ASEHST
ST Employee

Hello @ATPL,

The issue appears to be related to task management and synchronization. Using the same priority for all tasks in FreeRTOS can lead to conflicts and deadlocks, as multiple tasks may try to access the same resources simultaneously, disrupting system operation.

It is recommended to assign different priorities to your tasks based on their criticality. For example, assign a high priority to tcp_task to ensure smooth management of TCP/IP communication, while http_task and serial_task can retain a normal priority.

 

With Regards,

If your question is answered, please close this topic by clicking "Accept as Solution".

Hello @ASEHST  

Thank you for your valuable input. I already did that, but unfortunately, it didn't resolve the issue in my application.

I’d like to share how I ultimately solved the problem, which might be helpful for others facing a similar issue:

  • Assign different priorities to tasks.
  • Ensure every task has sufficient stack size.

In my case, the http_task had a smaller stack size than required, so I increased the stack size, and this resolved the issue in my application.

How I Handled This:

  1. Go to your application's .ioc file, or you can set it in FreeRTOSConfig.h.
  2. Navigate to FREERTOS Configuration -> Config Parameter -> Hook function related definitions.
  3. Find CHECK_FOR_STACK_OVERFLOW and set it to Option 2.
  4. Enable USE_MALLOC_FAILED_HOOK to help detect heap-related issues during memory allocation for incoming client sockets.

When a stack overflows, the void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName); function is called, allowing you to check which task's stack overflowed.

When malloc fails, the void vApplicationMallocFailedHook(void); function is triggered.

By following these steps, I was able to solve my application's problem.