annotate Common/Drivers/STM32F4xx_HAL_DRIVER_v120/Src/stm32f4xx_hal_flash_ex.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file stm32f4xx_hal_flash_ex.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author MCD Application Team
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V1.2.0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 26-December-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief Extended FLASH HAL module driver.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * This file provides firmware functions to manage the following
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * functionalities of the FLASH extension peripheral:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * + Extended programming operations functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ##### Flash Extension features #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 [..] Comparing to other previous devices, the FLASH interface for STM32F427xx/437xx and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 STM32F429xx/439xx devices contains the following additional features
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 (+) Capacity up to 2 Mbyte with dual bank architecture supporting read-while-write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 capability (RWW)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 (+) Dual bank memory organization
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 (+) PCROP protection for all banks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25 ##### How to use this driver #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 [..] This driver provides functions to configure and program the FLASH memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 of all STM32F427xx/437xx andSTM32F429xx/439xx devices. It includes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 (#) FLASH Memory Erase functions:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 (++) Lock and Unlock the FLASH interface using HAL_FLASH_Unlock() and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 HAL_FLASH_Lock() functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 (++) Erase function: Erase sector, erase all sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 (++) There are two modes of erase :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 (+++) Polling Mode using HAL_FLASHEx_Erase()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 (+++) Interrupt Mode using HAL_FLASHEx_Erase_IT()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 (#) Option Bytes Programming functions: Use HAL_FLASHEx_OBProgram() to :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 (++) Set/Reset the write protection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 (++) Set the Read protection Level
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 (++) Set the BOR level
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 (++) Program the user Option Bytes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42 (#) Advanced Option Bytes Programming functions: Use HAL_FLASHEx_AdvOBProgram() to :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 (++) Extended space (bank 2) erase function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 (++) Full FLASH space (2 Mo) erase (bank 1 and bank 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45 (++) Dual Boot activation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 (++) Write protection configuration for bank 2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 (++) PCROP protection configuration and control for both banks
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 * Redistribution and use in source and binary forms, with or without modification,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56 * are permitted provided that the following conditions are met:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 * 1. Redistributions of source code must retain the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 * this list of conditions and the following disclaimer.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * 2. Redistributions in binary form must reproduce the above copyright notice,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 * this list of conditions and the following disclaimer in the documentation
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * and/or other materials provided with the distribution.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 * 3. Neither the name of STMicroelectronics nor the names of its contributors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 * may be used to endorse or promote products derived from this software
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 * without specific prior written permission.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 /** @addtogroup STM32F4xx_HAL_Driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 /** @defgroup FLASHEx FLASHEx
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 * @brief FLASH HAL Extension module driver
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 #ifdef HAL_FLASH_MODULE_ENABLED
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 /* Private typedef -----------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 /* Private define ------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96 /** @addtogroup FLASHEx_Private_Constants
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 #define SECTOR_MASK ((uint32_t)0xFFFFFF07)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 /* Private macro -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 /** @addtogroup FLASHEx_Private_Variables
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 extern FLASH_ProcessTypeDef pFlash;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /* Private function prototypes -----------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 /** @addtogroup FLASHEx_Private_Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 /* Option bytes control */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120 static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
121 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
122 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
124 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
125 static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
126 static uint8_t FLASH_OB_GetUser(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
127 static uint16_t FLASH_OB_GetWRP(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
128 static FlagStatus FLASH_OB_GetRDP(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129 static uint8_t FLASH_OB_GetBOR(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
131 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132 static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
133 static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
134 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
137 static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
138 static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 static HAL_StatusTypeDef FLASH_OB_BootConfig(uint8_t BootConfig);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 #endif /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 extern HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148 /** @defgroup FLASHEx_Exported_Functions FLASHEx Exported Functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 /** @defgroup FLASHEx_Exported_Functions_Group1 Extended IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 * @brief Extended IO operation functions
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 ##### Extended programming operation functions #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 [..]
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
160 This subsection provides a set of functions allowing to manage the Extension FLASH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
161 programming operations Operations.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 * @{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 * @brief Perform a mass erase or erase the specified FLASH memory sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 * contains the configuration information for the erasing.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 * @param[out] SectorError: pointer to variable that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 * contains the configuration information on faulty sector in case of error
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173 * (0xFFFFFFFF means that all the sectors have been correctly erased)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *SectorError)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179 HAL_StatusTypeDef status = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 uint32_t index = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 __HAL_LOCK(&pFlash);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 /*Initialization of SectorError variable*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 *SectorError = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196 if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 /*Mass erase to be done*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 /* if the erase operation is completed, disable the MER Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 FLASH->CR &= (~FLASH_MER_BIT);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 /* Erase by sector by sector to be done*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 for(index = pEraseInit->Sector; index < (pEraseInit->NbSectors + pEraseInit->Sector); index++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 FLASH_Erase_Sector(index, (uint8_t) pEraseInit->VoltageRange);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 /* If the erase operation is completed, disable the SER Bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 FLASH->CR &= (~FLASH_CR_SER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 FLASH->CR &= SECTOR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 if(status != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 /* In case of error, stop erase procedure and return the faulty sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227 *SectorError = index;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 __HAL_UNLOCK(&pFlash);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 * @brief Perform a mass erase or erase the specified FLASH memory sectors with interrupt enabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 * contains the configuration information for the erasing.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 __HAL_LOCK(&pFlash);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 /* Enable End of FLASH Operation interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258 __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 /* Enable Error source interrupt */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 /* Clear pending flags (if any) */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_PGSERR);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 if(pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 /*Mass erase to be done*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270 pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 pFlash.Bank = pEraseInit->Banks;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 FLASH_MassErase((uint8_t) pEraseInit->VoltageRange, pEraseInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 /* Erase by sector to be done*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 assert_param(IS_FLASH_NBSECTORS(pEraseInit->NbSectors + pEraseInit->Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 pFlash.ProcedureOnGoing = FLASH_PROC_SECTERASE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 pFlash.NbSectorsToErase = pEraseInit->NbSectors;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 pFlash.Sector = pEraseInit->Sector;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 pFlash.VoltageForErase = (uint8_t)pEraseInit->VoltageRange;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 /*Erase 1st sector and wait for IT*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 * @brief Program option bytes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 * @param pOBInit: pointer to an FLASH_OBInitStruct structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 * contains the configuration information for the programming.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 HAL_StatusTypeDef status = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 /* Process Locked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 __HAL_LOCK(&pFlash);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 /*Write protection configuration*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 assert_param(IS_WRPSTATE(pOBInit->WRPState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(pOBInit->WRPState == OB_WRPSTATE_ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 /*Enable of Write protection on the selected Sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 status = FLASH_OB_EnableWRP(pOBInit->WRPSector, pOBInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 /*Disable of Write protection on the selected Sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 status = FLASH_OB_DisableWRP(pOBInit->WRPSector, pOBInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 /*Read protection configuration*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 /*USER configuration*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 status = FLASH_OB_UserConfig(pOBInit->USERConfig&OB_IWDG_SW,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 pOBInit->USERConfig&OB_STOP_NO_RST,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 pOBInit->USERConfig&OB_STDBY_NO_RST);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 /*BOR Level configuration*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 status = FLASH_OB_BOR_LevelConfig(pOBInit->BORLevel);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 /* Process Unlocked */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 __HAL_UNLOCK(&pFlash);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 * @brief Get the Option byte configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 * @param pOBInit: pointer to an FLASH_OBInitStruct structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 * contains the configuration information for the programming.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 /*Get WRP*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 pOBInit->WRPSector = FLASH_OB_GetWRP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 /*Get RDP Level*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 pOBInit->RDPLevel = FLASH_OB_GetRDP();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 /*Get USER*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 pOBInit->USERConfig = FLASH_OB_GetUser();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 /*Get BOR Level*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 pOBInit->BORLevel = FLASH_OB_GetBOR();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx) ||\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 * @brief Program option bytes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 * contains the configuration information for the programming.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 HAL_StatusTypeDef status = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 assert_param(IS_OBEX(pAdvOBInit->OptionType));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 /*Program PCROP option byte*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 if(((pAdvOBInit->OptionType) & OPTIONBYTE_PCROP) == OPTIONBYTE_PCROP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 assert_param(IS_PCROPSTATE(pAdvOBInit->PCROPState));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 if((pAdvOBInit->PCROPState) == OB_PCROP_STATE_ENABLE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 /*Enable of Write protection on the selected Sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 status = FLASH_OB_EnablePCROP(pAdvOBInit->Sectors);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403 status = FLASH_OB_EnablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 /*Disable of Write protection on the selected Sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 status = FLASH_OB_DisablePCROP(pAdvOBInit->Sectors);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412 status = FLASH_OB_DisablePCROP(pAdvOBInit->SectorsBank1, pAdvOBInit->SectorsBank2, pAdvOBInit->Banks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 /*Program BOOT config option byte*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 if(((pAdvOBInit->OptionType) & OPTIONBYTE_BOOTCONFIG) == OPTIONBYTE_BOOTCONFIG)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 status = FLASH_OB_BootConfig(pAdvOBInit->BootConfig);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 * @brief Get the OBEX byte configuration
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430 * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 * contains the configuration information for the programming.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 /*Get Sector*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439 pAdvOBInit->Sectors = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440 #else /* STM32F427xx || STM32F437xx || STM32F429xx|| STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 /*Get Sector for Bank1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 pAdvOBInit->SectorsBank1 = (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 /*Get Sector for Bank2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 pAdvOBInit->SectorsBank2 = (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 /*Get Boot config OB*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 pAdvOBInit->BootConfig = *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 * @brief Select the Protection Mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 * @note After PCROP activated Option Byte modification NOT POSSIBLE! excepted
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 * Global Read Out Protection modification (from level1 to level0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457 * @note Once SPRMOD bit is active unprotection of a protected sector is not possible
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 * @note This function can be used only for STM32F427xx/STM32F429xx/STM32F437xx/STM32F439xx/STM32F401xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 HAL_StatusTypeDef HAL_FLASHEx_OB_SelectPCROP(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 uint8_t optiontmp = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 /* Mask SPRMOD bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 /* Update Option Byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_SELECTED | optiontmp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 * @brief Deselect the Protection Mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 * @note After PCROP activated Option Byte modification NOT POSSIBLE! excepted
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 * Global Read Out Protection modification (from level1 to level0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 * @note Once SPRMOD bit is active unprotection of a protected sector is not possible
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 * @note This function can be used only for STM32F427xx/STM32F429xx/STM32F437xx/STM32F439xx/STM32F401xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 HAL_StatusTypeDef HAL_FLASHEx_OB_DeSelectPCROP(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 uint8_t optiontmp = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 /* Mask SPRMOD bit */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 /* Update Option Byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PCROP_DESELECTED | optiontmp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 * @brief Returns the FLASH Write Protection Option Bytes value for Bank 2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 * @note This function can be used only for STM32F427X and STM32F429X devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 * @retval The FLASH Write Protection Option Bytes value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 uint16_t HAL_FLASHEx_OB_GetBank2WRP(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 /* Return the FLASH write protection Register value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 * @brief Full erase of FLASH memory sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 * @param VoltageRange: The device voltage range which defines the erase parallelism.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 * the operation will be done by byte (8-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 * the operation will be done by half word (16-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 * the operation will be done by word (32-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 * the operation will be done by double word (64-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 * @param Banks: Banks to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 * @arg FLASH_BANK_1: Bank1 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 * @arg FLASH_BANK_2: Bank2 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 uint32_t tmp_psize = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 assert_param(IS_VOLTAGERANGE(VoltageRange));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 /* if the previous operation is completed, proceed to erase all sectors */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 FLASH->CR &= CR_PSIZE_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550 FLASH->CR |= tmp_psize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 if(Banks == FLASH_BANK_BOTH)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 /* bank1 & bank2 will be erased*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 FLASH->CR |= FLASH_MER_BIT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 else if(Banks == FLASH_BANK_1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 /*Only bank1 will be erased*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 FLASH->CR |= FLASH_CR_MER1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 /*Only bank2 will be erased*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 FLASH->CR |= FLASH_CR_MER2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 FLASH->CR |= FLASH_CR_STRT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 * @brief Erase the specified FLASH memory sector
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 * @param Sector: FLASH sector to erase
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 * The value of this parameter depend on device used within the same series
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 * @param VoltageRange: The device voltage range which defines the erase parallelism.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 * the operation will be done by byte (8-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 * the operation will be done by half word (16-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 * the operation will be done by word (32-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 * the operation will be done by double word (64-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 uint32_t tmp_psize = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 assert_param(IS_FLASH_SECTOR(Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592 assert_param(IS_VOLTAGERANGE(VoltageRange));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 if(VoltageRange == FLASH_VOLTAGE_RANGE_1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 tmp_psize = FLASH_PSIZE_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 else if(VoltageRange == FLASH_VOLTAGE_RANGE_2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 tmp_psize = FLASH_PSIZE_HALF_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 else if(VoltageRange == FLASH_VOLTAGE_RANGE_3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604 tmp_psize = FLASH_PSIZE_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 /* Need to add offset of 4 when sector higher than FLASH_SECTOR_11 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 if(Sector > FLASH_SECTOR_11)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 Sector += 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 /* If the previous operation is completed, proceed to erase the sector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 FLASH->CR &= CR_PSIZE_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 FLASH->CR |= tmp_psize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619 FLASH->CR &= SECTOR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 FLASH->CR |= FLASH_CR_SER | (Sector << POSITION_VAL(FLASH_CR_SNB));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 FLASH->CR |= FLASH_CR_STRT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 * @brief Enable the write protection of the desired bank1 or bank 2 sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 * @note When the memory read protection level is selected (RDP level = 1),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628 * it is not possible to program or erase the flash sector i if CortexM4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 * @param WRPSector: specifies the sector(s) to be write protected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 * @arg OB_WRP_SECTOR_All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 * @note BANK2 starts from OB_WRP_SECTOR_12
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 * @param Banks: Enable write protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 * @arg FLASH_BANK_1: WRP on all sectors of bank1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 * @arg FLASH_BANK_2: WRP on all sectors of bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 * @retval HAL FLASH State
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 assert_param(IS_OB_WRP_SECTOR(WRPSector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 if(((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) ||
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 (WRPSector < OB_WRP_SECTOR_12))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 if(WRPSector == OB_WRP_SECTOR_All)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 /*Write protection on all sector of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~(WRPSector>>12));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 /*Write protection done on sectors of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~WRPSector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector>>12));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 /*Write protection on all sector of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 if((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~(WRPSector>>12));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 * @brief Disable the write protection of the desired bank1 or bank 2 sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 * @note When the memory read protection level is selected (RDP level = 1),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 * it is not possible to program or erase the flash sector i if CortexM4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 * @param WRPSector: specifies the sector(s) to be write protected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 * @arg WRPSector: A value between OB_WRP_SECTOR_0 and OB_WRP_SECTOR_23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 * @arg OB_WRP_Sector_All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 * @note BANK2 starts from OB_WRP_SECTOR_12
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 * @param Banks: Disable write protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 * @arg FLASH_BANK_1: Bank1 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 * @arg FLASH_BANK_2: Bank2 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 * @arg FLASH_BANK_BOTH: Bank1 and Bank2 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 assert_param(IS_OB_WRP_SECTOR(WRPSector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 if(((WRPSector == OB_WRP_SECTOR_All) && ((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))) ||
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 (WRPSector < OB_WRP_SECTOR_12))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 if(WRPSector == OB_WRP_SECTOR_All)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 /*Write protection on all sector of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740 /*Write protection done on sectors of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)WRPSector;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 /*Write protection on all sector of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 if((WRPSector == OB_WRP_SECTOR_All) && (Banks == FLASH_BANK_BOTH))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)(WRPSector>>12);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 * @brief Configure the Dual Bank Boot.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 * @note This function can be used only for STM32F42xxx/43xxx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 * @param BootConfig specifies the Dual Bank Boot Option byte.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 * @arg OB_Dual_BootEnabled: Dual Bank Boot Enable
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 * @arg OB_Dual_BootDisabled: Dual Bank Boot Disabled
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 static HAL_StatusTypeDef FLASH_OB_BootConfig(uint8_t BootConfig)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 assert_param(IS_OB_BOOT(BootConfig));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 /* Set Dual Bank Boot */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BFB2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= BootConfig;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 * @brief Enable the read/write protection (PCROP) of the desired
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 * sectors of Bank 1 and/or Bank 2.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 * @note This function can be used only for STM32F42xxx/43xxx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 * @param SectorBank1 Specifies the sector(s) to be read/write protected or unprotected for bank1.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 * @arg OB_PCROP: A value between OB_PCROP_SECTOR_0 and OB_PCROP_SECTOR_11
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 * @arg OB_PCROP_SECTOR__All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 * @param SectorBank2 Specifies the sector(s) to be read/write protected or unprotected for bank2.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 * @arg OB_PCROP: A value between OB_PCROP_SECTOR_12 and OB_PCROP_SECTOR_23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 * @arg OB_PCROP_SECTOR__All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810 * @param Banks Enable PCROP protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 * @arg FLASH_BANK_1: WRP on all sectors of bank1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 * @arg FLASH_BANK_2: WRP on all sectors of bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 if((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 assert_param(IS_OB_PCROP(SectorBank1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 /*Write protection done on sectors of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)SectorBank1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 assert_param(IS_OB_PCROP(SectorBank2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 /*Write protection on all sector of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 if(Banks == FLASH_BANK_BOTH)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 assert_param(IS_OB_PCROP(SectorBank2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)SectorBank2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 * @brief Disable the read/write protection (PCROP) of the desired
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 * sectors of Bank 1 and/or Bank 2.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 * @note This function can be used only for STM32F42xxx/43xxx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 * @param SectorBank1 specifies the sector(s) to be read/write protected or unprotected for bank1.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 * @arg OB_PCROP: A value between OB_PCROP_SECTOR_0 and OB_PCROP_SECTOR_11
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 * @arg OB_PCROP_SECTOR__All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 * @param SectorBank2 Specifies the sector(s) to be read/write protected or unprotected for bank2.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872 * @arg OB_PCROP: A value between OB_PCROP_SECTOR_12 and OB_PCROP_SECTOR_23
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 * @arg OB_PCROP_SECTOR__All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 * @param Banks Disable PCROP protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 * @arg FLASH_BANK_1: WRP on all sectors of bank1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 * @arg FLASH_BANK_2: WRP on all sectors of bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 * @arg FLASH_BANK_BOTH: WRP on all sectors of bank1 & bank2
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t SectorBank1, uint32_t SectorBank2, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 if((Banks == FLASH_BANK_1) || (Banks == FLASH_BANK_BOTH))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 assert_param(IS_OB_PCROP(SectorBank1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 /*Write protection done on sectors of BANK1*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~SectorBank1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 assert_param(IS_OB_PCROP(SectorBank2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 /*Write protection on all sector of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 if(Banks == FLASH_BANK_BOTH)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 assert_param(IS_OB_PCROP(SectorBank2));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 /*Write protection done on sectors of BANK2*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~SectorBank2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx)|| defined(STM32F417xx) ||\
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 * @brief Mass erase of FLASH memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 * @param VoltageRange: The device voltage range which defines the erase parallelism.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 * the operation will be done by byte (8-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 * the operation will be done by half word (16-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 * the operation will be done by word (32-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 * the operation will be done by double word (64-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 * @param Banks: Banks to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 * @arg FLASH_BANK_1: Bank1 to be erased
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 uint32_t tmp_psize = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 assert_param(IS_VOLTAGERANGE(VoltageRange));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 /* If the previous operation is completed, proceed to erase all sectors */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 FLASH->CR &= CR_PSIZE_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 FLASH->CR |= tmp_psize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 FLASH->CR |= FLASH_CR_MER;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 FLASH->CR |= FLASH_CR_STRT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 * @brief Erase the specified FLASH memory sector
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 * @param Sector: FLASH sector to erase
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 * The value of this parameter depend on device used within the same series
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 * @param VoltageRange: The device voltage range which defines the erase parallelism.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 * @arg FLASH_VOLTAGE_RANGE_1: when the device voltage range is 1.8V to 2.1V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972 * the operation will be done by byte (8-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 * @arg FLASH_VOLTAGE_RANGE_2: when the device voltage range is 2.1V to 2.7V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 * the operation will be done by half word (16-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 * @arg FLASH_VOLTAGE_RANGE_3: when the device voltage range is 2.7V to 3.6V,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 * the operation will be done by word (32-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 * @arg FLASH_VOLTAGE_RANGE_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978 * the operation will be done by double word (64-bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 * @retval None
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 void FLASH_Erase_Sector(uint32_t Sector, uint8_t VoltageRange)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984 uint32_t tmp_psize = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 assert_param(IS_FLASH_SECTOR(Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 assert_param(IS_VOLTAGERANGE(VoltageRange));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 if(VoltageRange == FLASH_VOLTAGE_RANGE_1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 tmp_psize = FLASH_PSIZE_BYTE;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 else if(VoltageRange == FLASH_VOLTAGE_RANGE_2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 tmp_psize = FLASH_PSIZE_HALF_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 else if(VoltageRange == FLASH_VOLTAGE_RANGE_3)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 tmp_psize = FLASH_PSIZE_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 /* If the previous operation is completed, proceed to erase the sector */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 FLASH->CR &= CR_PSIZE_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 FLASH->CR |= tmp_psize;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 FLASH->CR &= SECTOR_MASK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 FLASH->CR |= FLASH_CR_SER | (Sector << POSITION_VAL(FLASH_CR_SNB));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 FLASH->CR |= FLASH_CR_STRT;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 * @brief Enable the write protection of the desired bank 1 sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 * @note When the memory read protection level is selected (RDP level = 1),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 * it is not possible to program or erase the flash sector i if CortexM4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023 * @param WRPSector: specifies the sector(s) to be write protected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 * The value of this parameter depend on device used within the same series
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1026 * @param Banks: Enable write protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 * @arg FLASH_BANK_1: WRP on all sectors of bank1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032 static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 assert_param(IS_OB_WRP_SECTOR(WRPSector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~WRPSector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 * @brief Disable the write protection of the desired bank 1 sectors
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 * @note When the memory read protection level is selected (RDP level = 1),
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 * it is not possible to program or erase the flash sector i if CortexM4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 * @param WRPSector: specifies the sector(s) to be write protected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 * The value of this parameter depend on device used within the same series
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 * @param Banks: Enable write protection on all the sectors for the specific bank
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 * @arg FLASH_BANK_1: WRP on all sectors of bank1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068 static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 assert_param(IS_OB_WRP_SECTOR(WRPSector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 assert_param(IS_FLASH_BANK(Banks));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)WRPSector;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 #if defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 * @brief Enable the read/write protection (PCROP) of the desired sectors.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 * @note This function can be used only for STM32F401xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 * @param Sector specifies the sector(s) to be read/write protected or unprotected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 * @arg OB_PCROP: A value between OB_PCROP_Sector0 and OB_PCROP_Sector5
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 * @arg OB_PCROP_Sector_All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 static HAL_StatusTypeDef FLASH_OB_EnablePCROP(uint32_t Sector)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 assert_param(IS_OB_PCROP(Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)Sector;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 * @brief Disable the read/write protection (PCROP) of the desired sectors.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 * @note This function can be used only for STM32F401xx devices.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 * @param Sector specifies the sector(s) to be read/write protected or unprotected.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 * @arg OB_PCROP: A value between OB_PCROP_Sector0 and OB_PCROP_Sector5
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 * @arg OB_PCROP_Sector_All
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 static HAL_StatusTypeDef FLASH_OB_DisablePCROP(uint32_t Sector)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131 assert_param(IS_OB_PCROP(Sector));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~Sector);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 #endif /* STM32F401xC || STM32F401xE || STM32F411xE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 * @brief Set the read protection level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 * @param Level: specifies the read protection level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 * @arg OB_RDP_LEVEL_0: No protection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 * @arg OB_RDP_LEVEL_1: Read protection of the memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 * @arg OB_RDP_LEVEL_2: Full chip protection
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 * @note WARNING: When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t Level)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 assert_param(IS_OB_RDP_LEVEL(Level));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 *(__IO uint8_t*)OPTCR_BYTE1_ADDRESS = Level;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 * @brief Program the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 * @param Iwdg: Selects the IWDG mode
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 * @arg OB_IWDG_SW: Software IWDG selected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 * @arg OB_IWDG_HW: Hardware IWDG selected
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 * @param Stop: Reset event when entering STOP mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 * @arg OB_STOP_NO_RST: No reset generated when entering in STOP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 * @arg OB_STOP_RST: Reset generated when entering in STOP
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 * @param Stdby: Reset event when entering Standby mode.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 * @arg OB_STDBY_NO_RST: No reset generated when entering in STANDBY
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t Iwdg, uint8_t Stop, uint8_t Stdby)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 uint8_t optiontmp = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195 HAL_StatusTypeDef status = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 assert_param(IS_OB_IWDG_SOURCE(Iwdg));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 assert_param(IS_OB_STOP_SOURCE(Stop));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 assert_param(IS_OB_STDBY_SOURCE(Stdby));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 /* Wait for last operation to be completed */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 if(status == HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 /* Mask OPTLOCK, OPTSTRT, BOR_LEV and BFB2 bits */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x1F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 /* Update User Option Byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS = Iwdg | (uint8_t)(Stdby | (uint8_t)(Stop | ((uint8_t)optiontmp)));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 return status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 * @brief Set the BOR Level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 * @param Level: specifies the Option Bytes BOR Reset Level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 * This parameter can be one of the following values:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 * @arg OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 * @arg OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 * @arg OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 * @arg OB_BOR_OFF: Supply voltage ranges from 1.62 to 2.1 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226 * @retval HAL Status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 static HAL_StatusTypeDef FLASH_OB_BOR_LevelConfig(uint8_t Level)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 /* Check the parameters */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 assert_param(IS_OB_BOR_LEVEL(Level));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 /* Set the BOR Level */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BOR_LEV);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= Level;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 return HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 * @brief Return the FLASH User Option Byte value.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 * @retval uint8_t FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 * and RST_STDBY(Bit2).
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 static uint8_t FLASH_OB_GetUser(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 /* Return the User Option Byte */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 return ((uint8_t)(FLASH->OPTCR & 0xE0));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 * @brief Return the FLASH Write Protection Option Bytes value.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 * @retval uint16_t FLASH Write Protection Option Bytes value
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 static uint16_t FLASH_OB_GetWRP(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 /* Return the FLASH write protection Register value */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 * @brief Returns the FLASH Read Protection level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 * @retval FlagStatus FLASH Readout Protection Status:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 * - SET, when OB_RDP_Level_1 or OB_RDP_Level_2 is set
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 * - RESET, when OB_RDP_Level_0 is set
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 static FlagStatus FLASH_OB_GetRDP(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 FlagStatus readstatus = RESET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 if((*(__IO uint8_t*)(OPTCR_BYTE1_ADDRESS) != (uint8_t)OB_RDP_LEVEL_0))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 readstatus = SET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 return readstatus;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 * @brief Returns the FLASH BOR level.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 * @retval uint8_t The FLASH BOR level:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 * - OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 * - OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 * - OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 * - OB_BOR_OFF : Supply voltage ranges from 1.62 to 2.1 V
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 static uint8_t FLASH_OB_GetBOR(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 /* Return the FLASH BOR level */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 return (uint8_t)(*(__IO uint8_t *)(OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0C);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 #endif /* HAL_FLASH_MODULE_ENABLED */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 * @}
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/