Power optimization - Improve SPI sleep mode

Ensure that all pins are set to their default configuration during sleep mode.
Disable the workaround for FTPAN58 (SPI freezes when transfering a single byte) at the end of the transfer. This disables the resources needed for the workaround.
Those changes reduce the power usage by 430-490µA.
This commit is contained in:
Jean-François Milants 2023-05-07 18:24:34 +02:00 committed by JF
parent 2fa3aaa161
commit 4c0f897953
4 changed files with 11 additions and 1 deletions

View File

@ -27,7 +27,8 @@ bool Spi::WriteCmdAndBuffer(const uint8_t* cmd, size_t cmdSize, const uint8_t* d
} }
bool Spi::Init() { bool Spi::Init() {
nrf_gpio_pin_set(pinCsn); /* disable Set slave select (inactive high) */ nrf_gpio_cfg_output(pinCsn);
nrf_gpio_pin_set(pinCsn);
return true; return true;
} }

View File

@ -204,6 +204,9 @@ bool SpiMaster::Write(uint8_t pinCsn, const uint8_t* data, size_t size) {
; ;
nrf_gpio_pin_set(this->pinCsn); nrf_gpio_pin_set(this->pinCsn);
currentBufferAddr = 0; currentBufferAddr = 0;
DisableWorkaroundForFtpan58(spiBaseAddress, 0, 0);
xSemaphoreGive(mutex); xSemaphoreGive(mutex);
} }

View File

@ -10,6 +10,7 @@ SpiNorFlash::SpiNorFlash(Spi& spi) : spi {spi} {
} }
void SpiNorFlash::Init() { void SpiNorFlash::Init() {
spi.Init();
device_id = ReadIdentificaion(); device_id = ReadIdentificaion();
NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d", NRF_LOG_INFO("[SpiNorFlash] Manufacturer : %d, Memory type : %d, memory density : %d",
device_id.manufacturer, device_id.manufacturer,
@ -23,10 +24,12 @@ void SpiNorFlash::Uninit() {
void SpiNorFlash::Sleep() { void SpiNorFlash::Sleep() {
auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown); auto cmd = static_cast<uint8_t>(Commands::DeepPowerDown);
spi.Write(&cmd, sizeof(uint8_t)); spi.Write(&cmd, sizeof(uint8_t));
spi.Sleep();
NRF_LOG_INFO("[SpiNorFlash] Sleep") NRF_LOG_INFO("[SpiNorFlash] Sleep")
} }
void SpiNorFlash::Wakeup() { void SpiNorFlash::Wakeup() {
spi.Wakeup();
// send Commands::ReleaseFromDeepPowerDown then 3 dummy bytes before reading Device ID // send Commands::ReleaseFromDeepPowerDown then 3 dummy bytes before reading Device ID
static constexpr uint8_t cmdSize = 4; static constexpr uint8_t cmdSize = 4;
uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03}; uint8_t cmd[cmdSize] = {static_cast<uint8_t>(Commands::ReleaseFromDeepPowerDown), 0x01, 0x02, 0x03};

View File

@ -187,10 +187,13 @@ void St7789::HardwareReset() {
void St7789::Sleep() { void St7789::Sleep() {
SleepIn(); SleepIn();
nrf_gpio_cfg_default(pinDataCommand); nrf_gpio_cfg_default(pinDataCommand);
nrf_gpio_cfg_default(26);
spi.Sleep();
NRF_LOG_INFO("[LCD] Sleep"); NRF_LOG_INFO("[LCD] Sleep");
} }
void St7789::Wakeup() { void St7789::Wakeup() {
spi.Wakeup();
nrf_gpio_cfg_output(pinDataCommand); nrf_gpio_cfg_output(pinDataCommand);
SleepOut(); SleepOut();
VerticalScrollStartAddress(verticalScrollingStartAddress); VerticalScrollStartAddress(verticalScrollingStartAddress);