-
Notifications
You must be signed in to change notification settings - Fork 8.1k
driver: flash: enable stm32 read-back protection at runtime #91945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ LOG_MODULE_REGISTER(LOG_DOMAIN); | |||||||||||||
| #include <zephyr/init.h> | ||||||||||||||
| #include <soc.h> | ||||||||||||||
| #include <stm32_ll_system.h> | ||||||||||||||
| #include <stm32_ll_cortex.h> | ||||||||||||||
| #include <stm32_ll_pwr.h> | ||||||||||||||
|
|
||||||||||||||
| #include "flash_stm32.h" | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -280,14 +282,6 @@ int flash_stm32_option_bytes_write(const struct device *dev, uint32_t mask, | |||||||||||||
| /* Make sure previous write is completed. */ | ||||||||||||||
| barrier_dsync_fence_full(); | ||||||||||||||
|
|
||||||||||||||
| rc = flash_stm32_wait_flash_idle(dev); | ||||||||||||||
| if (rc < 0) { | ||||||||||||||
| return rc; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| /* Force the option byte loading */ | ||||||||||||||
| regs->CR |= FLASH_CR_OBL_LAUNCH; | ||||||||||||||
|
|
||||||||||||||
| return flash_stm32_wait_flash_idle(dev); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -326,6 +320,15 @@ void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level) | |||||||||||||
| { | ||||||||||||||
| flash_stm32_option_bytes_write(dev, FLASH_OPTR_RDP_Msk, | ||||||||||||||
| (uint32_t)level << FLASH_OPTR_RDP_Pos); | ||||||||||||||
|
|
||||||||||||||
| /* | ||||||||||||||
| * POR needed to reload option bytes, done at runtime by entering standby mode | ||||||||||||||
| * /!\ make sure a wakeup source is configured! | ||||||||||||||
| */ | ||||||||||||||
| LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); | ||||||||||||||
| LL_LPM_EnableDeepSleep(); | ||||||||||||||
| /* enter SLEEP mode : WFE or WFI */ | ||||||||||||||
| k_cpu_idle(); | ||||||||||||||
|
Comment on lines
+330
to
+331
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
otherwise entry in low-power state is not guaranteed (and even this sequence may not be 100% safe) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have a STM32 SoC helper function to go into Standby mode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should go in common flash code if anywhere; PM needs something else (we don't want to force entry in low-power mode while doing PM, unlike here) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that is function should never return unless it fails (to reach SoC standby mode). I think the function declaration inline description should reflect this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True too, I guess it should be |
||||||||||||||
| } | ||||||||||||||
| #endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */ | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ LOG_MODULE_REGISTER(LOG_DOMAIN); | |
| #include <zephyr/sys/barrier.h> | ||
| #include <zephyr/init.h> | ||
| #include <soc.h> | ||
| #include <stm32_ll_system.h> | ||
| #include <stm32_ll_cortex.h> | ||
| #include <stm32_ll_pwr.h> | ||
|
|
||
| #include "flash_stm32.h" | ||
|
|
||
|
|
@@ -271,14 +274,6 @@ int flash_stm32_option_bytes_write(const struct device *dev, uint32_t mask, | |
| /* Make sure previous write is completed. */ | ||
| barrier_dsync_fence_full(); | ||
|
|
||
| rc = flash_stm32_wait_flash_idle(dev); | ||
| if (rc < 0) { | ||
| return rc; | ||
| } | ||
|
|
||
| /* Force the option byte loading */ | ||
| regs->CR |= FLASH_CR_OBL_LAUNCH; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Option bytes other than RDP in OTPR require OBL_LAUNCH or power reset to be loaded. |
||
|
|
||
| return flash_stm32_wait_flash_idle(dev); | ||
| } | ||
|
|
||
|
|
@@ -317,6 +312,15 @@ void flash_stm32_set_rdp_level(const struct device *dev, uint8_t level) | |
| { | ||
| flash_stm32_option_bytes_write(dev, FLASH_OPTR_RDP_Msk, | ||
| (uint32_t)level << FLASH_OPTR_RDP_Pos); | ||
|
|
||
| /* | ||
| * POR needed to reload option bytes, done at runtime by entering standby mode | ||
| * /!\ make sure a wakeup source is configured! | ||
| */ | ||
| LL_PWR_SetPowerMode(LL_PWR_MODE_STANDBY); | ||
| LL_LPM_EnableDeepSleep(); | ||
| /* enter SLEEP mode : WFE or WFI */ | ||
| k_cpu_idle(); | ||
| } | ||
| #endif /* CONFIG_FLASH_STM32_READOUT_PROTECTION */ | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change makes sense but would deserve a dedicated commit, aside proposing changes in
flash_stm32_option_bytes_write().