STM32L443xx 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 * Copyright (c) 2017 STMicroelectronics. 00039 * All rights reserved. 00040 * 00041 * This software is licensed under terms that can be found in the LICENSE file in 00042 * the root directory of this software component. 00043 * If no LICENSE file comes with this software, it is provided AS-IS. 00044 ****************************************************************************** 00045 */ 00046 00047 /* Includes ------------------------------------------------------------------*/ 00048 #include "stm32l4xx_hal.h" 00049 00050 /** @addtogroup STM32L4xx_HAL_Driver 00051 * @{ 00052 */ 00053 00054 /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC 00055 * @brief FLASH functions executed from RAM 00056 * @{ 00057 */ 00058 00059 #ifdef HAL_FLASH_MODULE_ENABLED 00060 00061 /* Private typedef -----------------------------------------------------------*/ 00062 /* Private define ------------------------------------------------------------*/ 00063 /* Private macro -------------------------------------------------------------*/ 00064 /* Private variables ---------------------------------------------------------*/ 00065 /* Private function prototypes -----------------------------------------------*/ 00066 /* Exported functions -------------------------------------------------------*/ 00067 00068 /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions 00069 * @{ 00070 */ 00071 00072 /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions 00073 * @brief Data transfers functions 00074 * 00075 @verbatim 00076 =============================================================================== 00077 ##### ramfunc functions ##### 00078 =============================================================================== 00079 [..] 00080 This subsection provides a set of functions that should be executed from RAM. 00081 00082 @endverbatim 00083 * @{ 00084 */ 00085 00086 /** 00087 * @brief Enable the Power down in Run Mode 00088 * @note This function should be called and executed from SRAM memory 00089 * @retval HAL status 00090 */ 00091 __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableRunPowerDown(void) 00092 { 00093 /* Enable the Power Down in Run mode*/ 00094 __HAL_FLASH_POWER_DOWN_ENABLE(); 00095 00096 return HAL_OK; 00097 00098 } 00099 00100 /** 00101 * @brief Disable the Power down in Run Mode 00102 * @note This function should be called and executed from SRAM memory 00103 * @retval HAL status 00104 */ 00105 __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableRunPowerDown(void) 00106 { 00107 /* Disable the Power Down in Run mode*/ 00108 __HAL_FLASH_POWER_DOWN_DISABLE(); 00109 00110 return HAL_OK; 00111 } 00112 00113 #if defined (STM32L4P5xx) || defined (STM32L4Q5xx) || defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx) 00114 /** 00115 * @brief Program the FLASH DBANK User Option Byte. 00116 * 00117 * @note To configure the user option bytes, the option lock bit OPTLOCK must 00118 * be cleared with the call of the HAL_FLASH_OB_Unlock() function. 00119 * @note To modify the DBANK option byte, no PCROP region should be defined. 00120 * To deactivate PCROP, user should perform RDP changing 00121 * 00122 * @param DBankConfig The FLASH DBANK User Option Byte value. 00123 * This parameter can be one of the following values: 00124 * @arg OB_DBANK_128_BITS: Single-bank with 128-bits data 00125 * @arg OB_DBANK_64_BITS: Dual-bank with 64-bits data 00126 * 00127 * @retval HAL status 00128 */ 00129 __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig) 00130 { 00131 uint32_t count, reg; 00132 HAL_StatusTypeDef status = HAL_ERROR; 00133 00134 /* Process Locked */ 00135 __HAL_LOCK(&pFlash); 00136 00137 /* Check if the PCROP is disabled */ 00138 reg = FLASH->PCROP1SR; 00139 if (reg > FLASH->PCROP1ER) 00140 { 00141 reg = FLASH->PCROP2SR; 00142 if (reg > FLASH->PCROP2ER) 00143 { 00144 /* Disable Flash prefetch */ 00145 __HAL_FLASH_PREFETCH_BUFFER_DISABLE(); 00146 00147 if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U) 00148 { 00149 /* Disable Flash instruction cache */ 00150 __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); 00151 00152 /* Flush Flash instruction cache */ 00153 __HAL_FLASH_INSTRUCTION_CACHE_RESET(); 00154 } 00155 00156 if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U) 00157 { 00158 /* Disable Flash data cache */ 00159 __HAL_FLASH_DATA_CACHE_DISABLE(); 00160 00161 /* Flush Flash data cache */ 00162 __HAL_FLASH_DATA_CACHE_RESET(); 00163 } 00164 00165 /* Disable WRP zone 1 of 1st bank if needed */ 00166 reg = FLASH->WRP1AR; 00167 if (((reg & FLASH_WRP1AR_WRP1A_STRT) >> FLASH_WRP1AR_WRP1A_STRT_Pos) <= 00168 ((reg & FLASH_WRP1AR_WRP1A_END) >> FLASH_WRP1AR_WRP1A_END_Pos)) 00169 { 00170 MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT); 00171 } 00172 00173 /* Disable WRP zone 2 of 1st bank if needed */ 00174 reg = FLASH->WRP1BR; 00175 if (((reg & FLASH_WRP1BR_WRP1B_STRT) >> FLASH_WRP1BR_WRP1B_STRT_Pos) <= 00176 ((reg & FLASH_WRP1BR_WRP1B_END) >> FLASH_WRP1BR_WRP1B_END_Pos)) 00177 { 00178 MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT); 00179 } 00180 00181 /* Disable WRP zone 1 of 2nd bank if needed */ 00182 reg = FLASH->WRP2AR; 00183 if (((reg & FLASH_WRP2AR_WRP2A_STRT) >> FLASH_WRP2AR_WRP2A_STRT_Pos) <= 00184 ((reg & FLASH_WRP2AR_WRP2A_END) >> FLASH_WRP2AR_WRP2A_END_Pos)) 00185 { 00186 MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT); 00187 } 00188 00189 /* Disable WRP zone 2 of 2nd bank if needed */ 00190 reg = FLASH->WRP2BR; 00191 if (((reg & FLASH_WRP2BR_WRP2B_STRT) >> FLASH_WRP2BR_WRP2B_STRT_Pos) <= 00192 ((reg & FLASH_WRP2BR_WRP2B_END) >> FLASH_WRP2BR_WRP2B_END_Pos)) 00193 { 00194 MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT); 00195 } 00196 00197 /* Modify the DBANK user option byte */ 00198 MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig); 00199 00200 /* Set OPTSTRT Bit */ 00201 SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 00202 00203 /* Wait for last operation to be completed */ 00204 /* 8 is the number of required instruction cycles for the below loop statement (timeout expressed in ms) */ 00205 count = FLASH_TIMEOUT_VALUE * (SystemCoreClock / 8U / 1000U); 00206 do 00207 { 00208 if (count == 0U) 00209 { 00210 break; 00211 } 00212 count--; 00213 } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET); 00214 00215 /* If the option byte program operation is completed, disable the OPTSTRT Bit */ 00216 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT); 00217 00218 /* Set the bit to force the option byte reloading */ 00219 SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH); 00220 } 00221 } 00222 00223 /* Process Unlocked */ 00224 __HAL_UNLOCK(&pFlash); 00225 00226 return status; 00227 } 00228 #endif 00229 00230 /** 00231 * @} 00232 */ 00233 00234 /** 00235 * @} 00236 */ 00237 #endif /* HAL_FLASH_MODULE_ENABLED */ 00238 00239 00240 00241 /** 00242 * @} 00243 */ 00244 00245 /** 00246 * @} 00247 */ 00248 00249 00250 00251