Skip to main content
GPaiv.1
Associate III
April 26, 2021
Solved

HardFault_Handler() error in SPI

  • April 26, 2021
  • 6 replies
  • 1733 views

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.

    This topic has been closed for replies.
    Best answer by DavidAlfa

    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.

    6 replies

    DavidAlfa
    Senior II
    April 26, 2021

    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
    GPaiv.1Author
    Associate III
    April 26, 2021

    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.

    Tesla DeLorean
    Guru
    April 26, 2021

    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 VenmoUp vote any posts that you find helpful, it shows what's working..
    Brian TIDAL
    Technical Moderator
    April 26, 2021

    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.
    GPaiv.1
    GPaiv.1Author
    Associate III
    April 26, 2021

    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
    Technical Moderator
    April 26, 2021

    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
    DavidAlfaBest answer
    Senior II
    April 26, 2021

    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.