Skip to content

Commit f205b57

Browse files
niedzwiecki-dawidkartben
authored andcommitted
drivers: flash: stm32h7: use a correct register to program RDP
The RDP level is set with the FLASH_OPTSR_PRG register and read with the FLASH_OPTSR_CUR register, not FLASH_OPTCR. Fix that to realy change and read RDP. Signed-off-by: Dawid Niedzwiecki <[email protected]>
1 parent a88e429 commit f205b57

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

drivers/flash/flash_stm32h7x.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ struct flash_stm32_sector_t {
6262
volatile uint32_t *sr;
6363
};
6464

65-
static __unused int write_optb(const struct device *dev, uint32_t mask,
66-
uint32_t value)
65+
static __unused int write_optsr(const struct device *dev, uint32_t mask, uint32_t value)
6766
{
6867
FLASH_TypeDef *regs = FLASH_STM32_REGS(dev);
6968
int rc;
@@ -73,7 +72,7 @@ static __unused int write_optb(const struct device *dev, uint32_t mask,
7372
return -EIO;
7473
}
7574

76-
if ((regs->OPTCR & mask) == value) {
75+
if ((regs->OPTSR_CUR & mask) == value) {
7776
/* Done already */
7877
return 0;
7978
}
@@ -84,12 +83,8 @@ static __unused int write_optb(const struct device *dev, uint32_t mask,
8483
return rc;
8584
}
8685

87-
regs->OPTCR = (regs->OPTCR & ~mask) | value;
88-
#ifdef CONFIG_SOC_SERIES_STM32H7RSX
89-
regs->OPTCR |= FLASH_OPTCR_PG_OPT;
90-
#else
86+
regs->OPTSR_PRG = (regs->OPTSR_CUR & ~mask) | value;
9187
regs->OPTCR |= FLASH_OPTCR_OPTSTART;
92-
#endif /* CONFIG_SOC_SERIES_STM32H7RSX */
9388
/* Make sure previous write is completed. */
9489
barrier_dsync_fence_full();
9590

@@ -99,7 +94,7 @@ static __unused int write_optb(const struct device *dev, uint32_t mask,
9994
return rc;
10095
}
10196

102-
return 0;
97+
return rc;
10398
}
10499

105100
#if defined(CONFIG_FLASH_STM32_READOUT_PROTECTION)
@@ -112,8 +107,7 @@ uint8_t flash_stm32_get_rdp_level(const struct device *dev)
112107

113108
void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level)
114109
{
115-
write_optb(dev, FLASH_OPTSR_RDP_Msk,
116-
(uint32_t)level << FLASH_OPTSR_RDP_Pos);
110+
write_optsr(dev, FLASH_OPTSR_RDP_Msk, (uint32_t)level << FLASH_OPTSR_RDP_Pos);
117111
}
118112
#endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */
119113

0 commit comments

Comments
 (0)