I tried (and failed) to create a working project to test deep sleep micro functionality.
I configured NMI pin as pin26 and have micro to go to sleep after it receives this interrupt. This part seems to work properly.
I also configured pin 35 al LLWU_P5 source on rising edge, my intent was to have a rising front wake the micro up from sleeping mode.
This part does not seem to work at all, What am I missing?
This is the very simple code of my program, all initialization are taken care by the SDK
bool goToSleep = false;
/* TODO: insert other definitions and declarations here. */
void APP_PowerModeSwitch()
{
smc_power_mode_vlls_config_t vlls_config;
vlls_config.enablePorDetectInVlls0 = true;
vlls_config.enableLpoClock = true;
vlls_config.subMode = kSMC_StopSub1;
SMC_PreEnterStopModes();
SMC_SetPowerModeVlls(SMC, &vlls_config);
SMC_PostExitStopModes();
}
/*
* @brief Application entry point.
*/
int main(void) {
/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
printf("Hello World\n");
/* Force the counter to be placed into memory. */
volatile static int i = 0 ;
//Toggle LED
GPIO_PortToggle(BOARD_INITPINS_GREEN_LED_GPIO, BOARD_INITPINS_GREEN_LED_GPIO_PIN_MASK);
/* Unlock all the power modes of chip. */
SMC_SetPowerModeProtection(SMC, kSMC_AllowPowerModeAll);
// Clear the low power lock bit.
if (kRCM_SourceWakeup & RCM_GetPreviousResetSources(RCM)) // Wakeup from VLLS
{
PMC_ClearPeriphIOIsolationFlag(PMC);
NVIC_ClearPendingIRQ(LLWU_IRQn);
//Toggle LED
GPIO_PortToggle(BOARD_INITPINS_GREEN_LED_GPIO, BOARD_INITPINS_GREEN_LED_GPIO_PIN_MASK);
}
//APP_PowerModeSwitch();
//GPIO_PinWrite(BOARD_INITPINS_TEST_PIN_GPIO, BOARD_INITPINS_TEST_PIN_PIN, 1);
/* Enter an infinite loop, just incrementing a counter. */
while(1)
{
i++ ;
if (i==0x0000FFFF)
{
//Toggle LED
GPIO_PortToggle(BOARD_INITPINS_GREEN_LED_GPIO, BOARD_INITPINS_GREEN_LED_GPIO_PIN_MASK);
//
i = 0;
}
if(goToSleep == true)
{
goToSleep = false;
APP_PowerModeSwitch();
}
/* 'Dummy' NOP to allow source level single stepping of
tight while() loop */
__asm volatile ("nop");
}
return 0 ;
}
/* LLWU_IRQn interrupt handler */
void LLWU_IRQHANDLER(void) {
/* Place your code here */
asm("nop");
PMC_ClearPeriphIOIsolationFlag(PMC);
NVIC_ClearPendingIRQ(LLWU_IRQn);
NVIC_SystemReset();
//Toggle LED
//GPIO_PortToggle(BOARD_INITPINS_GREEN_LED_GPIO, BOARD_INITPINS_GREEN_LED_GPIO_PIN_MASK);
//while(1);
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F
Store immediate overlapping exception return operation might vector to incorrect interrupt. */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}
void NMI_Handler(void)
{
goToSleep = true;
}