WatchDOG can't work in Release mode(KDS3.0 build)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

WatchDOG can't work in Release mode(KDS3.0 build)

Jump to solution
874 Views
icelee
Contributor III

hello


I ported WatchDOG driver of KSDK2.0 into MQX 4.2.0.2.
and test on FRDM-K64F.

 

SDK_2.0_FRDM-K64F/devices/MK64F12/drivers
fsl_wdog.c
fsl_wdog.h

 

When I build F/W with debug mode(KDS3.0), WatchDOG can work.
But When I build with release mode(KDS3.0), WatchDOG not working.


Could anyone know about this?

Thanks.

Labels (1)
0 Kudos
Reply
1 Solution
715 Views
icelee
Contributor III

Hi Jorge Alcala

Thank you for your advance.

Yes, i'm using KDS3.0.
And my project's Optimization Level is default.
・release mode: Optimize size (-Os)
・debug mode: None (-O0)

As your advance, I changed the level below the under in release mode.
・Optimize most (-O3)  
・Optimize more (-O2)  
・Optimize (-O1)       
But WDOG still can't work.
Only the level was set to None (-O0) same as debug mode, WDOG working.


------------------------------------------------------------------------------


[Real Reason]

Next, I built the wdog example (SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\wdog)
in release mode with Optimize size (-Os) level,
And when I tried to run it , I found wdog can work!!!

So the real reason may be the Problem in the process of porting code (WatchDOG driver of KSDK2.0 into MQX 4.2.0.2).
I checked the code, especially associated with Optimization.
Finally, I found the reason.


●In SDK_2.0, WDOG using the struct WDOG_Type below

#define     __IO    volatile             /*!< Defines 'read / write' permissions */

typedef struct {
  __IO uint16_t STCTRLH;                           /**< Watchdog Status and Control Register High, offset: 0x0 */
  __IO uint16_t STCTRLL;                           /**< Watchdog Status and Control Register Low, offset: 0x2 */
  __IO uint16_t TOVALH;                            /**< Watchdog Time-out Value Register High, offset: 0x4 */
  __IO uint16_t TOVALL;                            /**< Watchdog Time-out Value Register Low, offset: 0x6 */
  __IO uint16_t WINH;                              /**< Watchdog Window Register High, offset: 0x8 */
  __IO uint16_t WINL;                              /**< Watchdog Window Register Low, offset: 0xA */
  __IO uint16_t REFRESH;                           /**< Watchdog Refresh register, offset: 0xC */
  __IO uint16_t UNLOCK;                            /**< Watchdog Unlock register, offset: 0xE */
  __IO uint16_t TMROUTH;                           /**< Watchdog Timer Output Register High, offset: 0x10 */
  __IO uint16_t TMROUTL;                           /**< Watchdog Timer Output Register Low, offset: 0x12 */
  __IO uint16_t RSTCNT;                            /**< Watchdog Reset Count register, offset: 0x14 */
  __IO uint16_t PRESC;                             /**< Watchdog Prescaler register, offset: 0x16 */
} WDOG_Type;

●In MQX4.2, WDOG using the struct WDOG_MemMap below

typedef struct WDOG_MemMap {
  uint16_t STCTRLH;                                /**< Watchdog Status and Control Register High, offset: 0x0 */
  uint16_t STCTRLL;                                /**< Watchdog Status and Control Register Low, offset: 0x2 */
  uint16_t TOVALH;                                 /**< Watchdog Time-out Value Register High, offset: 0x4 */
  uint16_t TOVALL;                                 /**< Watchdog Time-out Value Register Low, offset: 0x6 */
  uint16_t WINH;                                   /**< Watchdog Window Register High, offset: 0x8 */
  uint16_t WINL;                                   /**< Watchdog Window Register Low, offset: 0xA */
  uint16_t REFRESH;                                /**< Watchdog Refresh register, offset: 0xC */
  uint16_t UNLOCK;                                 /**< Watchdog Unlock register, offset: 0xE */
  uint16_t TMROUTH;                                /**< Watchdog Timer Output Register High, offset: 0x10 */
  uint16_t TMROUTL;                                /**< Watchdog Timer Output Register Low, offset: 0x12 */
  uint16_t RSTCNT;                                 /**< Watchdog Reset Count register, offset: 0x14 */
  uint16_t PRESC;                                  /**< Watchdog Prescaler register, offset: 0x16 */
} volatile *WDOG_MemMapPtr;


I just wrote the "typedef struct WDOG_MemMap WDOG_Type;" code to use "WDOG_Type" in MQX4.2.
And this was the problem.

Every member in WDOG_Type has __IO (volatile) definition.
But WDOG_MemMap hasn't.

volatile is the key of optimize inhibition.
Without volatile, Watchdog Register may not execute in the step you wanted because of Optimization.


------------------------------------------------------------------------------


[Solution]

Finally, my solution is exchange "WDOG_Type *" to "WDOG_MemMapPtr".
And confirmed WDOG can work in release mode( Optimize size (-Os)).

Last, thanks your help.
Have a good day.

View solution in original post

0 Kudos
Reply
2 Replies
715 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Bing Li

