From 60839790fef867fb42ed93eb24e901da1b34f728 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 12 Dec 2023 00:11:41 +0000 Subject: [PATCH] spiFlash: Fixed a bug where the sector erase instruction was being run without the opcode being passed along --- src/include/spiFlash.hxx | 4 ++++ src/spiFlash.cxx | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/include/spiFlash.hxx b/src/include/spiFlash.hxx index 611070f..3976e34 100644 --- a/src/include/spiFlash.hxx +++ b/src/include/spiFlash.hxx @@ -81,6 +81,10 @@ namespace bmpflash::spiFlash pageRead = command(opcodeMode_t::with3BAddress, dataMode_t::dataIn, 0U, opcode_t::pageRead), }; + // NB: This technically invokes UB, however there's not really a better way to do this, so. + constexpr inline command_t operator |(const command_t &cmd, const uint8_t &opcode) noexcept + { return static_cast(uint16_t(cmd) | opcode); } + constexpr inline uint8_t spiStatusBusy{1}; constexpr inline uint8_t spiStatusWriteEnabled{2}; diff --git a/src/spiFlash.cxx b/src/spiFlash.cxx index 32658d1..4838d5c 100644 --- a/src/spiFlash.cxx +++ b/src/spiFlash.cxx @@ -33,7 +33,7 @@ namespace bmpflash::spiFlash console.debug("Erasing sector at 0x"sv, asHex_t<6, '0'>{address}); // Start by erasing the block if (!probe.runCommand(spiFlashCommand_t::writeEnable, 0U) || - !probe.runCommand(spiFlashCommand_t::sectorErase, static_cast(address)) || + !probe.runCommand(spiFlashCommand_t::sectorErase | sectorEraseOpcode_, static_cast(address)) || !waitFlashIdle(probe)) { console.error("Failed to prepare SPI Flash block for writing"sv);