Skip to main content
Associate III
February 13, 2023
Solved

Exception Handler

i try to crash my code to check the watchdog timer is reseting the code or not. for crashing my code i use timer interrupt. i.e

TIM2_IRQHandler()

{

---------------;

---------------;

}

TIM_IRQHandler() instead of TIM2_IRQHandler . so, code will be crash at that time watchdog timer should reset the my code and some Exception Handler is there.

Example,

1)Hardfault

2)MemManage

3)BusFault

4)UsageFault

how to make my code stuck in an exception handler.

    This topic has been closed for replies.
    KnarfB
    KnarfBBest answer
    Super User
    February 14, 2023

    Here is an excellent overview: https://wiki.segger.com/Cortex-M_Fault with code.

    If you don't make your variables volatile, the compiler can optimize the div away, especially if b is a compile-time known constant. Disasm may help here too.

    hth

    KnarfB

    6 replies

    Nikita91
    Lead II
    February 13, 2023

    On M3, M4 and M7 integer divide-by-zero generates a UsageFault exception,

    So divide by 0 and set an infinite loop in the UsageFault handler

    Piranha
    Principal III
    February 14, 2023
    Associate III
    February 14, 2023

    @Nikita91​ Thank you for your comment.

    i tried divide by 0.

    int a = 5, b = 0;

    a=a/b;

    but i'm not get infinite loop.

    if you know any other method tell me

    Piranha
    Principal III
    February 14, 2023
    for (;;);

    Infinite loop is not a hard fault...

    KnarfB
    KnarfBBest answer
    Super User
    February 14, 2023

    Here is an excellent overview: https://wiki.segger.com/Cortex-M_Fault with code.

    If you don't make your variables volatile, the compiler can optimize the div away, especially if b is a compile-time known constant. Disasm may help here too.

    hth

    KnarfB

    Associate III
    February 15, 2023

    @KnarfB​  Thank you