This problem is related with the optimization options:

  1. Debug builds have debugging and symbolic information included. The compiler is not optimizing to make debugging ‘easier’.
  2. Release builds have the debugging and symbolic information (Dwarf in ELF/Dwarf files) stripped off. Optimizations are enabled for best performance or code density.

Are you using KDS? in KDS you can switch optimization options in right click->proprieties->C/C++ Build->Settings and in the Tools Settings tab, select optimization, change it to the level that you want (debug has it as none).

For futher information please consult:

Debug vs. Release? | MCU on Eclipse 

Hope this information helps you
Have a great day,
Jorge Alcala

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

0 Kudos
Reply
716 Views
icelee
Contributor III

Hi Jorge Alcala

Thank you for your advance.

Yes, i'm using KDS3.0.
And my project's Optimization Level is default.
・release mode: Optimize size (-Os)
・debug mode: None (-O0)

As your advance, I changed the level below the under in release mode.
・Optimize most (-O3)  
・Optimize more (-O2)  
・Optimize (-O1)       
But WDOG still can't work.
Only the level was set to None (-O0) same as debug mode, WDOG working.


------------------------------------------------------------------------------


[Real Reason]

Next, I built the wdog example (SDK_2.0_FRDM-K64F\boards\frdmk64f\driver_examples\wdog)
in release mode with Optimize size (-Os) level,
And when I tried to run it , I found wdog can work!!!

So the real reason may be the Problem in the process of porting code (WatchDOG driver of KSDK2.0 into MQX 4.2.0.2).
I checked the code, especially associated with Optimization.
Finally, I found the reason.


●In SDK_2.0, WDOG using the struct WDOG_Type below

#define     __IO    volatile             /*!< Defines 'read / write' permissions */

typedef struct {
  __IO uint16_t STCTRLH;                           /**< Watchdog Status and Control Register High, offset: 0x0 */
  __IO uint16_t STCTRLL;                           /**< Watchdog Status and Control Register Low, offset: 0x2 */
  __IO uint16_t TOVALH;                            /**< Watchdog Time-out Value Register High, offset: 0x4 */
  __IO uint16_t TOVALL;                            /**< Watchdog Time-out Value Register Low, offset: 0x6 */
  __IO uint16_t WINH;                              /**< Watchdog Window Register High, offset: 0x8 */
  __IO uint16_t WINL;                              /**< Watchdog Window Register Low, offset: 0xA */
  __IO uint16_t REFRESH;                           /**< Watchdog Refresh register, offset: 0xC */
  __IO uint16_t UNLOCK;                            /**< Watchdog Unlock register, offset: 0xE */
  __IO uint16_t TMROUTH;                           /**< Watchdog Timer Output Register High, offset: 0x10 */
  __IO uint16_t TMROUTL;                           /**< Watchdog Timer Output Register Low, offset: 0x12 */
  __IO uint16_t RSTCNT;                            /**< Watchdog Reset Count register, offset: 0x14 */
  __IO uint16_t PRESC;                             /**< Watchdog Prescaler register, offset: 0x16 */
} WDOG_Type;

●In MQX4.2, WDOG using the struct WDOG_MemMap below

typedef struct WDOG_MemMap {
  uint16_t STCTRLH;                                /**< Watchdog Status and Control Register High, offset: 0x0 */
  uint16_t STCTRLL;                                /**< Watchdog Status and Control Register Low, offset: 0x2 */
  uint16_t TOVALH;                                 /**< Watchdog Time-out Value Register High, offset: 0x4 */
  uint16_t TOVALL;                                 /**< Watchdog Time-out Value Register Low, offset: 0x6 */
  uint16_t WINH;                                   /**< Watchdog Window Register High, offset: 0x8 */
  uint16_t WINL;                                   /**< Watchdog Window Register Low, offset: 0xA */
  uint16_t REFRESH;                                /**< Watchdog Refresh register, offset: 0xC */
  uint16_t UNLOCK;                                 /**< Watchdog Unlock register, offset: 0xE */
  uint16_t TMROUTH;                                /**< Watchdog Timer Output Register High, offset: 0x10 */
  uint16_t TMROUTL;                                /**< Watchdog Timer Output Register Low, offset: 0x12 */
  uint16_t RSTCNT;                                 /**< Watchdog Reset Count register, offset: 0x14 */
  uint16_t PRESC;                                  /**< Watchdog Prescaler register, offset: 0x16 */
} volatile *WDOG_MemMapPtr;


I just wrote the "typedef struct WDOG_MemMap WDOG_Type;" code to use "WDOG_Type" in MQX4.2.
And this was the problem.

Every member in WDOG_Type has __IO (volatile) definition.
But WDOG_MemMap hasn't.

volatile is the key of optimize inhibition.
Without volatile, Watchdog Register may not execute in the step you wanted because of Optimization.


------------------------------------------------------------------------------


[Solution]

Finally, my solution is exchange "WDOG_Type *" to "WDOG_MemMapPtr".
And confirmed WDOG can work in release mode( Optimize size (-Os)).

Last, thanks your help.
Have a good day.

0 Kudos
Reply