cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 + FreeRTOS: Newlib (sprintf) functions work only on every alternate task and it fails in rest of the tasks

Dhanyakumar Hosamane
Associate II

Hello Members

I am facing an issue while using standard library functions such as sprintf() on STM32H7 & Free RTOS platform (newlib)

IDE- Atollic true studio 9.3.0

RTOS: Free RTOS + heap_5

Controller : STM32H743XX

I have configured FreeRTOS to enable newlib re-entrant functionality (configUSE_NEWLIB_REENTRANT == 1) and configured atollic true studio project setting to use newlib standard library. I have created 8 tasks one after another with each stack size set to 2048. Only simple sprintf functionality is executed in all tasks.

Task code

void Task1(void const * argument)

{

  volatile float TestVar = 2.5;

  volatile char TestBuffer[25];

  while(1)

  {

     memset(TestBuffer, 0x00, sizeof(TestBuffer));

     sprintf(TestBuffer, "%6.2f", TestVar);

     osDelay(1000);

  }

}

Issue

sprintf functionality with float option works on every alternate task. other tasks it simply fails and formatted TestBuffer shows 0 instead of "2.5"

I am not sure where it's going wrong? and why this issue appears only on alternate tasks

I appreciate your comment or suggestions?

regards

Dhanya

5 REPLIES 5
Nikita91
Lead II

standard printf use malloc. Do you have a fonctionnal malloc and sbrk in syscall.c (or other specific dynamic allocation from FreeRTOS) ?

Dhanyakumar Hosamane
Associate II

Hi Nikita

Thank you for your quick response.

Yes, malloc and sbrk functions calls are functional. Functionality works in 4 out of 8 tasks. (same code running in all tasks and stack size (2048) and priority is also same for all tasks

Regards

Dhanya

TOlli
Senior

Hi TOlli

Thank you for your response.

Yes, I did. I followed Dave Nadler's instructions step by step by creating a new test project but I don't see any difference in the result

I am using the STM32H743XX controller which has non-continuous on-chip SRAM, so I must use heap_5 (which supports non-continuous blocks) to fulfill my project requirements.

By looking at heap_5 source code, I believe pvPortMalloc() & vPortFree() functions are thread-safe. I know newlib library functions use standard malloc() & free() functions. so I tired to make sure _sbrk(), __malloc_lock() and __malloc_unlock() functions are thread safe (as suggested by Dave Nadler)

Regards

Dhanya

I also followed Dave's instructions with STM32CubeIDE 1.5.1 for STM32F405RG and no luck. sprintf ("%f", f) causes hardfault