causes the F103 to crash at line buf = to_string(a1.read_voltage()); with the following error message:
++ MbedOS Error Info ++
Error Status: 0x8001011F Code: 287 Module: 1
Error Message: Operator new out of memory
Error Value: 0x80060E6
For more info, visit: https://mbed.com/s/error?error=0x8001011F&tgt=NUCLEO_F103RB
-- MbedOS Error Info --
the same error is thrown for code like
double val = a1.read_voltage();
buf = to_string(val);
I have similar code in an application for a STM32 F407, where no such error occurs. Is this a known issue on STM32F1s?
The STM32F103RB has only 20kbyte of SRAM on board. This is very little and much of it will be used by mbed-os. When you call the std::to_string function it needs to claim some work space. It looks like it wants to claim more than is available.
To solve this you can do two things: get a device with more onboard memory (STM32F103RD) or write your own to_string function which uses a buffer on the stack.
Bare-metal is using the small-c lib already, in the case of gcc it is newlib-nano. But the default for this lib is not to use float for printf and scanf. That must be enabled by additional Compiler Switches.
So Zoltans hint maybe a solution, but another caveat is that minimal-printf does not support precision specifiers.
thank you, this solves both the operator new out of memory issue and the issue of missing output of sprintf.
Interesting, do you know why this is? I cound not find any mention in the documentation. I would be ok with using the same precision setting in my whole application, but the "platform.minimal-printf-set-floating-point-max-decimals" option seems to be ignored. (also, the output is 3 decimal places regardless of "platform.minimal-printf-enable-floating-point" being set to true or false)