cancel
Showing results for 
Search instead for 
Did you mean: 

(SOLVED) Sprintf with Floating Point Number enters infinitive loop in Bare-Metal Programming

FEvra.1
Associate II

The problem is about Sprintf with floating point number on STM32L452RET6P.

Although all settings are correct, sprintf doesn't work with floating point number only. Although it works on stm32cubeMX, it doesn't work on bare-metal program. It loops endlessly in the Default_Handler function. I'm about to go crazy. 

First sprintf properly works. But the second one does not. After second sprintf, I've traced back the code on the debugger and I can see that the DefaultHandler executes and traps the board in an Infinite_Loop as a result of WWDG_IRQHandler misfiring. 

Error message tells me "No source available for "<signal handler called>() at 0xfffffff9" , No source available for "_printf_float() at 0x8001124", No source available for "_svfprintf_r() at 0x8004c8e", No source available for "sprintf() at 0x8001d08" . I can't seem to solve this problem, do you have any idea?

 Program is below:
_legacyfs_online_stmicro_images_0693W00000dJvDpQAK.png
_legacyfs_online_stmicro_images_0693W00000dJvIpQAK.png 

Here is linker flags.

 -mcpu=cortex-m4 -T"/Users/fatih/STM32CubeIDE/workspace_1.2.0/microprocessors/2023/Bare_Metal/Bare_Metal_HCSR04/STM32L452RETXP_FLASH.ld" --specs=nosys.specs -Wl,-Map="${BuildArtifactFileBaseName}.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -Wl,--start-group -lc -lm -Wl,--end-group

Compiler Settings:

 -mcpu=cortex-m4 -std=gnu11 -DDEBUG -DSTM32L452RETxP -DSTM32L4 -DSTM32 -DSTM32L452xx -c -I../Inc -I"/Users/fatih/STM32CubeIDE/workspace_1.2.0/microprocessors/2023/Bare_Metal/Bare_Metal_HCSR04/Drivers/CMSIS/Core/Include" -I"/Users/fatih/STM32CubeIDE/workspace_1.2.0/microprocessors/2023/Bare_Metal/Bare_Metal_HCSR04/Drivers/CMSIS/Device/ST/STM32L4xx/Include" -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb


_legacyfs_online_stmicro_images_0693W00000dJvDzQAK.png 

Here's a screenshot of the debug window.


_legacyfs_online_stmicro_images_0693W00000dJvDVQA0.png

1 ACCEPTED SOLUTION

Accepted Solutions

Typically done in SystemInit() from system_stm32l4xx

void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
   SCB->CPACR |= ((3UL << 20U)|(3UL << 22U));  /* set CP10 and CP11 Full Access */
  #endif
....

.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

10 REPLIES 10

Maybe this has nothing to do with printf() as such, and it ends up in default signal handler because of unhandled interrupt?

What's the content of SCB->ICSR register at that moment?

JW

HA.5
Associate III

repeat the first sprintf after the first one and comment out the second and see if it works.

i mean like that:

sprintf(str, "i=%d", i);

sprintf(str, "i=%d", i);

It works with integer numbers properly like what i said before.


_legacyfs_online_stmicro_images_0693W00000dJvwuQAC.png

I couldnt understand why same program in stm32cubemx works properly.

Before:


_legacyfs_online_stmicro_images_0693W00000dJvzeQAC.pngAfter:


_legacyfs_online_stmicro_images_0693W00000dJw0cQAC.png

FEvra.1
Associate II

when I disable FPU, it works:)


_legacyfs_online_stmicro_images_0693W00000dJwAXQA0.png

Okay so VECTACTIVE is 3, which is HardFault.

> when I disable FPU, it works:)

That would then point to FPU not being switched on in the startup code.

I don't know how this is accomplished through the magic of IDEs - maybe it selects a different startup source file (.s)? Snippet of startup file I see in the screenshot above doesn't look like there is any code (conditional or function call) to do that.

JW

Typically done in SystemInit() from system_stm32l4xx

void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
   SCB->CPACR |= ((3UL << 20U)|(3UL << 22U));  /* set CP10 and CP11 Full Access */
  #endif
....

.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks, you are great one!

yeap you are right, the problem is gone!