Skip to content

Commit ff34d57

Browse files
FRASTMaescolar
authored andcommitted
drivers: flash: stm32 qspi flash driver with unprotect command
Add the write_unprotect command to the stm32 qspi flash driver to un protect flash before any write operation to the external quad-NOR Signed-off-by: Francois Ramu <[email protected]>
1 parent 76740ae commit ff34d57

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

drivers/flash/flash_stm32_qspi.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,27 @@ static int qspi_read_jedec_id(const struct device *dev, uint8_t *id)
352352
}
353353
#endif /* CONFIG_FLASH_JESD216_API */
354354

355+
static int qspi_write_unprotect(const struct device *dev)
356+
{
357+
int ret = 0;
358+
QSPI_CommandTypeDef cmd_unprotect = {
359+
.Instruction = SPI_NOR_CMD_ULBPR,
360+
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
361+
};
362+
363+
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
364+
ret = qspi_send_cmd(dev, &cmd_write_en);
365+
366+
if (ret != 0) {
367+
return ret;
368+
}
369+
370+
ret = qspi_send_cmd(dev, &cmd_unprotect);
371+
}
372+
373+
return ret;
374+
}
375+
355376
/*
356377
* Read Serial Flash Discovery Parameter
357378
*/
@@ -1498,6 +1519,13 @@ static int flash_stm32_qspi_init(const struct device *dev)
14981519
}
14991520
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
15001521

1522+
ret = qspi_write_unprotect(dev);
1523+
if (ret != 0) {
1524+
LOG_ERR("write unprotect failed: %d", ret);
1525+
return -ENODEV;
1526+
}
1527+
LOG_DBG("Write Un-protected");
1528+
15011529
#ifdef CONFIG_STM32_MEMMAP
15021530
#if DT_PROP(DT_NODELABEL(quadspi), dual_flash) && defined(QUADSPI_CR_DFM)
15031531
/*

0 commit comments

Comments
 (0)