Using sprintf / sbrk_r
Posted: Fri Jan 04, 2013 11:02 pm
At the moment i am stuck trying to get sprintf to work with ChibiOS (STM32F4 / gcc-arm-embedded compiler).
At first i got linker errors because of missing sbrk_r function. Then i included the syscalls.c file that comes along with ChibiOS.
The code compiles, works for a few seconds and then the OS stops working.
I guess it's because i run out of memory. I created a new thread that calls sprintf about 100 times per second and the result is written to my display.
I noticed that chCoreAlloc is used in _sbrk_r implementation. As far as i found out the "incr" argument can also be negative to free memory - afaik chCoreAlloc can't free memory, so that might be the reason why i run out of memory after a while.
Any ideas what is going wrong and how to fix that?
At first i got linker errors because of missing sbrk_r function. Then i included the syscalls.c file that comes along with ChibiOS.
The code compiles, works for a few seconds and then the OS stops working.
I guess it's because i run out of memory. I created a new thread that calls sprintf about 100 times per second and the result is written to my display.
I noticed that chCoreAlloc is used in _sbrk_r implementation. As far as i found out the "incr" argument can also be negative to free memory - afaik chCoreAlloc can't free memory, so that might be the reason why i run out of memory after a while.
Any ideas what is going wrong and how to fix that?