Skip to main content
Neel
Associate II
July 31, 2020
Solved

FreeRTOs stuck at vsprintf

  • July 31, 2020
  • 5 replies
  • 2918 views

Hi,

I have used STM32l562-edk evk hardware and stm32cubeide for software. I have enable freertos in the project. For debug print message purpose I have created one function named as logPrint.

char g_msg_buf[100];

void logPrint(const char *format, ...)

{

int DataIdx = 0;

int len = 0;

va_list args;

va_start(args, format);

vsprintf(g_msg_buf,format, args);

len = strlen(g_msg_buf);

for (DataIdx = 0; DataIdx < len; DataIdx++) {

ITM_SendChar( g_msg_buf[DataIdx] );

}

va_end (args);

}

When I have run the program and invoke the logPrint function at that time OS stuck at vsprintf.

Observation:

  1. When I have disable the freeRTOS then function is working properly and i get the data on console.
  2. When I have enable the freeRTOS then OS stuck at vsprintf.

Please help me to figure out this issue.

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

1st check that the stack size of the task(s) using printf-family functions is large enough. They need a lot more than the minimal stack size often used at the beginning for whatever reason. Try e.g.. 2k and tailor it later.

Also there are FreeRTOS config items to enable stack checks and asserts. Enable them all while developing/ debugging.

5 replies

prain
Visitor II
July 31, 2020

printf family of functions are not thread safe (specially gcc implementation). use a thread safe printf library like this:

https://github.com/mpaland/printf

Nikita91
Lead II
July 31, 2020

Common problem, I think. Check your configuration with:

http://www.nadler.com/embedded/newlibAndFreeRTOS.html

hs2
hs2Best answer
Visitor II
July 31, 2020

1st check that the stack size of the task(s) using printf-family functions is large enough. They need a lot more than the minimal stack size often used at the beginning for whatever reason. Try e.g.. 2k and tailor it later.

Also there are FreeRTOS config items to enable stack checks and asserts. Enable them all while developing/ debugging.

hs2
Visitor II
July 31, 2020

There is a also a doc provided by STM which could be helpful:

Developing applications on STM32Cube with RTOS

and note that FreeRTOS Support by CubeIDE v1.4.0 is broken. Maybe use CubeIDE v1.3.0 instead.

Pavel A.
Super User
July 31, 2020

> and note that FreeRTOS Support by CubeIDE v1.4.0 is broken

Any details or reference, please?

-- pa

hs2
Visitor II
August 1, 2020

It‘s already reported and confirmed by ST here. It‘s messing up the interrupt prios.

Neel
NeelAuthor
Associate II
August 4, 2020

Hi All,

Thank you for your quick reply.

Issue is resolved.