Using the Cube: with Visual Studio and Nano lib supporting printing of floats.
sprintf crashes if the CDC USB output is not plugged into the PC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-07-29 11:41 PM
unplug my CDC USB output cable and
sprintf( string, "%.2f ",myFloat); will crash
plug it back in to the PC and without any comms, it works.
could it be a memory leak if the CDC driver is not handshook ?
anyhow the CUBE didn't allocate enough Stack space.
fixed here: in the stm32L4xx_flash.lds file
.reserved_for_stack (NOLOAD) :
{
. = ALIGN(4);
PROVIDE(__reserved_for_stack_start__ = .);
KEEP(*(.reserved_for_stack))
. = . + 0x100; /* <--- fixed here */
. = ALIGN(4);
PROVIDE(__reserved_for_stack_end__ = .);
} > SRAM
Solved! Go to Solution.
- Labels:
-
USB
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-05 8:31 AM
Hello @Community member​ ,
You're correct about the increase of stack. (s)printf (according to implementation) uses more stack if it processes more complex data (like floats for example). So, it is totally normal to have to increase the stack if it isn't already enough.
Are you using an OS, where the sprintf is located (interrupt, normal code, OS task, etc...)?
BeST Regards,
Walid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-05 8:31 AM
Hello @Community member​ ,
You're correct about the increase of stack. (s)printf (according to implementation) uses more stack if it processes more complex data (like floats for example). So, it is totally normal to have to increase the stack if it isn't already enough.
Are you using an OS, where the sprintf is located (interrupt, normal code, OS task, etc...)?
BeST Regards,
Walid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-10 6:57 PM
Hello Walid,
I use my own OS and never print in the background..
It was my fault in the end.
I changed the Stack and Heap in the Cube down to 0x800 each, to save RAM, but its not ok.
putting it back to 0x1000 for both fixed the issue.
BeST
Nick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-08-11 1:08 AM
Good news. Glad to help you.
