WatchDog doesn't do anything on my K60N512 tower!

cancel
Showing results for 
Search instead for 
Did you mean: 

WatchDog doesn't do anything on my K60N512 tower!

Jump to solution
2,574 Views
r_letourneur
Contributor III

Hi please could you help me why the command :  scb->AIRCR |= SCB_AIRCR_SYSRESETREQ_MASK;

doesn't do a reboot on my K60N512 kit when time time dog is elapsed!

Regards.

 

see below my code used :

 


/*FUNCTION*------------------------------------------------------
*
* Function Name  : handle_watchdog_expiry
* Returned Value : none
* Comments       :
*     This function is called when a watchdog has expired.
*END*-----------------------------------------------------------*/

void handle_watchdog_expiry
   (
      pointer td_ptr
   )
{
  printf("\n\rWatchdog expired for task: 0x%P", td_ptr);

  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCB_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->AIRCR);
  printf("\n\rAIRCR Register : 0x%P", scb->AIRCR);
 
  // Reboot...  
  scb->AIRCR |= SCB_AIRCR_SYSRESETREQ_MASK;

  // __boot();    The boot Branch do nothing!...
  // _mqx_exit(1);   

}

/*FUNCTION*------------------------------------------------------
*
* Function Name  : Init_Task(uint_32 data)
* Returned Value : none
* Comments       :
*     Kick-start all the other tasks used in this demo.
*END*-----------------------------------------------------------*/

void Init_Task(uint_32 data)
{
  uint_32 result;
 
  printf("\n\nKinetiSecure TWR-K60N512 MQX \n");
  printf("\n_mqx_generic_revision : %d \n", _mqx_generic_revision);
 

  /* Create watchdog component. */
   result = _watchdog_create_component(BSP_TIMER_INTERRUPT_VECTOR,
      handle_watchdog_expiry);
   if (result != MQX_OK) {
      printf("\nError creating watchdog component!");
      _mqx_exit(0);
   }




void main(
{
      /* Start watchdog component until 2ms the watchdog expires. */
      if(_watchdog_start(2000) == FALSE){
        printf("\nError starting watchdog component!");
        _mqx_exit(0);
      }    
etc....

}

0 Kudos
1 Solution
282 Views
DavidS
NXP Employee
NXP Employee

I found the solution hidden in Reference Manual that I had to register and download from ARM.com.  Read the comments ....here is the entire code to replace in the wacthdog.c file in the FSLMQX/mqx/examples/watchdog example:

 

void handle_watchdog_expiry
   (
      pointer td_ptr
   )
{
#if 1   //DES 1=test,0=default
  unsigned int temp_AIRCR=0;
//DES  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCB_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->AIRCR);
  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->SCB);
  temp_AIRCR = (unsigned int)scb->AIRCR;   //Read AIRCR register
  printf("\n\rREAD AIRCR Register : 0x%08P", temp_AIRCR);  //print what was read from AIRCR
  temp_AIRCR &= 0x0000ffff;   //DES mask of the top 16-bits
  temp_AIRCR |= 0x05Fa0000;   //DES When writing to AIRCR the update 16-bit must be "0x05FA" per ARMv7-M Architecture Reference Manual (must register on ARM.com to get)
  temp_AIRCR |= SCB_AIRCR_SYSRESETREQ_MASK;   //DES set the SYSRESETREQ bit to generate software reset
  printf("\n\rWRITE AIRCR Register : 0x%08P", temp_AIRCR);  //print what will be written to AIRCR
  // Reboot... 
  scb->AIRCR = temp_AIRCR;
 
  for(;:smileywink:{}
#endif

   printf("\nWatchdog expired for task: 0x%P", td_ptr);
   _mqx_exit(1);
}

 

Regards,

David

View solution in original post

0 Kudos
7 Replies
282 Views
DavidS
NXP Employee
NXP Employee

I found one error in your code.

//DES  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCB_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->AIRCR);


  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->SCB);

 

Arm7 Reference manual also said software reset might not be instantaneous and the access to AIRCR should be followed with infinite loop.

I tried that but still do not see a reset occuring.

Will keep trying.

Regards,

David

0 Kudos
283 Views
DavidS
NXP Employee
NXP Employee

I found the solution hidden in Reference Manual that I had to register and download from ARM.com.  Read the comments ....here is the entire code to replace in the wacthdog.c file in the FSLMQX/mqx/examples/watchdog example:

 

void handle_watchdog_expiry
   (
      pointer td_ptr
   )
{
#if 1   //DES 1=test,0=default
  unsigned int temp_AIRCR=0;
//DES  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCB_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->AIRCR);
  VCORTEX_SCB_STRUCT_PTR scb = (VCORTEX_SCB_STRUCT_PTR)&(((CORTEX_SCS_STRUCT_PTR)CORTEX_PRI_PERIPH_IN_BASE)->SCB);
  temp_AIRCR = (unsigned int)scb->AIRCR;   //Read AIRCR register
  printf("\n\rREAD AIRCR Register : 0x%08P", temp_AIRCR);  //print what was read from AIRCR
  temp_AIRCR &= 0x0000ffff;   //DES mask of the top 16-bits
  temp_AIRCR |= 0x05Fa0000;   //DES When writing to AIRCR the update 16-bit must be "0x05FA" per ARMv7-M Architecture Reference Manual (must register on ARM.com to get)
  temp_AIRCR |= SCB_AIRCR_SYSRESETREQ_MASK;   //DES set the SYSRESETREQ bit to generate software reset
  printf("\n\rWRITE AIRCR Register : 0x%08P", temp_AIRCR);  //print what will be written to AIRCR
  // Reboot... 
  scb->AIRCR = temp_AIRCR;
 
  for(;:smileywink:{}
#endif

   printf("\nWatchdog expired for task: 0x%P", td_ptr);
   _mqx_exit(1);
}

 

Regards,

David

0 Kudos
282 Views
r_letourneur
Contributor III

Hi DavidS, thank for your help so I have tried your code but nothing append when the watchdog interrupt is done! the processor doesn't do any reboot! So the printed value of AIRCR register is 0xFA050000 and not 0x05FA0000 is it normal?. I haven't the signification AIRCR bits documentation may be there is an error? So what I have to do for reaching a complete cortex M4 register documentation?

Regards.

0 Kudos
282 Views
r_letourneur
Contributor III

I finaly found the Cortex M4 datasheet. So the 0xFA050000 read value is normal in the SCR. The 0x05FA high value is the vectkey to validate the write access to the SCR register with the SYSRESETREQ bit 4 set. Finaly the AIRCR value written is 0x05FA0004. ButI don't understand why the CPU doesn't reboot after!!

0 Kudos
282 Views
DavidS
NXP Employee
NXP Employee

There are two printf's...one prints the AIRCR value that is read from the register (0xFA050000), the other is the value I want to write to the AIRCR register (0x05FA0004).

As soon as I write to the AIRCR register, I get a software reset and my debugger is pointing to the __boot (i.e. beginning code).

Please ensure you have compiled the RTOS fully and use the FSLMQX/mqx/examples/watchdog project with my code above to see if it will work.  If it still doesn't....then we'll have to do more thinking.

Regards,

David

0 Kudos
282 Views
r_letourneur
Contributor III

Oups!... Sorry DaviS thanks your code is ok, now the cpu make a reboot! The SCR value written was wrong before.

Regards.

0 Kudos
282 Views
KJFPE
Contributor III

Just in case this is any help in the bsp (C:\Program Files\Freescale\Freescale MQX 3.6\mqx\source\bsp\twrk60n512)

In the kinetis_init function have a look at kinetis_wdt_disable

0 Kudos