Oops! Error 2 :( Hard fault

YQN

5 years ago

Hi, got this nice error message with a bin that works in the online emulator and I don't know what to investigate.

I have removed late portions of my code and it still doesn't work, any idea how to debug? I don't know what these mean...

Thanks in advance for any help!

jicehel

NEW 5 years ago

Hi YQN to have a good idea and gain time, it's will be great to have a link to the source code to check it and see whee could be the problem

Sorunome

NEW 5 years ago

Common problems are for a hard fault are things like....

Array Overflow

Let's say you made an array of length n, and now you try to access past the array, e.g.:

int myArray[16];
int somevar = myArray[16]; // COULD lead down the road to a hard fault

for (int i = 0; i <= 16; i++) { // as i can also be 16 here, it also COULD lead to a hard fault
    int val = myArray[i];
}

RAM overflow

This is if you use too much RAM than you have. This is rather tricky to debug, just try to output gb.getFreeRam() here and there to see where you are hitting a lot of RAM


Undefined instructions and unaligned addresses isn't something to worry about. In fact, the array overflow often leads to either of those two, causing the hard fault.

YQN

NEW 5 years ago

JCL, thanks, I just hoped it would be ok without the code because I can't access my github right now and the code is big for a single forum message, with many files (trying to learn MVC architecture).

It was an array issue as Sorunome suggested. I declared an array of size 48 and set values up to 28 only, then browsed the array up to 48, didn't think such an error would pass the emulator test!

Thanks guys! I'm back on track! :D

Sorunome

NEW 5 years ago

Yeah, once you read past an array you land in undefined behaviour, so who knows what'll happen!

Odolyte

NEW 4 years ago

Hi everyone,

I got the same problem by trying the simple "Hello World" test with Circuit Python :

from gamebuino_meta import begin, waitForUpdate, display, buttons, color

while True:
    waitForUpdate()
    display.clear()
    display.print("Hello world")

Any idea how to fix this ?

Note that there is plenty of room on my sd card...

Odolyte

4 years ago

Sorry Guys updated to CircuitPython 0.0.5. the update fixed my problem...

Odolyte

NEW 4 years ago

Odolyte Odolyte

Sorry Guys updated to CircuitPython 0.0.5. the update fixed my problem...