Oops! Error 2 :( Hard fault

YQN

4 months 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 4 months 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 4 months 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 4 months 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 4 months ago

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

Odolyte

NEW 2 weeks 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

2 weeks ago

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

Odolyte

NEW 2 weeks ago

Odolyte Odolyte

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

You must be logged in in order to post a message on the forum

Log in