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


why trace_printf("%f",x); triggers a HARD FAULT on a stm32 MCU?

I’m using a stm32 F413ZH microncontroller with HAL libraries (mainly written to be used with c but can also be used with c++) in eclipse, actually I managed to completely configure eclipse including semihosting and debug mode(openOCD), the basic project files and also I managed to manually adapt the basic project files given by STM32CubeMX to work with c++. So... now I can use HAL libraries in a c++ eclipse environment and test my code via OpenOCD and trace_printf trace_puts using semihosting.

Now, again, after struggling too much setting up an stm32 environment, I find myself stuck, but this time is different.

These last 7 days I have been looking for a solution to my problem and I have tried many suggestions from similar issues online but none of them has solved my problem.

Well, the thing I’m facing is a HARD FAULT when using trace_printf() in semihosting while debugging, if I use this function to print via semihosting an integer (%d) everything is okay and I can read the printed value in the OpenOCD console but when I tried to print a value with the %f formater the supposedly printed data wasn’t being shown in the OpenOCD console, then I read that in order to enable the printing of floating point values I needed to add -u _printf_float to the linker flags, so after adding the flag I tried to trace_printf() a floating value, an integer value or whatever data type but all of them using the %f formater but I keep getting a HARD FAULT using %f in trace_printf().



[HardFault
Stack frame:
R0 = 00666E69
R1 = 2004FE78
R2 = 2004FF00
R3 = 00666E69
R12 = F642D800
LR = 08005DE7
PC = 08006586
PSR = 01000000
FSR/FAR:
CFSR = 00008200
HFSR = 40000000
DFSR = 0000000A
AFSR = 00000000
BFAR = 00666E69
Misc
LR/EXC_RETURN= FFFFFFF9

By debugging step by step the HARD FAULT handler is triggered after this function is called: vsnprintf()

I’m using this LINKER FLAGS -T mem.ld -T libs.ld -T sections.ld -Xlinker gc-sections -L”../ldscripts” -Wl,-Map,”ThreePhaseSignals.map” specs=nano.specs -u _printf_float

My project settings are:

[Project toolchains
[[https://i.stack.imgur.com/KXtq8.jpg]]

[Target processor settings
[https://i.stack.imgur.com/oAkBt.jpg]

[C++ preprocessor
[https://i.stack.imgur.com/lrxoJ.jpg]

[Linker settings and flags
[https://i.stack.imgur.com/SvzZB.jpg]

My _sbrk.c is:
[_sbrk.c]
[https://i.stack.imgur.com/d76dN.jpg]


my linker files are:

mem.ld is:
[mem.ld
[https://i.stack.imgur.com/EdgqL.jpg]


and sections.ld is:
the attached file in this post



On internet many people says that this is because printing floats consumes a lot of memory and probable the MCU is crashing due to memory overflow, so many suggestions aim to modify the linker script where stack and heap assignations are made, some others say that this hard faut is related to_sbrk.c in newlib.

I tried to adapt these solutions to my particular case but till now my problem still is not solved. I don’t know if I’m badly implementing the suggestions or simply my problem is different.

Can someone help me with this?

France

Hi,

Also you seem not being using System Workbench for STM32, you may try suppress the --specs=nano.specs flag from your linker flags.

Bernard (Ac6)

I’m using eclipse which basically is SWSTM32. I tried supressing --specs=nano.specs countless times but it makes the problem worse, when removed the debugger doesn’t start correctly.


What other ideas do you have?


Hi,

You might need “-specs=rdimon.specs -lc -lrdimon” on the linker command.

Regards,
Kevin.



 

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