Skip to content

Commit

Permalink
spiFlash: Fixed a bug where the sector erase instruction was being ru…
Browse files Browse the repository at this point in the history
…n without the opcode being passed along
  • Loading branch information
dragonmux committed Dec 12, 2023
1 parent 7efa905 commit 6083979
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/include/spiFlash.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<command_t>(uint16_t(cmd) | opcode); }

Check warning on line 86 in src/include/spiFlash.hxx

View check run for this annotation

Codecov / codecov/patch

src/include/spiFlash.hxx#L85-L86

Added lines #L85 - L86 were not covered by tests

constexpr inline uint8_t spiStatusBusy{1};
constexpr inline uint8_t spiStatusWriteEnabled{2};

Expand Down
2 changes: 1 addition & 1 deletion src/spiFlash.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(address)) ||
!probe.runCommand(spiFlashCommand_t::sectorErase | sectorEraseOpcode_, static_cast<uint32_t>(address)) ||
!waitFlashIdle(probe))
{
console.error("Failed to prepare SPI Flash block for writing"sv);
Expand Down

0 comments on commit 6083979

Please sign in to comment.