Wake XIAO QSPI flash and preserve access after failed resets
This commit is contained in:
1 parent
85a786e796
commit
61dc5ca3f1
9 files changed
+450
-55
No files matched your search
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include "QspiFlashWakePolicy.h"
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include <Arduino.h>
|
||||
#include <hal/nrf_gpio.h>
|
||||
#include <hal/nrf_qspi.h>
|
||||
#endif
|
||||
|
||||
namespace mesh {
|
||||
namespace nrf52 {
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
inline void wakeQspiFlashBeforeActivate(const nrf_qspi_pins_t& pins) {
|
||||
// TASKS_ACTIVATE talks to the NOR before CINSTR is available. A sleeping
|
||||
// chip ignores that traffic and can leave activation waiting forever.
|
||||
// Send only the non-destructive 0xAB wake byte over mode-0 GPIO first.
|
||||
nrf_gpio_pin_clear(pins.sck_pin);
|
||||
nrf_gpio_pin_set(pins.csn_pin);
|
||||
nrf_gpio_pin_set(pins.io0_pin);
|
||||
if (pins.io2_pin != NRF_QSPI_PIN_NOT_CONNECTED) nrf_gpio_pin_set(pins.io2_pin);
|
||||
if (pins.io3_pin != NRF_QSPI_PIN_NOT_CONNECTED) nrf_gpio_pin_set(pins.io3_pin);
|
||||
|
||||
nrf_gpio_cfg(pins.sck_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.csn_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.io0_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.io1_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
if (pins.io2_pin != NRF_QSPI_PIN_NOT_CONNECTED)
|
||||
nrf_gpio_cfg(pins.io2_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
if (pins.io3_pin != NRF_QSPI_PIN_NOT_CONNECTED)
|
||||
nrf_gpio_cfg(pins.io3_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_clear(pins.csn_pin);
|
||||
delayMicroseconds(1);
|
||||
for (uint8_t bit = 0; bit < 8u; bit++) {
|
||||
nrf_gpio_pin_write(pins.io0_pin, qspiReleaseFromDeepPowerDownBit(bit));
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_set(pins.sck_pin);
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_clear(pins.sck_pin);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
nrf_gpio_pin_set(pins.csn_pin);
|
||||
delayMicroseconds(QSPI_DPD_WAKE_GUARD_US);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace nrf52
|
||||
} // namespace mesh
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace mesh {
|
||||
namespace nrf52 {
|
||||
|
||||
// Supported NOR parts need up to 45 us after release from deep power-down.
|
||||
static const uint32_t QSPI_DPD_WAKE_GUARD_US = 50u;
|
||||
static const uint8_t QSPI_RELEASE_FROM_DPD_OPCODE = 0xABu;
|
||||
|
||||
inline bool qspiReleaseFromDeepPowerDownBit(uint8_t bit_index) {
|
||||
return bit_index < 8u &&
|
||||
((QSPI_RELEASE_FROM_DPD_OPCODE >> (7u - bit_index)) & 1u) != 0;
|
||||
}
|
||||
|
||||
} // namespace nrf52
|
||||
} // namespace mesh
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "OtaByteIO.h"
|
||||
#include "OtaFlashLayout_nrf52.h"
|
||||
#include <helpers/nrf52/QspiFlashWake.h>
|
||||
#include "hal/nrf_gpio.h"
|
||||
#include "hal/nrf_qspi.h"
|
||||
#include "nrf.h"
|
||||
@@ -235,47 +236,6 @@ static void release_rak3401_radio_bus() {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void wake_qspi_flash_before_activate(const nrf_qspi_pins_t& pins) {
|
||||
// nRF52840 TASKS_ACTIVATE communicates with the NOR before CINSTR is
|
||||
// available. A flash put to sleep by our preceding 0xB9 ignores that
|
||||
// activation traffic, so issue the only command it accepts (0xAB) with a
|
||||
// short mode-0 GPIO transaction first. IO2/WP# and IO3/HOLD# stay high.
|
||||
nrf_gpio_pin_clear(pins.sck_pin);
|
||||
nrf_gpio_pin_set(pins.csn_pin);
|
||||
nrf_gpio_pin_set(pins.io0_pin);
|
||||
if (pins.io2_pin != NRF_QSPI_PIN_NOT_CONNECTED) nrf_gpio_pin_set(pins.io2_pin);
|
||||
if (pins.io3_pin != NRF_QSPI_PIN_NOT_CONNECTED) nrf_gpio_pin_set(pins.io3_pin);
|
||||
|
||||
nrf_gpio_cfg(pins.sck_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.csn_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.io0_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
nrf_gpio_cfg(pins.io1_pin, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
if (pins.io2_pin != NRF_QSPI_PIN_NOT_CONNECTED)
|
||||
nrf_gpio_cfg(pins.io2_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
if (pins.io3_pin != NRF_QSPI_PIN_NOT_CONNECTED)
|
||||
nrf_gpio_cfg(pins.io3_pin, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT,
|
||||
NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0H1, NRF_GPIO_PIN_NOSENSE);
|
||||
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_clear(pins.csn_pin);
|
||||
delayMicroseconds(1);
|
||||
for (uint8_t bit = 0; bit < 8u; bit++) {
|
||||
nrf_gpio_pin_write(pins.io0_pin, mota_qspi_release_from_dpd_bit(bit));
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_set(pins.sck_pin);
|
||||
delayMicroseconds(1);
|
||||
nrf_gpio_pin_clear(pins.sck_pin);
|
||||
delayMicroseconds(1);
|
||||
}
|
||||
nrf_gpio_pin_set(pins.csn_pin);
|
||||
delayMicroseconds(MOTA_QSPI_DPD_WAKE_GUARD_US);
|
||||
}
|
||||
|
||||
#if defined(OTA_RAK_AUTO_STORE)
|
||||
static uint8_t gpio_spi_byte(const nrf_qspi_pins_t& pins, uint8_t out) {
|
||||
uint8_t in = 0;
|
||||
@@ -299,7 +259,7 @@ static uint32_t probe_nor(uint8_t cs) {
|
||||
};
|
||||
// A previous reset may have left the NOR in deep power-down. This GPIO
|
||||
// wake precedes the nRF QSPI ACTIVATE for the same reason as ensureFlash().
|
||||
wake_qspi_flash_before_activate(pins);
|
||||
mesh::nrf52::wakeQspiFlashBeforeActivate(pins);
|
||||
// The wake helper leaves GPIO input buffers disconnected for QSPI handoff.
|
||||
// This bit-banged JEDEC read instead samples IO1 through GPIO->IN, which
|
||||
// requires the MISO input buffer to be connected.
|
||||
@@ -552,7 +512,7 @@ bool OtaStoreQspiNrf52::ensureFlash() {
|
||||
// successful RDSR prove WIP clear, every failure path must retain power and
|
||||
// hold CS# high instead of sending B9 or cutting the flash rail.
|
||||
_memory_operation_pending = true;
|
||||
wake_qspi_flash_before_activate(pins);
|
||||
mesh::nrf52::wakeQspiFlashBeforeActivate(pins);
|
||||
configure_qspi_gpio(pins);
|
||||
nrf_qspi_pins_set(NRF_QSPI, &pins);
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "../nrf52/QspiFlashWakePolicy.h"
|
||||
|
||||
namespace mesh {
|
||||
namespace ota {
|
||||
|
||||
@@ -52,8 +54,10 @@ namespace ota {
|
||||
static const uint32_t MOTA_QSPI_DPD_ENTRY_GUARD_US = 50u;
|
||||
|
||||
// Release-from-deep-power-down latency is as high as 45 us on supported NOR.
|
||||
static const uint32_t MOTA_QSPI_DPD_WAKE_GUARD_US = 50u;
|
||||
static const uint8_t MOTA_QSPI_RELEASE_FROM_DPD_OPCODE = 0xABu;
|
||||
static const uint32_t MOTA_QSPI_DPD_WAKE_GUARD_US =
|
||||
mesh::nrf52::QSPI_DPD_WAKE_GUARD_US;
|
||||
static const uint8_t MOTA_QSPI_RELEASE_FROM_DPD_OPCODE =
|
||||
mesh::nrf52::QSPI_RELEASE_FROM_DPD_OPCODE;
|
||||
|
||||
// TASKS_ACTIVATE initiates traffic with the external memory. A NOR in deep
|
||||
// power-down ignores that traffic and the nRF QSPI peripheral can wait forever
|
||||
@@ -61,8 +65,7 @@ static const uint8_t MOTA_QSPI_RELEASE_FROM_DPD_OPCODE = 0xABu;
|
||||
// owns the pins. Keep the bit order host-testable instead of open-coding it in
|
||||
// the hardware-only path.
|
||||
inline bool mota_qspi_release_from_dpd_bit(uint8_t bit_index) {
|
||||
return bit_index < 8u &&
|
||||
((MOTA_QSPI_RELEASE_FROM_DPD_OPCODE >> (7u - bit_index)) & 1u) != 0;
|
||||
return mesh::nrf52::qspiReleaseFromDeepPowerDownBit(bit_index);
|
||||
}
|
||||
|
||||
// The nRF QSPI READY event only says that a program/erase command and its
|
||||
|
||||
Reference in new issue
Block a user