WDOG cannot use 8-bit sequence refresh

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

WDOG cannot use 8-bit sequence refresh

Jump to solution
773 Views
GXY
Contributor III

I am unable to use 4 8-bit writes to refresh the watchdog of S32K144. Both 16 bit and 32-bit are acceptable, but 8-bit is not. I tried the 8-bit writing method in the picture, but it all failedThe original manual is as follows:

The refresh write sequence can be
• either two 16-bit writes ( 0xA602, 0xB480) or four 8-bit writes (0xA6, 0x02, 0xB4,
0x80) if WDOG_CS[CMD32EN] is 0;
• one 32-bit write (0xB480_A602) if WDOG_CS[CMD32EN] is 1.
to the CNT register. Both methods must occur before the WDG timeout; otherwise, the
watchdog resets the MCU.

 

0 Kudos
Reply
1 Solution
677 Views
db16122
Contributor III

Before starting the refresh sequence, disable the global
interrupts. Otherwise, an interrupt could effectively invalidate
the refresh sequence, if the interrupt occurs before the refresh
writes finish. After the sequence finishes, restore the global
interrupt control state.  FYI for interrupt checking

View solution in original post

0 Kudos
Reply
3 Replies
44 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @GXY,

The WDOG supports an 8-bit refresh sequence, but it is highly timing-sensitive. Even if standard C code generates STRB instructions, the sequence can fail due to additional stack accesses or address reloads inserted between the byte writes. Using a compact GCC inline assembly block helps ensure the 8-bit refresh executes reliably.

static inline void WDOG_Refresh8_AsmInline(void)
{
 __asm volatile(
 // "mrs r2, PRIMASK \n"
 // "cpsid i \n"
 // "dsb \n"

 "ldr r0, =0x40052004 \n"

 "movs r1, #0xA6 \n"
 "strb r1, [r0, #1] \n"

 "movs r1, #0x02 \n"
 "strb r1, [r0, #0] \n"

 "movs r1, #0xB4 \n"
 "strb r1, [r0, #1] \n"

 "movs r1, #0x80 \n"
 "strb r1, [r0, #0] \n"

 // "dsb \n"
 // "isb \n"
 // "msr PRIMASK, r2 \n"
 );
}

 

Regards,

Daniel

678 Views
db16122
Contributor III

Before starting the refresh sequence, disable the global
interrupts. Otherwise, an interrupt could effectively invalidate
the refresh sequence, if the interrupt occurs before the refresh
writes finish. After the sequence finishes, restore the global
interrupt control state.  FYI for interrupt checking

0 Kudos
Reply
621 Views
GXY
Contributor III

I confirm that the switch was interrupted before and after feeding the dog. In the same scenario, only changing the feeding sequence and using the 16 bit feeding method succeeded, but the 8-bit feeding method failed, and adjusting the order of the 8-bit feeding sequence did not work.

