STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stm32h7xx_hal_flash_ex.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32h7xx_hal_flash_ex.c
4 * @author MCD Application Team
5 * @brief Extended FLASH HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the FLASH extension peripheral:
8 * + Extended programming operations functions
9 *
10 @verbatim
11 ==============================================================================
12 ##### Flash Extension features #####
13 ==============================================================================
14
15 [..] Comparing to other previous devices, the FLASH interface for STM32H7xx
16 devices contains the following additional features
17
18 (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write
19 capability (RWW)
20 (+) Dual bank memory organization
21 (+) PCROP protection for all banks
22 (+) Global readout protection (RDP)
23 (+) Write protection
24 (+) Secure access only protection
25 (+) Bank / register swapping (when Dual-Bank)
26 (+) Cyclic Redundancy Check (CRC)
27
28 ##### How to use this driver #####
29 ==============================================================================
30 [..] This driver provides functions to configure and program the FLASH memory
31 of all STM32H7xx devices. It includes
32 (#) FLASH Memory Erase functions:
33 (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
34 HAL_FLASH_Lock() functions
35 (++) Erase function: Sector erase, bank erase and dual-bank mass erase
36 (++) There are two modes of erase :
37 (+++) Polling Mode using HAL_FLASHEx_Erase()
38 (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT()
39
40 (#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to:
41 (++) Set/Reset the write protection per bank
42 (++) Set the Read protection Level
43 (++) Set the BOR level
44 (++) Program the user Option Bytes
45 (++) PCROP protection configuration and control per bank
46 (++) Secure area configuration and control per bank
47 (++) Core Boot address configuration
48 (++) TCM / AXI shared RAM configuration
49 (++) CPU Frequency Boost configuration
50
51 (#) FLASH Memory Lock and unlock per Bank: HAL_FLASHEx_Lock_Bank1(), HAL_FLASHEx_Unlock_Bank1(),
52 HAL_FLASHEx_Lock_Bank2() and HAL_FLASHEx_Unlock_Bank2() functions
53
54 (#) FLASH CRC computation function: Use HAL_FLASHEx_ComputeCRC() to:
55 (++) Enable CRC feature
56 (++) Program the desired burst size
57 (++) Define the user Flash Area on which the CRC has be computed
58 (++) Perform the CRC computation
59 (++) Disable CRC feature
60
61 (#) Error correction code error functions:
62 (++) Use the HAL_FLASHEx_EnableEccCorrectionInterrupt() and HAL_FLASHEx_DisableEccCorrectionInterrupt()
63 functions to enable and disable the FLASH ECC correction interruption.
64 (++) Use the HAL_FLASHEx_EnableEccDetectionInterrupt() and HAL_FLASHEx_DisableEccDetectionInterrupt()
65 functions to enable and disable the FLASH ECC Detection interruption.
66 (++) Handle ECCD interrupt by calling HAL_FLASHEx_BusFault_IRQHandler()
67 (++) Use HAL_FLASHEx_BusFault_IRQHandler() function called under BusFault_IRQHandler() interrupt subroutine
68 to handle the ECCD interrupt.
69 (++) Use HAL_FLASHEx_GetEccInfo() function to get the flash ECC fail information.
70
71 @endverbatim
72 ******************************************************************************
73 * @attention
74 *
75 * Copyright (c) 2017 STMicroelectronics.
76 * All rights reserved.
77 *
78 * This software is licensed under terms that can be found in the LICENSE file in
79 * the root directory of this software component.
80 * If no LICENSE file comes with this software, it is provided AS-IS.
81 ******************************************************************************
82 */
83
84/* Includes ------------------------------------------------------------------*/
85#include "stm32h7xx_hal.h"
86
87/** @addtogroup STM32H7xx_HAL_Driver
88 * @{
89 */
90
91/** @defgroup FLASHEx FLASHEx
92 * @brief FLASH HAL Extension module driver
93 * @{
94 */
95
96#ifdef HAL_FLASH_MODULE_ENABLED
97
98/* Private typedef -----------------------------------------------------------*/
99/* Private define ------------------------------------------------------------*/
100/** @addtogroup FLASHEx_Private_Constants
101 * @{
102 */
103#define FLASH_TIMEOUT_VALUE 50000U /* 50 s */
104
105/**
106 * @}
107 */
108/* Private macro -------------------------------------------------------------*/
109/* Private variables ---------------------------------------------------------*/
110/* Private function prototypes -----------------------------------------------*/
111/** @defgroup FLASHEx_Private_Functions FLASHEx Private Functions
112 * @{
113 */
114static void FLASH_MassErase(uint32_t VoltageRange, uint32_t Banks);
115static void FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks);
116static void FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Bank);
117static void FLASH_OB_GetWRP(uint32_t *WRPState, uint32_t *WRPSector, uint32_t Bank);
118static void FLASH_OB_RDPConfig(uint32_t RDPLevel);
119static uint32_t FLASH_OB_GetRDP(void);
120static void FLASH_OB_PCROPConfig(uint32_t PCROConfigRDP, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr, uint32_t Banks);
121static void FLASH_OB_GetPCROP(uint32_t *PCROPConfig, uint32_t *PCROPStartAddr,uint32_t *PCROPEndAddr, uint32_t Bank);
122static void FLASH_OB_BOR_LevelConfig(uint32_t Level);
123static uint32_t FLASH_OB_GetBOR(void);
124static void FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig);
125static uint32_t FLASH_OB_GetUser(void);
126static void FLASH_OB_BootAddConfig(uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1);
127static void FLASH_OB_GetBootAdd(uint32_t *BootAddress0, uint32_t *BootAddress1);
128static void FLASH_OB_SecureAreaConfig(uint32_t SecureAreaConfig, uint32_t SecureAreaStartAddr, uint32_t SecureAreaEndAddr, uint32_t Banks);
129static void FLASH_OB_GetSecureArea(uint32_t *SecureAreaConfig, uint32_t *SecureAreaStartAddr, uint32_t *SecureAreaEndAddr, uint32_t Bank);
130static void FLASH_CRC_AddSector(uint32_t Sector, uint32_t Bank);
131static void FLASH_CRC_SelectAddress(uint32_t CRCStartAddr, uint32_t CRCEndAddr, uint32_t Bank);
132
133#if defined (DUAL_CORE)
134static void FLASH_OB_CM4BootAddConfig(uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1);
135static void FLASH_OB_GetCM4BootAdd(uint32_t *BootAddress0, uint32_t *BootAddress1);
136#endif /*DUAL_CORE*/
137
138#if defined (FLASH_OTPBL_LOCKBL)
139static void FLASH_OB_OTP_LockConfig(uint32_t OTP_Block);
140static uint32_t FLASH_OB_OTP_GetLock(void);
141#endif /* FLASH_OTPBL_LOCKBL */
142
143#if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
144static void FLASH_OB_SharedRAM_Config(uint32_t SharedRamConfig);
145static uint32_t FLASH_OB_SharedRAM_GetConfig(void);
146#endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
147
148#if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
149static void FLASH_OB_CPUFreq_BoostConfig(uint32_t FreqBoost);
150static uint32_t FLASH_OB_CPUFreq_GetBoost(void);
151#endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
152/**
153 * @}
154 */
155
156/* Exported functions ---------------------------------------------------------*/
157/** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions
158 * @{
159 */
160
161/** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions
162 * @brief Extended IO operation functions
163 *
164@verbatim
165 ===============================================================================
166 ##### Extended programming operation functions #####
167 ===============================================================================
168 [..]
169 This subsection provides a set of functions allowing to manage the Extension FLASH
170 programming operations Operations.
171
172@endverbatim
173 * @{
174 */
175/**
176 * @brief Perform a mass erase or erase the specified FLASH memory sectors
177 * @param[in] pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
178 * contains the configuration information for the erasing.
179 *
180 * @param[out] SectorError pointer to variable that contains the configuration
181 * information on faulty sector in case of error (0xFFFFFFFF means that all
182 * the sectors have been correctly erased)
183 *
184 * @note For dual-bank devices, if the SWAP_BANK option byte is enabled, the parameter
185 * pEraseInit->Banks is modified accordingly. The logical bank addresses are swapped
186 * as follows:
187 * - FLASH_BANK_1 corresponds to the physical Bank2
188 * - FLASH_BANK_2 corresponds to the physical Bank1
189 *
190 * @retval HAL Status
191 */
192HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
193{
195 uint32_t sector_index;
196
197 /* Check the parameters */
199 assert_param(IS_FLASH_BANK(pEraseInit->Banks));
200
201 /* Process Locked */
203
204 /* Reset error code */
205 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
206
207 /* Wait for last operation to be completed on Bank1 */
208 if((pEraseInit->Banks & FLASH_BANK_1) == FLASH_BANK_1)
209 {
210 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1) != HAL_OK)
211 {
213 }
214 }
215
216#if defined (DUAL_BANK)
217 /* Wait for last operation to be completed on Bank2 */
218 if((pEraseInit->Banks & FLASH_BANK_2) == FLASH_BANK_2)
219 {
220 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2) != HAL_OK)
221 {
223 }
224 }
225#endif /* DUAL_BANK */
226
227 if(status == HAL_OK)
228 {
229 if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
230 {
231 /* Mass erase to be done */
232 FLASH_MassErase(pEraseInit->VoltageRange, pEraseInit->Banks);
233
234 /* Wait for last operation to be completed on Bank 1 */
235 if((pEraseInit->Banks & FLASH_BANK_1) == FLASH_BANK_1)
236 {
237 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1) != HAL_OK)
238 {
240 }
241 /* if the erase operation is completed, disable the Bank1 BER Bit */
242 FLASH->CR1 &= (~FLASH_CR_BER);
243 }
244#if defined (DUAL_BANK)
245 /* Wait for last operation to be completed on Bank 2 */
246 if((pEraseInit->Banks & FLASH_BANK_2) == FLASH_BANK_2)
247 {
248 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2) != HAL_OK)
249 {
251 }
252 /* if the erase operation is completed, disable the Bank2 BER Bit */
253 FLASH->CR2 &= (~FLASH_CR_BER);
254 }
255#endif /* DUAL_BANK */
256 }
257 else
258 {
259 /*Initialization of SectorError variable*/
260 *SectorError = 0xFFFFFFFFU;
261
262 /* Erase by sector by sector to be done*/
263 for(sector_index = pEraseInit->Sector; sector_index < (pEraseInit->NbSectors + pEraseInit->Sector); sector_index++)
264 {
265 FLASH_Erase_Sector(sector_index, pEraseInit->Banks, pEraseInit->VoltageRange);
266
267 if((pEraseInit->Banks & FLASH_BANK_1) == FLASH_BANK_1)
268 {
269 /* Wait for last operation to be completed */
270 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);
271
272 /* If the erase operation is completed, disable the SER Bit */
273 FLASH->CR1 &= (~(FLASH_CR_SER | FLASH_CR_SNB));
274 }
275#if defined (DUAL_BANK)
276 if((pEraseInit->Banks & FLASH_BANK_2) == FLASH_BANK_2)
277 {
278 /* Wait for last operation to be completed */
279 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2);
280
281 /* If the erase operation is completed, disable the SER Bit */
282 FLASH->CR2 &= (~(FLASH_CR_SER | FLASH_CR_SNB));
283 }
284#endif /* DUAL_BANK */
285
286 if(status != HAL_OK)
287 {
288 /* In case of error, stop erase procedure and return the faulty sector */
289 *SectorError = sector_index;
290 break;
291 }
292 }
293 }
294 }
295
296 /* Process Unlocked */
298
299 return status;
300}
301
302/**
303 * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled
304 * @param pEraseInit pointer to an FLASH_EraseInitTypeDef structure that
305 * contains the configuration information for the erasing.
306 *
307 * @note For dual-bank devices, if the SWAP_BANK option byte is enabled, the parameter
308 * pEraseInit->Banks is modified accordingly. The logical bank addresses are swapped
309 * as follows:
310 * - FLASH_BANK_1 corresponds to the physical Bank2
311 * - FLASH_BANK_2 corresponds to the physical Bank1
312 *
313 * @retval HAL Status
314 */
316{
318
319 /* Check the parameters */
321 assert_param(IS_FLASH_BANK(pEraseInit->Banks));
322
323 /* Process Locked */
325
326 /* Reset error code */
327 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
328
329 /* Wait for last operation to be completed on Bank 1 */
330 if((pEraseInit->Banks & FLASH_BANK_1) == FLASH_BANK_1)
331 {
332 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1) != HAL_OK)
333 {
335 }
336 }
337
338#if defined (DUAL_BANK)
339 /* Wait for last operation to be completed on Bank 2 */
340 if((pEraseInit->Banks & FLASH_BANK_2) == FLASH_BANK_2)
341 {
342 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2) != HAL_OK)
343 {
345 }
346 }
347#endif /* DUAL_BANK */
348
349 if (status != HAL_OK)
350 {
351 /* Process Unlocked */
353 }
354 else
355 {
356 if((pEraseInit->Banks & FLASH_BANK_1) == FLASH_BANK_1)
357 {
358 /* Enable End of Operation and Error interrupts for Bank 1 */
359#if defined (FLASH_CR_OPERRIE)
361 FLASH_IT_STRBERR_BANK1 | FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1);
362#else
365#endif /* FLASH_CR_OPERRIE */
366 }
367#if defined (DUAL_BANK)
368 if((pEraseInit->Banks & FLASH_BANK_2) == FLASH_BANK_2)
369 {
370 /* Enable End of Operation and Error interrupts for Bank 2 */
371#if defined (FLASH_CR_OPERRIE)
373 FLASH_IT_STRBERR_BANK2 | FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2);
374#else
377#endif /* FLASH_CR_OPERRIE */
378 }
379#endif /* DUAL_BANK */
380
381 if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
382 {
383 /*Mass erase to be done*/
384 if(pEraseInit->Banks == FLASH_BANK_1)
385 {
386 pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE_BANK1;
387 }
388#if defined (DUAL_BANK)
389 else if(pEraseInit->Banks == FLASH_BANK_2)
390 {
391 pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE_BANK2;
392 }
393#endif /* DUAL_BANK */
394 else
395 {
396 pFlash.ProcedureOnGoing = FLASH_PROC_ALLBANK_MASSERASE;
397 }
398
399 FLASH_MassErase(pEraseInit->VoltageRange, pEraseInit->Banks);
400 }
401 else
402 {
403 /* Erase by sector to be done */
404#if defined (DUAL_BANK)
405 if(pEraseInit->Banks == FLASH_BANK_1)
406 {
407 pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE_BANK1;
408 }
409 else
410 {
411 pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE_BANK2;
412 }
413#else
414 pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE_BANK1;
415#endif /* DUAL_BANK */
416
417 pFlash.NbSectorsToErase = pEraseInit->NbSectors;
418 pFlash.Sector = pEraseInit->Sector;
419 pFlash.VoltageForErase = pEraseInit->VoltageRange;
420
421 /* Erase first sector and wait for IT */
422 FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->Banks, pEraseInit->VoltageRange);
423 }
424 }
425
426 return status;
427}
428
429/**
430 * @brief Program option bytes
431 * @param pOBInit pointer to an FLASH_OBProgramInitTypeDef structure that
432 * contains the configuration information for the programming.
433 *
434 * @retval HAL Status
435 */
437{
439
440 /* Check the parameters */
442
443 /* Process Locked */
445
446 /* Reset Error Code */
447 pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
448
449 /* Wait for last operation to be completed */
450 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1) != HAL_OK)
451 {
453 }
454#if defined (DUAL_BANK)
455 else if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2) != HAL_OK)
456 {
458 }
459#endif /* DUAL_BANK */
460 else
461 {
462 status = HAL_OK;
463 }
464
465 if(status == HAL_OK)
466 {
467 /*Write protection configuration*/
468 if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
469 {
471
472 if(pOBInit->WRPState == OB_WRPSTATE_ENABLE)
473 {
474 /*Enable of Write protection on the selected Sector*/
475 FLASH_OB_EnableWRP(pOBInit->WRPSector,pOBInit->Banks);
476 }
477 else
478 {
479 /*Disable of Write protection on the selected Sector*/
480 FLASH_OB_DisableWRP(pOBInit->WRPSector, pOBInit->Banks);
481 }
482 }
483
484 /* Read protection configuration */
485 if((pOBInit->OptionType & OPTIONBYTE_RDP) != 0U)
486 {
487 /* Configure the Read protection level */
488 FLASH_OB_RDPConfig(pOBInit->RDPLevel);
489 }
490
491 /* User Configuration */
492 if((pOBInit->OptionType & OPTIONBYTE_USER) != 0U)
493 {
494 /* Configure the user option bytes */
495 FLASH_OB_UserConfig(pOBInit->USERType, pOBInit->USERConfig);
496 }
497
498 /* PCROP Configuration */
499 if((pOBInit->OptionType & OPTIONBYTE_PCROP) != 0U)
500 {
502
503 /*Configure the Proprietary code readout protection */
504 FLASH_OB_PCROPConfig(pOBInit->PCROPConfig, pOBInit->PCROPStartAddr, pOBInit->PCROPEndAddr, pOBInit->Banks);
505 }
506
507 /* BOR Level configuration */
508 if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR)
509 {
510 FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel);
511 }
512
513#if defined(DUAL_CORE)
514 /* CM7 Boot Address configuration */
515 if((pOBInit->OptionType & OPTIONBYTE_CM7_BOOTADD) == OPTIONBYTE_CM7_BOOTADD)
516 {
517 FLASH_OB_BootAddConfig(pOBInit->BootConfig, pOBInit->BootAddr0, pOBInit->BootAddr1);
518 }
519
520 /* CM4 Boot Address configuration */
521 if((pOBInit->OptionType & OPTIONBYTE_CM4_BOOTADD) == OPTIONBYTE_CM4_BOOTADD)
522 {
523 FLASH_OB_CM4BootAddConfig(pOBInit->CM4BootConfig, pOBInit->CM4BootAddr0, pOBInit->CM4BootAddr1);
524 }
525#else /* Single Core*/
526 /* Boot Address configuration */
528 {
529 FLASH_OB_BootAddConfig(pOBInit->BootConfig, pOBInit->BootAddr0, pOBInit->BootAddr1);
530 }
531#endif /*DUAL_CORE*/
532
533 /* Secure area configuration */
535 {
536 FLASH_OB_SecureAreaConfig(pOBInit->SecureAreaConfig, pOBInit->SecureAreaStartAddr, pOBInit->SecureAreaEndAddr,pOBInit->Banks);
537 }
538
539#if defined(FLASH_OTPBL_LOCKBL)
540 /* OTP Block Lock configuration */
541 if((pOBInit->OptionType & OPTIONBYTE_OTP_LOCK) == OPTIONBYTE_OTP_LOCK)
542 {
543 FLASH_OB_OTP_LockConfig(pOBInit->OTPBlockLock);
544 }
545#endif /* FLASH_OTPBL_LOCKBL */
546
547#if defined(FLASH_OPTSR2_TCM_AXI_SHARED)
548 /* TCM / AXI Shared RAM configuration */
549 if((pOBInit->OptionType & OPTIONBYTE_SHARED_RAM) == OPTIONBYTE_SHARED_RAM)
550 {
551 FLASH_OB_SharedRAM_Config(pOBInit->SharedRamConfig);
552 }
553#endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
554
555#if defined(FLASH_OPTSR2_CPUFREQ_BOOST)
556 /* CPU Frequency Boost configuration */
557 if((pOBInit->OptionType & OPTIONBYTE_FREQ_BOOST) == OPTIONBYTE_FREQ_BOOST)
558 {
559 FLASH_OB_CPUFreq_BoostConfig(pOBInit->FreqBoostState);
560 }
561#endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
562 }
563
564 /* Process Unlocked */
566
567 return status;
568}
569
570/**
571 * @brief Get the Option byte configuration
572 * @param pOBInit pointer to an FLASH_OBProgramInitTypeDef structure that
573 * contains the configuration information for the programming.
574 * @note The parameter Banks of the pOBInit structure must be set exclusively to FLASH_BANK_1 or FLASH_BANK_2,
575 * as this parameter is use to get the given Bank WRP, PCROP and secured area configuration.
576 *
577 * @retval None
578 */
580{
582
583 /* Get Read protection level */
584 pOBInit->RDPLevel = FLASH_OB_GetRDP();
585
586 /* Get the user option bytes */
587 pOBInit->USERConfig = FLASH_OB_GetUser();
588
589 /*Get BOR Level*/
590 pOBInit->BORLevel = FLASH_OB_GetBOR();
591
592#if defined (DUAL_BANK)
593 if ((pOBInit->Banks == FLASH_BANK_1) || (pOBInit->Banks == FLASH_BANK_2))
594#else
595 if (pOBInit->Banks == FLASH_BANK_1)
596#endif /* DUAL_BANK */
597 {
599
600 /* Get write protection on the selected area */
601 FLASH_OB_GetWRP(&(pOBInit->WRPState), &(pOBInit->WRPSector), pOBInit->Banks);
602
603 /* Get the Proprietary code readout protection */
604 FLASH_OB_GetPCROP(&(pOBInit->PCROPConfig), &(pOBInit->PCROPStartAddr), &(pOBInit->PCROPEndAddr), pOBInit->Banks);
605
606 /*Get Bank Secure area*/
607 FLASH_OB_GetSecureArea(&(pOBInit->SecureAreaConfig), &(pOBInit->SecureAreaStartAddr), &(pOBInit->SecureAreaEndAddr), pOBInit->Banks);
608 }
609
610 /*Get Boot Address*/
611 FLASH_OB_GetBootAdd(&(pOBInit->BootAddr0), &(pOBInit->BootAddr1));
612#if defined(DUAL_CORE)
613 pOBInit->OptionType |= OPTIONBYTE_CM7_BOOTADD | OPTIONBYTE_CM4_BOOTADD;
614
615 /*Get CM4 Boot Address*/
616 FLASH_OB_GetCM4BootAdd(&(pOBInit->CM4BootAddr0), &(pOBInit->CM4BootAddr1));
617#else
618 pOBInit->OptionType |= OPTIONBYTE_BOOTADD;
619#endif /*DUAL_CORE*/
620
621#if defined (FLASH_OTPBL_LOCKBL)
622 pOBInit->OptionType |= OPTIONBYTE_OTP_LOCK;
623
624 /* Get OTP Block Lock */
625 pOBInit->OTPBlockLock = FLASH_OB_OTP_GetLock();
626#endif /* FLASH_OTPBL_LOCKBL */
627
628#if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
629 pOBInit->OptionType |= OPTIONBYTE_SHARED_RAM;
630
631 /* Get TCM / AXI Shared RAM */
632 pOBInit->SharedRamConfig = FLASH_OB_SharedRAM_GetConfig();
633#endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
634
635#if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
636 pOBInit->OptionType |= OPTIONBYTE_FREQ_BOOST;
637
638 /* Get CPU Frequency Boost */
639 pOBInit->FreqBoostState = FLASH_OB_CPUFreq_GetBoost();
640#endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
641}
642
643/**
644 * @brief Unlock the FLASH Bank1 control registers access
645 * @retval HAL Status
646 */
648{
649 if(READ_BIT(FLASH->CR1, FLASH_CR_LOCK) != 0U)
650 {
651 /* Authorize the FLASH Bank1 Registers access */
652 WRITE_REG(FLASH->KEYR1, FLASH_KEY1);
653 WRITE_REG(FLASH->KEYR1, FLASH_KEY2);
654
655 /* Verify Flash Bank1 is unlocked */
656 if (READ_BIT(FLASH->CR1, FLASH_CR_LOCK) != 0U)
657 {
658 return HAL_ERROR;
659 }
660 }
661
662 return HAL_OK;
663}
664
665/**
666 * @brief Locks the FLASH Bank1 control registers access
667 * @retval HAL Status
668 */
670{
671 /* Set the LOCK Bit to lock the FLASH Bank1 Registers access */
673 return HAL_OK;
674}
675
676#if defined (DUAL_BANK)
677/**
678 * @brief Unlock the FLASH Bank2 control registers access
679 * @retval HAL Status
680 */
681HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank2(void)
682{
683 if(READ_BIT(FLASH->CR2, FLASH_CR_LOCK) != 0U)
684 {
685 /* Authorize the FLASH Bank2 Registers access */
686 WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
687 WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
688
689 /* Verify Flash Bank1 is unlocked */
690 if (READ_BIT(FLASH->CR2, FLASH_CR_LOCK) != 0U)
691 {
692 return HAL_ERROR;
693 }
694 }
695
696 return HAL_OK;
697}
698
699/**
700 * @brief Locks the FLASH Bank2 control registers access
701 * @retval HAL Status
702 */
703HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank2(void)
704{
705 /* Set the LOCK Bit to lock the FLASH Bank2 Registers access */
707 return HAL_OK;
708}
709#endif /* DUAL_BANK */
710
711/*
712 * @brief Perform a CRC computation on the specified FLASH memory area
713 * @param pCRCInit pointer to an FLASH_CRCInitTypeDef structure that
714 * contains the configuration information for the CRC computation.
715 * @note CRC computation uses CRC-32 (Ethernet) polynomial 0x4C11DB7
716 * @note The application should avoid running a CRC on PCROP or secure-only
717 * user Flash memory area since it may alter the expected CRC value.
718 * A special error flag (CRC read error: CRCRDERR) can be used to
719 * detect such a case.
720 * @retval HAL Status
721*/
723{
725 uint32_t sector_index;
726
727 /* Check the parameters */
730
731 /* Wait for OB change operation to be completed */
732 status = FLASH_OB_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
733
734 if (status == HAL_OK)
735 {
736 if (pCRCInit->Bank == FLASH_BANK_1)
737 {
738 /* Enable CRC feature */
739 FLASH->CR1 |= FLASH_CR_CRC_EN;
740
741 /* Clear CRC flags in Status Register: CRC end of calculation and CRC read error */
743 /* Clear burst size and type bits before setting new values */
745 /* Clear current CRC result, program burst size and define memory area on which CRC has to be computed */
746 FLASH->CRCCR1 |= FLASH_CRCCR_CLEAN_CRC | pCRCInit->BurstSize | pCRCInit->TypeCRC;
747
748 if (pCRCInit->TypeCRC == FLASH_CRC_SECTORS)
749 {
750 /* Clear sectors list */
751 FLASH->CRCCR1 |= FLASH_CRCCR_CLEAN_SECT;
752
753 /* Select CRC sectors */
754 for(sector_index = pCRCInit->Sector; sector_index < (pCRCInit->NbSectors + pCRCInit->Sector); sector_index++)
755 {
756 FLASH_CRC_AddSector(sector_index, FLASH_BANK_1);
757 }
758 }
759 else if (pCRCInit->TypeCRC == FLASH_CRC_BANK)
760 {
761 /* Enable Bank 1 CRC select bit */
762 FLASH->CRCCR1 |= FLASH_CRCCR_ALL_BANK;
763 }
764 else
765 {
766 /* Select CRC start and end addresses */
767 FLASH_CRC_SelectAddress(pCRCInit->CRCStartAddr, pCRCInit->CRCEndAddr, FLASH_BANK_1);
768 }
769
770 /* Start the CRC calculation */
771 FLASH->CRCCR1 |= FLASH_CRCCR_START_CRC;
772
773 /* Wait on CRC busy flag */
774 status = FLASH_CRC_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_1);
775
776 /* Return CRC result */
777 (*CRC_Result) = FLASH->CRCDATA;
778
779 /* Disable CRC feature */
780 FLASH->CR1 &= (~FLASH_CR_CRC_EN);
781
782 /* Clear CRC flags */
784 }
785#if defined (DUAL_BANK)
786 else
787 {
788 /* Enable CRC feature */
789 FLASH->CR2 |= FLASH_CR_CRC_EN;
790
791 /* Clear CRC flags in Status Register: CRC end of calculation and CRC read error */
793 /* Clear burst size and type bits before setting new values */
795 /* Clear current CRC result, program burst size and define memory area on which CRC has to be computed */
796 FLASH->CRCCR2 |= FLASH_CRCCR_CLEAN_CRC | pCRCInit->BurstSize | pCRCInit->TypeCRC;
797
798 if (pCRCInit->TypeCRC == FLASH_CRC_SECTORS)
799 {
800 /* Clear sectors list */
801 FLASH->CRCCR2 |= FLASH_CRCCR_CLEAN_SECT;
802
803 /* Add CRC sectors */
804 for(sector_index = pCRCInit->Sector; sector_index < (pCRCInit->NbSectors + pCRCInit->Sector); sector_index++)
805 {
806 FLASH_CRC_AddSector(sector_index, FLASH_BANK_2);
807 }
808 }
809 else if (pCRCInit->TypeCRC == FLASH_CRC_BANK)
810 {
811 /* Enable Bank 2 CRC select bit */
812 FLASH->CRCCR2 |= FLASH_CRCCR_ALL_BANK;
813 }
814 else
815 {
816 /* Select CRC start and end addresses */
817 FLASH_CRC_SelectAddress(pCRCInit->CRCStartAddr, pCRCInit->CRCEndAddr, FLASH_BANK_2);
818 }
819
820 /* Start the CRC calculation */
821 FLASH->CRCCR2 |= FLASH_CRCCR_START_CRC;
822
823 /* Wait on CRC busy flag */
824 status = FLASH_CRC_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE, FLASH_BANK_2);
825
826 /* Return CRC result */
827 (*CRC_Result) = FLASH->CRCDATA;
828
829 /* Disable CRC feature */
830 FLASH->CR2 &= (~FLASH_CR_CRC_EN);
831
832 /* Clear CRC flags */
834 }
835#endif /* DUAL_BANK */
836 }
837
838 return status;
839}
840
841/**
842 * @}
843 */
844
845#if (USE_FLASH_ECC == 1U)
846/** @defgroup FLASHEx_Exported_Functions_Group2 Extended ECC operation functions
847 * @brief Extended ECC operation functions
848 *
849@verbatim
850 ===============================================================================
851 ##### Extended ECC operation functions #####
852 ===============================================================================
853 [..]
854 This subsection provides a set of functions allowing to manage the Extended FLASH
855 ECC Operations.
856
857@endverbatim
858 * @{
859 */
860
861/**
862 * @brief Enable ECC correction interrupts on FLASH BANK1 and BANK2.
863 * @param None
864 * @retval None
865 */
866void HAL_FLASHEx_EnableEccCorrectionInterrupt(void)
867{
869
870#if defined (DUAL_BANK)
872#endif /* DUAL_BANK */
873}
874
875/**
876 * @brief Disable ECC correction interrupts on FLASH BANK1 and BANK2.
877 * @param None
878 * @retval None
879 */
880void HAL_FLASHEx_DisableEccCorrectionInterrupt(void)
881{
883
884#if defined (DUAL_BANK)
886#endif /* DUAL_BANK */
887}
888
889/**
890 * @brief Enable ECC correction interrupt on FLASH BANK1.
891 * @param None
892 * @retval None
893 */
894void HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank1(void)
895{
897}
898
899/**
900 * @brief Disable ECC correction interrupt on FLASH BANK1.
901 * @param None
902 * @retval None
903 */
904void HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank1(void)
905{
907}
908
909#if defined (DUAL_BANK)
910/**
911 * @brief Enable ECC correction interrupt on FLASH BANK2.
912 * @param None
913 * @retval None
914 */
915void HAL_FLASHEx_EnableEccCorrectionInterrupt_Bank2(void)
916{
918}
919
920/**
921 * @brief Disable ECC correction interrupt on FLASH BANK2.
922 * @param None
923 * @retval None
924 */
925void HAL_FLASHEx_DisableEccCorrectionInterrupt_Bank2(void)
926{
928}
929#endif /* DUAL_BANK */
930
931/**
932 * @brief Enable ECC Detection interrupts on FLASH BANK1 and BANK2.
933 * @param None
934 * @retval None
935 */
936void HAL_FLASHEx_EnableEccDetectionInterrupt(void)
937{
939
940#if defined (DUAL_BANK)
942#endif /* DUAL_BANK */
943}
944
945/**
946 * @brief Disable ECC Detection interrupts on FLASH BANK1 and BANK2.
947 * @param None
948 * @retval None
949 */
950void HAL_FLASHEx_DisableEccDetectionInterrupt(void)
951{
953
954#if defined (DUAL_BANK)
956#endif /* DUAL_BANK */
957}
958
959/**
960 * @brief Enable ECC Detection interrupt on FLASH BANK1.
961 * @param None
962 * @retval None
963 */
964void HAL_FLASHEx_EnableEccDetectionInterrupt_Bank1(void)
965{
967}
968
969/**
970 * @brief Disable ECC correction interrupt on FLASH BANK1.
971 * @param None
972 * @retval None
973 */
974void HAL_FLASHEx_DisableEccDetectionInterrupt_Bank1(void)
975{
977}
978
979#if defined (DUAL_BANK)
980/**
981 * @brief Enable ECC Detection interrupt on FLASH BANK2.
982 * @param None
983 * @retval None
984 */
985void HAL_FLASHEx_EnableEccDetectionInterrupt_Bank2(void)
986{
988}
989
990/**
991 * @brief Disable ECC Detection interrupt on FLASH BANK2.
992 * @param None
993 * @retval None
994 */
995void HAL_FLASHEx_DisableEccDetectionInterrupt_Bank2(void)
996{
998}
999#endif /* DUAL_BANK */
1000
1001/**
1002 * @brief Get the ECC error information.
1003 * @param pData Pointer to an FLASH_EccInfoTypeDef structure that contains the
1004 * ECC error information.
1005 * @note This function should be called before ECC bit is cleared
1006 * (in callback function)
1007 * @retval None
1008 */
1009void HAL_FLASHEx_GetEccInfo(FLASH_EccInfoTypeDef *pData)
1010{
1011 uint32_t errorflag;
1012
1013 /* Check FLASH Bank1 ECC single correction and double detection error flags */
1015 if(errorflag != 0U)
1016 {
1017 pData->Area = FLASH_ECC_AREA_USER_BANK1;
1018 pData->Address = ((((FLASH->ECC_FA1 & FLASH_ECC_FA_FAIL_ECC_ADDR))* FLASH_NB_32BITWORD_IN_FLASHWORD * 4) + FLASH_BANK1_BASE);
1019 }
1020#if defined (DUAL_BANK)
1021 /* Check FLASH Bank2 ECC single correction and double detection error flags */
1023 if(errorflag != 0U)
1024 {
1025 pData->Area = FLASH_ECC_AREA_USER_BANK2;
1026 pData->Address = ((((FLASH->ECC_FA2 & FLASH_ECC_FA_FAIL_ECC_ADDR))* FLASH_NB_32BITWORD_IN_FLASHWORD * 4) + FLASH_BANK2_BASE);
1027 }
1028#endif /* DUAL_BANK */
1029}
1030
1031/**
1032 * @brief Handle Flash ECC Detection interrupt request.
1033 * @retval None
1034 */
1035void HAL_FLASHEx_BusFault_IRQHandler(void)
1036{
1037 /* Check if the ECC double error occurred*/
1038 if ((FLASH->SR1 & FLASH_FLAG_DBECCERR_BANK1) != 0)
1039 {
1040 /* FLASH ECC detection user callback */
1041 HAL_FLASHEx_EccDetectionCallback();
1042
1043 /* Clear Bank 1 ECC double detection error flag
1044 note : this step will clear all the information related to the flash ECC detection
1045 */
1047 }
1048#if defined (DUAL_BANK)
1049 /* Check if the ECC double error occurred*/
1050 if ((FLASH->SR2 & FLASH_FLAG_DBECCERR_BANK2) != 0)
1051 {
1052 /* FLASH ECC detection user callback */
1053 HAL_FLASHEx_EccDetectionCallback();
1054
1055 /* Clear Bank 2 ECC double detection error flag
1056 note : this step will clear all the information related to the flash ECC detection
1057 */
1059 }
1060#endif /* DUAL_BANK */
1061}
1062
1063/**
1064 * @brief FLASH ECC Correction interrupt callback.
1065 * @retval None
1066 */
1067__weak void HAL_FLASHEx_EccCorrectionCallback(void)
1068{
1069 /* NOTE : This function should not be modified, when the callback is needed,
1070 the HAL_FLASHEx_EccCorrectionCallback could be implemented in the user file
1071 */
1072}
1073
1074/**
1075 * @brief FLASH ECC Detection interrupt callback.
1076 * @retval None
1077 */
1078__weak void HAL_FLASHEx_EccDetectionCallback(void)
1079{
1080 /* NOTE : This function should not be modified, when the callback is needed,
1081 the HAL_FLASHEx_EccDetectionCallback could be implemented in the user file
1082 */
1083}
1084
1085/**
1086 * @}
1087 */
1088#endif /* USE_FLASH_ECC */
1089
1090/**
1091 * @}
1092 */
1093
1094/* Private functions ---------------------------------------------------------*/
1095
1096/** @addtogroup FLASHEx_Private_Functions
1097 * @{
1098 */
1099
1100/**
1101 * @brief Mass erase of FLASH memory
1102 * @param VoltageRange The device program/erase parallelism.
1103 * This parameter can be one of the following values:
1104 * @arg FLASH_VOLTAGE_RANGE_1 : Flash program/erase by 8 bits
1105 * @arg FLASH_VOLTAGE_RANGE_2 : Flash program/erase by 16 bits
1106 * @arg FLASH_VOLTAGE_RANGE_3 : Flash program/erase by 32 bits
1107 * @arg FLASH_VOLTAGE_RANGE_4 : Flash program/erase by 64 bits
1108 *
1109 * @param Banks Banks to be erased
1110 * This parameter can be one of the following values:
1111 * @arg FLASH_BANK_1: Bank1 to be erased
1112 * @arg FLASH_BANK_2: Bank2 to be erased
1113 * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased
1114 *
1115 * @retval HAL Status
1116 */
1117static void FLASH_MassErase(uint32_t VoltageRange, uint32_t Banks)
1118{
1119 /* Check the parameters */
1120#if defined (FLASH_CR_PSIZE)
1121 assert_param(IS_VOLTAGERANGE(VoltageRange));
1122#else
1123 UNUSED(VoltageRange);
1124#endif /* FLASH_CR_PSIZE */
1126
1127#if defined (DUAL_BANK)
1128 /* Flash Mass Erase */
1129 if((Banks & FLASH_BANK_BOTH) == FLASH_BANK_BOTH)
1130 {
1131#if defined (FLASH_CR_PSIZE)
1132 /* Reset Program/erase VoltageRange for Bank1 and Bank2 */
1133 FLASH->CR1 &= (~FLASH_CR_PSIZE);
1134 FLASH->CR2 &= (~FLASH_CR_PSIZE);
1135
1136 /* Set voltage range */
1137 FLASH->CR1 |= VoltageRange;
1138 FLASH->CR2 |= VoltageRange;
1139#endif /* FLASH_CR_PSIZE */
1140
1141 /* Set Mass Erase Bit */
1142 FLASH->OPTCR |= FLASH_OPTCR_MER;
1143 }
1144 else
1145#endif /* DUAL_BANK */
1146 {
1147 /* Proceed to erase Flash Bank */
1148 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1149 {
1150#if defined (FLASH_CR_PSIZE)
1151 /* Set Program/erase VoltageRange for Bank1 */
1152 FLASH->CR1 &= (~FLASH_CR_PSIZE);
1153 FLASH->CR1 |= VoltageRange;
1154#endif /* FLASH_CR_PSIZE */
1155
1156 /* Erase Bank1 */
1157 FLASH->CR1 |= (FLASH_CR_BER | FLASH_CR_START);
1158 }
1159
1160#if defined (DUAL_BANK)
1161 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1162 {
1163#if defined (FLASH_CR_PSIZE)
1164 /* Set Program/erase VoltageRange for Bank2 */
1165 FLASH->CR2 &= (~FLASH_CR_PSIZE);
1166 FLASH->CR2 |= VoltageRange;
1167#endif /* FLASH_CR_PSIZE */
1168
1169 /* Erase Bank2 */
1170 FLASH->CR2 |= (FLASH_CR_BER | FLASH_CR_START);
1171 }
1172#endif /* DUAL_BANK */
1173 }
1174}
1175
1176/**
1177 * @brief Erase the specified FLASH memory sector
1178 * @param Sector FLASH sector to erase
1179 * This parameter can be a value of @ref FLASH_Sectors
1180 * @param Banks Banks to be erased
1181 * This parameter can be one of the following values:
1182 * @arg FLASH_BANK_1: Bank1 to be erased
1183 * @arg FLASH_BANK_2: Bank2 to be erased
1184 * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased
1185 * @param VoltageRange The device program/erase parallelism.
1186 * This parameter can be one of the following values:
1187 * @arg FLASH_VOLTAGE_RANGE_1 : Flash program/erase by 8 bits
1188 * @arg FLASH_VOLTAGE_RANGE_2 : Flash program/erase by 16 bits
1189 * @arg FLASH_VOLTAGE_RANGE_3 : Flash program/erase by 32 bits
1190 * @arg FLASH_VOLTAGE_RANGE_4 : Flash program/erase by 64 bits
1191 *
1192 * @retval None
1193 */
1194void FLASH_Erase_Sector(uint32_t Sector, uint32_t Banks, uint32_t VoltageRange)
1195{
1198#if defined (FLASH_CR_PSIZE)
1199 assert_param(IS_VOLTAGERANGE(VoltageRange));
1200#else
1201 UNUSED(VoltageRange);
1202#endif /* FLASH_CR_PSIZE */
1203
1204 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1205 {
1206#if defined (FLASH_CR_PSIZE)
1207 /* Reset Program/erase VoltageRange and Sector Number for Bank1 */
1208 FLASH->CR1 &= ~(FLASH_CR_PSIZE | FLASH_CR_SNB);
1209
1210 FLASH->CR1 |= (FLASH_CR_SER | VoltageRange | (Sector << FLASH_CR_SNB_Pos) | FLASH_CR_START);
1211#else
1212 /* Reset Sector Number for Bank1 */
1213 FLASH->CR1 &= ~(FLASH_CR_SNB);
1214
1215 FLASH->CR1 |= (FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos) | FLASH_CR_START);
1216#endif /* FLASH_CR_PSIZE */
1217 }
1218
1219#if defined (DUAL_BANK)
1220 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1221 {
1222#if defined (FLASH_CR_PSIZE)
1223 /* Reset Program/erase VoltageRange and Sector Number for Bank2 */
1224 FLASH->CR2 &= ~(FLASH_CR_PSIZE | FLASH_CR_SNB);
1225
1226 FLASH->CR2 |= (FLASH_CR_SER | VoltageRange | (Sector << FLASH_CR_SNB_Pos) | FLASH_CR_START);
1227#else
1228 /* Reset Sector Number for Bank2 */
1229 FLASH->CR2 &= ~(FLASH_CR_SNB);
1230
1231 FLASH->CR2 |= (FLASH_CR_SER | (Sector << FLASH_CR_SNB_Pos) | FLASH_CR_START);
1232#endif /* FLASH_CR_PSIZE */
1233 }
1234#endif /* DUAL_BANK */
1235}
1236
1237/**
1238 * @brief Enable the write protection of the desired bank1 or bank 2 sectors
1239 * @param WRPSector specifies the sector(s) to be write protected.
1240 * This parameter can be one of the following values:
1241 * @arg WRPSector: A combination of OB_WRP_SECTOR_0 to OB_WRP_SECTOR_7 or OB_WRP_SECTOR_ALL
1242 *
1243 * @param Banks the specific bank to apply WRP sectors
1244 * This parameter can be one of the following values:
1245 * @arg FLASH_BANK_1: enable WRP on specified bank1 sectors
1246 * @arg FLASH_BANK_2: enable WRP on specified bank2 sectors
1247 * @arg FLASH_BANK_BOTH: enable WRP on both bank1 and bank2 specified sectors
1248 *
1249 * @retval HAL FLASH State
1250 */
1251static void FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
1252{
1253 /* Check the parameters */
1254 assert_param(IS_OB_WRP_SECTOR(WRPSector));
1256
1257 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1258 {
1259 /* Enable Write Protection for bank 1 */
1260 FLASH->WPSN_PRG1 &= (~(WRPSector & FLASH_WPSN_WRPSN));
1261 }
1262
1263#if defined (DUAL_BANK)
1264 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1265 {
1266 /* Enable Write Protection for bank 2 */
1267 FLASH->WPSN_PRG2 &= (~(WRPSector & FLASH_WPSN_WRPSN));
1268 }
1269#endif /* DUAL_BANK */
1270}
1271
1272/**
1273 * @brief Disable the write protection of the desired bank1 or bank 2 sectors
1274 * @param WRPSector specifies the sector(s) to disable write protection.
1275 * This parameter can be one of the following values:
1276 * @arg WRPSector: A combination of FLASH_OB_WRP_SECTOR_0 to FLASH_OB_WRP_SECTOR_7 or FLASH_OB_WRP_SECTOR_ALL
1277 *
1278 * @param Banks the specific bank to apply WRP sectors
1279 * This parameter can be one of the following values:
1280 * @arg FLASH_BANK_1: disable WRP on specified bank1 sectors
1281 * @arg FLASH_BANK_2: disable WRP on specified bank2 sectors
1282 * @arg FLASH_BANK_BOTH: disable WRP on both bank1 and bank2 specified sectors
1283 *
1284 * @retval HAL FLASH State
1285 */
1286static void FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
1287{
1288 /* Check the parameters */
1289 assert_param(IS_OB_WRP_SECTOR(WRPSector));
1291
1292 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1293 {
1294 /* Disable Write Protection for bank 1 */
1295 FLASH->WPSN_PRG1 |= (WRPSector & FLASH_WPSN_WRPSN);
1296 }
1297
1298#if defined (DUAL_BANK)
1299 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1300 {
1301 /* Disable Write Protection for bank 2 */
1302 FLASH->WPSN_PRG2 |= (WRPSector & FLASH_WPSN_WRPSN);
1303 }
1304#endif /* DUAL_BANK */
1305}
1306
1307/**
1308 * @brief Get the write protection of the given bank 1 or bank 2 sectors
1309 * @param WRPState gives the write protection state on the given bank.
1310 * This parameter can be one of the following values:
1311 * @arg WRPState: OB_WRPSTATE_DISABLE or OB_WRPSTATE_ENABLE
1312
1313 * @param WRPSector gives the write protected sector(s) on the given bank .
1314 * This parameter can be one of the following values:
1315 * @arg WRPSector: A combination of FLASH_OB_WRP_SECTOR_0 to FLASH_OB_WRP_SECTOR_7 or FLASH_OB_WRP_SECTOR_ALL
1316 *
1317 * @param Bank the specific bank to apply WRP sectors
1318 * This parameter can be exclusively one of the following values:
1319 * @arg FLASH_BANK_1: Get bank1 WRP sectors
1320 * @arg FLASH_BANK_2: Get bank2 WRP sectors
1321 * @arg FLASH_BANK_BOTH: note allowed in this functions
1322 *
1323 * @retval HAL FLASH State
1324 */
1325static void FLASH_OB_GetWRP(uint32_t *WRPState, uint32_t *WRPSector, uint32_t Bank)
1326{
1327 uint32_t regvalue = 0U;
1328
1329 if(Bank == FLASH_BANK_1)
1330 {
1331 regvalue = FLASH->WPSN_CUR1;
1332 }
1333
1334#if defined (DUAL_BANK)
1335 if(Bank == FLASH_BANK_2)
1336 {
1337 regvalue = FLASH->WPSN_CUR2;
1338 }
1339#endif /* DUAL_BANK */
1340
1341 (*WRPSector) = (~regvalue) & FLASH_WPSN_WRPSN;
1342
1343 if(*WRPSector == 0U)
1344 {
1345 (*WRPState) = OB_WRPSTATE_DISABLE;
1346 }
1347 else
1348 {
1349 (*WRPState) = OB_WRPSTATE_ENABLE;
1350 }
1351}
1352
1353/**
1354 * @brief Set the read protection level.
1355 *
1356 * @note To configure the RDP level, the option lock bit OPTLOCK must be
1357 * cleared with the call of the HAL_FLASH_OB_Unlock() function.
1358 * @note To validate the RDP level, the option bytes must be reloaded
1359 * through the call of the HAL_FLASH_OB_Launch() function.
1360 * @note !!! Warning : When enabling OB_RDP level 2 it's no more possible
1361 * to go back to level 1 or 0 !!!
1362 *
1363 * @param RDPLevel specifies the read protection level.
1364 * This parameter can be one of the following values:
1365 * @arg OB_RDP_LEVEL_0: No protection
1366 * @arg OB_RDP_LEVEL_1: Read protection of the memory
1367 * @arg OB_RDP_LEVEL_2: Full chip protection
1368 *
1369 * @retval HAL status
1370 */
1371static void FLASH_OB_RDPConfig(uint32_t RDPLevel)
1372{
1373 /* Check the parameters */
1374 assert_param(IS_OB_RDP_LEVEL(RDPLevel));
1375
1376 /* Configure the RDP level in the option bytes register */
1377 MODIFY_REG(FLASH->OPTSR_PRG, FLASH_OPTSR_RDP, RDPLevel);
1378}
1379
1380/**
1381 * @brief Get the read protection level.
1382 * @retval RDPLevel specifies the read protection level.
1383 * This return value can be one of the following values:
1384 * @arg OB_RDP_LEVEL_0: No protection
1385 * @arg OB_RDP_LEVEL_1: Read protection of the memory
1386 * @arg OB_RDP_LEVEL_2: Full chip protection
1387 */
1388static uint32_t FLASH_OB_GetRDP(void)
1389{
1390 uint32_t rdp_level = READ_BIT(FLASH->OPTSR_CUR, FLASH_OPTSR_RDP);
1391
1392 if ((rdp_level != OB_RDP_LEVEL_0) && (rdp_level != OB_RDP_LEVEL_2))
1393 {
1394 return (OB_RDP_LEVEL_1);
1395 }
1396 else
1397 {
1398 return rdp_level;
1399 }
1400}
1401
1402#if defined(DUAL_CORE)
1403/**
1404 * @brief Program the FLASH User Option Byte.
1405 *
1406 * @note To configure the user option bytes, the option lock bit OPTLOCK must
1407 * be cleared with the call of the HAL_FLASH_OB_Unlock() function.
1408 *
1409 * @note To validate the user option bytes, the option bytes must be reloaded
1410 * through the call of the HAL_FLASH_OB_Launch() function.
1411 *
1412 * @param UserType The FLASH User Option Bytes to be modified :
1413 * a combination of @ref FLASHEx_OB_USER_Type
1414 *
1415 * @param UserConfig The FLASH User Option Bytes values:
1416 * IWDG1_SW(Bit4), IWDG2_SW(Bit 5), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7),
1417 * FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]),
1418 * SECURITY(Bit 21), BCM4(Bit 22), BCM7(Bit 23), nRST_STOP_D2(Bit 24),
1419 * nRST_STDY_D2(Bit 25), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).
1420 *
1421 * @retval HAL status
1422 */
1423#else
1424/**
1425 * @brief Program the FLASH User Option Byte.
1426 *
1427 * @note To configure the user option bytes, the option lock bit OPTLOCK must
1428 * be cleared with the call of the HAL_FLASH_OB_Unlock() function.
1429 *
1430 * @note To validate the user option bytes, the option bytes must be reloaded
1431 * through the call of the HAL_FLASH_OB_Launch() function.
1432 *
1433 * @param UserType The FLASH User Option Bytes to be modified :
1434 * a combination of @arg FLASHEx_OB_USER_Type
1435 *
1436 * @param UserConfig The FLASH User Option Bytes values:
1437 * IWDG_SW(Bit4), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7),
1438 * FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]),
1439 * SECURITY(Bit 21), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).
1440 *
1441 * @retval HAL status
1442 */
1443#endif /*DUAL_CORE*/
1444static void FLASH_OB_UserConfig(uint32_t UserType, uint32_t UserConfig)
1445{
1446 uint32_t optr_reg_val = 0;
1447 uint32_t optr_reg_mask = 0;
1448
1449 /* Check the parameters */
1450 assert_param(IS_OB_USER_TYPE(UserType));
1451
1452 if((UserType & OB_USER_IWDG1_SW) != 0U)
1453 {
1454 /* IWDG_HW option byte should be modified */
1456
1457 /* Set value and mask for IWDG_HW option byte */
1458 optr_reg_val |= (UserConfig & FLASH_OPTSR_IWDG1_SW);
1459 optr_reg_mask |= FLASH_OPTSR_IWDG1_SW;
1460 }
1461#if defined(DUAL_CORE)
1462 if((UserType & OB_USER_IWDG2_SW) != 0U)
1463 {
1464 /* IWDG2_SW option byte should be modified */
1465 assert_param(IS_OB_IWDG2_SOURCE(UserConfig & FLASH_OPTSR_IWDG2_SW));
1466
1467 /* Set value and mask for IWDG2_SW option byte */
1468 optr_reg_val |= (UserConfig & FLASH_OPTSR_IWDG2_SW);
1469 optr_reg_mask |= FLASH_OPTSR_IWDG2_SW;
1470 }
1471#endif /*DUAL_CORE*/
1472 if((UserType & OB_USER_NRST_STOP_D1) != 0U)
1473 {
1474 /* NRST_STOP option byte should be modified */
1476
1477 /* Set value and mask for NRST_STOP option byte */
1478 optr_reg_val |= (UserConfig & FLASH_OPTSR_NRST_STOP_D1);
1479 optr_reg_mask |= FLASH_OPTSR_NRST_STOP_D1;
1480 }
1481
1482 if((UserType & OB_USER_NRST_STDBY_D1) != 0U)
1483 {
1484 /* NRST_STDBY option byte should be modified */
1486
1487 /* Set value and mask for NRST_STDBY option byte */
1488 optr_reg_val |= (UserConfig & FLASH_OPTSR_NRST_STBY_D1);
1489 optr_reg_mask |= FLASH_OPTSR_NRST_STBY_D1;
1490 }
1491
1492 if((UserType & OB_USER_IWDG_STOP) != 0U)
1493 {
1494 /* IWDG_STOP option byte should be modified */
1496
1497 /* Set value and mask for IWDG_STOP option byte */
1498 optr_reg_val |= (UserConfig & FLASH_OPTSR_FZ_IWDG_STOP);
1499 optr_reg_mask |= FLASH_OPTSR_FZ_IWDG_STOP;
1500 }
1501
1502 if((UserType & OB_USER_IWDG_STDBY) != 0U)
1503 {
1504 /* IWDG_STDBY option byte should be modified */
1506
1507 /* Set value and mask for IWDG_STDBY option byte */
1508 optr_reg_val |= (UserConfig & FLASH_OPTSR_FZ_IWDG_SDBY);
1509 optr_reg_mask |= FLASH_OPTSR_FZ_IWDG_SDBY;
1510 }
1511
1512 if((UserType & OB_USER_ST_RAM_SIZE) != 0U)
1513 {
1514 /* ST_RAM_SIZE option byte should be modified */
1516
1517 /* Set value and mask for ST_RAM_SIZE option byte */
1518 optr_reg_val |= (UserConfig & FLASH_OPTSR_ST_RAM_SIZE);
1519 optr_reg_mask |= FLASH_OPTSR_ST_RAM_SIZE;
1520 }
1521
1522 if((UserType & OB_USER_SECURITY) != 0U)
1523 {
1524 /* SECURITY option byte should be modified */
1526
1527 /* Set value and mask for SECURITY option byte */
1528 optr_reg_val |= (UserConfig & FLASH_OPTSR_SECURITY);
1529 optr_reg_mask |= FLASH_OPTSR_SECURITY;
1530 }
1531
1532#if defined(DUAL_CORE)
1533 if((UserType & OB_USER_BCM4) != 0U)
1534 {
1535 /* BCM4 option byte should be modified */
1536 assert_param(IS_OB_USER_BCM4(UserConfig & FLASH_OPTSR_BCM4));
1537
1538 /* Set value and mask for BCM4 option byte */
1539 optr_reg_val |= (UserConfig & FLASH_OPTSR_BCM4);
1540 optr_reg_mask |= FLASH_OPTSR_BCM4;
1541 }
1542
1543 if((UserType & OB_USER_BCM7) != 0U)
1544 {
1545 /* BCM7 option byte should be modified */
1546 assert_param(IS_OB_USER_BCM7(UserConfig & FLASH_OPTSR_BCM7));
1547
1548 /* Set value and mask for BCM7 option byte */
1549 optr_reg_val |= (UserConfig & FLASH_OPTSR_BCM7);
1550 optr_reg_mask |= FLASH_OPTSR_BCM7;
1551 }
1552#endif /* DUAL_CORE */
1553
1554#if defined (FLASH_OPTSR_NRST_STOP_D2)
1555 if((UserType & OB_USER_NRST_STOP_D2) != 0U)
1556 {
1557 /* NRST_STOP option byte should be modified */
1558 assert_param(IS_OB_STOP_D2_RESET(UserConfig & FLASH_OPTSR_NRST_STOP_D2));
1559
1560 /* Set value and mask for NRST_STOP option byte */
1561 optr_reg_val |= (UserConfig & FLASH_OPTSR_NRST_STOP_D2);
1562 optr_reg_mask |= FLASH_OPTSR_NRST_STOP_D2;
1563 }
1564
1565 if((UserType & OB_USER_NRST_STDBY_D2) != 0U)
1566 {
1567 /* NRST_STDBY option byte should be modified */
1568 assert_param(IS_OB_STDBY_D2_RESET(UserConfig & FLASH_OPTSR_NRST_STBY_D2));
1569
1570 /* Set value and mask for NRST_STDBY option byte */
1571 optr_reg_val |= (UserConfig & FLASH_OPTSR_NRST_STBY_D2);
1572 optr_reg_mask |= FLASH_OPTSR_NRST_STBY_D2;
1573 }
1574#endif /* FLASH_OPTSR_NRST_STOP_D2 */
1575
1576#if defined (DUAL_BANK)
1577 if((UserType & OB_USER_SWAP_BANK) != 0U)
1578 {
1579 /* SWAP_BANK_OPT option byte should be modified */
1580 assert_param(IS_OB_USER_SWAP_BANK(UserConfig & FLASH_OPTSR_SWAP_BANK_OPT));
1581
1582 /* Set value and mask for SWAP_BANK_OPT option byte */
1583 optr_reg_val |= (UserConfig & FLASH_OPTSR_SWAP_BANK_OPT);
1584 optr_reg_mask |= FLASH_OPTSR_SWAP_BANK_OPT;
1585 }
1586#endif /* DUAL_BANK */
1587
1588 if((UserType & OB_USER_IOHSLV) != 0U)
1589 {
1590 /* IOHSLV_OPT option byte should be modified */
1592
1593 /* Set value and mask for IOHSLV_OPT option byte */
1594 optr_reg_val |= (UserConfig & FLASH_OPTSR_IO_HSLV);
1595 optr_reg_mask |= FLASH_OPTSR_IO_HSLV;
1596 }
1597
1598#if defined (FLASH_OPTSR_VDDMMC_HSLV)
1599 if((UserType & OB_USER_VDDMMC_HSLV) != 0U)
1600 {
1601 /* VDDMMC_HSLV option byte should be modified */
1602 assert_param(IS_OB_USER_VDDMMC_HSLV(UserConfig & FLASH_OPTSR_VDDMMC_HSLV));
1603
1604 /* Set value and mask for VDDMMC_HSLV option byte */
1605 optr_reg_val |= (UserConfig & FLASH_OPTSR_VDDMMC_HSLV);
1606 optr_reg_mask |= FLASH_OPTSR_VDDMMC_HSLV;
1607 }
1608#endif /* FLASH_OPTSR_VDDMMC_HSLV */
1609
1610 /* Configure the option bytes register */
1611 MODIFY_REG(FLASH->OPTSR_PRG, optr_reg_mask, optr_reg_val);
1612}
1613
1614#if defined(DUAL_CORE)
1615/**
1616 * @brief Return the FLASH User Option Byte value.
1617 * @retval The FLASH User Option Bytes values
1618 * IWDG1_SW(Bit4), IWDG2_SW(Bit 5), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7),
1619 * FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]),
1620 * SECURITY(Bit 21), BCM4(Bit 22), BCM7(Bit 23), nRST_STOP_D2(Bit 24),
1621 * nRST_STDY_D2(Bit 25), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).
1622 */
1623#else
1624/**
1625 * @brief Return the FLASH User Option Byte value.
1626 * @retval The FLASH User Option Bytes values
1627 * IWDG_SW(Bit4), nRST_STOP_D1(Bit 6), nRST_STDY_D1(Bit 7),
1628 * FZ_IWDG_STOP(Bit 17), FZ_IWDG_SDBY(Bit 18), ST_RAM_SIZE(Bit[19:20]),
1629 * SECURITY(Bit 21), IO_HSLV (Bit 29) and SWAP_BANK_OPT(Bit 31).
1630 */
1631#endif /*DUAL_CORE*/
1632static uint32_t FLASH_OB_GetUser(void)
1633{
1634 uint32_t userConfig = READ_REG(FLASH->OPTSR_CUR);
1635 userConfig &= (~(FLASH_OPTSR_BOR_LEV | FLASH_OPTSR_RDP));
1636
1637 return userConfig;
1638}
1639
1640/**
1641 * @brief Configure the Proprietary code readout protection of the desired addresses
1642 *
1643 * @note To configure the PCROP options, the option lock bit OPTLOCK must be
1644 * cleared with the call of the HAL_FLASH_OB_Unlock() function.
1645 * @note To validate the PCROP options, the option bytes must be reloaded
1646 * through the call of the HAL_FLASH_OB_Launch() function.
1647 *
1648 * @param PCROPConfig specifies if the PCROP area for the given Bank shall be erased or not
1649 * when RDP level decreased from Level 1 to Level 0, or after a bank erase with protection removal
1650 * This parameter must be a value of @arg FLASHEx_OB_PCROP_RDP enumeration
1651 *
1652 * @param PCROPStartAddr specifies the start address of the Proprietary code readout protection
1653 * This parameter can be an address between begin and end of the bank
1654 *
1655 * @param PCROPEndAddr specifies the end address of the Proprietary code readout protection
1656 * This parameter can be an address between PCROPStartAddr and end of the bank
1657 *
1658 * @param Banks the specific bank to apply PCROP protection
1659 * This parameter can be one of the following values:
1660 * @arg FLASH_BANK_1: PCROP on specified bank1 area
1661 * @arg FLASH_BANK_2: PCROP on specified bank2 area
1662 * @arg FLASH_BANK_BOTH: PCROP on specified bank1 and bank2 area (same config will be applied on both banks)
1663 *
1664 * @retval None
1665 */
1666static void FLASH_OB_PCROPConfig(uint32_t PCROPConfig, uint32_t PCROPStartAddr, uint32_t PCROPEndAddr, uint32_t Banks)
1667{
1668 /* Check the parameters */
1670 assert_param(IS_OB_PCROP_RDP(PCROPConfig));
1671
1672 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1673 {
1676
1677 /* Configure the Proprietary code readout protection */
1678 FLASH->PRAR_PRG1 = ((PCROPStartAddr - FLASH_BANK1_BASE) >> 8) | \
1679 (((PCROPEndAddr - FLASH_BANK1_BASE) >> 8) << FLASH_PRAR_PROT_AREA_END_Pos) | \
1680 PCROPConfig;
1681 }
1682
1683#if defined (DUAL_BANK)
1684 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1685 {
1686 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(PCROPStartAddr));
1687 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(PCROPEndAddr));
1688
1689 /* Configure the Proprietary code readout protection */
1690 FLASH->PRAR_PRG2 = ((PCROPStartAddr - FLASH_BANK2_BASE) >> 8) | \
1691 (((PCROPEndAddr - FLASH_BANK2_BASE) >> 8) << FLASH_PRAR_PROT_AREA_END_Pos) | \
1692 PCROPConfig;
1693 }
1694#endif /* DUAL_BANK */
1695}
1696
1697/**
1698 * @brief Get the Proprietary code readout protection configuration on a given Bank
1699 *
1700 * @param PCROPConfig indicates if the PCROP area for the given Bank shall be erased or not
1701 * when RDP level decreased from Level 1 to Level 0 or after a bank erase with protection removal
1702 *
1703 * @param PCROPStartAddr gives the start address of the Proprietary code readout protection of the bank
1704 *
1705 * @param PCROPEndAddr gives the end address of the Proprietary code readout protection of the bank
1706 *
1707 * @param Bank the specific bank to apply PCROP protection
1708 * This parameter can be exclusively one of the following values:
1709 * @arg FLASH_BANK_1: PCROP on specified bank1 area
1710 * @arg FLASH_BANK_2: PCROP on specified bank2 area
1711 * @arg FLASH_BANK_BOTH: is not allowed here
1712 *
1713 * @retval None
1714 */
1715static void FLASH_OB_GetPCROP(uint32_t *PCROPConfig, uint32_t *PCROPStartAddr, uint32_t *PCROPEndAddr, uint32_t Bank)
1716{
1717 uint32_t regvalue = 0;
1718 uint32_t bankBase = 0;
1719
1720 if(Bank == FLASH_BANK_1)
1721 {
1722 regvalue = FLASH->PRAR_CUR1;
1723 bankBase = FLASH_BANK1_BASE;
1724 }
1725
1726#if defined (DUAL_BANK)
1727 if(Bank == FLASH_BANK_2)
1728 {
1729 regvalue = FLASH->PRAR_CUR2;
1730 bankBase = FLASH_BANK2_BASE;
1731 }
1732#endif /* DUAL_BANK */
1733
1734 (*PCROPConfig) = (regvalue & FLASH_PRAR_DMEP);
1735
1736 (*PCROPStartAddr) = ((regvalue & FLASH_PRAR_PROT_AREA_START) << 8) + bankBase;
1737 (*PCROPEndAddr) = (regvalue & FLASH_PRAR_PROT_AREA_END) >> FLASH_PRAR_PROT_AREA_END_Pos;
1738 (*PCROPEndAddr) = ((*PCROPEndAddr) << 8) + bankBase;
1739}
1740
1741/**
1742 * @brief Set the BOR Level.
1743 * @param Level specifies the Option Bytes BOR Reset Level.
1744 * This parameter can be one of the following values:
1745 * @arg OB_BOR_LEVEL0: Reset level threshold is set to 1.6V
1746 * @arg OB_BOR_LEVEL1: Reset level threshold is set to 2.1V
1747 * @arg OB_BOR_LEVEL2: Reset level threshold is set to 2.4V
1748 * @arg OB_BOR_LEVEL3: Reset level threshold is set to 2.7V
1749 * @retval None
1750 */
1751static void FLASH_OB_BOR_LevelConfig(uint32_t Level)
1752{
1754
1755 /* Configure BOR_LEV option byte */
1756 MODIFY_REG(FLASH->OPTSR_PRG, FLASH_OPTSR_BOR_LEV, Level);
1757}
1758
1759/**
1760 * @brief Get the BOR Level.
1761 * @retval The Option Bytes BOR Reset Level.
1762 * This parameter can be one of the following values:
1763 * @arg OB_BOR_LEVEL0: Reset level threshold is set to 1.6V
1764 * @arg OB_BOR_LEVEL1: Reset level threshold is set to 2.1V
1765 * @arg OB_BOR_LEVEL2: Reset level threshold is set to 2.4V
1766 * @arg OB_BOR_LEVEL3: Reset level threshold is set to 2.7V
1767 */
1768static uint32_t FLASH_OB_GetBOR(void)
1769{
1770 return (FLASH->OPTSR_CUR & FLASH_OPTSR_BOR_LEV);
1771}
1772
1773/**
1774 * @brief Set Boot address
1775 * @param BootOption Boot address option byte to be programmed,
1776 * This parameter must be a value of @ref FLASHEx_OB_BOOT_OPTION
1777 (OB_BOOT_ADD0, OB_BOOT_ADD1 or OB_BOOT_ADD_BOTH)
1778 *
1779 * @param BootAddress0 Specifies the Boot Address 0
1780 * @param BootAddress1 Specifies the Boot Address 1
1781 * @retval HAL Status
1782 */
1783static void FLASH_OB_BootAddConfig(uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1)
1784{
1785 /* Check the parameters */
1787
1788 if((BootOption & OB_BOOT_ADD0) == OB_BOOT_ADD0)
1789 {
1790 /* Check the parameters */
1791 assert_param(IS_BOOT_ADDRESS(BootAddress0));
1792
1793 /* Configure CM7 BOOT ADD0 */
1794#if defined(DUAL_CORE)
1795 MODIFY_REG(FLASH->BOOT7_PRG, FLASH_BOOT7_BCM7_ADD0, (BootAddress0 >> 16));
1796#else /* Single Core*/
1797 MODIFY_REG(FLASH->BOOT_PRG, FLASH_BOOT_ADD0, (BootAddress0 >> 16));
1798#endif /* DUAL_CORE */
1799 }
1800
1801 if((BootOption & OB_BOOT_ADD1) == OB_BOOT_ADD1)
1802 {
1803 /* Check the parameters */
1804 assert_param(IS_BOOT_ADDRESS(BootAddress1));
1805
1806 /* Configure CM7 BOOT ADD1 */
1807#if defined(DUAL_CORE)
1808 MODIFY_REG(FLASH->BOOT7_PRG, FLASH_BOOT7_BCM7_ADD1, BootAddress1);
1809#else /* Single Core*/
1810 MODIFY_REG(FLASH->BOOT_PRG, FLASH_BOOT_ADD1, BootAddress1);
1811#endif /* DUAL_CORE */
1812 }
1813}
1814
1815/**
1816 * @brief Get Boot address
1817 * @param BootAddress0 Specifies the Boot Address 0.
1818 * @param BootAddress1 Specifies the Boot Address 1.
1819 * @retval HAL Status
1820 */
1821static void FLASH_OB_GetBootAdd(uint32_t *BootAddress0, uint32_t *BootAddress1)
1822{
1823 uint32_t regvalue;
1824
1825#if defined(DUAL_CORE)
1826 regvalue = FLASH->BOOT7_CUR;
1827
1828 (*BootAddress0) = (regvalue & FLASH_BOOT7_BCM7_ADD0) << 16;
1829 (*BootAddress1) = (regvalue & FLASH_BOOT7_BCM7_ADD1);
1830#else /* Single Core */
1831 regvalue = FLASH->BOOT_CUR;
1832
1833 (*BootAddress0) = (regvalue & FLASH_BOOT_ADD0) << 16;
1834 (*BootAddress1) = (regvalue & FLASH_BOOT_ADD1);
1835#endif /* DUAL_CORE */
1836}
1837
1838#if defined(DUAL_CORE)
1839/**
1840 * @brief Set CM4 Boot address
1841 * @param BootOption Boot address option byte to be programmed,
1842 * This parameter must be a value of @ref FLASHEx_OB_BOOT_OPTION
1843 (OB_BOOT_ADD0, OB_BOOT_ADD1 or OB_BOOT_ADD_BOTH)
1844 *
1845 * @param BootAddress0 Specifies the CM4 Boot Address 0.
1846 * @param BootAddress1 Specifies the CM4 Boot Address 1.
1847 * @retval HAL Status
1848 */
1849static void FLASH_OB_CM4BootAddConfig(uint32_t BootOption, uint32_t BootAddress0, uint32_t BootAddress1)
1850{
1851 /* Check the parameters */
1853
1854 if((BootOption & OB_BOOT_ADD0) == OB_BOOT_ADD0)
1855 {
1856 /* Check the parameters */
1857 assert_param(IS_BOOT_ADDRESS(BootAddress0));
1858
1859 /* Configure CM4 BOOT ADD0 */
1860 MODIFY_REG(FLASH->BOOT4_PRG, FLASH_BOOT4_BCM4_ADD0, (BootAddress0 >> 16));
1861
1862 }
1863
1864 if((BootOption & OB_BOOT_ADD1) == OB_BOOT_ADD1)
1865 {
1866 /* Check the parameters */
1867 assert_param(IS_BOOT_ADDRESS(BootAddress1));
1868
1869 /* Configure CM4 BOOT ADD1 */
1870 MODIFY_REG(FLASH->BOOT4_PRG, FLASH_BOOT4_BCM4_ADD1, BootAddress1);
1871 }
1872}
1873
1874/**
1875 * @brief Get CM4 Boot address
1876 * @param BootAddress0 Specifies the CM4 Boot Address 0.
1877 * @param BootAddress1 Specifies the CM4 Boot Address 1.
1878 * @retval HAL Status
1879 */
1880static void FLASH_OB_GetCM4BootAdd(uint32_t *BootAddress0, uint32_t *BootAddress1)
1881{
1882 uint32_t regvalue;
1883
1884 regvalue = FLASH->BOOT4_CUR;
1885
1886 (*BootAddress0) = (regvalue & FLASH_BOOT4_BCM4_ADD0) << 16;
1887 (*BootAddress1) = (regvalue & FLASH_BOOT4_BCM4_ADD1);
1888}
1889#endif /*DUAL_CORE*/
1890
1891/**
1892 * @brief Set secure area configuration
1893 * @param SecureAreaConfig specify if the secure area will be deleted or not
1894 * when RDP level decreased from Level 1 to Level 0 or during a mass erase.
1895 *
1896 * @param SecureAreaStartAddr Specifies the secure area start address
1897 * @param SecureAreaEndAddr Specifies the secure area end address
1898 * @param Banks the specific bank to apply Security protection
1899 * This parameter can be one of the following values:
1900 * @arg FLASH_BANK_1: Secure area on specified bank1 area
1901 * @arg FLASH_BANK_2: Secure area on specified bank2 area
1902 * @arg FLASH_BANK_BOTH: Secure area on specified bank1 and bank2 area (same config will be applied on both banks)
1903 * @retval None
1904 */
1905static void FLASH_OB_SecureAreaConfig(uint32_t SecureAreaConfig, uint32_t SecureAreaStartAddr, uint32_t SecureAreaEndAddr, uint32_t Banks)
1906{
1907 /* Check the parameters */
1909 assert_param(IS_OB_SECURE_RDP(SecureAreaConfig));
1910
1911 if((Banks & FLASH_BANK_1) == FLASH_BANK_1)
1912 {
1913 /* Check the parameters */
1914 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK1(SecureAreaStartAddr));
1915 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK1(SecureAreaEndAddr));
1916
1917 /* Configure the secure area */
1918 FLASH->SCAR_PRG1 = ((SecureAreaStartAddr - FLASH_BANK1_BASE) >> 8) | \
1919 (((SecureAreaEndAddr - FLASH_BANK1_BASE) >> 8) << FLASH_SCAR_SEC_AREA_END_Pos) | \
1920 (SecureAreaConfig & FLASH_SCAR_DMES);
1921 }
1922
1923#if defined (DUAL_BANK)
1924 if((Banks & FLASH_BANK_2) == FLASH_BANK_2)
1925 {
1926 /* Check the parameters */
1927 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(SecureAreaStartAddr));
1928 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(SecureAreaEndAddr));
1929
1930 /* Configure the secure area */
1931 FLASH->SCAR_PRG2 = ((SecureAreaStartAddr - FLASH_BANK2_BASE) >> 8) | \
1932 (((SecureAreaEndAddr - FLASH_BANK2_BASE) >> 8) << FLASH_SCAR_SEC_AREA_END_Pos) | \
1933 (SecureAreaConfig & FLASH_SCAR_DMES);
1934 }
1935#endif /* DUAL_BANK */
1936}
1937
1938/**
1939 * @brief Get secure area configuration
1940 * @param SecureAreaConfig indicates if the secure area will be deleted or not
1941 * when RDP level decreased from Level 1 to Level 0 or during a mass erase.
1942 * @param SecureAreaStartAddr gives the secure area start address
1943 * @param SecureAreaEndAddr gives the secure area end address
1944 * @param Bank Specifies the Bank
1945 * @retval None
1946 */
1947static void FLASH_OB_GetSecureArea(uint32_t *SecureAreaConfig, uint32_t *SecureAreaStartAddr, uint32_t *SecureAreaEndAddr, uint32_t Bank)
1948{
1949 uint32_t regvalue = 0;
1950 uint32_t bankBase = 0;
1951
1952 /* Check Bank parameter value */
1953 if(Bank == FLASH_BANK_1)
1954 {
1955 regvalue = FLASH->SCAR_CUR1;
1956 bankBase = FLASH_BANK1_BASE;
1957 }
1958
1959#if defined (DUAL_BANK)
1960 if(Bank == FLASH_BANK_2)
1961 {
1962 regvalue = FLASH->SCAR_CUR2;
1963 bankBase = FLASH_BANK2_BASE;
1964 }
1965#endif /* DUAL_BANK */
1966
1967 /* Get the secure area settings */
1968 (*SecureAreaConfig) = (regvalue & FLASH_SCAR_DMES);
1969 (*SecureAreaStartAddr) = ((regvalue & FLASH_SCAR_SEC_AREA_START) << 8) + bankBase;
1970 (*SecureAreaEndAddr) = (regvalue & FLASH_SCAR_SEC_AREA_END) >> FLASH_SCAR_SEC_AREA_END_Pos;
1971 (*SecureAreaEndAddr) = ((*SecureAreaEndAddr) << 8) + bankBase;
1972}
1973
1974/**
1975 * @brief Add a CRC sector to the list of sectors on which the CRC will be calculated
1976 * @param Sector Specifies the CRC sector number
1977 * @param Bank Specifies the Bank
1978 * @retval None
1979 */
1980static void FLASH_CRC_AddSector(uint32_t Sector, uint32_t Bank)
1981{
1982 /* Check the parameters */
1984
1985 if (Bank == FLASH_BANK_1)
1986 {
1987 /* Clear CRC sector */
1988 FLASH->CRCCR1 &= (~FLASH_CRCCR_CRC_SECT);
1989
1990 /* Select CRC Sector and activate ADD_SECT bit */
1991 FLASH->CRCCR1 |= Sector | FLASH_CRCCR_ADD_SECT;
1992 }
1993#if defined (DUAL_BANK)
1994 else
1995 {
1996 /* Clear CRC sector */
1997 FLASH->CRCCR2 &= (~FLASH_CRCCR_CRC_SECT);
1998
1999 /* Select CRC Sector and activate ADD_SECT bit */
2000 FLASH->CRCCR2 |= Sector | FLASH_CRCCR_ADD_SECT;
2001 }
2002#endif /* DUAL_BANK */
2003}
2004
2005/**
2006 * @brief Select CRC start and end memory addresses on which the CRC will be calculated
2007 * @param CRCStartAddr Specifies the CRC start address
2008 * @param CRCEndAddr Specifies the CRC end address
2009 * @param Bank Specifies the Bank
2010 * @retval None
2011 */
2012static void FLASH_CRC_SelectAddress(uint32_t CRCStartAddr, uint32_t CRCEndAddr, uint32_t Bank)
2013{
2014 if (Bank == FLASH_BANK_1)
2015 {
2018
2019 /* Write CRC Start and End addresses */
2020 FLASH->CRCSADD1 = CRCStartAddr;
2021 FLASH->CRCEADD1 = CRCEndAddr;
2022 }
2023#if defined (DUAL_BANK)
2024 else
2025 {
2026 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(CRCStartAddr));
2027 assert_param(IS_FLASH_PROGRAM_ADDRESS_BANK2(CRCEndAddr));
2028
2029 /* Write CRC Start and End addresses */
2030 FLASH->CRCSADD2 = CRCStartAddr;
2031 FLASH->CRCEADD2 = CRCEndAddr;
2032 }
2033#endif /* DUAL_BANK */
2034}
2035/**
2036 * @}
2037 */
2038
2039#if defined (FLASH_OTPBL_LOCKBL)
2040/**
2041 * @brief Configure the OTP Block Lock.
2042 * @param OTP_Block specifies the OTP Block to lock.
2043 * This parameter can be a value of @ref FLASHEx_OTP_Blocks
2044 * @retval None
2045 */
2046static void FLASH_OB_OTP_LockConfig(uint32_t OTP_Block)
2047{
2048 /* Check the parameters */
2049 assert_param(IS_OTP_BLOCK(OTP_Block));
2050
2051 /* Configure the OTP Block lock in the option bytes register */
2052 FLASH->OTPBL_PRG |= (OTP_Block & FLASH_OTPBL_LOCKBL);
2053}
2054
2055/**
2056 * @brief Get the OTP Block Lock.
2057 * @retval OTP_Block specifies the OTP Block to lock.
2058 * This return value can be a value of @ref FLASHEx_OTP_Blocks
2059 */
2060static uint32_t FLASH_OB_OTP_GetLock(void)
2061{
2062 return (FLASH->OTPBL_CUR);
2063}
2064#endif /* FLASH_OTPBL_LOCKBL */
2065
2066#if defined (FLASH_OPTSR2_TCM_AXI_SHARED)
2067/**
2068 * @brief Configure the TCM / AXI Shared RAM.
2069 * @param SharedRamConfig specifies the Shared RAM configuration.
2070 * This parameter can be a value of @ref FLASHEx_OB_TCM_AXI_SHARED
2071 * @retval None
2072 */
2073static void FLASH_OB_SharedRAM_Config(uint32_t SharedRamConfig)
2074{
2075 /* Check the parameters */
2076 assert_param(IS_OB_USER_TCM_AXI_SHARED(SharedRamConfig));
2077
2078 /* Configure the TCM / AXI Shared RAM in the option bytes register */
2079 MODIFY_REG(FLASH->OPTSR2_PRG, FLASH_OPTSR2_TCM_AXI_SHARED, SharedRamConfig);
2080}
2081
2082/**
2083 * @brief Get the TCM / AXI Shared RAM configuration.
2084 * @retval SharedRamConfig returns the TCM / AXI Shared RAM configuration.
2085 * This return value can be a value of @ref FLASHEx_OB_TCM_AXI_SHARED
2086 */
2087static uint32_t FLASH_OB_SharedRAM_GetConfig(void)
2088{
2089 return (FLASH->OPTSR2_CUR & FLASH_OPTSR2_TCM_AXI_SHARED);
2090}
2091#endif /* FLASH_OPTSR2_TCM_AXI_SHARED */
2092
2093#if defined (FLASH_OPTSR2_CPUFREQ_BOOST)
2094/**
2095 * @brief Configure the CPU Frequency Boost.
2096 * @param FreqBoost specifies the CPU Frequency Boost state.
2097 * This parameter can be a value of @ref FLASHEx_OB_CPUFREQ_BOOST
2098 * @retval None
2099 */
2100static void FLASH_OB_CPUFreq_BoostConfig(uint32_t FreqBoost)
2101{
2102 /* Check the parameters */
2103 assert_param(IS_OB_USER_CPUFREQ_BOOST(FreqBoost));
2104
2105 /* Configure the CPU Frequency Boost in the option bytes register */
2106 MODIFY_REG(FLASH->OPTSR2_PRG, FLASH_OPTSR2_CPUFREQ_BOOST, FreqBoost);
2107}
2108
2109/**
2110 * @brief Get the CPU Frequency Boost state.
2111 * @retval FreqBoost returns the CPU Frequency Boost state.
2112 * This return value can be a value of @ref FLASHEx_OB_CPUFREQ_BOOST
2113 */
2114static uint32_t FLASH_OB_CPUFreq_GetBoost(void)
2115{
2116 return (FLASH->OPTSR2_CUR & FLASH_OPTSR2_CPUFREQ_BOOST);
2117}
2118#endif /* FLASH_OPTSR2_CPUFREQ_BOOST */
2119
2120#endif /* HAL_FLASH_MODULE_ENABLED */
2121
2122/**
2123 * @}
2124 */
2125
2126/**
2127 * @}
2128 */
2129
#define SET_BIT(REG, BIT)
Definition stm32h7xx.h:207
#define WRITE_REG(REG, VAL)
Definition stm32h7xx.h:215
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition stm32h7xx.h:219
#define READ_BIT(REG, BIT)
Definition stm32h7xx.h:211
#define READ_REG(REG)
Definition stm32h7xx.h:217
#define FLASH_BANK_1
Bank 1.
#define FLASH_CRC_BANK
CRC selection type by bank.
#define FLASH_CRC_SECTORS
CRC selection type by sectors.
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
HAL_StatusTypeDef HAL_FLASHEx_ComputeCRC(FLASH_CRCInitTypeDef *pCRCInit, uint32_t *CRC_Result)
HAL_StatusTypeDef HAL_FLASHEx_Unlock_Bank1(void)
HAL_StatusTypeDef HAL_FLASHEx_Lock_Bank1(void)
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
#define IS_OB_USER_IWDG_STDBY(VALUE)
#define IS_OB_USER_IWDG_STOP(VALUE)
#define IS_OB_IWDG1_SOURCE(SOURCE)
#define IS_FLASH_TYPECRC(VALUE)
#define IS_OB_USER_TYPE(TYPE)
#define IS_OB_PCROP_RDP(CONFIG)
#define IS_OB_SECURE_RDP(CONFIG)
#define IS_OB_USER_ST_RAM_SIZE(VALUE)
#define IS_WRPSTATE(VALUE)
#define IS_OPTIONBYTE(VALUE)
#define IS_OB_RDP_LEVEL(LEVEL)
#define IS_FLASH_SECTOR(SECTOR)
#define IS_OB_USER_IOHSLV(VALUE)
#define IS_OB_BOOT_ADD_OPTION(VALUE)
#define IS_OB_USER_SECURITY(VALUE)
#define IS_OB_STDBY_D1_RESET(VALUE)
#define IS_OB_BOR_LEVEL(LEVEL)
#define IS_OB_WRP_SECTOR(SECTOR)
#define IS_OB_STOP_D1_RESET(VALUE)
#define IS_FLASH_TYPEERASE(VALUE)
#define OB_BOOT_ADD1
Select Boot Address 1.
#define OB_BOOT_ADD0
Select Boot Address 0.
#define OB_USER_SECURITY
security selection
#define OB_USER_IWDG_STOP
Independent watchdog counter freeze in stop mode.
#define OB_USER_NRST_STOP_D1
Reset when entering Stop mode selection.
#define OB_USER_IWDG_STDBY
Independent watchdog counter freeze in standby mode.
#define OB_USER_ST_RAM_SIZE
dedicated DTCM Ram size selection
#define OB_USER_NRST_STDBY_D1
Reset when entering standby mode selection.
#define OB_USER_IOHSLV
IO HSLV selection.
#define OB_USER_IWDG1_SW
Independent watchdog selection.
#define OB_RDP_LEVEL_2
Warning: When enabling read protection level 2 it s no more possible to go back to level 1 or 0.
#define OB_RDP_LEVEL_0
#define OB_RDP_LEVEL_1
#define OPTIONBYTE_BOOTADD
BOOT ADD option byte configuration.
#define OPTIONBYTE_WRP
WRP option byte configuration.
#define OPTIONBYTE_RDP
RDP option byte configuration.
#define OPTIONBYTE_SECURE_AREA
secure area option byte configuration
#define OPTIONBYTE_USER
USER option byte configuration.
#define OPTIONBYTE_PCROP
PCROP option byte configuration.
#define OPTIONBYTE_BOR
BOR option byte configuration.
void FLASH_Erase_Sector(uint32_t Sector, uint32_t Banks, uint32_t VoltageRange)
#define FLASH_TYPEERASE_MASSERASE
Flash Mass erase activation.
#define OB_WRPSTATE_ENABLE
Enable the write protection of the desired bank 1 sectors.
#define OB_WRPSTATE_DISABLE
Disable the write protection of the desired bank 1 sectors.
#define HAL_FLASH_ERROR_NONE
No error.
#define __HAL_FLASH_ENABLE_IT_BANK1(__INTERRUPT__)
Enable the specified FLASH interrupt.
#define __HAL_FLASH_ENABLE_IT_BANK2(__INTERRUPT__)
#define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)
#define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)
#define __HAL_FLASH_CLEAR_FLAG_BANK2(__FLAG__)
#define __HAL_FLASH_CLEAR_FLAG_BANK1(__FLAG__)
Clear the specified FLASH flag.
@ FLASH_PROC_MASSERASE_BANK2
@ FLASH_PROC_MASSERASE_BANK1
@ FLASH_PROC_SECTERASE_BANK2
@ FLASH_PROC_SECTERASE_BANK1
@ FLASH_PROC_ALLBANK_MASSERASE
#define FLASH_FLAG_CRCEND_BANK1
CRC End of Calculation on Bank 1 flag.
#define FLASH_FLAG_DBECCERR_BANK1
Double Detection ECC Error on Bank 1 flag.
#define FLASH_FLAG_CRCRDERR_BANK2
CRC Read error on Bank 2 flag.
#define FLASH_FLAG_DBECCERR_BANK2
Double Detection ECC Error on Bank 2 flag.
#define FLASH_FLAG_CRCRDERR_BANK1
CRC Read error on Bank 1 flag.
#define FLASH_FLAG_CRCEND_BANK2
CRC End of Calculation on Bank 2 flag.
#define FLASH_FLAG_SNECCERR_BANK2
Single ECC Error Correction on Bank 2 flag.
#define FLASH_FLAG_SNECCERR_BANK1
Single ECC Error Correction on Bank 1 flag.
#define FLASH_IT_WRPERR_BANK1
Write Protection Error on Bank 1 Interrupt source.
#define FLASH_IT_WRPERR_BANK2
Write Protection Error on Bank 2 Interrupt source.
#define FLASH_IT_EOP_BANK1
End of FLASH Bank 1 Operation Interrupt source.
#define FLASH_IT_STRBERR_BANK1
Strobe Error on Bank 1 Interrupt source.
#define FLASH_IT_SNECCERR_BANK1
Single ECC Error Correction on Bank 1 Interrupt source.
#define FLASH_IT_SNECCERR_BANK2
Single ECC Error Correction on Bank 2 Interrupt source.
#define FLASH_IT_INCERR_BANK2
Inconsistency Error on Bank 2 Interrupt source.
#define FLASH_IT_PGSERR_BANK1
Program Sequence Error on Bank 1 Interrupt source.
#define FLASH_IT_EOP_BANK2
End of FLASH Bank 2 Operation Interrupt source.
#define FLASH_IT_DBECCERR_BANK2
Double Detection ECC Error on Bank 2 Interrupt source.
#define FLASH_IT_INCERR_BANK1
Inconsistency Error on Bank 1 Interrupt source.
#define FLASH_IT_DBECCERR_BANK1
Double Detection ECC Error on Bank 1 Interrupt source.
#define FLASH_IT_STRBERR_BANK2
Strobe Error on Bank 2 Interrupt source.
#define FLASH_IT_PGSERR_BANK2
Program Sequence Error on Bank 2 Interrupt source.
#define FLASH_KEY2
#define FLASH_KEY1
HAL_StatusTypeDef FLASH_CRC_WaitForLastOperation(uint32_t Timeout, uint32_t Bank)
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout, uint32_t Bank)
HAL_StatusTypeDef FLASH_OB_WaitForLastOperation(uint32_t Timeout)
#define IS_FLASH_BANK(BANK)
#define IS_FLASH_PROGRAM_ADDRESS_BANK1(ADDRESS)
#define IS_FLASH_BANK_EXCLUSIVE(BANK)
#define IS_BOOT_ADDRESS(ADDRESS)
FLASH_ProcessTypeDef pFlash
#define FLASH_OPTSR_IWDG1_SW
IWDG1 control mode option status bit.
#define FLASH_BOOT_ADD0
Arm Cortex-M7 boot address 0.
#define FLASH_OPTSR_NRST_STOP_D1
D1 domain DStop entry reset option status bit.
#define FLASH_OPTSR_SECURITY
Security enable option status bit.
#define FLASH_CRCCR_ADD_SECT
CRC sector select bit.
#define FLASH_CR_CRC_EN
CRC control bit.
#define FLASH_CCR_CLR_CRCEND
CRCEND flag clear bit.
#define FLASH_SCAR_SEC_AREA_START
Secure-only area start status bits.
#define FLASH_NB_32BITWORD_IN_FLASHWORD
#define FLASH_SCAR_SEC_AREA_END
Secure-only area end status bits.
#define FLASH_ECC_FA_FAIL_ECC_ADDR
ECC error address.
#define FLASH_CRCCR_ALL_BANK
CRC select bit.
#define FLASH_OPTSR2_CPUFREQ_BOOST
CPU frequency boost.
#define FLASH_OPTSR_ST_RAM_SIZE
ST RAM size option status.
#define FLASH_CR_SNB
Sector erase selection number.
#define FLASH_OPTSR_NRST_STBY_D1
D1 domain DStandby entry reset option status bit.
#define FLASH_SCAR_DMES
Secure access protected erase enable option status bit.
#define FLASH_CR_BER
Bank erase request.
#define FLASH_OPTSR_FZ_IWDG_SDBY
IWDG Standby mode freeze option status bit.
#define FLASH_CRCCR_START_CRC
CRC start bit.
#define FLASH_OPTSR_BOR_LEV
Brownout level option status bit.
#define FLASH_PRAR_PROT_AREA_END
PCROP area end status bits.
#define FLASH_PRAR_PROT_AREA_START
PCROP area start status bits.
#define FLASH_CRCCR_CRC_BURST_Msk
0x00300000
#define FLASH_BOOT_ADD1
Arm Cortex-M7 boot address 1.
#define FLASH_CRCCR_CRC_SECT
CRC sector number.
#define FLASH_OPTSR2_TCM_AXI_SHARED
TCM RAM shared.
#define FLASH_PRAR_DMEP
PCROP protected erase enable option status bit.
#define FLASH_OPTSR_IO_HSLV
I/O high-speed at low-voltage status bit.
#define FLASH_OPTSR_NRST_STBY_D2
D2 domain DStandby entry reset option status bit.
#define FLASH_CR_PSIZE
Program size.
#define FLASH_CR_START
Erase start control bit.
#define FLASH_PRAR_PROT_AREA_END_Pos
#define FLASH_WPSN_WRPSN
Sector write protection option status byte.
#define FLASH_CR_LOCK
Configuration lock bit.
#define FLASH_CR_SNB_Pos
#define FLASH_SCAR_SEC_AREA_END_Pos
#define FLASH_CRCCR_CLEAN_CRC
CRC clear bit.
#define FLASH_CRCCR_CLEAN_SECT
CRC sector list clear bit.
#define FLASH_OPTSR_NRST_STOP_D2
D2 domain DStop entry reset option status bit.
#define FLASH_OPTSR_RDP
Readout protection level option status byte.
#define FLASH_CCR_CLR_CRCRDERR
CRCRDERR flag clear bit.
#define FLASH_CR_SER
Sector erase request.
#define FLASH_OPTSR_FZ_IWDG_STOP
IWDG Stop mode freeze option status bit.
#define FLASH
#define FLASH_BANK1_BASE
Base address of : (up to 1 MB) Flash Bank1 accessible over AXI.
This file contains all the functions prototypes for the HAL module driver.
#define assert_param(expr)
Uncomment the line below to expanse the "assert_param" macro in the HAL drivers code.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_ERROR
@ HAL_OK
#define __HAL_UNLOCK(__HANDLE__)
#define UNUSED(x)
#define __HAL_LOCK(__HANDLE__)
FLASH Erase structure definition.
uint32_t TypeCRC
CRC Selection Type.
uint32_t BurstSize
CRC Burst Size.
uint32_t CRCStartAddr
CRC Start address.
uint32_t Sector
Initial FLASH sector from which starts the CRC computation This parameter must be a value of FLASH Se...
uint32_t NbSectors
Number of sectors to be computed.
uint32_t Bank
Select bank where CRC computation is enabled.
uint32_t CRCEndAddr
CRC End address.
FLASH Erase structure definition.
uint32_t Sector
Initial FLASH sector to erase when Mass erase is disabled This parameter must be a value of FLASH Sec...
uint32_t VoltageRange
The device voltage range which defines the erase parallelism This parameter must be a value of FLASHE...
uint32_t TypeErase
Mass erase or sector Erase.
uint32_t Banks
Select banks to erase when Mass erase is enabled.
uint32_t NbSectors
Number of sectors to be erased.
FLASH Option Bytes Program structure definition.
uint32_t BootAddr0
Boot Address 0.
uint32_t RDPLevel
Set the read protection level.
uint32_t WRPState
Write protection activation or deactivation.
uint32_t BootAddr1
Boot Address 1.
uint32_t PCROPConfig
specifies if the PCROP area shall be erased or not when RDP level decreased from Level 1 to Level 0 o...
uint32_t SecureAreaConfig
specifies if the bank secured area shall be erased or not when RDP level decreased from Level 1 to Le...
uint32_t OptionType
Option byte to be configured.
uint32_t BORLevel
Set the BOR Level.
uint32_t Banks
Select banks for WRP , PCROP and secure area config .
uint32_t SecureAreaStartAddr
Bank Secure area Start address.
uint32_t USERType
User option byte(s) to be configured (used for OPTIONBYTE_USER).
uint32_t WRPSector
Specifies the sector(s) to be write protected.
uint32_t SecureAreaEndAddr
Bank Secure area End address.
uint32_t BootConfig
Specifies if the Boot Address to be configured BOOT_ADD0, BOOT_ADD1 or both.
uint32_t PCROPStartAddr
PCROP Start address (used for OPTIONBYTE_PCROP).
uint32_t PCROPEndAddr
PCROP End address (used for OPTIONBYTE_PCROP).
uint32_t USERConfig
Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY / IWDG_FREEZE_STOP / IWDG_FREEZE_S...