@@ -62,6 +62,67 @@ struct flash_stm32_sector_t {
6262 volatile uint32_t * sr ;
6363};
6464
65+ #if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION )
66+ uint8_t flash_stm32_get_rdp_level (const struct device * dev )
67+ {
68+ FLASH_TypeDef * regs = FLASH_STM32_REGS (dev );
69+
70+ return (regs -> OPTSR_CUR & FLASH_OPTSR_RDP_Msk ) >> FLASH_OPTSR_RDP_Pos ;
71+ }
72+
73+ void flash_stm32_set_rdp_level (const struct device * dev , uint8_t level )
74+ {
75+ FLASH_TypeDef * regs = FLASH_STM32_REGS (dev );
76+ uint32_t value = (uint32_t )level << FLASH_OPTSR_RDP_Pos ;
77+
78+ if (regs -> OPTCR & FLASH_OPTCR_OPTLOCK ) {
79+ LOG_ERR ("Option bytes locked" );
80+ return ;
81+ }
82+
83+ if ((regs -> OPTCR & FLASH_OPTSR_RDP_Msk ) == value ) {
84+ /* Done already */
85+ return ;
86+ }
87+
88+ if (flash_stm32_wait_flash_idle (dev ) != 0 ) {
89+ LOG_ERR ("Err flash no idle" );
90+ return ;
91+ }
92+
93+ regs -> OPTCR = (regs -> OPTCR & ~FLASH_OPTSR_RDP_Msk ) | value ;
94+ regs -> OPTCR |= FLASH_OPTCR_OPTSTART ;
95+
96+ /* Make sure previous write is completed. */
97+ barrier_dsync_fence_full ();
98+
99+ if (flash_stm32_wait_flash_idle (dev ) != 0 ) {
100+ LOG_ERR ("Err flash no idle" );
101+ return ;
102+ }
103+ }
104+ #endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
105+
106+ int flash_stm32_option_bytes_lock (const struct device * dev , bool enable )
107+ {
108+ FLASH_TypeDef * regs = FLASH_STM32_REGS (dev );
109+
110+ if (enable ) {
111+ regs -> OPTCR |= FLASH_OPTCR_OPTLOCK ;
112+ } else if (regs -> OPTCR & FLASH_OPTCR_OPTLOCK ) {
113+ regs -> OPTKEYR = FLASH_OPT_KEY1 ;
114+ regs -> OPTKEYR = FLASH_OPT_KEY2 ;
115+ }
116+
117+ if (enable ) {
118+ LOG_DBG ("Option bytes locked" );
119+ } else {
120+ LOG_DBG ("Option bytes unlocked" );
121+ }
122+
123+ return 0 ;
124+ }
125+
65126bool flash_stm32_valid_range (const struct device * dev , off_t offset , uint32_t len , bool write )
66127{
67128#if defined(DUAL_BANK )
@@ -649,6 +710,9 @@ static const struct flash_driver_api flash_stm32h7_api = {
649710#ifdef CONFIG_FLASH_PAGE_LAYOUT
650711 .page_layout = flash_stm32_page_layout ,
651712#endif
713+ #ifdef CONFIG_FLASH_EX_OP_ENABLED
714+ .ex_op = flash_stm32_ex_op ,
715+ #endif
652716};
653717
654718static int stm32h7_flash_init (const struct device * dev )
0 commit comments