Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » why trace_printf("%f",x); triggers a HARD FAULT on a stm32 MCU?
why trace_printf("%f",x); triggers a HARD FAULT on a stm32 MCU? [message #1776288] Wed, 15 November 2017 05:35 Go to next message
Humberto Bolaños Cerrud is currently offline Humberto Bolaños CerrudFriend
Messages: 1
Registered: November 2017
Junior Member
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().

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

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

I'm using these LINKER FLAGS
-T mem.ld -T libs.ld -T sections.ld -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"" --specs=nano.specs -u _printf_float

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?

Re: why trace_printf("%f",x); triggers a HARD FAULT on a stm32 MCU? [message #1776368 is a reply to message #1776288] Wed, 15 November 2017 18:05 Go to previous message
Jonah Graham is currently offline Jonah GrahamFriend
Messages: 401
Registered: June 2014
Senior Member
Hi Humberto,

I am sure someone can help you, unfortunately this forum is about using Eclipse CDT, the IDE, as opposed to debugging/building your target application. I recommend googling around for a forum more on topic, such as a newlib or stm topic (or stack overflow?)

Previous Topic:Missing GDB Debugging Preferences in Neon-4.6.3/CDT 9.2.1
Next Topic:what happen to Miscellaneous settings?
Goto Forum:

Current Time: Tue Oct 16 05:20:24 GMT 2018

Powered by FUDForum. Page generated in 0.02045 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top