Skip to content

Commit b6138a8

Browse files
committed
driver: flash: stm32 option bytes reloaded when locking
do not force option byte reloading in the write function because RDP byte cannot be reloaded that way: it needs a POR through Standby mode. when FLASH_CR_OBL_LAUNCH is defined, use it to force-reload option bytes directly in the locking function. Signed-off-by: Cyril Fougeray <[email protected]>
1 parent 2016f05 commit b6138a8

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

drivers/flash/flash_stm32_ex_op.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ int flash_stm32_option_bytes_lock(const struct device *dev, bool enable)
2424
{
2525
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
2626

27+
#if defined(FLASH_CR_OBL_LAUNCH)
28+
/* Force the option byte loading before locking */
29+
if (enable) {
30+
regs->CR |= FLASH_CR_OBL_LAUNCH;
31+
}
32+
#endif
33+
2734
#if defined(FLASH_OPTCR_OPTLOCK) /* F2, F4, F7 or H7 */
2835
if (enable) {
2936
regs->OPTCR |= FLASH_OPTCR_OPTLOCK;

drivers/flash/flash_stm32g4x.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,6 @@ int flash_stm32_option_bytes_write(const struct device *dev, uint32_t mask,
280280
/* Make sure previous write is completed. */
281281
barrier_dsync_fence_full();
282282

283-
rc = flash_stm32_wait_flash_idle(dev);
284-
if (rc < 0) {
285-
return rc;
286-
}
287-
288-
/* Force the option byte loading */
289-
regs->CR |= FLASH_CR_OBL_LAUNCH;
290-
291283
return flash_stm32_wait_flash_idle(dev);
292284
}
293285

drivers/flash/flash_stm32l4x.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,6 @@ int flash_stm32_option_bytes_write(const struct device *dev, uint32_t mask,
271271
/* Make sure previous write is completed. */
272272
barrier_dsync_fence_full();
273273

274-
rc = flash_stm32_wait_flash_idle(dev);
275-
if (rc < 0) {
276-
return rc;
277-
}
278-
279-
/* Force the option byte loading */
280-
regs->CR |= FLASH_CR_OBL_LAUNCH;
281-
282274
return flash_stm32_wait_flash_idle(dev);
283275
}
284276

0 commit comments

Comments
 (0)