]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c
Rename STM32Cube to GCC for STM32L4 Discovery projects as GCC is
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_flash_ramfunc.c
1 /**\r
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
10   *\r
11   *  @verbatim\r
12   ==============================================================================\r
13                    ##### Flash RAM functions #####\r
14   ==============================================================================\r
15 \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
24 \r
25     *** ICCARM Compiler ***\r
26     -----------------------\r
27     [..] RAM functions are defined using a specific toolchain keyword "__ramfunc".\r
28 \r
29     *** GNU Compiler ***\r
30     --------------------\r
31     [..] RAM functions are defined using a specific toolchain attribute\r
32          "__attribute__((section(".RamFunc")))".\r
33 \r
34   @endverbatim\r
35   ******************************************************************************\r
36   * @attention\r
37   *\r
38   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
39   * All rights reserved.</center></h2>\r
40   *\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
45   *\r
46   ******************************************************************************\r
47   */\r
48 \r
49 /* Includes ------------------------------------------------------------------*/\r
50 #include "stm32l4xx_hal.h"\r
51 \r
52 /** @addtogroup STM32L4xx_HAL_Driver\r
53   * @{\r
54   */\r
55 \r
56 /** @defgroup FLASH_RAMFUNC FLASH_RAMFUNC\r
57   * @brief FLASH functions executed from RAM\r
58   * @{\r
59   */\r
60 \r
61 #ifdef HAL_FLASH_MODULE_ENABLED\r
62 \r
63 /* Private typedef -----------------------------------------------------------*/\r
64 /* Private define ------------------------------------------------------------*/\r
65 /* Private macro -------------------------------------------------------------*/\r
66 /* Private variables ---------------------------------------------------------*/\r
67 extern FLASH_ProcessTypeDef pFlash;\r
68 \r
69 /* Private function prototypes -----------------------------------------------*/\r
70 /* Exported functions -------------------------------------------------------*/\r
71 \r
72 /** @defgroup FLASH_RAMFUNC_Exported_Functions FLASH in RAM function Exported Functions\r
73   * @{\r
74   */\r
75 \r
76 /** @defgroup FLASH_RAMFUNC_Exported_Functions_Group1 Peripheral features functions\r
77  *  @brief   Data transfers functions\r
78  *\r
79 @verbatim\r
80  ===============================================================================\r
81                       ##### ramfunc functions #####\r
82  ===============================================================================\r
83     [..]\r
84     This subsection provides a set of functions that should be executed from RAM.\r
85 \r
86 @endverbatim\r
87   * @{\r
88   */\r
89 \r
90 /**\r
91   * @brief   Enable the Power down in Run Mode\r
92   * @note    This function should be called and executed from SRAM memory\r
93   * @retval None\r
94   */\r
95 __RAM_FUNC HAL_FLASHEx_EnableRunPowerDown(void)\r
96 {\r
97   /* Enable the Power Down in Run mode*/\r
98   __HAL_FLASH_POWER_DOWN_ENABLE();\r
99 \r
100   return HAL_OK;\r
101 \r
102 }\r
103 \r
104 /**\r
105   * @brief   Disable the Power down in Run Mode\r
106   * @note    This function should be called and executed from SRAM memory\r
107   * @retval None\r
108   */\r
109 __RAM_FUNC HAL_FLASHEx_DisableRunPowerDown(void)\r
110 {\r
111   /* Disable the Power Down in Run mode*/\r
112   __HAL_FLASH_POWER_DOWN_DISABLE();\r
113 \r
114   return HAL_OK;\r
115 }\r
116 \r
117 #if defined (STM32L4R5xx) || defined (STM32L4R7xx) || defined (STM32L4R9xx) || defined (STM32L4S5xx) || defined (STM32L4S7xx) || defined (STM32L4S9xx)\r
118 /**\r
119   * @brief  Program the FLASH DBANK User Option Byte.\r
120   *\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
125   *\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
130   *\r
131   * @retval HAL status\r
132   */\r
133 __RAM_FUNC HAL_FLASHEx_OB_DBankConfig(uint32_t DBankConfig)\r
134 {\r
135   register uint32_t count, reg;\r
136   HAL_StatusTypeDef status = HAL_ERROR;\r
137 \r
138   /* Process Locked */\r
139   __HAL_LOCK(&pFlash);\r
140 \r
141   /* Check if the PCROP is disabled */\r
142   reg = FLASH->PCROP1SR;\r
143   if (reg > FLASH->PCROP1ER)\r
144   {\r
145     reg = FLASH->PCROP2SR;\r
146     if (reg > FLASH->PCROP2ER)\r
147     {\r
148       /* Disable Flash prefetch */\r
149       __HAL_FLASH_PREFETCH_BUFFER_DISABLE();\r
150 \r
151       if (READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) != 0U)\r
152       {\r
153         /* Disable Flash instruction cache */\r
154         __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();\r
155 \r
156         /* Flush Flash instruction cache */\r
157         __HAL_FLASH_INSTRUCTION_CACHE_RESET();\r
158       }\r
159 \r
160       if (READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) != 0U)\r
161       {\r
162         /* Disable Flash data cache */\r
163         __HAL_FLASH_DATA_CACHE_DISABLE();\r
164 \r
165         /* Flush Flash data cache */\r
166         __HAL_FLASH_DATA_CACHE_RESET();\r
167       }\r
168 \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
173       {\r
174         MODIFY_REG(FLASH->WRP1AR, (FLASH_WRP1AR_WRP1A_STRT | FLASH_WRP1AR_WRP1A_END), FLASH_WRP1AR_WRP1A_STRT);\r
175       }\r
176 \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
181       {\r
182         MODIFY_REG(FLASH->WRP1BR, (FLASH_WRP1BR_WRP1B_STRT | FLASH_WRP1BR_WRP1B_END), FLASH_WRP1BR_WRP1B_STRT);\r
183       }\r
184 \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
189       {\r
190         MODIFY_REG(FLASH->WRP2AR, (FLASH_WRP2AR_WRP2A_STRT | FLASH_WRP2AR_WRP2A_END), FLASH_WRP2AR_WRP2A_STRT);\r
191       }\r
192 \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
197       {\r
198         MODIFY_REG(FLASH->WRP2BR, (FLASH_WRP2BR_WRP2B_STRT | FLASH_WRP2BR_WRP2B_END), FLASH_WRP2BR_WRP2B_STRT);\r
199       }\r
200 \r
201       /* Modify the DBANK user option byte */\r
202       MODIFY_REG(FLASH->OPTR, FLASH_OPTR_DBANK, DBankConfig);\r
203 \r
204       /* Set OPTSTRT Bit */\r
205       SET_BIT(FLASH->CR, FLASH_CR_OPTSTRT);\r
206 \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
210       do\r
211       {\r
212         if (count == 0U)\r
213         {\r
214           break;\r
215         }\r
216         count--;\r
217       } while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY) != RESET);\r
218 \r
219       /* If the option byte program operation is completed, disable the OPTSTRT Bit */\r
220       CLEAR_BIT(FLASH->CR, FLASH_CR_OPTSTRT);\r
221 \r
222       /* Set the bit to force the option byte reloading */\r
223       SET_BIT(FLASH->CR, FLASH_CR_OBL_LAUNCH);\r
224     }\r
225   }\r
226 \r
227   /* Process Unlocked */\r
228   __HAL_UNLOCK(&pFlash);\r
229 \r
230   return status;\r
231 }\r
232 #endif\r
233 \r
234 /**\r
235   * @}\r
236   */\r
237 \r
238 /**\r
239   * @}\r
240   */\r
241 #endif /* HAL_FLASH_MODULE_ENABLED */\r
242 \r
243 \r
244 \r
245 /**\r
246   * @}\r
247   */\r
248 \r
249 /**\r
250   * @}\r
251   */\r
252 \r
253 \r
254 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r
255 \r
256 \r