cancel
Showing results for 
Search instead for 
Did you mean: 

HardFault_Handler() error in SPI

GPaiv.1
Associate III

Hi, 

When I leave my code to play for more than one hour I received the error HardFault_Handler(), I found in registers whats the last line executed before entering in the error function, below I put a picture of this part of the code. 0693W00000AMXbnQAH.png 

Note: That error is random, don't have a specific moment time when happens.

1 ACCEPTED SOLUTION

Accepted Solutions
DavidAlfa
Senior II

Are you using dynamic allocation? (malloc() ,calloc()...).

If so, do your best to avoid that, as it's completely broken.

Better to declare an array and use it.

What I do when using big buffers but none at the same time,​ is making a big union with them.

So I can use any without eating up all my RAM.

View solution in original post

7 REPLIES 7
DavidAlfa
Senior II

Are you changing the SPI pointer at some point? An interrupt in that moment might cause trouble.

Can't help more without seeing any code.

GPaiv.1
Associate III

Hi, Thanks for your answer.

No, I do not change de SPI pointer.

I'm using the demo code ST25R3911B-DISCO, I'm just using mifare_ul.c to read an EEPROM of a Tag.

Brian TIDAL
ST Employee

Hi,

hpsi->pRxBuffPtr is at @0x20017fff which is the end of STM32L476 internal SRAM1 area. Access to next byte (@0x20018000) will cause a fault...

it looks like a HAL_SPI_TransmitReceive call with an incorrect/corrupted length parameter...

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Is the buffer on the stack or heap?

Looks to be blowing the buffer's scope, add some better sanity checking in your code.

Watch for stack/heap overflow, or resource leaks within your implementation.

Remember callbacks are done under interrupt context, and there is likely a lot of non thread-safe code, or other things that are ill-considered.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
GPaiv.1
Associate III

Hi,

I resolve the problem increase de size of my buffer then received information by tag.

But now I had a new problem, below has a print of my new problem.

0693W00000AMZoFQAX.png

Brian TIDAL
ST Employee

Hi,

hspi pointer seems to be corrupted (value 0x44444444: it looks like a buffer overflow has corrupted this pointer....).

I would recommend to check buffers size.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DavidAlfa
Senior II

Are you using dynamic allocation? (malloc() ,calloc()...).

If so, do your best to avoid that, as it's completely broken.

Better to declare an array and use it.

What I do when using big buffers but none at the same time,​ is making a big union with them.

So I can use any without eating up all my RAM.