You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/14 23:28:01 UTC
[incubator-nuttx] 01/03: arch/arm/src/stm32h7/stm32_flash.c: Lock
flash option register
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit f9a886f8b7a2211ed2e7957778f96118e27ae69c
Author: Jukka Laitinen <ju...@intel.com>
AuthorDate: Fri Apr 17 15:00:06 2020 +0300
arch/arm/src/stm32h7/stm32_flash.c: Lock flash option register
If the flash option register was locked before modifying it, return
it to the locked state after modify.
Signed-off-by: Jukka Laitinen <ju...@intel.com>
---
arch/arm/src/stm32h7/stm32_flash.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/arch/arm/src/stm32h7/stm32_flash.c b/arch/arm/src/stm32h7/stm32_flash.c
index 85f4498..269652d 100644
--- a/arch/arm/src/stm32h7/stm32_flash.c
+++ b/arch/arm/src/stm32h7/stm32_flash.c
@@ -339,11 +339,14 @@ FAR struct stm32h7_flash_priv_s * stm32h7_flash_bank(size_t address)
*
* Description:
* Unlock the flash option bytes
+ * Returns true if the flash was locked before, false otherwise
*
****************************************************************************/
-static void stm32h7_unlock_flashopt(FAR struct stm32h7_flash_priv_s *priv)
+static bool stm32h7_unlock_flashopt(FAR struct stm32h7_flash_priv_s *priv)
{
+ bool ret = false;
+
while (stm32h7_flash_getreg32(priv, STM32_FLASH_SR1_OFFSET) & FLASH_SR_BSY)
{
}
@@ -357,7 +360,13 @@ static void stm32h7_unlock_flashopt(FAR struct stm32h7_flash_priv_s *priv)
FLASH_OPTKEY1);
stm32h7_flash_putreg32(priv, STM32_FLASH_OPTKEYR_OFFSET,
FLASH_OPTKEY2);
+
+ /* Was locked before and now unlocked */
+
+ ret = true;
}
+
+ return ret;
}
/****************************************************************************
@@ -439,7 +448,7 @@ int stm32h7_flash_unlock(size_t addr)
stm32h7_flash_sem_unlock(priv);
}
- return ret:;
+ return ret;
}
/****************************************************************************
@@ -542,13 +551,19 @@ uint32_t stm32h7_flash_getopt(void)
void stm32h7_flash_optmodify(uint32_t clear, uint32_t set)
{
struct stm32h7_flash_priv_s *priv;
+ bool was_locked;
+
priv = stm32h7_flash_bank(STM32_FLASH_BANK1);
if (priv)
{
- stm32h7_unlock_flashopt(priv);
- stm32h7_flash_modifyreg32(priv, STM32_FLASH_OPTSR_PRG_OFFSET,
- clear, set);
- stm32h7_save_flashopt(priv);
+ was_locked = stm32h7_unlock_flashopt(priv);
+ stm32h7_flash_modifyreg32(priv, STM32_FLASH_OPTSR_PRG_OFFSET,
+ clear, set);
+ stm32h7_save_flashopt(priv);
+ if (was_locked)
+ {
+ stm32h7_lock_flashopt(priv);
+ }
}
}