Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

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.