rogerclarkmelbourne / Arduino_STM32

Arduino STM32. Hardware files to support STM32 boards, on Arduino IDE 1.8.x including LeafLabs Maple and other generic STM32F103 boards
Other
2.49k stars 1.25k forks source link

Implementing Low power modes #901

Closed Imlerih closed 1 year ago

Imlerih commented 1 year ago

I'm trying to implement standby and stop modes on this core for STM32F103 mcu. I had no isues with standby mode, it wirks properly wit power consumption about of 46 uA. Here it's sources:

void lp_init() { //enable power clock RCC_BASE->APB1ENR |= RCC_APB1ENR_PWREN; delay(10);

/* Enable access to RTC and backup registers */
PWR_BASE->CR |= PWR_CR_DBP;

///* Check if the system was resumed from StandBy mode */
if (PWR_BASE->CSR & SCB_SCR_SLEEPONEXIT)
{
    PWR_BASE->CSR &= ~SCB_SCR_SLEEPONEXIT;
}

//Clear wakeup flag
PWR_BASE->CR |= PWR_CR_CWUF;

}

void standby() { stop(); return; lp_init(); nvic_globalirq_disable();

SCB_BASE->SCR |= SCB_SCR_SLEEPDEEP;
//Power down deepsleep
PWR_BASE->CR |= PWR_CR_PDDS;
//Enable wakeup pin 
PWR_BASE->CSR |= PWR_CSR_EWUP;
asm volatile("WFI":::"memory");

}

But there are difficuelties with stop mode. It consumes 18 mA when entered, must be mutch less. Here the sources:

void stop() { lp_init();

for (int i = PA0; i <= PC15; i++)
{
    pinMode(i, INPUT);
    digitalWrite(i, 0);
}

systick_disable();

bitClear(PWR_BASE->CR, PWR_CR_PDDS);
//Low-power deepsleep
bitSet(PWR_BASE->CR, PWR_CR_LPDS);

bitSet(SCB_BASE->SCR, SCB_SCR_SLEEPDEEP);

asm volatile("WFI":::"memory");

bitClear(SCB_BASE->SCR, SCB_SCR_SLEEPDEEP);

//setup clock back to HSE after exiting stop mode
setup_clocks();
systick_enable();

}

rogerclarkmelbourne commented 1 year ago

Try posting to www.stm32duino.com or STM's community forum