Hi,
Good to hear it works, but still not on my board. Here is the code I used to test, it does nothing but initializes the clock and running mode, and then goes to VLPS mode with interrupt disabled. The SIRCDIV3 is set to 2 here, but the current is the same whether it is 0 or 2.
int main(void)
{
__disable_interrupt();
/* Enable SIRC at 8MHz, SIRC_DIV3 = 4MHz */
SCG->SIRCDIV = SCG_SIRCDIV_SIRCDIV1(0) + SCG_SIRCDIV_SIRCDIV2(0) +
SCG_SIRCDIV_SIRCDIV3(2);
SCG->SIRCCFG = SCG_SIRCCFG_RANGE_MASK;
/* Enable SIRC in STOP and Low power mode */
SCG->SIRCCSR = SCG_SIRCCSR_SIRCEN_MASK | SCG_SIRCCSR_SIRCSTEN_MASK |
SCG_SIRCCSR_SIRCLPEN_MASK;
while ((SCG->SIRCCSR & SCG_SIRCCSR_SIRCVLD_MASK) == 0) {
/* Wait for SIRC to stable */
}
/* Set mode to RUN mode and VLPS mode */
SMC->PMCTRL = SMC_PMCTRL_RUNM(0) + SMC_PMCTRL_STOPM(2);
while (SMC->PMSTAT != SMC_PMSTAT_PMSTAT(1)) {
/* Wait for system transitting to RUN mode */
}
/* Set Run mode with SIRC at DIVCORE = 4MHz, DIVSLOW = 4MHz */
SCG->RCCR = SCG_RCCR_DIVCORE(1) + SCG_RCCR_DIVSLOW(1) + SCG_RCCR_SCS(2);
while ((SCG->CSR & SCG_CSR_SCS_MASK) != SCG_CSR_SCS(2)) {
/* Wait for RUN mode clock transitting to SIRC */
}
/* Set VLPR mode with SIRC at DIVCORE = 4MHz, DIVSLOW = 1MHz */
SCG->VCCR = SCG_VCCR_DIVCORE(1) + SCG_VCCR_DIVSLOW(7) + SCG_VCCR_SCS(2);
/* Disable SOSC */
SCG->SOSCCSR = SCG_SOSCCSR_SOSCERR_MASK;
/* Disable FIRC */
SCG->FIRCCSR = SCG_FIRCCSR_FIRCERR_MASK;
/* Disable SPLL */
SCG->SPLLCSR = SCG_SPLLCSR_SPLLERR_MASK;
/* Allow VLP modes */
SMC->PMPROT = SMC_PMPROT_AVLP_MASK;
/* Set the SLEEPDEEP bit to enable deep sleep mode */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Change to VLPR mode */
/* Set mode to RUN mode and VLPS mode */
SMC->PMCTRL = SMC_PMCTRL_RUNM(2) + SMC_PMCTRL_STOPM(2);
while (SMC->PMSTAT != SMC_PMSTAT_PMSTAT(4)) {
/* Wait for system transitting to VLPR mode */
}
while (1) {
SMC->PMCTRL &= ~SMC_PMCTRL_STOPM_MASK;
SMC->PMCTRL |= SMC_PMCTRL_STOPM(2); /* VLPS */
/* read back to make sure the configuration valid before enter stop mode */
(void)SMC->PMCTRL;
__DSB();
__WFI();
}
}