Skip to main content
Explorer II
January 3, 2024
Question

[Need Help] Hard Fault Analysis On LR after ADC check HAL_OK

  • January 3, 2024
  • 4 replies
  • 3796 views
Hi i am a student, building a program using STM32F4 Discoery board for my research's hardware. So my program which i write for STM32F4 Discovery board has been stuck in Hard Fault after certain ADC Poll code. An overview of my code is :
  • Use different ADC Channels from ADC1 only (just 1 ADC, multi channel) to read 3 sensors.
  • Each time i about to read any ADC channel i configure the channels (e.g 2 or 5) >> start hadc1 >> poll conversion >> get the value >> stop hadc1 and i repeat that for other channels.
  • After some calculation programs i fetch it to USART
 
After reading a blog about HardFault analyzer, i managed to tweak my code and get the info about on which line i got stuck, including the LR and PC (showed by number 1 in the pic, top left). Turns out it is faulting when it is checking whether HAL_OK is TRUE in the main.c (number 3 in the pic, bottom).
The LR (call return address) has the adress 0x08000955 whis is not listed in the dissasembly (number 2 in the pic, top right)
HARDFAULT KONTOL.JPG

 

I think the bad LR address might be the problem, i.e. reffering to the non-exist address in disassembly, note that in disassembly window (number 2) there is no address 0x8000955 after 0x08000954, but it goes straight to 0x8000956 instead.
But i am not really sure about it. Also, if thats the case then i would need group member's suggestion on how to deal with the fault. So i dont really know how what to do in this situation. Could anyone please help me?
 
 
some notes:
The USART works fine, i did try the code by commenting out the ADC related code (using //) and using incremental values as dummy data.
 
 
I had some trouble with HAL getting locked which send me to the Hal_Locked instance
But, I changed the Hal_Locked function so it can unlock itself in stm32f4xx_hal_def.h.
heres the Hal_locked function 
HARDFAULT KONTOL1.JPGThanks in advance!
_____________________________________________________________
 
 
    This topic has been closed for replies.

    4 replies

    ST Employee
    January 3, 2024

    Hello @dios_kuri

    Could you please share your project? 

    Thank you! 

    Super User
    January 3, 2024

    >The LR (call return address) has the adress 0x08000955 whis is not listed in the dissasembly

    The address is actually 0x08000954. (Clear the lowest bit. this is because of thumb instruction set  TL;DR)

     

     

    dios_kuriAuthor
    Explorer II
    January 3, 2024

    Thanks for the insight, Pavel. But I am sorry i don't understand how to clear the lowest bit, and i dont know where to put it since the code is an if code to check if hal_adc_configchannel is OK. May i get an example?
    Any kind of suggestion helps. 

    Graduate II
    January 3, 2024

    Inconveniently you truncate the register display in the screen shot.

    Problem is likely with one of the parameters / structures passed to HAL_ADC_ConfigChannel()

    Graduate II
    January 3, 2024
    Super User
    January 3, 2024

    > LR address doesnt exist

    As @Pavel A. said, [in your head] mask the LR LSB (set it to 0) to get 0x8001ec2 AS THE RETURN ADDRESS.

    But LR is not what you should be paying attention to.  Look at the PC value 0x8000203a, THAT is where the problem was.  As @Tesla DeLorean said, it is probably an issue with the configuration structure you pass (0 in some field that expects a non-zero value, perhaps).