提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file stm32f0xx_hal_flash_ex.c |
|
4 |
* @author MCD Application Team |
|
5 |
* @brief Extended FLASH HAL module driver. |
|
6 |
* |
|
7 |
* This file provides firmware functions to manage the following |
|
8 |
* functionalities of the FLASH peripheral: |
|
9 |
* + Extended Initialization/de-initialization functions |
|
10 |
* + Extended I/O operation functions |
|
11 |
* + Extended Peripheral Control functions |
|
12 |
* |
|
13 |
@verbatim |
|
14 |
============================================================================== |
|
15 |
##### Flash peripheral extended features ##### |
|
16 |
============================================================================== |
|
17 |
|
|
18 |
##### How to use this driver ##### |
|
19 |
============================================================================== |
|
20 |
[..] This driver provides functions to configure and program the FLASH memory |
|
21 |
of all STM32F0xxx devices. It includes |
|
22 |
|
|
23 |
(++) Set/Reset the write protection |
|
24 |
(++) Program the user Option Bytes |
|
25 |
(++) Get the Read protection Level |
|
26 |
|
|
27 |
@endverbatim |
|
28 |
****************************************************************************** |
|
29 |
* @attention |
|
30 |
* |
|
31 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
|
32 |
* |
|
33 |
* Redistribution and use in source and binary forms, with or without modification, |
|
34 |
* are permitted provided that the following conditions are met: |
|
35 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
36 |
* this list of conditions and the following disclaimer. |
|
37 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
38 |
* this list of conditions and the following disclaimer in the documentation |
|
39 |
* and/or other materials provided with the distribution. |
|
40 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
41 |
* may be used to endorse or promote products derived from this software |
|
42 |
* without specific prior written permission. |
|
43 |
* |
|
44 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
45 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
46 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
47 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
48 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
49 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
50 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
51 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
52 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
53 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
54 |
* |
|
55 |
****************************************************************************** |
|
56 |
*/ |
|
57 |
|
|
58 |
/* Includes ------------------------------------------------------------------*/ |
|
59 |
#include "stm32f0xx_hal.h" |
|
60 |
|
|
61 |
/** @addtogroup STM32F0xx_HAL_Driver |
|
62 |
* @{ |
|
63 |
*/ |
|
64 |
#ifdef HAL_FLASH_MODULE_ENABLED |
|
65 |
|
|
66 |
/** @addtogroup FLASH |
|
67 |
* @{ |
|
68 |
*/ |
|
69 |
/** @addtogroup FLASH_Private_Variables |
|
70 |
* @{ |
|
71 |
*/ |
|
72 |
/* Variables used for Erase pages under interruption*/ |
|
73 |
extern FLASH_ProcessTypeDef pFlash; |
|
74 |
/** |
|
75 |
* @} |
|
76 |
*/ |
|
77 |
|
|
78 |
/** |
|
79 |
* @} |
|
80 |
*/ |
|
81 |
|
|
82 |
/** @defgroup FLASHEx FLASHEx |
|
83 |
* @brief FLASH HAL Extension module driver |
|
84 |
* @{ |
|
85 |
*/ |
|
86 |
|
|
87 |
/* Private typedef -----------------------------------------------------------*/ |
|
88 |
/* Private define ------------------------------------------------------------*/ |
|
89 |
/** @defgroup FLASHEx_Private_Constants FLASHEx Private Constants |
|
90 |
* @{ |
|
91 |
*/ |
|
92 |
#define FLASH_POSITION_IWDGSW_BIT 8U |
|
93 |
#define FLASH_POSITION_OB_USERDATA0_BIT 16U |
|
94 |
#define FLASH_POSITION_OB_USERDATA1_BIT 24U |
|
95 |
/** |
|
96 |
* @} |
|
97 |
*/ |
|
98 |
|
|
99 |
/* Private macro -------------------------------------------------------------*/ |
|
100 |
/** @defgroup FLASHEx_Private_Macros FLASHEx Private Macros |
|
101 |
* @{ |
|
102 |
*/ |
|
103 |
/** |
|
104 |
* @} |
|
105 |
*/ |
|
106 |
|
|
107 |
/* Private variables ---------------------------------------------------------*/ |
|
108 |
/* Private function prototypes -----------------------------------------------*/ |
|
109 |
/** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions |
|
110 |
* @{ |
|
111 |
*/ |
|
112 |
/* Erase operations */ |
|
113 |
static void FLASH_MassErase(void); |
|
114 |
void FLASH_PageErase(uint32_t PageAddress); |
|
115 |
|
|
116 |
/* Option bytes control */ |
|
117 |
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage); |
|
118 |
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage); |
|
119 |
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel); |
|
120 |
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig); |
|
121 |
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data); |
|
122 |
static uint32_t FLASH_OB_GetWRP(void); |
|
123 |
static uint32_t FLASH_OB_GetRDP(void); |
|
124 |
static uint8_t FLASH_OB_GetUser(void); |
|
125 |
|
|
126 |
/** |
|
127 |
* @} |
|
128 |
*/ |
|
129 |
|
|
130 |
/* Exported functions ---------------------------------------------------------*/ |
|
131 |
/** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions |
|
132 |
* @{ |
|
133 |
*/ |
|
134 |
|
|
135 |
/** @defgroup FLASHEx_Exported_Functions_Group1 FLASHEx Memory Erasing functions |
|
136 |
* @brief FLASH Memory Erasing functions |
|
137 |
* |
|
138 |
@verbatim |
|
139 |
============================================================================== |
|
140 |
##### FLASH Erasing Programming functions ##### |
|
141 |
============================================================================== |
|
142 |
|
|
143 |
[..] The FLASH Memory Erasing functions, includes the following functions: |
|
144 |
(+) @ref HAL_FLASHEx_Erase: return only when erase has been done |
|
145 |
(+) @ref HAL_FLASHEx_Erase_IT: end of erase is done when @ref HAL_FLASH_EndOfOperationCallback |
|
146 |
is called with parameter 0xFFFFFFFF |
|
147 |
|
|
148 |
[..] Any operation of erase should follow these steps: |
|
149 |
(#) Call the @ref HAL_FLASH_Unlock() function to enable the flash control register and |
|
150 |
program memory access. |
|
151 |
(#) Call the desired function to erase page. |
|
152 |
(#) Call the @ref HAL_FLASH_Lock() to disable the flash program memory access |
|
153 |
(recommended to protect the FLASH memory against possible unwanted operation). |
|
154 |
|
|
155 |
@endverbatim |
|
156 |
* @{ |
|
157 |
*/ |
|
158 |
|
|
159 |
|
|
160 |
/** |
|
161 |
* @brief Perform a mass erase or erase the specified FLASH memory pages |
|
162 |
* @note To correctly run this function, the @ref HAL_FLASH_Unlock() function |
|
163 |
* must be called before. |
|
164 |
* Call the @ref HAL_FLASH_Lock() to disable the flash memory access |
|
165 |
* (recommended to protect the FLASH memory against possible unwanted operation) |
|
166 |
* @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
|
167 |
* contains the configuration information for the erasing. |
|
168 |
* |
|
169 |
* @param[out] PageError pointer to variable that |
|
170 |
* contains the configuration information on faulty page in case of error |
|
171 |
* (0xFFFFFFFF means that all the pages have been correctly erased) |
|
172 |
* |
|
173 |
* @retval HAL_StatusTypeDef HAL Status |
|
174 |
*/ |
|
175 |
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) |
|
176 |
{ |
|
177 |
HAL_StatusTypeDef status = HAL_ERROR; |
|
178 |
uint32_t address = 0U; |
|
179 |
|
|
180 |
/* Process Locked */ |
|
181 |
__HAL_LOCK(&pFlash); |
|
182 |
|
|
183 |
/* Check the parameters */ |
|
184 |
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
|
185 |
|
|
186 |
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
|
187 |
{ |
|
188 |
/* Mass Erase requested for Bank1 */ |
|
189 |
/* Wait for last operation to be completed */ |
|
190 |
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
|
191 |
{ |
|
192 |
/*Mass erase to be done*/ |
|
193 |
FLASH_MassErase(); |
|
194 |
|
|
195 |
/* Wait for last operation to be completed */ |
|
196 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
197 |
|
|
198 |
/* If the erase operation is completed, disable the MER Bit */ |
|
199 |
CLEAR_BIT(FLASH->CR, FLASH_CR_MER); |
|
200 |
} |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
/* Page Erase is requested */ |
|
205 |
/* Check the parameters */ |
|
206 |
assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
|
207 |
assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); |
|
208 |
|
|
209 |
/* Page Erase requested on address located on bank1 */ |
|
210 |
/* Wait for last operation to be completed */ |
|
211 |
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) |
|
212 |
{ |
|
213 |
/*Initialization of PageError variable*/ |
|
214 |
*PageError = 0xFFFFFFFFU; |
|
215 |
|
|
216 |
/* Erase page by page to be done*/ |
|
217 |
for(address = pEraseInit->PageAddress; |
|
218 |
address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress); |
|
219 |
address += FLASH_PAGE_SIZE) |
|
220 |
{ |
|
221 |
FLASH_PageErase(address); |
|
222 |
|
|
223 |
/* Wait for last operation to be completed */ |
|
224 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
225 |
|
|
226 |
/* If the erase operation is completed, disable the PER Bit */ |
|
227 |
CLEAR_BIT(FLASH->CR, FLASH_CR_PER); |
|
228 |
|
|
229 |
if (status != HAL_OK) |
|
230 |
{ |
|
231 |
/* In case of error, stop erase procedure and return the faulty address */ |
|
232 |
*PageError = address; |
|
233 |
break; |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
/* Process Unlocked */ |
|
240 |
__HAL_UNLOCK(&pFlash); |
|
241 |
|
|
242 |
return status; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* @brief Perform a mass erase or erase the specified FLASH memory pages with interrupt enabled |
|
247 |
* @note To correctly run this function, the @ref HAL_FLASH_Unlock() function |
|
248 |
* must be called before. |
|
249 |
* Call the @ref HAL_FLASH_Lock() to disable the flash memory access |
|
250 |
* (recommended to protect the FLASH memory against possible unwanted operation) |
|
251 |
* @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that |
|
252 |
* contains the configuration information for the erasing. |
|
253 |
* |
|
254 |
* @retval HAL_StatusTypeDef HAL Status |
|
255 |
*/ |
|
256 |
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
|
257 |
{ |
|
258 |
HAL_StatusTypeDef status = HAL_OK; |
|
259 |
|
|
260 |
/* Process Locked */ |
|
261 |
__HAL_LOCK(&pFlash); |
|
262 |
|
|
263 |
/* If procedure already ongoing, reject the next one */ |
|
264 |
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) |
|
265 |
{ |
|
266 |
return HAL_ERROR; |
|
267 |
} |
|
268 |
|
|
269 |
/* Check the parameters */ |
|
270 |
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase)); |
|
271 |
|
|
272 |
/* Enable End of FLASH Operation and Error source interrupts */ |
|
273 |
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP | FLASH_IT_ERR); |
|
274 |
|
|
275 |
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) |
|
276 |
{ |
|
277 |
/*Mass erase to be done*/ |
|
278 |
pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE; |
|
279 |
FLASH_MassErase(); |
|
280 |
} |
|
281 |
else |
|
282 |
{ |
|
283 |
/* Erase by page to be done*/ |
|
284 |
|
|
285 |
/* Check the parameters */ |
|
286 |
assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress)); |
|
287 |
assert_param(IS_FLASH_NB_PAGES(pEraseInit->PageAddress, pEraseInit->NbPages)); |
|
288 |
|
|
289 |
pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE; |
|
290 |
pFlash.DataRemaining = pEraseInit->NbPages; |
|
291 |
pFlash.Address = pEraseInit->PageAddress; |
|
292 |
|
|
293 |
/*Erase 1st page and wait for IT*/ |
|
294 |
FLASH_PageErase(pEraseInit->PageAddress); |
|
295 |
} |
|
296 |
|
|
297 |
return status; |
|
298 |
} |
|
299 |
|
|
300 |
/** |
|
301 |
* @} |
|
302 |
*/ |
|
303 |
|
|
304 |
/** @defgroup FLASHEx_Exported_Functions_Group2 Option Bytes Programming functions |
|
305 |
* @brief Option Bytes Programming functions |
|
306 |
* |
|
307 |
@verbatim |
|
308 |
============================================================================== |
|
309 |
##### Option Bytes Programming functions ##### |
|
310 |
============================================================================== |
|
311 |
[..] |
|
312 |
This subsection provides a set of functions allowing to control the FLASH |
|
313 |
option bytes operations. |
|
314 |
|
|
315 |
@endverbatim |
|
316 |
* @{ |
|
317 |
*/ |
|
318 |
|
|
319 |
/** |
|
320 |
* @brief Erases the FLASH option bytes. |
|
321 |
* @note This functions erases all option bytes except the Read protection (RDP). |
|
322 |
* The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
|
323 |
* The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
|
324 |
* The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
|
325 |
* (system reset will occur) |
|
326 |
* @retval HAL status |
|
327 |
*/ |
|
328 |
|
|
329 |
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) |
|
330 |
{ |
|
331 |
uint8_t rdptmp = OB_RDP_LEVEL_0; |
|
332 |
HAL_StatusTypeDef status = HAL_ERROR; |
|
333 |
|
|
334 |
/* Get the actual read protection Option Byte value */ |
|
335 |
rdptmp = FLASH_OB_GetRDP(); |
|
336 |
|
|
337 |
/* Wait for last operation to be completed */ |
|
338 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
339 |
|
|
340 |
if(status == HAL_OK) |
|
341 |
{ |
|
342 |
/* Clean the error context */ |
|
343 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
344 |
|
|
345 |
/* If the previous operation is completed, proceed to erase the option bytes */ |
|
346 |
SET_BIT(FLASH->CR, FLASH_CR_OPTER); |
|
347 |
SET_BIT(FLASH->CR, FLASH_CR_STRT); |
|
348 |
|
|
349 |
/* Wait for last operation to be completed */ |
|
350 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
351 |
|
|
352 |
/* If the erase operation is completed, disable the OPTER Bit */ |
|
353 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER); |
|
354 |
|
|
355 |
if(status == HAL_OK) |
|
356 |
{ |
|
357 |
/* Restore the last read protection Option Byte value */ |
|
358 |
status = FLASH_OB_RDP_LevelConfig(rdptmp); |
|
359 |
} |
|
360 |
} |
|
361 |
|
|
362 |
/* Return the erase status */ |
|
363 |
return status; |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* @brief Program option bytes |
|
368 |
* @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
|
369 |
* The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
|
370 |
* The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
|
371 |
* (system reset will occur) |
|
372 |
* |
|
373 |
* @param pOBInit pointer to an FLASH_OBInitStruct structure that |
|
374 |
* contains the configuration information for the programming. |
|
375 |
* |
|
376 |
* @retval HAL_StatusTypeDef HAL Status |
|
377 |
*/ |
|
378 |
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
|
379 |
{ |
|
380 |
HAL_StatusTypeDef status = HAL_ERROR; |
|
381 |
|
|
382 |
/* Process Locked */ |
|
383 |
__HAL_LOCK(&pFlash); |
|
384 |
|
|
385 |
/* Check the parameters */ |
|
386 |
assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
|
387 |
|
|
388 |
/* Write protection configuration */ |
|
389 |
if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
|
390 |
{ |
|
391 |
assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
|
392 |
if (pOBInit->WRPState == OB_WRPSTATE_ENABLE) |
|
393 |
{ |
|
394 |
/* Enable of Write protection on the selected page */ |
|
395 |
status = FLASH_OB_EnableWRP(pOBInit->WRPPage); |
|
396 |
} |
|
397 |
else |
|
398 |
{ |
|
399 |
/* Disable of Write protection on the selected page */ |
|
400 |
status = FLASH_OB_DisableWRP(pOBInit->WRPPage); |
|
401 |
} |
|
402 |
if (status != HAL_OK) |
|
403 |
{ |
|
404 |
/* Process Unlocked */ |
|
405 |
__HAL_UNLOCK(&pFlash); |
|
406 |
return status; |
|
407 |
} |
|
408 |
} |
|
409 |
|
|
410 |
/* Read protection configuration */ |
|
411 |
if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
|
412 |
{ |
|
413 |
status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel); |
|
414 |
if (status != HAL_OK) |
|
415 |
{ |
|
416 |
/* Process Unlocked */ |
|
417 |
__HAL_UNLOCK(&pFlash); |
|
418 |
return status; |
|
419 |
} |
|
420 |
} |
|
421 |
|
|
422 |
/* USER configuration */ |
|
423 |
if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
|
424 |
{ |
|
425 |
status = FLASH_OB_UserConfig(pOBInit->USERConfig); |
|
426 |
if (status != HAL_OK) |
|
427 |
{ |
|
428 |
/* Process Unlocked */ |
|
429 |
__HAL_UNLOCK(&pFlash); |
|
430 |
return status; |
|
431 |
} |
|
432 |
} |
|
433 |
|
|
434 |
/* DATA configuration*/ |
|
435 |
if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) |
|
436 |
{ |
|
437 |
status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData); |
|
438 |
if (status != HAL_OK) |
|
439 |
{ |
|
440 |
/* Process Unlocked */ |
|
441 |
__HAL_UNLOCK(&pFlash); |
|
442 |
return status; |
|
443 |
} |
|
444 |
} |
|
445 |
|
|
446 |
/* Process Unlocked */ |
|
447 |
__HAL_UNLOCK(&pFlash); |
|
448 |
|
|
449 |
return status; |
|
450 |
} |
|
451 |
|
|
452 |
/** |
|
453 |
* @brief Get the Option byte configuration |
|
454 |
* @param pOBInit pointer to an FLASH_OBInitStruct structure that |
|
455 |
* contains the configuration information for the programming. |
|
456 |
* |
|
457 |
* @retval None |
|
458 |
*/ |
|
459 |
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
|
460 |
{ |
|
461 |
pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER; |
|
462 |
|
|
463 |
/*Get WRP*/ |
|
464 |
pOBInit->WRPPage = FLASH_OB_GetWRP(); |
|
465 |
|
|
466 |
/*Get RDP Level*/ |
|
467 |
pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
|
468 |
|
|
469 |
/*Get USER*/ |
|
470 |
pOBInit->USERConfig = FLASH_OB_GetUser(); |
|
471 |
} |
|
472 |
|
|
473 |
/** |
|
474 |
* @brief Get the Option byte user data |
|
475 |
* @param DATAAdress Address of the option byte DATA |
|
476 |
* This parameter can be one of the following values: |
|
477 |
* @arg @ref OB_DATA_ADDRESS_DATA0 |
|
478 |
* @arg @ref OB_DATA_ADDRESS_DATA1 |
|
479 |
* @retval Value programmed in USER data |
|
480 |
*/ |
|
481 |
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress) |
|
482 |
{ |
|
483 |
uint32_t value = 0U; |
|
484 |
|
|
485 |
if (DATAAdress == OB_DATA_ADDRESS_DATA0) |
|
486 |
{ |
|
487 |
/* Get value programmed in OB USER Data0 */ |
|
488 |
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT; |
|
489 |
} |
|
490 |
else |
|
491 |
{ |
|
492 |
/* Get value programmed in OB USER Data1 */ |
|
493 |
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT; |
|
494 |
} |
|
495 |
|
|
496 |
return value; |
|
497 |
} |
|
498 |
|
|
499 |
/** |
|
500 |
* @} |
|
501 |
*/ |
|
502 |
|
|
503 |
/** |
|
504 |
* @} |
|
505 |
*/ |
|
506 |
|
|
507 |
/** @addtogroup FLASHEx_Private_Functions |
|
508 |
* @{ |
|
509 |
*/ |
|
510 |
|
|
511 |
/** |
|
512 |
* @brief Full erase of FLASH memory Bank |
|
513 |
* |
|
514 |
* @retval None |
|
515 |
*/ |
|
516 |
static void FLASH_MassErase(void) |
|
517 |
{ |
|
518 |
/* Clean the error context */ |
|
519 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
520 |
|
|
521 |
/* Only bank1 will be erased*/ |
|
522 |
SET_BIT(FLASH->CR, FLASH_CR_MER); |
|
523 |
SET_BIT(FLASH->CR, FLASH_CR_STRT); |
|
524 |
} |
|
525 |
|
|
526 |
/** |
|
527 |
* @brief Enable the write protection of the desired pages |
|
528 |
* @note An option byte erase is done automatically in this function. |
|
529 |
* @note When the memory read protection level is selected (RDP level = 1), |
|
530 |
* it is not possible to program or erase the flash page i if |
|
531 |
* debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
|
532 |
* |
|
533 |
* @param WriteProtectPage specifies the page(s) to be write protected. |
|
534 |
* The value of this parameter depend on device used within the same series |
|
535 |
* @retval HAL status |
|
536 |
*/ |
|
537 |
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) |
|
538 |
{ |
|
539 |
HAL_StatusTypeDef status = HAL_OK; |
|
540 |
uint16_t WRP0_Data = 0xFFFFU; |
|
541 |
#if defined(OB_WRP1_WRP1) |
|
542 |
uint16_t WRP1_Data = 0xFFFFU; |
|
543 |
#endif /* OB_WRP1_WRP1 */ |
|
544 |
#if defined(OB_WRP2_WRP2) |
|
545 |
uint16_t WRP2_Data = 0xFFFFU; |
|
546 |
#endif /* OB_WRP2_WRP2 */ |
|
547 |
#if defined(OB_WRP3_WRP3) |
|
548 |
uint16_t WRP3_Data = 0xFFFFU; |
|
549 |
#endif /* OB_WRP3_WRP3 */ |
|
550 |
|
|
551 |
/* Check the parameters */ |
|
552 |
assert_param(IS_OB_WRP(WriteProtectPage)); |
|
553 |
|
|
554 |
/* Get current write protected pages and the new pages to be protected ******/ |
|
555 |
WriteProtectPage = (uint32_t)(~((~FLASH_OB_GetWRP()) | WriteProtectPage)); |
|
556 |
|
|
557 |
#if defined(OB_WRP_PAGES0TO15MASK) |
|
558 |
WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); |
|
559 |
#elif defined(OB_WRP_PAGES0TO31MASK) |
|
560 |
WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); |
|
561 |
#endif /* OB_WRP_PAGES0TO31MASK */ |
|
562 |
|
|
563 |
#if defined(OB_WRP_PAGES16TO31MASK) |
|
564 |
WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U); |
|
565 |
#elif defined(OB_WRP_PAGES32TO63MASK) |
|
566 |
WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8U); |
|
567 |
#endif /* OB_WRP_PAGES32TO63MASK */ |
|
568 |
|
|
569 |
#if defined(OB_WRP_PAGES32TO47MASK) |
|
570 |
WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U); |
|
571 |
#endif /* OB_WRP_PAGES32TO47MASK */ |
|
572 |
|
|
573 |
#if defined(OB_WRP_PAGES48TO63MASK) |
|
574 |
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO63MASK) >> 24U); |
|
575 |
#elif defined(OB_WRP_PAGES48TO127MASK) |
|
576 |
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U); |
|
577 |
#endif /* OB_WRP_PAGES48TO63MASK */ |
|
578 |
|
|
579 |
/* Wait for last operation to be completed */ |
|
580 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
581 |
|
|
582 |
if(status == HAL_OK) |
|
583 |
{ |
|
584 |
/* Clean the error context */ |
|
585 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
586 |
|
|
587 |
/* To be able to write again option byte, need to perform a option byte erase */ |
|
588 |
status = HAL_FLASHEx_OBErase(); |
|
589 |
if (status == HAL_OK) |
|
590 |
{ |
|
591 |
/* Enable write protection */ |
|
592 |
SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
593 |
|
|
594 |
#if defined(OB_WRP0_WRP0) |
|
595 |
if(WRP0_Data != 0xFFU) |
|
596 |
{ |
|
597 |
OB->WRP0 &= WRP0_Data; |
|
598 |
|
|
599 |
/* Wait for last operation to be completed */ |
|
600 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
601 |
} |
|
602 |
#endif /* OB_WRP0_WRP0 */ |
|
603 |
|
|
604 |
#if defined(OB_WRP1_WRP1) |
|
605 |
if((status == HAL_OK) && (WRP1_Data != 0xFFU)) |
|
606 |
{ |
|
607 |
OB->WRP1 &= WRP1_Data; |
|
608 |
|
|
609 |
/* Wait for last operation to be completed */ |
|
610 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
611 |
} |
|
612 |
#endif /* OB_WRP1_WRP1 */ |
|
613 |
|
|
614 |
#if defined(OB_WRP2_WRP2) |
|
615 |
if((status == HAL_OK) && (WRP2_Data != 0xFFU)) |
|
616 |
{ |
|
617 |
OB->WRP2 &= WRP2_Data; |
|
618 |
|
|
619 |
/* Wait for last operation to be completed */ |
|
620 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
621 |
} |
|
622 |
#endif /* OB_WRP2_WRP2 */ |
|
623 |
|
|
624 |
#if defined(OB_WRP3_WRP3) |
|
625 |
if((status == HAL_OK) && (WRP3_Data != 0xFFU)) |
|
626 |
{ |
|
627 |
OB->WRP3 &= WRP3_Data; |
|
628 |
|
|
629 |
/* Wait for last operation to be completed */ |
|
630 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
631 |
} |
|
632 |
#endif /* OB_WRP3_WRP3 */ |
|
633 |
|
|
634 |
/* if the program operation is completed, disable the OPTPG Bit */ |
|
635 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
636 |
} |
|
637 |
} |
|
638 |
|
|
639 |
return status; |
|
640 |
} |
|
641 |
|
|
642 |
/** |
|
643 |
* @brief Disable the write protection of the desired pages |
|
644 |
* @note An option byte erase is done automatically in this function. |
|
645 |
* @note When the memory read protection level is selected (RDP level = 1), |
|
646 |
* it is not possible to program or erase the flash page i if |
|
647 |
* debug features are connected or boot code is executed in RAM, even if nWRPi = 1 |
|
648 |
* |
|
649 |
* @param WriteProtectPage specifies the page(s) to be write unprotected. |
|
650 |
* The value of this parameter depend on device used within the same series |
|
651 |
* @retval HAL status |
|
652 |
*/ |
|
653 |
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) |
|
654 |
{ |
|
655 |
HAL_StatusTypeDef status = HAL_OK; |
|
656 |
uint16_t WRP0_Data = 0xFFFFU; |
|
657 |
#if defined(OB_WRP1_WRP1) |
|
658 |
uint16_t WRP1_Data = 0xFFFFU; |
|
659 |
#endif /* OB_WRP1_WRP1 */ |
|
660 |
#if defined(OB_WRP2_WRP2) |
|
661 |
uint16_t WRP2_Data = 0xFFFFU; |
|
662 |
#endif /* OB_WRP2_WRP2 */ |
|
663 |
#if defined(OB_WRP3_WRP3) |
|
664 |
uint16_t WRP3_Data = 0xFFFFU; |
|
665 |
#endif /* OB_WRP3_WRP3 */ |
|
666 |
|
|
667 |
/* Check the parameters */ |
|
668 |
assert_param(IS_OB_WRP(WriteProtectPage)); |
|
669 |
|
|
670 |
/* Get current write protected pages and the new pages to be unprotected ******/ |
|
671 |
WriteProtectPage = (FLASH_OB_GetWRP() | WriteProtectPage); |
|
672 |
|
|
673 |
#if defined(OB_WRP_PAGES0TO15MASK) |
|
674 |
WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO15MASK); |
|
675 |
#elif defined(OB_WRP_PAGES0TO31MASK) |
|
676 |
WRP0_Data = (uint16_t)(WriteProtectPage & OB_WRP_PAGES0TO31MASK); |
|
677 |
#endif /* OB_WRP_PAGES0TO31MASK */ |
|
678 |
|
|
679 |
#if defined(OB_WRP_PAGES16TO31MASK) |
|
680 |
WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES16TO31MASK) >> 8U); |
|
681 |
#elif defined(OB_WRP_PAGES32TO63MASK) |
|
682 |
WRP1_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO63MASK) >> 8U); |
|
683 |
#endif /* OB_WRP_PAGES32TO63MASK */ |
|
684 |
|
|
685 |
#if defined(OB_WRP_PAGES32TO47MASK) |
|
686 |
WRP2_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES32TO47MASK) >> 16U); |
|
687 |
#endif /* OB_WRP_PAGES32TO47MASK */ |
|
688 |
|
|
689 |
#if defined(OB_WRP_PAGES48TO63MASK) |
|
690 |
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO63MASK) >> 24U); |
|
691 |
#elif defined(OB_WRP_PAGES48TO127MASK) |
|
692 |
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U); |
|
693 |
#endif /* OB_WRP_PAGES48TO63MASK */ |
|
694 |
|
|
695 |
|
|
696 |
/* Wait for last operation to be completed */ |
|
697 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
698 |
|
|
699 |
if(status == HAL_OK) |
|
700 |
{ |
|
701 |
/* Clean the error context */ |
|
702 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
703 |
|
|
704 |
/* To be able to write again option byte, need to perform a option byte erase */ |
|
705 |
status = HAL_FLASHEx_OBErase(); |
|
706 |
if (status == HAL_OK) |
|
707 |
{ |
|
708 |
SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
709 |
|
|
710 |
#if defined(OB_WRP0_WRP0) |
|
711 |
if(WRP0_Data != 0xFFU) |
|
712 |
{ |
|
713 |
OB->WRP0 |= WRP0_Data; |
|
714 |
|
|
715 |
/* Wait for last operation to be completed */ |
|
716 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
717 |
} |
|
718 |
#endif /* OB_WRP0_WRP0 */ |
|
719 |
|
|
720 |
#if defined(OB_WRP1_WRP1) |
|
721 |
if((status == HAL_OK) && (WRP1_Data != 0xFFU)) |
|
722 |
{ |
|
723 |
OB->WRP1 |= WRP1_Data; |
|
724 |
|
|
725 |
/* Wait for last operation to be completed */ |
|
726 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
727 |
} |
|
728 |
#endif /* OB_WRP1_WRP1 */ |
|
729 |
|
|
730 |
#if defined(OB_WRP2_WRP2) |
|
731 |
if((status == HAL_OK) && (WRP2_Data != 0xFFU)) |
|
732 |
{ |
|
733 |
OB->WRP2 |= WRP2_Data; |
|
734 |
|
|
735 |
/* Wait for last operation to be completed */ |
|
736 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
737 |
} |
|
738 |
#endif /* OB_WRP2_WRP2 */ |
|
739 |
|
|
740 |
#if defined(OB_WRP3_WRP3) |
|
741 |
if((status == HAL_OK) && (WRP3_Data != 0xFFU)) |
|
742 |
{ |
|
743 |
OB->WRP3 |= WRP3_Data; |
|
744 |
|
|
745 |
/* Wait for last operation to be completed */ |
|
746 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
747 |
} |
|
748 |
#endif /* OB_WRP3_WRP3 */ |
|
749 |
|
|
750 |
/* if the program operation is completed, disable the OPTPG Bit */ |
|
751 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
752 |
} |
|
753 |
} |
|
754 |
return status; |
|
755 |
} |
|
756 |
|
|
757 |
/** |
|
758 |
* @brief Set the read protection level. |
|
759 |
* @param ReadProtectLevel specifies the read protection level. |
|
760 |
* This parameter can be one of the following values: |
|
761 |
* @arg @ref OB_RDP_LEVEL_0 No protection |
|
762 |
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory |
|
763 |
* @arg @ref OB_RDP_LEVEL_2 Full chip protection |
|
764 |
* @note Warning: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0 |
|
765 |
* @retval HAL status |
|
766 |
*/ |
|
767 |
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) |
|
768 |
{ |
|
769 |
HAL_StatusTypeDef status = HAL_OK; |
|
770 |
|
|
771 |
/* Check the parameters */ |
|
772 |
assert_param(IS_OB_RDP_LEVEL(ReadProtectLevel)); |
|
773 |
|
|
774 |
/* Wait for last operation to be completed */ |
|
775 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
776 |
|
|
777 |
if(status == HAL_OK) |
|
778 |
{ |
|
779 |
/* Clean the error context */ |
|
780 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
781 |
|
|
782 |
/* If the previous operation is completed, proceed to erase the option bytes */ |
|
783 |
SET_BIT(FLASH->CR, FLASH_CR_OPTER); |
|
784 |
SET_BIT(FLASH->CR, FLASH_CR_STRT); |
|
785 |
|
|
786 |
/* Wait for last operation to be completed */ |
|
787 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
788 |
|
|
789 |
/* If the erase operation is completed, disable the OPTER Bit */ |
|
790 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER); |
|
791 |
|
|
792 |
if(status == HAL_OK) |
|
793 |
{ |
|
794 |
/* Enable the Option Bytes Programming operation */ |
|
795 |
SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
796 |
|
|
797 |
WRITE_REG(OB->RDP, ReadProtectLevel); |
|
798 |
|
|
799 |
/* Wait for last operation to be completed */ |
|
800 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
801 |
|
|
802 |
/* if the program operation is completed, disable the OPTPG Bit */ |
|
803 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
804 |
} |
|
805 |
} |
|
806 |
|
|
807 |
return status; |
|
808 |
} |
|
809 |
|
|
810 |
/** |
|
811 |
* @brief Program the FLASH User Option Byte. |
|
812 |
* @note Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
|
813 |
* @param UserConfig The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), nBOOT1(Bit4), |
|
814 |
* VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6). |
|
815 |
* For few devices, following option bytes are available: nBOOT0(Bit3) & BOOT_SEL(Bit7). |
|
816 |
* @retval HAL status |
|
817 |
*/ |
|
818 |
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) |
|
819 |
{ |
|
820 |
HAL_StatusTypeDef status = HAL_OK; |
|
821 |
|
|
822 |
/* Check the parameters */ |
|
823 |
assert_param(IS_OB_IWDG_SOURCE((UserConfig&OB_IWDG_SW))); |
|
824 |
assert_param(IS_OB_STOP_SOURCE((UserConfig&OB_STOP_NO_RST))); |
|
825 |
assert_param(IS_OB_STDBY_SOURCE((UserConfig&OB_STDBY_NO_RST))); |
|
826 |
assert_param(IS_OB_BOOT1((UserConfig&OB_BOOT1_SET))); |
|
827 |
assert_param(IS_OB_VDDA_ANALOG((UserConfig&OB_VDDA_ANALOG_ON))); |
|
828 |
assert_param(IS_OB_SRAM_PARITY((UserConfig&OB_SRAM_PARITY_RESET))); |
|
829 |
#if defined(FLASH_OBR_BOOT_SEL) |
|
830 |
assert_param(IS_OB_BOOT_SEL((UserConfig&OB_BOOT_SEL_SET))); |
|
831 |
assert_param(IS_OB_BOOT0((UserConfig&OB_BOOT0_SET))); |
|
832 |
#endif /* FLASH_OBR_BOOT_SEL */ |
|
833 |
|
|
834 |
/* Wait for last operation to be completed */ |
|
835 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
836 |
|
|
837 |
if(status == HAL_OK) |
|
838 |
{ |
|
839 |
/* Clean the error context */ |
|
840 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
841 |
|
|
842 |
/* Enable the Option Bytes Programming operation */ |
|
843 |
SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
844 |
|
|
845 |
#if defined(FLASH_OBR_BOOT_SEL) |
|
846 |
OB->USER = UserConfig; |
|
847 |
#else |
|
848 |
OB->USER = (UserConfig | 0x88U); |
|
849 |
#endif |
|
850 |
|
|
851 |
/* Wait for last operation to be completed */ |
|
852 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
853 |
|
|
854 |
/* if the program operation is completed, disable the OPTPG Bit */ |
|
855 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
856 |
} |
|
857 |
|
|
858 |
return status; |
|
859 |
} |
|
860 |
|
|
861 |
/** |
|
862 |
* @brief Programs a half word at a specified Option Byte Data address. |
|
863 |
* @note The function @ref HAL_FLASH_Unlock() should be called before to unlock the FLASH interface |
|
864 |
* The function @ref HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes |
|
865 |
* The function @ref HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes |
|
866 |
* (system reset will occur) |
|
867 |
* Programming of the OB should be performed only after an erase (otherwise PGERR occurs) |
|
868 |
* @param Address specifies the address to be programmed. |
|
869 |
* This parameter can be 0x1FFFF804 or 0x1FFFF806. |
|
870 |
* @param Data specifies the data to be programmed. |
|
871 |
* @retval HAL status |
|
872 |
*/ |
|
873 |
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) |
|
874 |
{ |
|
875 |
HAL_StatusTypeDef status = HAL_ERROR; |
|
876 |
|
|
877 |
/* Check the parameters */ |
|
878 |
assert_param(IS_OB_DATA_ADDRESS(Address)); |
|
879 |
|
|
880 |
/* Wait for last operation to be completed */ |
|
881 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
882 |
|
|
883 |
if(status == HAL_OK) |
|
884 |
{ |
|
885 |
/* Clean the error context */ |
|
886 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
887 |
|
|
888 |
/* Enables the Option Bytes Programming operation */ |
|
889 |
SET_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
890 |
*(__IO uint16_t*)Address = Data; |
|
891 |
|
|
892 |
/* Wait for last operation to be completed */ |
|
893 |
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); |
|
894 |
|
|
895 |
/* If the program operation is completed, disable the OPTPG Bit */ |
|
896 |
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTPG); |
|
897 |
} |
|
898 |
/* Return the Option Byte Data Program Status */ |
|
899 |
return status; |
|
900 |
} |
|
901 |
|
|
902 |
/** |
|
903 |
* @brief Return the FLASH Write Protection Option Bytes value. |
|
904 |
* @retval The FLASH Write Protection Option Bytes value |
|
905 |
*/ |
|
906 |
static uint32_t FLASH_OB_GetWRP(void) |
|
907 |
{ |
|
908 |
/* Return the FLASH write protection Register value */ |
|
909 |
return (uint32_t)(READ_REG(FLASH->WRPR)); |
|
910 |
} |
|
911 |
|
|
912 |
/** |
|
913 |
* @brief Returns the FLASH Read Protection level. |
|
914 |
* @retval FLASH RDP level |
|
915 |
* This parameter can be one of the following values: |
|
916 |
* @arg @ref OB_RDP_LEVEL_0 No protection |
|
917 |
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory |
|
918 |
* @arg @ref OB_RDP_LEVEL_2 Full chip protection |
|
919 |
*/ |
|
920 |
static uint32_t FLASH_OB_GetRDP(void) |
|
921 |
{ |
|
922 |
uint32_t tmp_reg = 0U; |
|
923 |
|
|
924 |
/* Read RDP level bits */ |
|
925 |
tmp_reg = READ_BIT(FLASH->OBR, (FLASH_OBR_RDPRT1 | FLASH_OBR_RDPRT2)); |
|
926 |
|
|
927 |
if (tmp_reg == FLASH_OBR_RDPRT1) |
|
928 |
{ |
|
929 |
return OB_RDP_LEVEL_1; |
|
930 |
} |
|
931 |
else if (tmp_reg == FLASH_OBR_RDPRT2) |
|
932 |
{ |
|
933 |
return OB_RDP_LEVEL_2; |
|
934 |
} |
|
935 |
else |
|
936 |
{ |
|
937 |
return OB_RDP_LEVEL_0; |
|
938 |
} |
|
939 |
} |
|
940 |
|
|
941 |
/** |
|
942 |
* @brief Return the FLASH User Option Byte value. |
|
943 |
* @retval The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1), RST_STDBY(Bit2), nBOOT1(Bit4), |
|
944 |
* VDDA_Analog_Monitoring(Bit5) and SRAM_Parity_Enable(Bit6). |
|
945 |
* For few devices, following option bytes are available: nBOOT0(Bit3) & BOOT_SEL(Bit7). |
|
946 |
*/ |
|
947 |
static uint8_t FLASH_OB_GetUser(void) |
|
948 |
{ |
|
949 |
/* Return the User Option Byte */ |
|
950 |
return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT); |
|
951 |
} |
|
952 |
|
|
953 |
/** |
|
954 |
* @} |
|
955 |
*/ |
|
956 |
|
|
957 |
/** |
|
958 |
* @} |
|
959 |
*/ |
|
960 |
|
|
961 |
/** @addtogroup FLASH |
|
962 |
* @{ |
|
963 |
*/ |
|
964 |
|
|
965 |
/** @addtogroup FLASH_Private_Functions |
|
966 |
* @{ |
|
967 |
*/ |
|
968 |
|
|
969 |
/** |
|
970 |
* @brief Erase the specified FLASH memory page |
|
971 |
* @param PageAddress FLASH page to erase |
|
972 |
* The value of this parameter depend on device used within the same series |
|
973 |
* |
|
974 |
* @retval None |
|
975 |
*/ |
|
976 |
void FLASH_PageErase(uint32_t PageAddress) |
|
977 |
{ |
|
978 |
/* Clean the error context */ |
|
979 |
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE; |
|
980 |
|
|
981 |
/* Proceed to erase the page */ |
|
982 |
SET_BIT(FLASH->CR, FLASH_CR_PER); |
|
983 |
WRITE_REG(FLASH->AR, PageAddress); |
|
984 |
SET_BIT(FLASH->CR, FLASH_CR_STRT); |
|
985 |
} |
|
986 |
|
|
987 |
/** |
|
988 |
* @} |
|
989 |
*/ |
|
990 |
|
|
991 |
/** |
|
992 |
* @} |
|
993 |
*/ |
|
994 |
|
|
995 |
#endif /* HAL_FLASH_MODULE_ENABLED */ |
|
996 |
/** |
|
997 |
* @} |
|
998 |
*/ |
|
999 |
|
|
1000 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |