summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYihui Xiong <yihui.xiong@hotmail.com>2020-08-07 16:23:42 +0800
committerYihui Xiong <yihui.xiong@hotmail.com>2020-08-07 16:23:42 +0800
commitaf1291ec28a8d2881e820fc1ce9b938ab5a6f097 (patch)
tree8d84c9da2651b569cb9c32b9ec9f8f71dc0fa597
parentd8257380d7e1658d710bf841424a64c2c6451d5f (diff)
dynamically enable or disable QSPI by default
-rw-r--r--ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h3
-rw-r--r--ports/nrf/supervisor/port.c4
-rw-r--r--ports/nrf/supervisor/qspi_flash.c40
3 files changed, 18 insertions, 29 deletions
diff --git a/ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h b/ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h
index e8c268d5b..4fb6049c5 100644
--- a/ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h
+++ b/ports/nrf/boards/makerdiary_m60_keyboard/mpconfigboard.h
@@ -30,7 +30,7 @@
#define MICROPY_HW_BOARD_NAME "Makerdiary M60 Keyboard"
#define MICROPY_HW_MCU_NAME "nRF52840"
-// not use the RGB LEDs to save energy
+// RGB LEDs use PWM peripheral, avoid using them to save energy
// #define CP_RGB_STATUS_R (&pin_P0_30)
// #define CP_RGB_STATUS_G (&pin_P0_29)
// #define CP_RGB_STATUS_B (&pin_P0_31)
@@ -41,7 +41,6 @@
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(1, 12)
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(1, 11)
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 13)
-#define MICROPY_QSPI_OFF_WHEN_SLEEP
#define BOARD_HAS_CRYSTAL 1
diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c
index 36c9f836e..87a4d7396 100644
--- a/ports/nrf/supervisor/port.c
+++ b/ports/nrf/supervisor/port.c
@@ -65,7 +65,7 @@
#include "common-hal/audiopwmio/PWMAudioOut.h"
#endif
-#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+#if defined(MICROPY_QSPI_CS)
extern void qspi_disable(void);
#endif
@@ -299,7 +299,7 @@ void port_interrupt_after_ticks(uint32_t ticks) {
}
void port_sleep_until_interrupt(void) {
-#if defined(MICROPY_QSPI_CS) && defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+#if defined(MICROPY_QSPI_CS)
qspi_disable();
#endif
diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c
index 852f0c44a..5ab56c6bc 100644
--- a/ports/nrf/supervisor/qspi_flash.c
+++ b/ports/nrf/supervisor/qspi_flash.c
@@ -39,7 +39,21 @@
#include "supervisor/shared/external_flash/qspi_flash.h"
// When USB is disconnected, disable QSPI in sleep mode to save energy
-#if defined(MICROPY_QSPI_OFF_WHEN_SLEEP)
+void qspi_disable(void)
+{
+ // If VBUS is detected, no need to disable QSPI
+ if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
+ // Keep CS high when QSPI is diabled
+ nrf_gpio_cfg_output(MICROPY_QSPI_CS);
+ nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
+
+ // Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
+ NRF_QSPI->TASKS_DEACTIVATE = 1;
+ *(volatile uint32_t *)0x40029054 = 1;
+ NRF_QSPI->ENABLE = 0;
+ }
+}
+
void qspi_enable(void)
{
if (NRF_QSPI->ENABLE) {
@@ -60,30 +74,6 @@ void qspi_enable(void)
} while (--remaining_attempts);
}
-void qspi_disable(void)
-{
- // Turn off QSPI when USB is disconnected
- if (NRF_QSPI->ENABLE && !(NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk)) {
- // Keep CS high when QSPI is diabled
- nrf_gpio_cfg_output(MICROPY_QSPI_CS);
- nrf_gpio_pin_write(MICROPY_QSPI_CS, 1);
-
- // Workaround to disable QSPI according to nRF52840 Revision 1 Errata V1.4 - 3.8
- NRF_QSPI->TASKS_DEACTIVATE = 1;
- *(volatile uint32_t *)0x40029054 = 1;
- NRF_QSPI->ENABLE = 0;
- }
-}
-#else
-void qspi_enable(void)
-{
-}
-
-void qspi_disable(void)
-{
-}
-#endif
-
bool spi_flash_command(uint8_t command) {
qspi_enable();
nrf_qspi_cinstr_conf_t cinstr_cfg = {