From 730525cec965a912354454ec015a3d043d5579d3 Mon Sep 17 00:00:00 2001 From: Victor Rajewski Date: Tue, 4 Jul 2023 15:11:06 +1000 Subject: [PATCH] stm32/qspi: Allow qspi_write_cmd_data to write cmd with 1 data byte. The existing qspi for stm32 implementation can only send a spi command with exactly 0 or 2 data bytes. Certain spiflash chips (e.g. AT25SF321B) have commands that only take a single data byte, and will ignore the command if more than that is sent. This commit allows sending a command with a single data byte. Signed-off-by: Victor Rajewski --- ports/stm32/qspi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ports/stm32/qspi.c b/ports/stm32/qspi.c index a79e692e0e..c10bec2365 100644 --- a/ports/stm32/qspi.c +++ b/ports/stm32/qspi.c @@ -232,8 +232,12 @@ STATIC int qspi_write_cmd_data(void *self_in, uint8_t cmd, size_t len, uint32_t while (!(QUADSPI->SR & QUADSPI_SR_FTF)) { } - // This assumes len==2 - *(uint16_t *)&QUADSPI->DR = data; + if (len == 1) { + *(uint8_t *)&QUADSPI->DR = data; + } else { + // This assumes len==2 + *(uint16_t *)&QUADSPI->DR = data; + } } // Wait for write to finish