cancel
Showing results for 
Search instead for 
Did you mean: 

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

T J
Lead

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3

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

T J
Lead

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

Good news. Glad to help you.