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..c579729 100644 --- a/src/spiFlash.cxx +++ b/src/spiFlash.cxx @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BSD-3-Clause // SPDX-FileCopyrightText: 2023 1BitSquared // SPDX-FileContributor: Written by Rachel Mant +#include #include #include #include @@ -33,7 +34,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);