cancel
Showing results for 
Search instead for 
Did you mean: 

sprintf causes runtime error

Jorgie
Associate III

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 */
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Jorgie
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.

View solution in original post

3 REPLIES 3
SofLit
ST Employee

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 on "Accept as Solution" on the reply which solved your issue or answered your question.

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.

 

Jorgie
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.