cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Fault test error?

Zanon.Luciano
Senior
Posted on January 09, 2014 at 13:14

In order to test the Hard Fault interrupt, I modified the Systick example on ''STM32F0xx_Discovery_FW_V1.0.0'' as follows..

on main.c I added two lines:

------------------------------

int main(void)

{

uint8_t* BytePtr = (uint8_t)0x20002000;

    

    *BytePtr = 0x5a;        //generate hardfault IRQ

    

    

  /*!< ...........comment

     */     

       

  /* Initialize Leds mounted on STM32F0-discovery */

  STM_EVAL_LEDInit(LED3);

--------------------------------------

on stm32f0xx_it.c I modified the error handler:

-----------------------------------

void HardFault_Handler(void)

{

  TimingDelay_Decrement();    //really do nothing...

}

---------------------------------------

So, when the line

      *BytePtr = 0x5a;

is executed and the processor access the wrong location 0x20002000

a HardFault_Handler is called and executed.

At return I expect the processor to execute the line

  STM_EVAL_LEDInit(LED3);

but instead it returns still at line ''*BytePtr = 0x5a;  and newly execute it, entering in loop!!!

I am a novice on STM32  so it must be a stupid error but if I repeat

the same test on the ''STM32F10x_vldiscovery_package'' it works as expected...

Can someone help me??

Thanks,

Luciano

3 REPLIES 3
chen
Associate II
Posted on January 09, 2014 at 13:45

Hi

RTI - Return from Interrupt will load the Program Counter with the value before/at the IRQ trigger.

Since the IRQ was cause at line ''*BytePtr = 0x5a;''

That is where it will return.

That is why the ISR for HardFault is usually an infinite loop.

Nice experiment though - never thought of doing this myself

Zanon.Luciano
Senior
Posted on January 09, 2014 at 14:32

If you repeat this experiment on  ''STM32F10x_vldiscovery_package''

(stm32f100  cortex m3)  il works well, NOT entering in loop!!!

You are telling me that on stm32f0xx (cortex M0)

the ''Return from Interrupt will load the Program Counter with the value before/at the IRQ trigger''

but on stm32f100 (cortex M3)

Return from Interrupt will load the Program Counter with the value AFTER the IRQ trigger???

Very strange thing....

chen
Associate II
Posted on January 09, 2014 at 15:09

Hi

''You are telling me that on stm32f0xx (cortex M0)

the ''Return from Interrupt will load the Program Counter with the value before/at the IRQ trigger''

but on stm32f100 (cortex M3)

Return from Interrupt will load the Program Counter with the value AFTER the IRQ trigger''

No, Im telling you that in GENERAL RTI  SHOULD return you to the exactly where the code was before the IRQ. Other wise IRQs would cause strange differences in behaviour when they go off and pause the flow of execution.

No comment on the difference between the result on the 2 processors - I do not know why.