Skip to main content
Associate III
Solved

sprintf causes runtime error

Hi, 

I am using sprintf to format data before sending it over a UART. 

STM Cube IDE 1.16.1

STM32F103 

The code works in one project but not in another. I have ticked "Use float with printf in MCU/MPU Settings"

int size = sprintf(&Buffer,"{\"src_addr\":\"%s\",\"PDOP\":%5.2lf,\"HDOP\":%5.2lf,\"VDOP\":%.2lf,\"Volts\":%.2f}\n",
"2", pdop, hdop, vdop,Volts);

for some reason the code end up in syscall.c

void _exit (int status)
{
 _kill(status, -1);
 while (1) {} /* Make sure we hang here */
}

 

This topic has been closed for replies.
JorgieBest answer
Associate III

I have rebuilt the project from scratch, must be something in the setup that caused an issue, perhaps I somehow put the buffer in an area that was not RAM.

Either way the code above does work correctly.

3 replies

mƎALLEm
ST Technical Moderator

Hello,


@Jorgie wrote:

The code works in one project but not in another. I have ticked "Use float with printf in MCU/MPU Settings"

 

 This occurs only when you print floats or whatever the type you print?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
JorgieAuthor
Associate III

I have managed to format with a string I will try with an integer tomorrow.

However, as mentioned this same line of code works correctly in a different project.

 

JorgieAuthorBest answer
Associate III

I have rebuilt the project from scratch, must be something in the setup that caused an issue, perhaps I somehow put the buffer in an area that was not RAM.

Either way the code above does work correctly.