Hi Gary Lynch,
Our FAE also transfer your question to me!
I already help you check your code, this code will enter in the DefaultISR, because I find in the void LLWU_init(void) function, it even didn't enable the LLWU module clock, then if you configure the LLWU register, it will enter in DefaultISR.
So you should write function LLWU_init(void) like this:
void LLWU_init(void) {
/* + + + + + + + + + + + + + + + + + */
/* Configure LLWU_P2 pin to trigger */
/* an interrupt on rising edge */
/* + + + + + + + + + + + + + + + + + */
// LLWU_PE1_REG(LLWU_BASE_PTR) = (0x1U << 4);
//
SIM_SCGC4 |= SIM_SCGC4_LLWU_MASK;
LLWU_PE1 = LLWU_PE1_WUPE2(0X1);//rising wakeup
LLWU_F1 = LLWU_F1_WUF2_MASK;
return;
} /* END LLWU_init() */
Besides, I also help you do some modifications:
1, enable the internal pullup resistor in the PTE4 which used as the wakeup source.
2. The ENTER_VLLS3 function write as follows:
void ENTER_VLLS3(void)
{
volatile unsigned int dummyread;
SMC_PMPROT = SMC_PMPROT_AVLLS_MASK;
/* Set the STOPM field to 0b100 for VLLS3 mode */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x4);
SCB->SCR &= (unsigned int)~(unsigned int)(SCB_SCR_SLEEPONEXIT_Msk);
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/*wait for write to complete to SMC before stopping core */
dummyread = SMC_PMCTRL;
/* Now execute the stop instruction to go into LLS */
//stop();
__asm__("WFI"); //KDS
//asm("WFI"); //Iar
}
3. #define CLOCK_SETUP as 0, then it will configure the system clock as the default clock, and also configure the according register as follows:
#if (CLOCK_SETUP == 0)
#define DEFAULT_SYSTEM_CLOCK 20971520U /* Default System clock value */
#define MCG_MODE MCG_MODE_FEI /* Clock generator mode */
/* MCG_C1: CLKS=0,FRDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=0 */
#define SYSTEM_MCG_C1_VALUE 0x06U /* MCG_C1 */
/* MCG_C2: LOCRE0=0,RANGE0=2,HGO0=0,EREFS0=1,LP=0,IRCS=0 */
#define SYSTEM_MCG_C2_VALUE 0x24U /* MCG_C2 */
/* MCG_C4: DMX32=0,DRST_DRS=0,FCTRIM=0,SCFTRIM=0 */
#define SYSTEM_MCG_C4_VALUE 0x00U /* MCG_C4 */
/* MCG_SC: ATME=0,ATMS=0,ATMF=0,FLTPRSRV=0,FCRDIV=0,LOCS0=0 */
#define SYSTEM_MCG_SC_VALUE 0x00U /* MCG_SC */
/* MCG_C5: PLLCLKEN0=0,PLLSTEN0=0,PRDIV0=0 */
#define SYSTEM_MCG_C5_VALUE 0x00U /* MCG_C5 */
/* MCG_C6: LOLIE0=0,PLLS=0,CME0=0,VDIV0=0 */
#define SYSTEM_MCG_C6_VALUE 0x00U /* MCG_C6 */
/* MCG_C7: OSCSEL=0 */
#define SYSTEM_MCG_C7_VALUE 0x00U /* MCG_C7 */
/* OSC_CR: ERCLKEN=1,EREFSTEN=0,SC2P=0,SC4P=0,SC8P=0,SC16P=0 */
#define SYSTEM_OSC_CR_VALUE 0x80U /* OSC_CR */
/* SMC_PMCTRL: LPWUI=0,RUNM=0,STOPA=0,STOPM=0 */
#define SYSTEM_SMC_PMCTRL_VALUE 0x00U /* SMC_PMCTRL */
/* SIM_CLKDIV1: OUTDIV1=0,OUTDIV2=0,OUTDIV3=1,OUTDIV4=1 */
#define SYSTEM_SIM_CLKDIV1_VALUE 0x00110000U /* SIM_CLKDIV1 */
/* SIM_SOPT1: USBREGEN=0,USBSSTBY=0,USBVSTBY=0,OSC32KSEL=3,RAMSIZE=0 */
#define SYSTEM_SIM_SOPT1_VALUE 0x000C0000U /* SIM_SOPT1 */
/* SIM_SOPT2: SDHCsrc=0,USBsrc=0,PLLFLLSEL=0,TRACECLKSEL=0,PTD7PAD=0,FBSL=0,CLKOUTSEL=0,RTCCLKOUTSEL=0 */
#define SYSTEM_SIM_SOPT2_VALUE 0x00U /* SIM_SOPT2 */
After the above modification, I can use your code working ok on my side, it will wait about 5 seconds then enter in the VLLS3, the power consumption is about 8uA.
Then if you give a external rising wave in the PTE4 pin, the MCU will wake up and wait 5 seconds, enter the VLLS3 again...
You can test my project on your side, the project is the KDS3.0 project, please find the project from the attachment.
Wish it helps you!
If you still have question, please let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------