0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2363091%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EWDOG%20cannot%20use%208-bit%20sequence%20refresh%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2363091%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20am%20unable%20to%20use%204%208-bit%20writes%20to%20refresh%20the%20watchdog%20of%20S32K144.%20Both%2016%20bit%20and%2032-bit%20are%20acceptable%2C%20but%208-bit%20is%20not.%20I%20tried%20the%208-bit%20writing%20method%20in%20the%20picture%2C%20but%20it%20all%20failedThe%20original%20manual%20is%20as%20follows%3A%3C%2FP%3E%3CP%3EThe%20refresh%20write%20sequence%20can%20be%3CBR%20%2F%3E%E2%80%A2%20either%20two%2016-bit%20writes%20(%200xA602%2C%200xB480)%20or%20four%208-bit%20writes%20(0xA6%2C%200x02%2C%200xB4%2C%3CBR%20%2F%3E0x80)%20if%20WDOG_CS%5BCMD32EN%5D%20is%200%3B%3CBR%20%2F%3E%E2%80%A2%20one%2032-bit%20write%20(0xB480_A602)%20if%20WDOG_CS%5BCMD32EN%5D%20is%201.%3CBR%20%2F%3Eto%20the%20CNT%20register.%20Both%20methods%20must%20occur%20before%20the%20WDG%20timeout%3B%20otherwise%2C%20the%3CBR%20%2F%3Ewatchdog%20resets%20the%20MCU.%3C%2FP%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2364476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20WDOG%20cannot%20use%208-bit%20sequence%20refresh%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2364476%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EBefore%20starting%20the%20refresh%20sequence%2C%20disable%20the%20global%3CBR%20%2F%3Einterrupts.%20Otherwise%2C%20an%20interrupt%20could%20effectively%20invalidate%3CBR%20%2F%3Ethe%20refresh%20sequence%2C%20if%20the%20interrupt%20occurs%20before%20the%20refresh%3CBR%20%2F%3Ewrites%20finish.%20After%20the%20sequence%20finishes%2C%20restore%20the%20global%3CBR%20%2F%3Einterrupt%20control%20state.%26nbsp%3B%20FYI%20for%20interrupt%20checking%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2365277%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20WDOG%20cannot%20use%208-bit%20sequence%20refresh%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2365277%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EI%20confirm%20that%20the%20switch%20was%20interrupted%20before%20and%20after%20feeding%20the%20dog.%20In%20the%20same%20scenario%2C%20only%20changing%20the%20feeding%20sequence%20and%20using%20the%2016%20bit%20feeding%20method%20succeeded%2C%20but%20the%208-bit%20feeding%20method%20failed%2C%20and%20adjusting%20the%20order%20of%20the%208-bit%20feeding%20sequence%20did%20not%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2381320%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20WDOG%20cannot%20use%208-bit%20sequence%20refresh%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2381320%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F254513%22%20target%3D%22_blank%22%3E%40GXY%3C%2FA%3E%2C%3C%2FP%3E%0A%3CP%3EThe%20WDOG%20supports%20an%208-bit%20refresh%20sequence%2C%20but%20it%20is%20highly%20timing-sensitive.%20Even%20if%20standard%20C%20code%20generates%20STRB%20instructions%2C%20the%20sequence%20can%20fail%20due%20to%20additional%20stack%20accesses%20or%20address%20reloads%20inserted%20between%20the%20byte%20writes.%20Using%20a%20compact%20GCC%20inline%20assembly%20block%20helps%20ensure%20the%208-bit%20refresh%20executes%20reliably.%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CPRE%20class%3D%22lia-code-sample%20language-c%22%3E%3CCODE%3Estatic%20inline%20void%20WDOG_Refresh8_AsmInline(void)%0A%7B%0A%20__asm%20volatile(%0A%20%2F%2F%20%22mrs%20r2%2C%20PRIMASK%20%5Cn%22%0A%20%2F%2F%20%22cpsid%20i%20%5Cn%22%0A%20%2F%2F%20%22dsb%20%5Cn%22%0A%0A%20%22ldr%20r0%2C%20%3D0x40052004%20%5Cn%22%0A%0A%20%22movs%20r1%2C%20%230xA6%20%5Cn%22%0A%20%22strb%20r1%2C%20%5Br0%2C%20%231%5D%20%5Cn%22%0A%0A%20%22movs%20r1%2C%20%230x02%20%5Cn%22%0A%20%22strb%20r1%2C%20%5Br0%2C%20%230%5D%20%5Cn%22%0A%0A%20%22movs%20r1%2C%20%230xB4%20%5Cn%22%0A%20%22strb%20r1%2C%20%5Br0%2C%20%231%5D%20%5Cn%22%0A%0A%20%22movs%20r1%2C%20%230x80%20%5Cn%22%0A%20%22strb%20r1%2C%20%5Br0%2C%20%230%5D%20%5Cn%22%0A%0A%20%2F%2F%20%22dsb%20%5Cn%22%0A%20%2F%2F%20%22isb%20%5Cn%22%0A%20%2F%2F%20%22msr%20PRIMASK%2C%20r2%20%5Cn%22%0A%20)%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FBLOCKQUOTE%3E%0A%3CBR%20%2F%3E%0A%3CP%3ERegards%2C%3C%2FP%3E%0A%3CP%3EDaniel%3C%2FP%3E%3C%2FLINGO-BODY%3E