Skip to main content
Associate III
October 7, 2024
Solved

sprintf causes runtime error

  • October 7, 2024
  • 2 replies
  • 1279 views

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

 

Best answer by Jorgie

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.

2 replies

mƎALLEm
Technical Moderator
October 7, 2024

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
October 7, 2024

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
October 10, 2024

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.