Error Message: Fault exception

Hi all,
I am building a spectrum analyser using the STM32 NUCLEO-L476RG and the CMSIS-DSP library. Building the program doesn’t generate any errors however, when I run it, I am met with the fault message below. I was wondering if anyone had any thoughts as to what the cause could be as the MBED error decoder isn’t very helpful with its none responsive web links though it does mention:

HardFault exception
Cortex-M HardFault exception has occurred. Please see Analyzing Mbed OS crash dump - Debugging and testing | Mbed OS 6 Documentation for more info.

The latest version of my code can be found here should you wish to have a closer look.

Many thanks,
Andy

++ MbedOS Fault Handler ++
FaultType: HardFault
Context:
R 0: 3EDBEDC0
R 1: 00000000
R 2: 10003E0C
R 3: 00000040
R 4: 1000234C
R 5: 10000388
R 6: 00000040
R 7: 10001B50
R 8: 10000390
R 9: 00000200
R 10: 10001348
R 11: 10000350
R 12: 10000B48
SP : 20017FB8
LR : 0801B267
PC : 080066C8
xPSR : 01000051
PSP : 10002CB8
MSP : 20017F98
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000000
BFSR : 00000082
UFSR : 00000000
DFSR : 00000008
AFSR : 00000000
BFAR : 3EDBEDC0
Mode : Handler
Priv : Privileged
Stack: MSP
– MbedOS Fault Handler –
++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x80066C8
Error Value: 0x10000188
Current Thread: main Id: 0x100041D0 Entry: 0x801CBED StackSize: 0x1000 StackMem: 0x10002DE8 SP: 0x20017FB8
For more info, visit: mbedos-error
– MbedOS Error Info –
= System will be rebooted due to a fatal error =
= Reboot count(=1) reached maximum, system will halt after rebooting =

Hello,

I remember this discussion about Mbed error decoder. But I usually place few printfs across the program and I am trying determine where the code crash.

However I see potential issue (lines 38-54)

            //read pin and store in FFT_inputBuffer
            FFT_inputBuffer[bufferPtr] = signal.read(); //range 0-1

            //once all samples have been taken, pass to FFT()
            if(bufferPtr > SAMPLES){
                FFT();

                //display frequency values on lcd
                drawWaveform();

                //reset buffer pointer
                bufferPtr = 0;

            }else{
                //increment buffer pointer
                bufferPtr++;
            }

The value of macro SAMPLES = 2048, but your if condition become true with number 2049. It means the last index of array, where last data was stored, was 2048 and that is out of size of your array because the size 2048 is range of 0-2047.

Similar it can be for line 80.

Result of the for condition below is 012345678910

for(int i = 0;i <= 10; i++) cout << i;

So it seems again your for statement hit 2048 instead of 2047 only.

BR, Jan

1 Like