8000 ports/rp2/modmachine.c: Fix lightsleep watchdog interactions. by cpottle9 · Pull Request #17232 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

ports/rp2/modmachine.c: Fix lightsleep watchdog interactions. #17232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions ports/rp2/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
#include "clocks_extra.h"
#include "hardware/pll.h"
#include "hardware/structs/rosc.h"
#if PICO_RP2040
#include "hardware/structs/psm.h"
#endif
#include "hardware/structs/scb.h"
#include "hardware/structs/syscfg.h"
#include "hardware/structs/watchdog.h"
#include "hardware/watchdog.h"
#include "hardware/xosc.h"
#include "pico/bootrom.h"
Expand Down Expand Up @@ -177,6 +181,8 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
if (disable_usb) {
clock_stop(clk_usb);
}
uint32_t wdt_ctrl = watchdog_hw->ctrl;
bool watchdog_active = (wdt_ctrl & WATCHDOG_CTRL_ENABLE_BITS) != 0;

clock_stop(clk_adc);
#if PICO_RP2350
Expand Down Expand Up @@ -205,7 +211,12 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {

// Disable ROSC.
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_DISABLE << ROSC_CTRL_ENABLE_LSB;

#if PICO_RP2040
if (watchdog_active) {
// Configure Power-On State Machine to reset the ROSC on a watchdog timeout.
psm_hw->wdsel |= PSM_WDSEL_ROSC_BITS;
}
#endif
if (n_args == 0) {
#if MICROPY_PY_NETWORK_CYW43
gpio_set_dormant_irq_enabled(CYW43_PIN_WL_HOST_WAKE, GPIO_IRQ_LEVEL_HIGH, true);
Expand All @@ -229,7 +240,12 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
#if PICO_RP2040
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_SYS_TIMER_BITS;
#elif PICO_RP2350
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_REF_TICKS_BITS | CLOCKS_SLEEP_EN1_CLK_SYS_TIMER0_BITS;
if (watchdog_active) {
// clk_sys watchdog and clk_ref ticks must be enabled for the watchdog counter to decrement on RP2350.
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_REF_TICKS_BITS | CLOCKS_SLEEP_EN1_CLK_SYS_TIMER0_BITS | CLOCKS_SLEEP_EN1_CLK_SYS_WATCHDOG_BITS;
} else {
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_REF_TICKS_BITS | CLOCKS_SLEEP_EN1_CLK_SYS_TIMER0_BITS;
}
#else
#error Unknown processor
#endif
Expand Down Expand Up @@ -275,7 +291,12 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {

// Enable ROSC.
rosc_hw->ctrl = ROSC_CTRL_ENABLE_VALUE_ENABLE << ROSC_CTRL_ENABLE_LSB;

#if PICO_RP2040
if (watchdog_active) {
// No longer need the Power-On State Machine to reset the ROSC on a watchdog timeout.
psm_hw->wdsel &= ~PSM_WDSEL_ROSC_BITS;
}
#endif
// Bring back all clocks.
runtime_init_clocks_optional_usb(disable_usb);
MICROPY_END_ATOMIC_SECTION(my_interrupts);
Expand Down
Loading
0