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?
Using sprintf / sbrk_r
Moderators: RoccoMarco, lbednarz, tfAteba
Re: Using sprintf / sbrk_r
I just modified chprintf to chsprintf and it works good. But still i would like to know how one could fix the issue with sbrk_r?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Using sprintf / sbrk_r
Hi,
Not sure, is sbrk_r() really invoked with a negative parameter? if so then it cannot be implemented using chCoreAlloc() because chCoreAlloc() cab also be called by other allocators and the application, the library is not the only user.
The only solution would be creating a dedicated heap for the library and implement a sbrk() working inside that space.
Giovanni
Not sure, is sbrk_r() really invoked with a negative parameter? if so then it cannot be implemented using chCoreAlloc() because chCoreAlloc() cab also be called by other allocators and the application, the library is not the only user.
The only solution would be creating a dedicated heap for the library and implement a sbrk() working inside that space.
Giovanni