AnsweredAssumed Answered

Hard Fault When Watchdog Unlock is Written (MK20FX512)

Question asked by nicholasf on Jan 15, 2014
Latest reply on Nov 18, 2015 by Butcher

I have a program which is about 200KB, and I am attempting to run on an MK20FX512, using Codewarrior for the download and debug.  When the standard CW generated __init_hardware() runs, and attempts to write to the watchdog unlock register, a hard fault interrupt is generated (by the strh instruction) and the processor is reset.

 

          __init_hardware:

21        SCB_VTOR = (uint32_t)__vector_table; /* Set the interrupt vector table position */

00000800:   ldr r1,[pc,#0x34]

00000804:   movw r0,#0xed08

00000808:   movt r0,#0xe000

0000080c:   str r1,[r0,#0]

35       *(volatile unsigned short *)KINETIS_WDOG_UNLOCK_ADDR = KINETIS_WDOG_UNLOCK_SEQ_1;

0000080e:   movw r1,#0xc520

00000812:   movw r0,#0x200e

00000816:   movt r0,#0x4005

0000081a:   strh r1,[r0,#0] // INTERRUPT GENERATED HERE

 

It is also worth noting that when this same initialization is run in a different project (with smaller code size), no interrupt is generated.

 

Another interesting fact is that if I refresh the watchdog instead of trying to unlock it, no hard fault is generated, but the processor has another interrupt when it attempts to initialize the stack pointer (after __init_hardware).

 

  lda r0,__SP_INIT

  // skip stack setup if __SP_INIT is 0

  // assume sp is already setup.

  cmp r0,#0

  beq skip_sp

  mov sp,r0

  sub sp,#4

  mov r0,#0

  mvn r0,r0

  str r0,[sp,#0]

  add sp,#4 // INTERRUPT GENERATED HERE

skip_sp:

Outcomes