Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


sprintf call causes STM32L4xx to crash

Hello,
I am trying to convert an integer number into a string. I have tried both a locally defined string and a global instance. I have increased my stack size. Interestingly this works correctly when tried on STM32CubeIDE. I am only passing 101 as an int. M am presuming it’s to do with hoc GCC being being called? Ignore RetVal as that was going to be converted into a float like 10.1.

Code excerpt:

float32_t ParamConverter(int32_t Input){

float32_t RetVal = 0;
char Holding5;

sprintf(Holding, “%i”, Input);

return 0;
}

First - use snprintf() instead of sprintf(). While THIS example with THIS specific value (101) will not overflow your 5 byte buffer, it is a good habit to get in to. For example:

sprintf( Holding, sizeof(Holding), “%i”, Input );

Second - can you be more specific about what “crash” means? Does your code end up somewhere you don’t expect, like a fault handler? Note that by default, all fault handlers are simply an empty loop, which usually ends up as a “jump to self” instruction in the startup code just after the call to main(). You may need real code in your fault handlers, or at least a breakpoint so you can inspect the fault registers to see what caused the fault.

Is that code snippet you showed us REALLY the entire function? Or is there more to it?


STM32 crashes when using the sprintf function

1. Software environment: Keil MDK 5.15
2. Hardware environment: STM32F103C8T6 minimum system
Today, when I was programming STM32, I made a strange mistake. The program was blocked in a function. After looking it up for a long time, I found that it was blocked in the sprintf function!!
Serial port printed the first sentence, the card died, the next sentence did not execute to.



The reasons are as follows

__’‘void foo(char *path)
{
...
printu(“enter dir:%s\r\n”, path);
sprintf(path + i, “/%s”, fn);
printu(“enter1 dir:%s\r\n”, path);
...

}

call foo(“0:”);’‘__



The access to the path array is out of bounds! When calling, write as follows:

__’‘char path10 =”0:”;
foo(path);’‘__


 

Newest Forum Posts

  1. reservation car service Seattle by Jamesprede, 2025-05-01 10:06
  2. Last day: drone bonus by Danielrug, 2025-04-19 16:55
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Insightful Perspectives on This Subject by davidsycle, 2025-03-04 05:45
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  9. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  10. Build a project in "release" mode by tang, 2025-02-20 10:36

Last-Modified Blogs