drivers: flash: stm32_{q|o|x}spi: Fix write unprotect logs

The STM32 QSPI, OSPI, and XSPI drivers support sending the ULBPR command
for flash ICs that require unlocking before writing to. This is done
conditionally based on the requires_ulbpr devicetree property.

Previously the driver would always log "Write Un-protected", even if a
write un-protect was not attempted. Fix this so that "Write Un-protected"
is only logged when a write un-protect is attempted and succeeds.

Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
This commit is contained in:
Ben Marsh
2025-10-17 10:25:07 +01:00
committed by Johan Hedberg
parent 46de640492
commit ce08f16a05
3 changed files with 33 additions and 42 deletions

View File

@@ -720,17 +720,12 @@ static int ospi_write_unprotect(const struct device *dev)
cmd_unprotect.AddressMode = HAL_OSPI_ADDRESS_NONE;
cmd_unprotect.DataMode = HAL_OSPI_DATA_NONE;
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = stm32_ospi_write_enable(dev_data, OSPI_SPI_MODE, OSPI_STR_TRANSFER);
if (ret != 0) {
return ret;
}
ret = ospi_send_cmd(dev, &cmd_unprotect);
ret = stm32_ospi_write_enable(dev_data, OSPI_SPI_MODE, OSPI_STR_TRANSFER);
if (ret != 0) {
return ret;
}
return ret;
return ospi_send_cmd(dev, &cmd_unprotect);
}
/* Write Flash configuration register 2 with new dummy cycles */
@@ -2599,12 +2594,14 @@ static int flash_stm32_ospi_init(const struct device *dev)
}
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
ret = ospi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = ospi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
}
LOG_DBG("Write Un-protected");
}
LOG_DBG("Write Un-protected");
#ifdef CONFIG_STM32_MEMMAP
/* Now configure the octo Flash in MemoryMapped (access by address) */

View File

@@ -454,17 +454,12 @@ static int qspi_write_unprotect(const struct device *dev)
.InstructionMode = QSPI_INSTRUCTION_1_LINE,
};
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = qspi_send_cmd(dev, &cmd_write_en);
if (ret != 0) {
return ret;
}
ret = qspi_send_cmd(dev, &cmd_unprotect);
ret = qspi_send_cmd(dev, &cmd_write_en);
if (ret != 0) {
return ret;
}
return ret;
return qspi_send_cmd(dev, &cmd_unprotect);
}
/*
@@ -1739,12 +1734,14 @@ static int flash_stm32_qspi_init(const struct device *dev)
}
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
ret = qspi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = qspi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
}
LOG_DBG("Write Un-protected");
}
LOG_DBG("Write Un-protected");
#ifdef CONFIG_STM32_MEMMAP
ret = stm32_qspi_set_memory_mapped(dev);

View File

@@ -579,17 +579,12 @@ static int xspi_write_unprotect(const struct device *dev)
cmd_unprotect.AddressMode = HAL_XSPI_ADDRESS_NONE;
cmd_unprotect.DataMode = HAL_XSPI_DATA_NONE;
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = stm32_xspi_write_enable(dev, XSPI_SPI_MODE, XSPI_STR_TRANSFER);
if (ret != 0) {
return ret;
}
ret = xspi_send_cmd(dev, &cmd_unprotect);
ret = stm32_xspi_write_enable(dev, XSPI_SPI_MODE, XSPI_STR_TRANSFER);
if (ret != 0) {
return ret;
}
return ret;
return xspi_send_cmd(dev, &cmd_unprotect);
}
/* Write Flash configuration register 2 with new dummy cycles */
@@ -2401,12 +2396,14 @@ static int flash_stm32_xspi_init(const struct device *dev)
}
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
ret = xspi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
if (IS_ENABLED(DT_INST_PROP(0, requires_ulbpr))) {
ret = xspi_write_unprotect(dev);
if (ret != 0) {
LOG_ERR("write unprotect failed: %d", ret);
return -ENODEV;
}
LOG_DBG("Write Un-protected");
}
LOG_DBG("Write Un-protected");
#ifdef CONFIG_STM32_MEMMAP
ret = stm32_xspi_set_memorymap(dev);