I compile the "same" code on 2 targets (one Freescale, one STM32 both with cortex M4). I use --specs=nano.specs
and I have implemented the _write
function as an empty function and this causes the whole printf
to be optimized away by GCC's -Wno-unused-function
even with -O0
on the STM32 target (seen in map). This is fine and I would like to reproduce that on Freescale target.
But on the Freescale target (with same compile flags) the printf causes hardfault. But if I go step by step with the debugger (assembly stepping) the printf
goes through the library without hardfaulting. Simple breakpoint breakpoint sometimes not hit and run from any location in printf
causes hardfault too (so it is unlikely that it is a peripheral issue).
So far I checked that stack and heap are not overlapping and some other far-fetched disassembly.
Why isn't the printf optimized away on freescale target ? What can cause the library code to hardfault ? Why is it OK when doing assembly step by step debug ?
EDIT:
- Using arm-none-eabi-gcc 5.4.1 for both MCU with same libraries.
- I do not want to remove printf, this is only a first step to be able to use them or not.
- Vector table has default weak vectors for all ISR so it should be OK
- Using the register dump it seems that the faulty instruction is at address 4 (reset vector) so the new question is now: why does the chip reset ?