mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 09:40:07 +01:00
[ion/device] External flash: Send instruction only once in memory-mapped mode
This commit is contained in:
committed by
Romain Goyet
parent
8ce7be5ff2
commit
e11deaa874
@@ -126,14 +126,28 @@ static void set_as_memory_mapped() {
|
||||
send_command_full(
|
||||
QUADSPI::CCR::FunctionalMode::MemoryMapped,
|
||||
DefaultOperatingMode,
|
||||
Command::FastRead,
|
||||
Command::FastReadQuadIO,
|
||||
reinterpret_cast<uint8_t *>(FlashAddressSpaceSize),
|
||||
0, 0,
|
||||
FastReadDummyCycles,
|
||||
0xA0, 1,
|
||||
2, //FIXME
|
||||
nullptr, 0
|
||||
);
|
||||
}
|
||||
|
||||
static void unset_memory_mapped_mode() {
|
||||
/* Reset Continuous Read Mode Bits before issuing normal instructions. */
|
||||
uint8_t dummyData;
|
||||
send_command_full(
|
||||
QUADSPI::CCR::FunctionalMode::IndirectRead,
|
||||
DefaultOperatingMode,
|
||||
Command::FastReadQuadIO,
|
||||
0,
|
||||
~(0xA0), 1,
|
||||
2, //FIXME
|
||||
&dummyData, 1
|
||||
);
|
||||
}
|
||||
|
||||
void send_command_full(QUADSPI::CCR::FunctionalMode functionalMode, QUADSPI::CCR::OperatingMode operatingMode, Command c, uint8_t * address, uint32_t altBytes, size_t numberOfAltBytes, uint8_t dummyCycles, uint8_t * data, size_t dataLength) {
|
||||
class QUADSPI::CCR ccr(0);
|
||||
ccr.setFMODE(functionalMode);
|
||||
@@ -155,6 +169,11 @@ void send_command_full(QUADSPI::CCR::FunctionalMode functionalMode, QUADSPI::CCR
|
||||
}
|
||||
ccr.setIMODE(operatingMode);
|
||||
ccr.setINSTRUCTION(static_cast<uint8_t>(c));
|
||||
if (functionalMode == QUADSPI::CCR::FunctionalMode::MemoryMapped) {
|
||||
ccr.setSIOO(true);
|
||||
/* If the SIOO bit is set, the instruction is sent only for the first command following a write to QUADSPI_CCR.
|
||||
* Subsequent command sequences skip the instruction phase, until there is a write to QUADSPI_CCR. */
|
||||
}
|
||||
QUADSPI.CCR()->set(ccr);
|
||||
if (address != reinterpret_cast<uint8_t *>(FlashAddressSpaceSize)) {
|
||||
QUADSPI.AR()->set(reinterpret_cast<uint32_t>(address));
|
||||
@@ -246,6 +265,7 @@ int SectorAtAddress(uint32_t address) {
|
||||
}
|
||||
|
||||
void MassErase() {
|
||||
unset_memory_mapped_mode();
|
||||
send_command(Command::WriteEnable);
|
||||
wait();
|
||||
send_command(Command::ChipErase);
|
||||
@@ -255,6 +275,7 @@ void MassErase() {
|
||||
|
||||
void EraseSector(int i) {
|
||||
assert(i >= 0 && i < NumberOfSectors);
|
||||
unset_memory_mapped_mode();
|
||||
send_command(Command::WriteEnable);
|
||||
wait();
|
||||
send_write_command(Command::Erase64KbyteBlock, reinterpret_cast<uint8_t *>(i << NumberOfAddressBitsIn64KbyteBlock), nullptr, 0);
|
||||
@@ -263,6 +284,7 @@ void EraseSector(int i) {
|
||||
}
|
||||
|
||||
void WriteMemory(uint8_t * source, uint8_t * destination, size_t length) {
|
||||
unset_memory_mapped_mode();
|
||||
/* Each 256-byte page of the external flash memory (contained in a previously erased area)
|
||||
* may be programmed in burst mode with a single Page Program instruction.
|
||||
* However, when the end of a page is reached, the addressing wraps to the beginning.
|
||||
|
||||
@@ -53,6 +53,7 @@ enum class Command : uint8_t {
|
||||
WriteEnable = 0x06,
|
||||
ReadData = 0x03,
|
||||
FastRead = 0x0B,
|
||||
FastReadQuadIO = 0xEB,
|
||||
// Program previously erased memory areas as being "0"
|
||||
PageProgram = 0x02,
|
||||
QuadPageProgram = 0x33,
|
||||
|
||||
Reference in New Issue
Block a user