2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_flash_ramfunc.c
\r
4 * @author MCD Application Team
\r
5 * @brief FLASH RAMFUNC driver.
\r
6 * This file provides a Flash firmware functions which should be
\r
7 * executed from internal SRAM
\r
8 * + FLASH HalfPage Programming
\r
9 * + FLASH Power Down in Run mode
\r
12 ==============================================================================
\r
13 ##### Flash RAM functions #####
\r
14 ==============================================================================
\r
16 *** ARM Compiler ***
\r
17 --------------------
\r
18 [..] RAM functions are defined using the toolchain options.
\r
19 Functions that are executed in RAM should reside in a separate
\r
20 source module. Using the 'Options for File' dialog you can simply change
\r
21 the 'Code / Const' area of a module to a memory space in physical RAM.
\r
22 Available memory areas are declared in the 'Target' tab of the
\r
23 Options for Target' dialog.
\r
25 *** ICCARM Compiler ***
\r
26 -----------------------
\r
27 [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".
\r
29 *** GNU Compiler ***
\r
30 --------------------
\r
31 [..] RAM functions are defined using a specific toolchain attribute
\r
32 "__attribute__((section(".RamFunc")))".
\r
35 ******************************************************************************
\r
38 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
39 * All rights reserved.</center></h2>
\r
41 * This software component is licensed by ST under BSD 3-Clause license,
\r
42 * the "License"; You may not use this file except in compliance with the
\r
43 * License. You may obtain a copy of the License at:
\r
44 * opensource.org/licenses/BSD-3-Clause
\r
46 ******************************************************************************
\r
49 /* Includes ------------------------------------------------------------------*/
\r
50 #include "stm32l4xx_hal.h"
\r
52 /** @addtogroup STM32L4xx_HAL_Driver
\r
56 /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC
\r
57 * @brief FLASH functions executed from RAM
\r
61 #ifdef HAL_FLASH_MODULE_ENABLED
\r
63 /* Private typedef -----------------------------------------------------------*/
\r
64 /* Private define ------------------------------------------------------------*/
\r
65 /* Private macro -------------------------------------------------------------*/
\r
66 /* Private variables ---------------------------------------------------------*/
\r
67 extern FLASH_ProcessTypeDef pFlash;
\r
69 /* Private function prototypes -----------------------------------------------*/
\r
70 /* Exported functions -------------------------------------------------------*/
\r
72 /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions
\r
76 /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions
\r
77 * @brief Data transfers functions
\r
80 ===============================================================================
\r
81 ##### ramfunc functions #####
\r
82 ===============================================================================
\r
84 This subsection provides a set of functions that should be executed from RAM.
\r
91 * @brief Enable the Power down in Run Mode
\r
92 * @note This function should be called and executed from SRAM memory
\r
95 __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void)
\r
97 /* Enable the Power Down in Run mode*/
\r
98 __HAL_FLASH_POWER_DOWN_ENABLE();
\r
105 * @brief Disable the Power down in Run Mode
\r
106 * @note This function should be called and executed from SRAM memory
\r
109 __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void)
\r
111 /* Disable the Power Down in Run mode*/
\r
112 __HAL_FLASH_POWER_DOWN_DISABLE();
\r
117 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)
\r
119 * @brief Program the FLASH DBANK User Option Byte.
\r
121 * @note To configure the user option bytes, the option lock bit OPTLOCK must
\r
122 * be cleared with the call of the HAL_FLASH_OB_Unlock() function.
\r
123 * @note To modify the DBANK option byte, no PCROP region should be defined.
\r
124 * To deactivate PCROP, user should perform RDP changing
\r
126 * @param DBankConfig: The FLASH DBANK User Option Byte value.
\r
127 * This parameter can be one of the following values:
\r
128 * @arg OB_DBANK_128_BITS: Single-bank with 128-bits data
\r
129 * @arg OB_DBANK_64_BITS: Dual-bank with 64-bits data
\r
131 * @retval HAL status
\r
133 __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig)
\r
135 register uint32_t count, reg;
\r
136 HAL_StatusTypeDef status = HAL_ERROR;
\r
138 /* Process Locked */
\r
139 __HAL_LOCK(&pFlash);
\r
141 /* Check if the PCROP is disabled */
\r
142 reg = FLASH->PCROP1SR;
\r
143 if (reg > FLASH->PCROP1ER)
\r
145 reg = FLASH->PCROP2SR;
\r
146 if (reg > FLASH->PCROP2ER)
\r
148 /* Disable Flash prefetch */
\r
149 __HAL_FLASH_PREFETCH_BUFFER_DISABLE();
\r
151 if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U)
\r
153 /* Disable Flash instruction cache */
\r
154 __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
\r
156 /* Flush Flash instruction cache */
\r
157 __HAL_FLASH_INSTRUCTION_CACHE_RESET();
\r
160 if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)
\r
162 /* Disable Flash data cache */
\r
163 __HAL_FLASH_DATA_CACHE_DISABLE();
\r
165 /* Flush Flash data cache */
\r
166 __HAL_FLASH_DATA_CACHE_RESET();
\r
169 /* Disable WRP zone 1 of 1st bank if needed */
\r
170 reg = FLASH->WRP1AR;
\r
171 if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> FLASH_WRP1AR_WRP1A_STRT_Pos) <=
\r
172 ((reg & FLASH_WRP1AR_WRP1A_END) >> FLASH_WRP1AR_WRP1A_END_Pos))
\r
174 MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT);
\r
177 /* Disable WRP zone 2 of 1st bank if needed */
\r
178 reg = FLASH->WRP1BR;
\r
179 if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> FLASH_WRP1BR_WRP1B_STRT_Pos) <=
\r
180 ((reg & FLASH_WRP1BR_WRP1B_END) >> FLASH_WRP1BR_WRP1B_END_Pos))
\r
182 MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT);
\r
185 /* Disable WRP zone 1 of 2nd bank if needed */
\r
186 reg = FLASH->WRP2AR;
\r
187 if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> FLASH_WRP2AR_WRP2A_STRT_Pos) <=
\r
188 ((reg & FLASH_WRP2AR_WRP2A_END) >> FLASH_WRP2AR_WRP2A_END_Pos))
\r
190 MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT);
\r
193 /* Disable WRP zone 2 of 2nd bank if needed */
\r
194 reg = FLASH->WRP2BR;
\r
195 if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> FLASH_WRP2BR_WRP2B_STRT_Pos) <=
\r
196 ((reg & FLASH_WRP2BR_WRP2B_END) >> FLASH_WRP2BR_WRP2B_END_Pos))
\r
198 MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT);
\r
201 /* Modify the DBANK user option byte */
\r
202 MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig);
\r
204 /* Set OPTSTRT Bit */
\r
205 SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
\r
207 /* Wait for last operation to be completed */
\r
208 /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */
\r
209 count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8U / 1000U);
\r
217 } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET);
\r
219 /* If the option byte program operation is completed, disable the OPTSTRT Bit */
\r
220 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);
\r
222 /* Set the bit to force the option byte reloading */
\r
223 SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);
\r
227 /* Process Unlocked */
\r
228 __HAL_UNLOCK(&pFlash);
\r
241 #endif /* HAL_FLASH_MODULE_ENABLED */
\r
254 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r