Skip to content

Commit 866dff0

Browse files
martinjaegercfriedt
authored andcommitted
drivers: flash: stm32g0: Implement set|get_rdp_level API
Allows to set readout protection bits for this series at runtime. Signed-off-by: Martin Jäger <[email protected]>
1 parent faf661e commit 866dff0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

drivers/flash/Kconfig.stm32

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ config FLASH_STM32_WRITE_PROTECT_DISABLE_PREVENTION
4949

5050
config FLASH_STM32_READOUT_PROTECTION
5151
bool "Extended operation for flash readout protection control"
52-
depends on SOC_SERIES_STM32F4X || SOC_SERIES_STM32L4X || \
53-
SOC_SERIES_STM32G4X || SOC_SERIES_STM32F7X || \
54-
SOC_SERIES_STM32H7X
52+
depends on SOC_SERIES_STM32F4X || \
53+
SOC_SERIES_STM32F7X || \
54+
SOC_SERIES_STM32G0X || \
55+
SOC_SERIES_STM32G4X || \
56+
SOC_SERIES_STM32H7X || \
57+
SOC_SERIES_STM32L4X
5558
select FLASH_HAS_EX_OP
5659
default n
5760
help

drivers/flash/flash_stm32g0x.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,21 @@ uint32_t flash_stm32_option_bytes_read(const struct device *dev)
239239
return regs->OPTR;
240240
}
241241

242+
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
243+
uint8_t flash_stm32_get_rdp_level(const struct device *dev)
244+
{
245+
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
246+
247+
return (regs->OPTR & FLASH_OPTR_RDP_Msk) >> FLASH_OPTR_RDP_Pos;
248+
}
249+
250+
void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level)
251+
{
252+
flash_stm32_option_bytes_write(dev, FLASH_OPTR_RDP_Msk,
253+
(uint32_t)level << FLASH_OPTR_RDP_Pos);
254+
}
255+
#endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
256+
242257
/*
243258
* The address space is always continuous, even though a subset of G0 SoCs has
244259
* two flash banks.

0 commit comments

Comments
 (0)