STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_flash_ramfunc.c
Go to the documentation of this file.
1 
49 /* Includes ------------------------------------------------------------------*/
50 #include "stm32l4xx_hal.h"
51 
61 #ifdef HAL_FLASH_MODULE_ENABLED
62 
63 /* Private typedef -----------------------------------------------------------*/
64 /* Private define ------------------------------------------------------------*/
65 /* Private macro -------------------------------------------------------------*/
66 /* Private variables ---------------------------------------------------------*/
68 
69 /* Private function prototypes -----------------------------------------------*/
70 /* Exported functions -------------------------------------------------------*/
71 
96 {
97  /* Enable the Power Down in Run mode*/
98  __HAL_FLASH_POWER_DOWN_ENABLE();
99 
100  return HAL_OK;
101 
102 }
103 
110 {
111  /* Disable the Power Down in Run mode*/
112  __HAL_FLASH_POWER_DOWN_DISABLE();
113 
114  return HAL_OK;
115 }
116 
117 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
118 
133 __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig)
134 {
135  register uint32_t count, reg;
136  HAL_StatusTypeDef status = HAL_ERROR;
137 
138  /* Process Locked */
139  __HAL_LOCK(&pFlash);
140 
141  /* Check if the PCROP is disabled */
142  reg = FLASH->PCROP1SR;
143  if (reg > FLASH->PCROP1ER)
144  {
145  reg = FLASH->PCROP2SR;
146  if (reg > FLASH->PCROP2ER)
147  {
148  /* Disable Flash prefetch */
149  __HAL_FLASH_PREFETCH_BUFFER_DISABLE();
150 
151  if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U)
152  {
153  /* Disable Flash instruction cache */
154  __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
155 
156  /* Flush Flash instruction cache */
157  __HAL_FLASH_INSTRUCTION_CACHE_RESET();
158  }
159 
160  if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
161  {
162  /* Disable Flash data cache */
163  __HAL_FLASH_DATA_CACHE_DISABLE();
164 
165  /* Flush Flash data cache */
166  __HAL_FLASH_DATA_CACHE_RESET();
167  }
168 
169  /* Disable WRP zone 1 of 1st bank if needed */
170  reg = FLASH->WRP1AR;
171  if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> FLASH_WRP1AR_WRP1A_STRT_Pos) <=
172  ((reg & FLASH_WRP1AR_WRP1A_END) >> FLASH_WRP1AR_WRP1A_END_Pos))
173  {
174  MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT);
175  }
176 
177  /* Disable WRP zone 2 of 1st bank if needed */
178  reg = FLASH->WRP1BR;
179  if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> FLASH_WRP1BR_WRP1B_STRT_Pos) <=
180  ((reg & FLASH_WRP1BR_WRP1B_END) >> FLASH_WRP1BR_WRP1B_END_Pos))
181  {
182  MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT);
183  }
184 
185  /* Disable WRP zone 1 of 2nd bank if needed */
186  reg = FLASH->WRP2AR;
187  if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> FLASH_WRP2AR_WRP2A_STRT_Pos) <=
188  ((reg & FLASH_WRP2AR_WRP2A_END) >> FLASH_WRP2AR_WRP2A_END_Pos))
189  {
190  MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT);
191  }
192 
193  /* Disable WRP zone 2 of 2nd bank if needed */
194  reg = FLASH->WRP2BR;
195  if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> FLASH_WRP2BR_WRP2B_STRT_Pos) <=
196  ((reg & FLASH_WRP2BR_WRP2B_END) >> FLASH_WRP2BR_WRP2B_END_Pos))
197  {
198  MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT);
199  }
200 
201  /* Modify the DBANK user option byte */
202  MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig);
203 
204  /* Set OPTSTRT Bit */
205  SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
206 
207  /* Wait for last operation to be completed */
208  /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */
209  count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8U / 1000U);
210  do
211  {
212  if (count == 0U)
213  {
214  break;
215  }
216  count--;
217  } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET);
218 
219  /* If the option byte program operation is completed, disable the OPTSTRT Bit */
220  CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
221 
222  /* Set the bit to force the option byte reloading */
223  SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
224  }
225  }
226 
227  /* Process Unlocked */
228  __HAL_UNLOCK(&pFlash);
229 
230  return status;
231 }
232 #endif
233 
241 #endif /* HAL_FLASH_MODULE_ENABLED */
242 
243 
244 
254 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
255 
256 
__RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void)
Disable the Power down in Run Mode.
This file contains all the functions prototypes for the HAL module driver.
__RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig)
Program the FLASH DBANK User Option Byte.
__RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void)
Enable the Power down in Run Mode.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
FLASH_ProcessTypeDef pFlash
Variable used for Program/Erase sectors under interruption.
FLASH handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)