STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_flash_ramfunc.c 00004 * @author MCD Application Team 00005 * @brief FLASH RAMFUNC driver. 00006 * This file provides a Flash firmware functions which should be 00007 * executed from internal SRAM 00008 * + FLASH HalfPage Programming 00009 * + FLASH Power Down in Run mode 00010 * 00011 * @verbatim 00012 ============================================================================== 00013 ##### Flash RAM functions ##### 00014 ============================================================================== 00015 00016 *** ARM Compiler *** 00017 -------------------- 00018 [..] RAM functions are defined using the toolchain options. 00019 Functions that are executed in RAM should reside in a separate 00020 source module. Using the 'Options for File' dialog you can simply change 00021 the 'Code / Const' area of a module to a memory space in physical RAM. 00022 Available memory areas are declared in the 'Target' tab of the 00023 Options for Target' dialog. 00024 00025 *** ICCARM Compiler *** 00026 ----------------------- 00027 [..] RAM functions are defined using a specific toolchain keyword "__ramfunc". 00028 00029 *** GNU Compiler *** 00030 -------------------- 00031 [..] RAM functions are defined using a specific toolchain attribute 00032 "__attribute__((section(".RamFunc")))". 00033 00034 @endverbatim 00035 ****************************************************************************** 00036 * @attention 00037 * 00038 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00039 * 00040 * Redistribution and use in source and binary forms, with or without modification, 00041 * are permitted provided that the following conditions are met: 00042 * 1. Redistributions of source code must retain the above copyright notice, 00043 * this list of conditions and the following disclaimer. 00044 * 2. Redistributions in binary form must reproduce the above copyright notice, 00045 * this list of conditions and the following disclaimer in the documentation 00046 * and/or other materials provided with the distribution. 00047 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00048 * may be used to endorse or promote products derived from this software 00049 * without specific prior written permission. 00050 * 00051 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00052 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00053 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00054 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00055 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00056 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00057 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00058 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00059 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00060 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00061 * 00062 ****************************************************************************** 00063 */ 00064 00065 /* Includes ------------------------------------------------------------------*/ 00066 #include "stm32l4xx_hal.h" 00067 00068 /** @addtogroup STM32L4xx_HAL_Driver 00069 * @{ 00070 */ 00071 00072 /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC 00073 * @brief FLASH functions executed from RAM 00074 * @{ 00075 */ 00076 00077 #ifdef HAL_FLASH_MODULE_ENABLED 00078 00079 /* Private typedef -----------------------------------------------------------*/ 00080 /* Private define ------------------------------------------------------------*/ 00081 /* Private macro -------------------------------------------------------------*/ 00082 /* Private variables ---------------------------------------------------------*/ 00083 extern FLASH_ProcessTypeDef pFlash; 00084 00085 /* Private function prototypes -----------------------------------------------*/ 00086 /* Exported functions -------------------------------------------------------*/ 00087 00088 /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions 00089 * @{ 00090 */ 00091 00092 /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions 00093 * @brief Data transfers functions 00094 * 00095 @verbatim 00096 =============================================================================== 00097 ##### ramfunc functions ##### 00098 =============================================================================== 00099 [..] 00100 This subsection provides a set of functions that should be executed from RAM. 00101 00102 @endverbatim 00103 * @{ 00104 */ 00105 00106 /** 00107 * @brief Enable the Power down in Run Mode 00108 * @note This function should be called and executed from SRAM memory 00109 * @retval None 00110 */ 00111 __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void) 00112 { 00113 /* Enable the Power Down in Run mode*/ 00114 __HAL_FLASH_POWER_DOWN_ENABLE(); 00115 00116 return HAL_OK; 00117 00118 } 00119 00120 /** 00121 * @brief Disable the Power down in Run Mode 00122 * @note This function should be called and executed from SRAM memory 00123 * @retval None 00124 */ 00125 __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void) 00126 { 00127 /* Disable the Power Down in Run mode*/ 00128 __HAL_FLASH_POWER_DOWN_DISABLE(); 00129 00130 return HAL_OK; 00131 } 00132 00133 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 00134 /** 00135 * @brief Program the FLASH DBANK User Option Byte. 00136 * 00137 * @note To configure the user option bytes, the option lock bit OPTLOCK must 00138 * be cleared with the call of the HAL_FLASH_OB_Unlock() function. 00139 * @note To modify the DBANK option byte, no PCROP region should be defined. 00140 * To deactivate PCROP, user should perform RDP changing 00141 * 00142 * @param DBankConfig: The FLASH DBANK User Option Byte value. 00143 * This parameter can be one of the following values: 00144 * @arg OB_DBANK_128_BITS: Single-bank with 128-bits data 00145 * @arg OB_DBANK_64_BITS: Dual-bank with 64-bits data 00146 * 00147 * @retval HAL status 00148 */ 00149 __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig) 00150 { 00151 register uint32_t count, reg; 00152 HAL_StatusTypeDef status = HAL_ERROR; 00153 00154 /* Process Locked */ 00155 __HAL_LOCK(&pFlash); 00156 00157 /* Check if the PCROP is disabled */ 00158 reg = FLASH->PCROP1SR; 00159 if (reg > FLASH->PCROP1ER) 00160 { 00161 reg = FLASH->PCROP2SR; 00162 if (reg > FLASH->PCROP2ER) 00163 { 00164 /* Disable Flash prefetch */ 00165 __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); 00166 00167 if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U) 00168 { 00169 /* Disable Flash instruction cache */ 00170 __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); 00171 00172 /* Flush Flash instruction cache */ 00173 __HAL_FLASH_INSTRUCTION_CACHE_RESET(); 00174 } 00175 00176 if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U) 00177 { 00178 /* Disable Flash data cache */ 00179 __HAL_FLASH_DATA_CACHE_DISABLE(); 00180 00181 /* Flush Flash data cache */ 00182 __HAL_FLASH_DATA_CACHE_RESET(); 00183 } 00184 00185 /* Disable WRP zone 1 of 1st bank if needed */ 00186 reg = FLASH->WRP1AR; 00187 if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> FLASH_WRP1AR_WRP1A_STRT_Pos) <= 00188 ((reg & FLASH_WRP1AR_WRP1A_END) >> FLASH_WRP1AR_WRP1A_END_Pos)) 00189 { 00190 MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT); 00191 } 00192 00193 /* Disable WRP zone 2 of 1st bank if needed */ 00194 reg = FLASH->WRP1BR; 00195 if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> FLASH_WRP1BR_WRP1B_STRT_Pos) <= 00196 ((reg & FLASH_WRP1BR_WRP1B_END) >> FLASH_WRP1BR_WRP1B_END_Pos)) 00197 { 00198 MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT); 00199 } 00200 00201 /* Disable WRP zone 1 of 2nd bank if needed */ 00202 reg = FLASH->WRP2AR; 00203 if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> FLASH_WRP2AR_WRP2A_STRT_Pos) <= 00204 ((reg & FLASH_WRP2AR_WRP2A_END) >> FLASH_WRP2AR_WRP2A_END_Pos)) 00205 { 00206 MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT); 00207 } 00208 00209 /* Disable WRP zone 2 of 2nd bank if needed */ 00210 reg = FLASH->WRP2BR; 00211 if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> FLASH_WRP2BR_WRP2B_STRT_Pos) <= 00212 ((reg & FLASH_WRP2BR_WRP2B_END) >> FLASH_WRP2BR_WRP2B_END_Pos)) 00213 { 00214 MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT); 00215 } 00216 00217 /* Modify the DBANK user option byte */ 00218 MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig); 00219 00220 /* Set OPTSTRT Bit */ 00221 SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 00222 00223 /* Wait for last operation to be completed */ 00224 /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */ 00225 count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8U / 1000U); 00226 do 00227 { 00228 if (count == 0U) 00229 { 00230 break; 00231 } 00232 count--; 00233 } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET); 00234 00235 /* If the option byte program operation is completed, disable the OPTSTRT Bit */ 00236 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 00237 00238 /* Set the bit to force the option byte reloading */ 00239 SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); 00240 } 00241 } 00242 00243 /* Process Unlocked */ 00244 __HAL_UNLOCK(&pFlash); 00245 00246 return status; 00247 } 00248 #endif 00249 00250 /** 00251 * @} 00252 */ 00253 00254 /** 00255 * @} 00256 */ 00257 #endif /* HAL_FLASH_MODULE_ENABLED */ 00258 00259 00260 00261 /** 00262 * @} 00263 */ 00264 00265 /** 00266 * @} 00267 */ 00268 00269 00270 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00271 00272