Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/flexspi/nor_storage_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,20 +608,17 @@ impl BlockingNorStorageBusDriver for FlexspiNorStorageBus<'_, Blocking> {
read_buf: Option<&mut [u8]>,
write_buf: Option<&[u8]>,
) -> Result<(), NorStorageBusError> {
// `program_lut` expects data_bytes to be available so we bail out early if that's not the case
let Some(data_bytes) = cmd.data_bytes else {
return Err(NorStorageBusError::StorageBusInternalError);
};

if data_bytes > MAX_TRANSFER_SIZE_PER_COMMAND as u32 {
if let Some(data_bytes) = cmd.data_bytes
&& data_bytes > MAX_TRANSFER_SIZE_PER_COMMAND as u32
{
return Err(NorStorageBusError::StorageBusInternalError);
}

// Setup the transfer to be sent of the FlexSPI IP Port
self.setup_ip_transfer(self.command_sequence_number, cmd.addr, cmd.data_bytes);

// Program the LUT instructions for the command
self.program_lut(&cmd, data_bytes, self.command_sequence_number);
self.program_lut(&cmd, self.command_sequence_number)?;

// Start the transfer
self.execute_ip_cmd();
Expand Down Expand Up @@ -932,7 +929,7 @@ impl<M: Mode> FlexspiNorStorageBus<'_, M> {
cookie.next_instruction();
}

fn program_lut(&self, cmd: &NorStorageCmd, data_bytes: u32, seq_id: u8) {
fn program_lut(&self, cmd: &NorStorageCmd, seq_id: u8) -> Result<(), NorStorageBusError> {
let mut cookie = LutInstrCookie {
seq_num: seq_id * 4,
instr_num: LutInstrNum::First,
Expand Down Expand Up @@ -973,6 +970,8 @@ impl<M: Mode> FlexspiNorStorageBus<'_, M> {
self.program_dummy_instruction_if_non_zero(cmd, &mut cookie);

if let Some(transfertype) = cmd.cmdtype {
let data_bytes = cmd.data_bytes.ok_or(NorStorageBusError::StorageBusInternalError)?;

match transfertype {
NorStorageCmdType::Read => {
self.program_read_data_instruction(cmd, &mut cookie, data_bytes as u8);
Expand All @@ -991,6 +990,8 @@ impl<M: Mode> FlexspiNorStorageBus<'_, M> {
.lutkey()
.modify(|_, w| unsafe { w.key().bits(LUT_UNLOCK_CODE) });
self.info.regs.lutcr().modify(|_, w| w.lock().set_bit());

Ok(())
}
}

Expand Down