This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Watchdog

When a watchdog timeout occurs, it could be the result of many causes. The code could be 'out in space' due to a bad pointer corrupting anything it wants to. It could be due to a fault condition that did not affect data space. Who knows?

Since the watchdog reset is considered a 'hard reset' we know where it will then start execution from.

If I want to save existing data ram into flash prior to executing __main() I would think the place to do this would be here:

; Reset Handler
Reset_Handler   PROC
                EXPORT  Reset_Handler             [WEAK]
                IMPORT  __main
                LDR     R0, =__main
                BX      R0
                ENDP

I could jump into a routine which calls an IAP command to save RAM to flash and then return to finish the startup.

I would have to EXPORT the routine I want to jump to as well as load the LR with the return value. Is there anything else that I am missing?

BTW: the processor is a Cortex M3 core.

Thanks.

  • isn't it better to trigger an interrupt in case of a watchdog violation, save to non-volatile memory, and then reprogram the watchdog to actually reset the system...?

  • According to the users manual:

    "...the intent of the watchdog interrupt is to allow debugging watchdog activity without resetting the device when the watchdog overflows."

    "Watchdog reset mode: operate with the Watchdog interrupt and WDRESET enabled. When this mode is selected, a watchdog counter underflow will reset the microcontroller. Although the Watchdog interrupt is also enabled in this case (WDEN = 1) it will not be recognized since the watchdog reset will clear the WDINT flag."

    "Once the WDEN and/or WDRESET bits are set they can not be cleared by software."

    So the watchdog can either be set for INT or RESET, but once set thats it. It must be set for a RESET condition. Earlier tests I ran confirm this behavior.

  • then set a flag in a none-ZI section indicating a watchdog reset. you can then backup what you need in the next startup!

  • He most probably already know that a watchdog reset has happened - most chips has a flag to find out the reset reason.

    The question is the best way to patch in the flash write befire the C startup code starts to mess with the RAM contents.

  • What about $Super$$ ?
    The OP can override __main that way.

  • This seems to do what I want (albeit crude .asm code).

    But a side effect is that when I do an SVC call I get a hard fault (still working on it - is probably related as I was not getting them before).

    ; Reset Handler
    Reset_Handler   PROC
                    EXPORT  Reset_Handler             [WEAK]
                    IMPORT  __main
                    IMPORT  GoFlash
    
                    LDR     R0, =0x400FC180 ; load RSID
                    LDR     R0, [R0]        ; load value at RSID
                    TST     R0,#0x02        ; Is W/D timeout?
                    BNE     __GoBoot        ; No, skip next
                    BL      GoFlash         ; Go Save Flash
    
    __GoBoot        LDR     LR, =0          ; Boot
                    LDR     R0, =__main
                    BX      R0
                    ENDP
    

    Tamir, I need to look into this $Super$$ - what it is about.

    Thanks.

  • See your linker and utilities guide, paragraph 4.5 ("Using $Super$$ and $Sub$$ to override symbol definitions").

  • My bad.

    Same .asm code is used for both. Did open my damn eyes enough.

    __asm void SVC_Handler(void)
    {
            IMPORT SVC_Handler_C
            TST lr, #4
            MRSEQ r0, MSP
            MRSNE r0, PSP
            B SVC_Handler_C
    }
    
    __asm void HardFault_Handler(void)
    {
            IMPORT HardFault_Handler_C
            TST LR, #4
            MRSEQ R0, MSP
            MRSNE R0, PSP
            B HardFault_Handler_C
    }
    

    FYI: The above code seems to work fine - so far.