So I'm trying to put my microcontroller into deep sleep mode (stop) or the VLPS mode. In my code I'm calling a function that suppose to put the uC in sleep mode and then I would like to use a UART port as a wake up. From what I have read in STOP mode any interrupt should wake the microcontroller (without use of the LLWU). Here is a code that I'm using to put the system in sleep:
NVIC_EnableIRQ(UART4_RX_TX_IRQn); //enable UART4 interrupts
SMC_PMPROT = SMC_PMPROT_AVLP_MASK;
/* Set the STOPM field to 0b010 for VLPS mode */
SMC_PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC_PMCTRL |= SMC_PMCTRL_STOPM(0x2);
//exit to run on interrupt
SMC_PMCTRL |= SMC_PMCTRL_LPWUI_MASK;
/*wait for write to complete to SMC before stopping core */
dummyread = SMC_PMCTRL;
/* Now execute the stop instruction to go into VLPS */
/* Set the SLEEPDEEP bit to enable deep sleep mode - enter stop mode*/
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* WFI instruction will start entry into STOP mode */
There are multiple issues that I observed with both STOP and VLPS modes:
1. The current is regular RUN mode is around 40mA at 3V, which is what the datasheet specifies. After I execute the sleep instruction it decreases to around 25 mA, which is way to big. According to datasheet it should be around 0.5mA.
2. The system does not wake up, when I send any command through UART. It looks like it is not responding at all.
3. The sleep function does not work in debug mode. It looks like the instructions are executed but it does not go into any sleep modes. (I'm using Keil development studio).
Any help or suggestions is greatly appreciated.