2020-05-12 12:12 AM
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
2020-05-12 04:57 AM
standard printf use malloc. Do you have a fonctionnal malloc and sbrk in syscall.c (or other specific dynamic allocation from FreeRTOS) ?
2020-05-12 05:26 AM
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
2020-05-13 10:28 PM
Hi,
Are you by any chance familiar with this:
http://www.nadler.com/embedded/newlibAndFreeRTOS.html
There are also numerous posts here on the official forum:
From Dave Nadler:
https://community.st.com/s/question/0D50X0000BB1eL7SQJ/bug-cubemx-freertos-projects-corrupt-memory
Best regards.
2020-05-14 09:52 PM
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
2021-02-02 03:10 AM
I also followed Dave's instructions with STM32CubeIDE 1.5.1 for STM32F405RG and no luck. sprintf ("%f", f) causes hardfault
2024-11-20 02:45 PM
Is Dave's solution still the best way to handle this?
https://github.com/DRNadler/FreeRTOS_helpers
I'm running into printf() working before calling vTaskStartScheduler(), and failing after calling it.
STM32F405
STM32CubeIDE v1.14.1
GNU tools 10.3-2021.10
ST FW v1.28.1