From 3f124a2e0474e601f303650c5d869e6aef38f493 Mon Sep 17 00:00:00 2001 From: Balazs Racz Date: Sat, 12 Nov 2022 15:31:26 +0100 Subject: [PATCH] Adds implementation of chip_erase() to SpiFlash driver. (#676) --- src/freertos_drivers/common/SPIFlash.cxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/freertos_drivers/common/SPIFlash.cxx b/src/freertos_drivers/common/SPIFlash.cxx index 8d22b9a47..0e5fb6b20 100644 --- a/src/freertos_drivers/common/SPIFlash.cxx +++ b/src/freertos_drivers/common/SPIFlash.cxx @@ -202,3 +202,19 @@ void SPIFlash::erase(uint32_t addr, size_t len) addr += cfg_->sectorSize_; } } + +void SPIFlash::chip_erase() +{ + struct spi_ioc_transfer xfer[2] = {0, 0}; + xfer[0].tx_buf = (uintptr_t)&cfg_->writeEnableCommand_; + xfer[0].len = 1; + xfer[0].cs_change = true; + xfer[1].tx_buf = (uintptr_t)&cfg_->chipEraseCommand_; + xfer[1].len = 1; + xfer[1].cs_change = true; + + ::ioctl(spiFd_, SPI_IOC_MESSAGE(2), &xfer); + + unsigned waitcount = wait_for_write(); + LOG(INFO, "chip-erase, success after %u iter", waitcount); +}