Skip to content

Commit 6aeb12d

Browse files
taltenbachdanieldegrasse
authored andcommitted
drivers: flash: stm32_qspi: Fix flash not reset when in QPI mode
The reset commands were sent only in SPI mode, causing the device not to be properly reset when in QPI mode. On the STM32H747I-DISCO boards, this was causing the driver initialization to fail due to a bad SFDP magic after flashing the external memory using STM32CubeProgrammer since the external loader is configuring the flash memory in QPI mode. The commands are sent in QPI mode first, then in SPI mode: - If the flash memory was in QPI mode, the two first reset commands are processed and after reset, the flash memory is in SPI mode and correctly handles the SPI mode reset commands. - If the flash memory was in SPI mode, for each QPI command the chip select signal will be released before the flash memory had the opportunity to receive a whole command (1 byte), so the partially received commands will be ignored and won't cause any harm. Then, the chip is reset by the commands sent in SPI mode. Signed-off-by: Thomas Altenbach <altenbach.thomas@gmail.com>
1 parent 0081207 commit 6aeb12d

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/flash/flash_stm32_qspi.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,10 +1402,29 @@ static int flash_stm32_qspi_send_reset(const struct device *dev)
14021402
{
14031403
QSPI_CommandTypeDef cmd = {
14041404
.Instruction = SPI_NOR_CMD_RESET_EN,
1405-
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
1405+
.InstructionMode = QSPI_INSTRUCTION_4_LINES
14061406
};
14071407
int ret;
14081408

1409+
/*
1410+
* The device might be in SPI or QPI mode, so to ensure the device is properly reset send
1411+
* the reset commands in both QPI and SPI modes.
1412+
*/
1413+
ret = qspi_send_cmd(dev, &cmd);
1414+
if (ret != 0) {
1415+
LOG_ERR("%d: Failed to send RESET_EN", ret);
1416+
return ret;
1417+
}
1418+
1419+
cmd.Instruction = SPI_NOR_CMD_RESET_MEM;
1420+
ret = qspi_send_cmd(dev, &cmd);
1421+
if (ret != 0) {
1422+
LOG_ERR("%d: Failed to send RESET_MEM", ret);
1423+
return ret;
1424+
}
1425+
1426+
cmd.Instruction = SPI_NOR_CMD_RESET_EN;
1427+
cmd.InstructionMode = QSPI_INSTRUCTION_1_LINE;
14091428
ret = qspi_send_cmd(dev, &cmd);
14101429
if (ret != 0) {
14111430
LOG_ERR("%d: Failed to send RESET_EN", ret);

0 commit comments

Comments
 (0)