After searching for while i attempted myself with the understanding from the datasheet.
It works. Hope it helps someone in need. Thanks to @TDK .
Code snippet for SEVONPEND = 1 as below
int main(void)
{
/* Add your application code here */
__IO uint32_t tmpreg;
/* Enable clock for toggle LED */
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOIEN);
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOIEN);
/* Enable clock for switch input (EXTI) */
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
/* Enable clock for SYSCFG that connects switch to EXTI */
SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);
/* Configure toggle LED */
GPIOI->MODER |= GPIO_MODER_MODER15_0;
GPIOI->PUPDR |= GPIO_PUPDR_PUPDR15_0;
GPIOI->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR15;
GPIOI->BSRR= GPIO_BSRR_BS15; // Reset
/* Configure switch input */
GPIOC->PUPDR = 0;
GPIOC->MODER = 0;
SYSCFG->EXTICR[3] = 0x20;
EXTI->IMR = 0x2000;
EXTI->EMR = 0;
EXTI->RTSR = 0x2000;
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
/* Infinite loop */
while (1)
{
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Ensure that all instructions done before entering SLEEP mode */
__DSB();
__ISB();
/* Request Wait For Event */
__SEV();
__WFE();
__WFE();
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
/* Clear the flag responding to the event */
EXTI->PR = 0x2000;
while (EXTI->PR != 0);
/* Clear the pending flag responding to the event in NVIC */
NVIC_ClearPendingIRQ(EXTI15_10_IRQn);
ToggleLed();
}
}
Code snippet for SEVONPEND = 0 as below
int main(void)
{
/* Add your application code here */
__IO uint32_t tmpreg;
/* Enable clock for toggle LED */
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOIEN);
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOIEN);
/* Enable clock for switch input (EXTI) */
SET_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
tmpreg = READ_BIT(RCC->AHB1ENR, RCC_AHB1ENR_GPIOCEN);
/* Enable clock for SYSCFG that connects switch to EXTI */
SET_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_SYSCFGEN);
/* Configure toggle LED */
GPIOI->MODER |= GPIO_MODER_MODER15_0;
GPIOI->PUPDR |= GPIO_PUPDR_PUPDR15_0;
GPIOI->OSPEEDR |= GPIO_OSPEEDR_OSPEEDR15;
GPIOI->BSRR= GPIO_BSRR_BS15; // Reset
/* Configure switch input */
GPIOC->PUPDR = 0;
GPIOC->MODER = 0;
SYSCFG->EXTICR[3] = 0x20;
EXTI->IMR = 0;
EXTI->EMR = 0x2000;
EXTI->RTSR = 0x2000;
/* Infinite loop */
while (1)
{
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Ensure that all instructions done before entering SLEEP mode */
__DSB();
__ISB();
/* Request Wait For Event */
__SEV();
__WFE();
__WFE();
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= (uint32_t)~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
ToggleLed();
}
}