AnsweredAssumed Answered

hard fault with watchdog, bootloader K64

Question asked by PO220 on Jan 25, 2018
Latest reply on Jan 27, 2018 by PO220

Hi

 

I create a bootloader with a special protocol for a K64.

I encountered several problems of hard fault before the jump but I solved them by deactivating the modules and their interruptions.

I'm using KDS V3.2 with SDK2.

 

Without watchdog this jump works well (SD card and USB cdc) :

#define USER_APP_ADDRESS                0x00010000
#define USER_APP_MAX_SIZE               0x000F0000


if (*((unsigned long*)USER_APP_ADDRESS) != 0xFFFFFFFF)
{
   // Stop usb module and interruptions
   USB_deInit() ;


   //stop all interruptions
   __asm volatile ("cpsid i");

   // Stop SDcard interruptions and module
   SDHC_DisableInterruptStatus(SDHC, (uint32_t)kSDHC_AllInterruptFlags);
   SDHC_DisableInterruptSignal(SDHC, (uint32_t)kSDHC_AllInterruptFlags);
   DisableIRQ(BOARD_SDHC_IRQ);
   sd_disk_deinit();

   // Stop systick
   SysTick->CTRL = 0 ;

   __DSB(); //Data Synchronization Barrier.
   __ISB(); // Instruction Synchronization Barrier.

   //jump
   JumpToUserApplication(*((unsigned long*)USER_APP_ADDRESS), *((unsigned long*)(USER_APP_ADDRESS+4)));
}

void JumpToUserApplication(uint32_t userSP, uint32_t userStartup)
{
  __asm("msr msp, r0");
  __asm("msr psp, r0");
  __asm("mov pc,  r1");
}

if I activate the watchdog it works very well until the jump (hard fault)

if I disable it before the jump it does not change anything and this does not surprise me since it does not handle interruptions.

here is how i activate the watchdog

void Activate_wd(void)
{
wdog_config_t config ;

    WDOG_GetDefaultConfig(&config) ;
    config.timeoutValue = WATCHDOG_28_SECONDES ;
    WDOG_Init(wdog_base, &config) ;
    WaitWctClose(wdog_base) ;
}

void WaitWctClose(WDOG_Type *base)
{
    /* Accessing register by bus clock */
    for (uint32_t i = 0; i < 256; i++)
    {
        (void)base->RSTCNT;
    }
}

How can I avoid this hard fault?
How to know the exact origin at the time of the jump (the debug does not work at this time)
?

Thank you very much in advance

Outcomes