2023-11-02 10:49 AM - edited 2023-11-03 05:42 AM
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()
Here's the problem:
EDIT: The problem is only there when I try to printf floats ... whereas with normal strings or ints everything goes
2023-11-02 04:28 PM
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.
2023-11-03 01:58 AM - edited 2023-11-03 01:59 AM
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.
2023-11-03 03:06 AM
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.
2023-11-03 03:08 AM
@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
2023-11-03 03:23 AM
You'll find this information at;
STM32CubeIDE > Windows > Preferences > STM32Cube > Toolchain Manager.
Try to make the change and see if this solves the issue.
2023-11-03 03:40 AM
2023-11-03 04:36 AM
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.
2023-11-03 05:44 AM
UPDATE: The problem appears only when I try to printf floats ... whereas with normal strings or ints everything goes.
2023-11-03 05:58 AM
>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.
2023-11-03 10:31 AM
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