From 4e01674cbde4021731d452f0fa92bedb6664bb69 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 13 Jul 2023 14:49:08 -0700 Subject: [PATCH] Fix rp2 safe mode via reset press The picodvi PR #7880 switched the saved word to the watchdog register since it reworked the RAM layout. This works for reset_into_safe_mode because the watchdog scratch registers are preserved by soft resets. They *aren't* preserved for pressing the reset button. So it broken manual safe mode. Switch back to using RAM to store the saved word but use the pico-sdks "uninitialized" designation instead of a fixed location. Also fixes USB host feather status neopixel by setting the power pin. --- .../adafruit_feather_rp2040_usb_host/mpconfigboard.h | 1 + ports/raspberrypi/supervisor/port.c | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_usb_host/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_usb_host/mpconfigboard.h index f300bfe711..053d5b523b 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_usb_host/mpconfigboard.h +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_usb_host/mpconfigboard.h @@ -2,6 +2,7 @@ #define MICROPY_HW_MCU_NAME "rp2040" #define MICROPY_HW_NEOPIXEL (&pin_GPIO21) +#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO20) #define DEFAULT_I2C_BUS_SCL (&pin_GPIO3) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO2) diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 08a9d96c2e..cfbf3b6a04 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -247,14 +247,15 @@ uint32_t *port_heap_get_top(void) { return port_stack_get_top(); } +uint32_t __uninitialized_ram(saved_word); void port_set_saved_word(uint32_t value) { - // Store in a watchdog scratch register instead of RAM. 4-7 are used by the - // sdk. 0 is used by alarm. 1-3 are free. - watchdog_hw->scratch[1] = value; + // Store in RAM because the watchdog scratch registers don't survive + // resetting by pulling the RUN pin low. + saved_word = value; } uint32_t port_get_saved_word(void) { - return watchdog_hw->scratch[1]; + return saved_word; } static volatile bool ticks_enabled;