Skip to content

Commit

Permalink
Wait while busy on entry
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuskleist committed Aug 7, 2023
1 parent 71e9cae commit d595bd0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/modm/driver/storage/block_device_spiflash_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ modm::BdSpiFlash<Spi, Cs, flashSize>::read(uint8_t* buffer, bd_address_t address

if((size == 0) || (size % BlockSizeRead != 0) || (address + size > flashSize)) {
RF_RETURN(false);
} else {
RF_CALL(waitWhileBusy());
}

RF_CALL(spiOperation(Instruction::FR, address, nullptr, buffer, size, 1));
Expand All @@ -93,13 +95,14 @@ modm::BdSpiFlash<Spi, Cs, flashSize>::program(const uint8_t* buffer, bd_address_

if((size == 0) || (size % BlockSizeWrite != 0) || (address + size > flashSize)) {
RF_RETURN(false);
} else {
RF_CALL(waitWhileBusy());
}

index = 0;
while(index < size) {
RF_CALL(spiOperation(Instruction::WE));
RF_CALL(spiOperation(Instruction::PP, address + index, &buffer[index], nullptr, BlockSizeWrite));
RF_CALL(waitWhileBusy());
index += BlockSizeWrite;
}

Expand All @@ -116,17 +119,17 @@ modm::BdSpiFlash<Spi, Cs, flashSize>::erase(bd_address_t address, bd_size_t size

if((size == 0) || (size % BlockSizeErase != 0) || (address + size > flashSize)) {
RF_RETURN(false);
} else {
RF_CALL(waitWhileBusy());
}

if (address == 0 && size == flashSize) {
RF_CALL(spiOperation(Instruction::CE));
RF_CALL(waitWhileBusy());
} else {
index = 0;
while(index < size) {
RF_CALL(spiOperation(Instruction::WE));
RF_CALL(spiOperation(Instruction::SE, address + index));
RF_CALL(waitWhileBusy());
index += BlockSizeErase;
}
}
Expand Down Expand Up @@ -175,6 +178,8 @@ modm::BdSpiFlash<Spi, Cs, flashSize>::selectDie(uint8_t die)
RF_BEGIN();

RF_CALL(spiOperation(Instruction::SDS, &die, nullptr, 1));
RF_CALL(waitWhileBusy());

RF_CALL(spiOperation(Instruction::WE));
RF_CALL(spiOperation(Instruction::GBU));
RF_CALL(waitWhileBusy());
Expand Down

0 comments on commit d595bd0

Please sign in to comment.