Skip to content

Commit 1a3b177

Browse files
authored
Fix incorrect flexspi error handling (#537)
I had mistakenly thought `program_lut` always requires a `Some(data_bytes)` but looking at it again it only needs `Some(data_bytes)` in the case of `Some(transfertype)`. Because of my mistaken assumption, I was returning an error early from `send_command` when I shouldn't have, so this PR fixes it so we don't do that.
1 parent e621e1f commit 1a3b177

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/flexspi/nor_storage_bus.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,20 +608,17 @@ impl BlockingNorStorageBusDriver for FlexspiNorStorageBus<'_, Blocking> {
608608
read_buf: Option<&mut [u8]>,
609609
write_buf: Option<&[u8]>,
610610
) -> Result<(), NorStorageBusError> {
611-
// `program_lut` expects data_bytes to be available so we bail out early if that's not the case
612-
let Some(data_bytes) = cmd.data_bytes else {
613-
return Err(NorStorageBusError::StorageBusInternalError);
614-
};
615-
616-
if data_bytes > MAX_TRANSFER_SIZE_PER_COMMAND as u32 {
611+
if let Some(data_bytes) = cmd.data_bytes
612+
&& data_bytes > MAX_TRANSFER_SIZE_PER_COMMAND as u32
613+
{
617614
return Err(NorStorageBusError::StorageBusInternalError);
618615
}
619616

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

623620
// Program the LUT instructions for the command
624-
self.program_lut(&cmd, data_bytes, self.command_sequence_number);
621+
self.program_lut(&cmd, self.command_sequence_number)?;
625622

626623
// Start the transfer
627624
self.execute_ip_cmd();
@@ -932,7 +929,7 @@ impl<M: Mode> FlexspiNorStorageBus<'_, M> {
932929
cookie.next_instruction();
933930
}
934931

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

975972
if let Some(transfertype) = cmd.cmdtype {
973+
let data_bytes = cmd.data_bytes.ok_or(NorStorageBusError::StorageBusInternalError)?;
974+
976975
match transfertype {
977976
NorStorageCmdType::Read => {
978977
self.program_read_data_instruction(cmd, &mut cookie, data_bytes as u8);
@@ -991,6 +990,8 @@ impl<M: Mode> FlexspiNorStorageBus<'_, M> {
991990
.lutkey()
992991
.modify(|_, w| unsafe { w.key().bits(LUT_UNLOCK_CODE) });
993992
self.info.regs.lutcr().modify(|_, w| w.lock().set_bit());
993+
994+
Ok(())
994995
}
995996
}
996997

0 commit comments

Comments
 (0)