cancel
Showing results for 
Search instead for 
Did you mean: 

printf hard fault

luke514
Senior

Whenever the compiler executes

printf("frequency %f: %f \n", ((float32_t)(i * SAMPLING_RATE) / FFT_BUFFER_SIZE), output_fft_mag);

it goes to HardFault.

I attach main.c and syscall.c

All the code that we need to analyze is inside the function void get_sineval_FFT2()

luke514_0-1698947305139.png

Here's the problem:

luke514_0-1698949948629.png

EDIT: The problem is only there when I try to printf floats ... whereas with normal strings or ints everything goes

 

 

 

23 REPLIES 23
Authority
Associate II

May I know which compiler toolchain version you are using? I am asking because I have recently experienced the similar error and it was because I was using compiler toolchain version 12.3... Compiler version 11 and 12 provided by ARM have known issues with how they were compiled and people are using them by performing a manual patch to fix the error. I won't go into details.

 

Anyways; to fix your problem try using compiler version 10.3 instead. This will most likely solve your issue.

btw on my (old , from 2017) MX linux system new toolchains dont work, (IDE 1.13.1) ,

so i use 9-2020-q2 ; no problems so far.

If you feel a post has answered your question, please click "Accept as Solution".

STM32CUbeIDE Version: 1.11.0
Build: 13638_20221122_1308 (UTC)

I don't know if this is the compiler toolchain version you asked me. If it is not, tell me where I can find it so I can tell you.

@AuthorityThis toolchain version issue are you sure it applies here? Because, as I said, printf works in all my other projects and has never given me any problems with this version .. so maybe there is a technical problem in this project either in the code or incompatibility with the DSP libraries I have installed

You'll find this information at;

STM32CubeIDE > Windows > Preferences > STM32Cube > Toolchain Manager.

Try to make the change and see if this solves the issue.

luke514_0-1699008048066.png

 

Thats OK.

 

Now, check how you have configured your printf. There is no information if you are using it as SWO or as a UART.

If it is SWO then check if the corresponding port is enabled. You can see those settings from the ITM menu. If you are using UART then check if your you have configured UART properly and your __io_putchar function call is implemented properly.

 

Regards.

UPDATE: The problem appears only when I try to printf floats ... whereas with normal strings or ints everything goes.

@AScha.3 @Pavel A. @Tesla DeLorean 

Pavel A.
Evangelist III

>The problem appears only when I try to printf floats

Printing floats in the newlib requires something more than integers - maybe, extra allocation. So, not surprising. You can look for alternative 3rd party printf that is more eco-friendly. This or others.

I finally solved it by declaring "double" variables to be used inside print .. and not "floats". However, the code doesn't print what it is supposed to print, and I hope it is not due to this little change