annotate f103c8/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0c59e7a7782a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 * @file stm32f1xx_hal_flash.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * @author MCD Application Team
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * @version V1.0.4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 * @date 29-April-2016
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * @brief FLASH HAL module driver.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 * This file provides firmware functions to manage the following
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 * functionalities of the internal FLASH memory:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * + Program operations functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 * + Memory Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 * + Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 ##### FLASH peripheral features #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 [..] The Flash memory interface manages CPU AHB I-Code and D-Code accesses
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 to the Flash memory. It implements the erase and program Flash memory operations
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 and the read and write protection mechanisms.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 [..] The Flash memory interface accelerates code execution with a system of instruction
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 prefetch.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 [..] The FLASH main features are:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 (+) Flash memory read operations
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 (+) Flash memory program/erase operations
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 (+) Read / write protections
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 (+) Prefetch on I-Code
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 (+) Option Bytes programming
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 ##### How to use this driver #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 This driver provides functions and macros to configure and program the FLASH
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 memory of all STM32F1xx devices.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 (#) FLASH Memory I/O Programming functions: this group includes all needed
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 functions to erase and program the main memory:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 (++) Lock and Unlock the FLASH interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42 (++) Erase function: Erase page, erase all pages
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 (++) Program functions: half word, word and doubleword
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 (#) FLASH Option Bytes Programming functions: this group includes all needed
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 functions to manage the Option Bytes:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47 (++) Lock and Unlock the Option Bytes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48 (++) Set/Reset the write protection
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 (++) Set the Read protection Level
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 (++) Program the user Option Bytes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 (++) Launch the Option Bytes loader
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 (++) Erase Option Bytes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 (++) Program the data Option Bytes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 (++) Get the Write protection.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55 (++) Get the user option bytes.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 (#) Interrupts and flags management functions : this group
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 includes all needed functions to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59 (++) Handle FLASH interrupts
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 (++) Wait for last FLASH operation according to its status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 (++) Get error flag status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 [..] In addition to these function, this driver includes a set of macros allowing
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64 to handle the following operations:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66 (+) Set/Get the latency
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 (+) Enable/Disable the prefetch buffer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68 (+) Enable/Disable the half cycle access
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 (+) Enable/Disable the FLASH interrupts
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 (+) Monitor the FLASH flags status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 /* Includes ------------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 #include "stm32f1xx_hal.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 /** @addtogroup STM32F1xx_HAL_Driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 #ifdef HAL_FLASH_MODULE_ENABLED
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 /** @defgroup FLASH FLASH
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 * @brief FLASH HAL module driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 /* Private typedef -----------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 /* Private define ------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 /** @defgroup FLASH_Private_Constants FLASH Private Constants
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126 /* Private macro ---------------------------- ---------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127 /** @defgroup FLASH_Private_Macros FLASH Private Macros
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 /* Private variables ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136 /** @defgroup FLASH_Private_Variables FLASH Private Variables
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139 /* Variables used for Erase pages under interruption*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 FLASH_ProcessTypeDef pFlash;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145 /* Private function prototypes -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 /** @defgroup FLASH_Private_Functions FLASH Private Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150 static void FLASH_SetErrorCode(void);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 /* Exported functions ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156 /** @defgroup FLASH_Exported_Functions FLASH Exported Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160 /** @defgroup FLASH_Exported_Functions_Group1 Programming operation functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 * @brief Programming operation functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169 * @brief Program halfword, word or double word at a specified address
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173 * @note If an erase and a program operations are requested simultaneously,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174 * the erase operation is performed before the program one.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 * @note FLASH should be previously erased before new programmation (only exception to this
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 * is when 0x0000 is programmed)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179 * @param TypeProgram: Indicate the way to program at a specified address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180 * This parameter can be a value of @ref FLASH_Type_Program
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181 * @param Address: Specifies the address to be programmed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 * @param Data: Specifies the data to be programmed
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 * @retval HAL_StatusTypeDef HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 HAL_StatusTypeDef status = HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189 uint8_t index = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190 uint8_t nbiterations = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 /* Process Locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193 __HAL_LOCK(&pFlash);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200 if(Address <= FLASH_BANK1_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203 /* Wait for last operation to be completed */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209 /* Wait for last operation to be completed */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 if(status == HAL_OK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216 if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218 /* Program halfword (16-bit) at a specified address. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 nbiterations = 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221 else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223 /* Program word (32-bit = 2*16-bit) at a specified address. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224 nbiterations = 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228 /* Program double word (64-bit = 4*16-bit) at a specified address. */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229 nbiterations = 4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 for (index = 0; index < nbiterations; index++)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234 FLASH_Program_HalfWord((Address + (2*index)), (uint16_t)(Data >> (16*index)));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237 if(Address <= FLASH_BANK1_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 /* Wait for last operation to be completed */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 /* If the program operation is completed, disable the PG Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244 CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249 /* Wait for last operation to be completed */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250 status = FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 /* If the program operation is completed, disable the PG Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253 CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256 /* In case of error, stop programation procedure */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257 if (status != HAL_OK)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 __HAL_UNLOCK(&pFlash);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267 return status;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 * @brief Program halfword, word or double word at a specified address with interrupt enabled.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272 * @note The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273 * The function HAL_FLASH_Lock() should be called after to lock the FLASH interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 * @note If an erase and a program operations are requested simultaneously,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276 * the erase operation is performed before the program one.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278 * @param TypeProgram: Indicate the way to program at a specified address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279 * This parameter can be a value of @ref FLASH_Type_Program
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280 * @param Address: Specifies the address to be programmed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 * @param Data: Specifies the data to be programmed
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283 * @retval HAL_StatusTypeDef HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
286 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
287 HAL_StatusTypeDef status = HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
288
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289 /* Process Locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 __HAL_LOCK(&pFlash);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293 assert_param(IS_FLASH_TYPEPROGRAM(TypeProgram));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294 assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 /* If procedure already ongoing, reject the next one */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298 if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 if(Address <= FLASH_BANK1_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305 /* Enable End of FLASH Operation and Error source interrupts */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308 }else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310 /* Enable End of FLASH Operation and Error source interrupts */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314 /* Enable End of FLASH Operation and Error source interrupts */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318 pFlash.Address = Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319 pFlash.Data = Data;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321 if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 /*Program halfword (16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325 pFlash.DataRemaining = 1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330 /*Program word (32-bit : 2*16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331 pFlash.DataRemaining = 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 /*Program double word (64-bit : 4*16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337 pFlash.DataRemaining = 4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 /*Program halfword (16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341 FLASH_Program_HalfWord(Address, (uint16_t)Data);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343 return status;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 * @brief This function handles FLASH interrupt request.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 void HAL_FLASH_IRQHandler(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 uint32_t addresstmp = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354 /* Check FLASH operation error flags */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357 (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 /*return the faulty address*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363 addresstmp = pFlash.Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 /* Reset address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365 pFlash.Address = 0xFFFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367 /*Save the Error code*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 FLASH_SetErrorCode();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 /* FLASH error interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 HAL_FLASH_OperationErrorCallback(addresstmp);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373 /* Stop the procedure ongoing*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 /* Check FLASH End of Operation flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 /* Clear FLASH End of Operation pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 /* Clear FLASH End of Operation pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 /* Process can continue only if no error detected */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391 if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
395 /* Nb of pages to erased can be decreased */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
396 pFlash.DataRemaining--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
398 /* Check if there are still pages to erase*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 if(pFlash.DataRemaining != 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401 addresstmp = pFlash.Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 /*Indicate user which sector has been erased*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 HAL_FLASH_EndOfOperationCallback(addresstmp);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 /*Increment sector number*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406 addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407 pFlash.Address = addresstmp;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409 /* If the erase operation is completed, disable the PER Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410 CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412 FLASH_PageErase(addresstmp);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416 /*No more pages to Erase, user callback can be called.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 /*Reset Sector and stop Erase pages procedure*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418 pFlash.Address = addresstmp = 0xFFFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421 HAL_FLASH_EndOfOperationCallback(addresstmp);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424 else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426 /* Operation is completed, disable the MER Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427 CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430 /* Stop Mass Erase procedure if no pending mass erase on other bank */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 /* MassErase ended. Return the selected bank*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436 HAL_FLASH_EndOfOperationCallback(0);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 /* Stop Mass Erase procedure*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446 /* Nb of 16-bit data to program can be decreased */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 pFlash.DataRemaining--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
449 /* Check if there are still 16-bit data to program */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
450 if(pFlash.DataRemaining != 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
451 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
452 /* Increment address to 16-bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
453 pFlash.Address += 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
454 addresstmp = pFlash.Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
455
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
456 /* Shift to have next 16-bit data */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
457 pFlash.Data = (pFlash.Data >> 16);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
458
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
459 /* Operation is completed, disable the PG Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
460 CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
461
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
462 /*Program halfword (16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
463 FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
464 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
465 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
466 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
467 /*Program ended. Return the selected address*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
468 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
469 if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
470 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
471 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
472 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
473 else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
474 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
475 HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
476 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
477 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
478 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
479 HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
480 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
481
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
482 /* Reset Address and stop Program procedure*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
483 pFlash.Address = 0xFFFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
484 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
485 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
486 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
487 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
488 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
489
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
490 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
491 /* Check FLASH End of Operation flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
492 if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
493 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
494 /* Clear FLASH End of Operation pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
495 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
496
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
497 /* Process can continue only if no error detected */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
498 if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
499 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
500 if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
501 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
502 /* Nb of pages to erased can be decreased */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
503 pFlash.DataRemaining--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
504
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
505 /* Check if there are still pages to erase*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
506 if(pFlash.DataRemaining != 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
507 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
508 /* Indicate user which page address has been erased*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
509 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
510
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
511 /* Increment page address to next page */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
512 pFlash.Address += FLASH_PAGE_SIZE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
513 addresstmp = pFlash.Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
514
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
515 /* Operation is completed, disable the PER Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
516 CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
517
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
518 FLASH_PageErase(addresstmp);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
519 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
520 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
521 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
522 /*No more pages to Erase*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
523
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
524 /*Reset Address and stop Erase pages procedure*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
525 pFlash.Address = 0xFFFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
526 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
527
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
528 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
529 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
530 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
531 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
532 else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
533 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
534 /* Operation is completed, disable the MER Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
535 CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
536
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
537 if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
538 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
539 /* MassErase ended. Return the selected bank*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
540 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
541 HAL_FLASH_EndOfOperationCallback(0);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
542
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
543 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
544 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
545 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
546 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
547 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
548 /* Nb of 16-bit data to program can be decreased */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
549 pFlash.DataRemaining--;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
550
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
551 /* Check if there are still 16-bit data to program */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
552 if(pFlash.DataRemaining != 0)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
553 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
554 /* Increment address to 16-bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
555 pFlash.Address += 2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
556 addresstmp = pFlash.Address;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
557
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
558 /* Shift to have next 16-bit data */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
559 pFlash.Data = (pFlash.Data >> 16);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
560
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
561 /* Operation is completed, disable the PG Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
562 CLEAR_BIT(FLASH->CR2, FLASH_CR2_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
563
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
564 /*Program halfword (16-bit) at a specified address.*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
565 FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
566 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
567 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
568 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
569 /*Program ended. Return the selected address*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
570 /* FLASH EOP interrupt user callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
571 if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
572 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
573 HAL_FLASH_EndOfOperationCallback(pFlash.Address);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
574 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
575 else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
576 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
577 HAL_FLASH_EndOfOperationCallback(pFlash.Address-2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
578 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
579 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
580 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
581 HAL_FLASH_EndOfOperationCallback(pFlash.Address-6);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
582 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
583
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
584 /* Reset Address and stop Program procedure*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
585 pFlash.Address = 0xFFFFFFFF;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
586 pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
587 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
588 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
589 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
590 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
591 #endif
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
592
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
593 if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
594 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
595 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
596 /* Operation is completed, disable the PG, PER and MER Bits for both bank */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
597 CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
598 CLEAR_BIT(FLASH->CR2, (FLASH_CR2_PG | FLASH_CR2_PER | FLASH_CR2_MER));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
599
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
600 /* Disable End of FLASH Operation and Error source interrupts for both banks */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
601 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1 | FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
602 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
603 /* Operation is completed, disable the PG, PER and MER Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
604 CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
605
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
606 /* Disable End of FLASH Operation and Error source interrupts */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
607 __HAL_FLASH_DISABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
608 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
609
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
610 /* Process Unlocked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
611 __HAL_UNLOCK(&pFlash);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
612 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
613 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
614
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
615
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
616 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
617 * @brief FLASH end of operation interrupt callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
618 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
619 * - Mass Erase: No return value expected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
620 * - Pages Erase: Address of the page which has been erased
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
621 * (if 0xFFFFFFFF, it means that all the selected pages have been erased)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
622 * - Program: Address which was selected for data program
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
623 * @retval none
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
624 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
625 __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
626 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
627 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
628 UNUSED(ReturnValue);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
629 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
630 the HAL_FLASH_EndOfOperationCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
631 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
632 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
633
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
634 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
635 * @brief FLASH operation error interrupt callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
636 * @param ReturnValue: The value saved in this parameter depends on the ongoing procedure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
637 * - Mass Erase: No return value expected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
638 * - Pages Erase: Address of the page which returned an error
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
639 * - Program: Address which was selected for data program
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
640 * @retval none
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
641 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
642 __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
643 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
644 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
645 UNUSED(ReturnValue);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
646 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
647 the HAL_FLASH_OperationErrorCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
648 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
649 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
650
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
651 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
652 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
653 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
654
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
655 /** @defgroup FLASH_Exported_Functions_Group2 Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
656 * @brief management functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
657 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
658 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
659 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
660 ##### Peripheral Control functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
661 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
662 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
663 This subsection provides a set of functions allowing to control the FLASH
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
664 memory operations.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
665
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
666 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
667 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
668 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
669
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
670 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
671 * @brief Unlock the FLASH control register access
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
672 * @retval HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
673 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
674 HAL_StatusTypeDef HAL_FLASH_Unlock(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
675 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
676 if (HAL_IS_BIT_SET(FLASH->CR, FLASH_CR_LOCK))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
677 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
678 /* Authorize the FLASH Registers access */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
679 WRITE_REG(FLASH->KEYR, FLASH_KEY1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
680 WRITE_REG(FLASH->KEYR, FLASH_KEY2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
681 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
682 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
683 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
684 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
685 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
686
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
687 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
688 if (HAL_IS_BIT_SET(FLASH->CR2, FLASH_CR2_LOCK))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
689 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
690 /* Authorize the FLASH BANK2 Registers access */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
691 WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
692 WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
693 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
694 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
695 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
696 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
697 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
698
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
699 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
700 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
701 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
702
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
703 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
704 * @brief Locks the FLASH control register access
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
705 * @retval HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
706 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
707 HAL_StatusTypeDef HAL_FLASH_Lock(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
708 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
709 /* Set the LOCK Bit to lock the FLASH Registers access */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
710 SET_BIT(FLASH->CR, FLASH_CR_LOCK);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
711
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
712 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
713 /* Set the LOCK Bit to lock the FLASH BANK2 Registers access */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
714 SET_BIT(FLASH->CR2, FLASH_CR2_LOCK);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
715 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
716
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
717 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
718 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
719
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
720
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
721 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
722 * @brief Unlock the FLASH Option Control Registers access.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
723 * @retval HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
724 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
725 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
726 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
727 if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
728 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
729 /* Authorizes the Option Byte register programming */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
730 WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
731 WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
732 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
733 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
734 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
735 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
736 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
737
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
738 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
739 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
740
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
741 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
742 * @brief Lock the FLASH Option Control Registers access.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
743 * @retval HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
744 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
745 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
746 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
747 /* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
748 CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
749
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
750 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
751 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
752
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
753 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
754 * @brief Launch the option byte loading.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
755 * @note This function will reset automatically the MCU.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
756 * @retval HAL_StatusTypeDef HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
757 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
758 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
759 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
760 /* Initiates a system reset request to launch the option byte loading */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
761 HAL_NVIC_SystemReset();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
762
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
763 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
764 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
765
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
766 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
767 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
768 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
769
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
770 /** @defgroup FLASH_Exported_Functions_Group3 Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
771 * @brief Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
772 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
773 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
774 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
775 ##### Peripheral State functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
776 ===============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
777 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
778 This subsection permit to get in run-time the status of the FLASH peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
779
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
780 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
781 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
782 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
783
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
784 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
785 * @brief Get the specific FLASH error flag.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
786 * @retval FLASH_ErrorCode: The returned value can be:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
787 * @ref FLASH_Error_Codes
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
788 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
789 uint32_t HAL_FLASH_GetError(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
790 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
791 return pFlash.ErrorCode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
792 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
793 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
794 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
795 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
796
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
797 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
798 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
799 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
800
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
801 /** @addtogroup FLASH_Private_Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
802 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
803 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
804
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
805 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
806 * @brief Program a half-word (16-bit) at a specified address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
807 * @param Address: specifies the address to be programmed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
808 * @param Data: specifies the data to be programmed.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
809 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
810 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
811 static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
812 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
813 /* Clean the error context */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
814 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
815
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
816 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
817 if(Address <= FLASH_BANK1_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
818 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
819 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
820 /* Proceed to program the new data */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
821 SET_BIT(FLASH->CR, FLASH_CR_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
822 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
823 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
824 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
825 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
826 /* Proceed to program the new data */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
827 SET_BIT(FLASH->CR2, FLASH_CR2_PG);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
828 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
829 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
830
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
831 /* Write data in the address */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
832 *(__IO uint16_t*)Address = Data;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
833 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
834
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
835 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
836 * @brief Wait for a FLASH operation to complete.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
837 * @param Timeout: maximum flash operation timeout
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
838 * @retval HAL_StatusTypeDef HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
839 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
840 HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
841 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
842 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
843 Even if the FLASH operation fails, the BUSY flag will be reset and an error
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
844 flag will be set */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
845
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
846 uint32_t tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
847
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
848 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
849 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
850 if (Timeout != HAL_MAX_DELAY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
851 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
852 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
853 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
854 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
855 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
856 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
857 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
858
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
859 /* Check FLASH End of Operation flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
860 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
861 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
862 /* Clear FLASH End of Operation pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
863 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
864 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
865
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
866 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
867 __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
868 __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
869 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
870 /*Save the error code*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
871 FLASH_SetErrorCode();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
872 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
873 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
874
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
875 /* If there is no error flag set */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
876 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
877 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
878
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
879 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
880 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
881 * @brief Wait for a FLASH BANK2 operation to complete.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
882 * @param Timeout: maximum flash operation timeout
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
883 * @retval HAL_StatusTypeDef HAL Status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
884 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
885 HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
886 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
887 /* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
888 Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
889 flag will be set */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
890
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
891 uint32_t tickstart = HAL_GetTick();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
892
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
893 while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
894 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
895 if (Timeout != HAL_MAX_DELAY)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
896 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
897 if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
898 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
899 return HAL_TIMEOUT;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
900 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
901 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
902 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
903
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
904 /* Check FLASH End of Operation flag */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
905 if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
906 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
907 /* Clear FLASH End of Operation pending bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
908 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
909 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
910
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
911 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
912 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
913 /*Save the error code*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
914 FLASH_SetErrorCode();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
915 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
916 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
917
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
918 /* If there is an error flag set */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
919 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
920
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
921 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
922 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
923
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
924 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
925 * @brief Set the specific FLASH error flag.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
926 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
927 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
928 static void FLASH_SetErrorCode(void)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
929 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
930 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
931 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
932 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
933 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
934 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
935 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
936 pFlash.ErrorCode |= HAL_FLASH_ERROR_WRP;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
937 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
938 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
939 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
940 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
941 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
942 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
943 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
944 pFlash.ErrorCode |= HAL_FLASH_ERROR_PROG;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
945 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
946
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
947 if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
948 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
949 pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
950 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
951 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
952
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
953 /* Clear FLASH error pending bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
954 #if defined(FLASH_BANK2_END)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
955 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGERR | FLASH_FLAG_PGERR_BANK2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
956 #else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
957 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
958 #endif /* FLASH_BANK2_END */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
959 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
960 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
961 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
962 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
963
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
964 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
965 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
966 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
967
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
968 #endif /* HAL_FLASH_MODULE_ENABLED */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
969
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
970 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
971 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
972 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
973
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
974 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/