You need to disable the Low Voltage detector, which adds 120 uA to the current.
int main(void)
{
int counter = 0;
PMC_Init();
GoToLowPower(WAIT);
for(;;) {
counter++;
}
return 0;
}
void GoToLowPower (uint8_t OperationMode) {
switch (OperationMode) {
case WAIT:
/* SCB_SCR: SLEEPDEEP=0 */
SCB_SCR &= (uint32_t)~(uint32_t)(SCB_SCR_SLEEPDEEP_MASK);
/* SCB_SCR: SLEEPONEXIT=0 */
SCB_SCR &= (uint32_t)~(uint32_t)(SCB_SCR_SLEEPONEXIT_MASK);
__asm("WFI");
break;
case STOP:
/* SCB_SCR: SLEEPONEXIT=0 */
SCB_SCR &= (uint32_t)~(uint32_t)(SCB_SCR_SLEEPONEXIT_MASK);
/* SCB_SCR: SLEEPDEEP=1 */
SCB_SCR |= SCB_SCR_SLEEPDEEP_MASK;
__asm("WFI");
break;
default:
for(;;);
}
}
void PMC_Init () {
/* PMC_SPMSC2: LVDV=0,LVWV=0 */
PMC_SPMSC2 &= (uint8_t)~(uint8_t)(
PMC_SPMSC2_LVDV_MASK |
PMC_SPMSC2_LVWV(0x03)
);
/* PMC_SPMSC1: LVWACK=1,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */
PMC_SPMSC1 = (uint8_t)((PMC_SPMSC1 & (uint8_t)~(uint8_t)(
PMC_SPMSC1_LVWIE_MASK |
PMC_SPMSC1_BGBE_MASK |
0x02U|
PMC_SPMSC1_LVDE_MASK
)) | (uint8_t)(
PMC_SPMSC1_LVWACK_MASK |
PMC_SPMSC1_LVDRE_MASK |
PMC_SPMSC1_LVDSE_MASK
));
}