hard fault with watchdog, bootloader K64

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

hard fault with watchdog, bootloader K64

跳至解决方案
1,952 次查看
PO220
Contributor IV

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

标签 (1)
0 项奖励
回复
1 解答
1,429 次查看
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

My colleague had written a document about tracking down hard faults.

Please check here to find the detailed info.

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

3 回复数
1,429 次查看
PO220
Contributor IV

Hi

I find solution thaks to https://community.nxp.com/thread/338114 

0 项奖励
回复
1,429 次查看
PO220
Contributor IV

Hi,

Thanks for hard fault debugging. I'm a fan of MCUoneclipse blog but I have missed this one Debugging ARM Cortex-M Hard Faults with GDB Custom Command | MCU on Eclipse, great !

In fact my problem has nothing to do with the watchdog!

To use the watchdog I had to optimize the size of my code with -Os option...  does it create alignment problems?

Would there be an option to not disrupt the jump with a -Os optimization?

Thanks

0 项奖励
回复
1,430 次查看
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

My colleague had written a document about tracking down hard faults.

Please check here to find the detailed info.

Wish it helps.


Have a great day,
Mike

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------