first release for keyboard

Dependencies:   F401RE-USBHost2 mbed

Committer:
Ownasaurus
Date:
Mon May 29 14:51:08 2017 +0000
Revision:
4:dbb0d3d2ad8b
Parent:
2:77b20c9b1933
fix for certain types of keyboards

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ownasaurus 2:77b20c9b1933 1 /**
Ownasaurus 2:77b20c9b1933 2 ******************************************************************************
Ownasaurus 2:77b20c9b1933 3 * @file stm32f4xx_flash.c
Ownasaurus 2:77b20c9b1933 4 * @author MCD Application Team
Ownasaurus 2:77b20c9b1933 5 * @version V1.7.1
Ownasaurus 2:77b20c9b1933 6 * @date 20-May-2016
Ownasaurus 2:77b20c9b1933 7 * @brief This file provides firmware functions to manage the following
Ownasaurus 2:77b20c9b1933 8 * functionalities of the FLASH peripheral:
Ownasaurus 2:77b20c9b1933 9 * + FLASH Interface configuration
Ownasaurus 2:77b20c9b1933 10 * + FLASH Memory Programming
Ownasaurus 2:77b20c9b1933 11 * + Option Bytes Programming
Ownasaurus 2:77b20c9b1933 12 * + Interrupts and flags management
Ownasaurus 2:77b20c9b1933 13 *
Ownasaurus 2:77b20c9b1933 14 @verbatim
Ownasaurus 2:77b20c9b1933 15 ===============================================================================
Ownasaurus 2:77b20c9b1933 16 ##### How to use this driver #####
Ownasaurus 2:77b20c9b1933 17 ===============================================================================
Ownasaurus 2:77b20c9b1933 18 [..]
Ownasaurus 2:77b20c9b1933 19 This driver provides functions to configure and program the FLASH memory
Ownasaurus 2:77b20c9b1933 20 of all STM32F4xx devices. These functions are split in 4 groups:
Ownasaurus 2:77b20c9b1933 21
Ownasaurus 2:77b20c9b1933 22 (#) FLASH Interface configuration functions: this group includes the
Ownasaurus 2:77b20c9b1933 23 management of the following features:
Ownasaurus 2:77b20c9b1933 24 (++) Set the latency
Ownasaurus 2:77b20c9b1933 25 (++) Enable/Disable the prefetch buffer
Ownasaurus 2:77b20c9b1933 26 (++) Enable/Disable the Instruction cache and the Data cache
Ownasaurus 2:77b20c9b1933 27 (++) Reset the Instruction cache and the Data cache
Ownasaurus 2:77b20c9b1933 28
Ownasaurus 2:77b20c9b1933 29 (#) FLASH Memory Programming functions: this group includes all needed
Ownasaurus 2:77b20c9b1933 30 functions to erase and program the main memory:
Ownasaurus 2:77b20c9b1933 31 (++) Lock and Unlock the FLASH interface
Ownasaurus 2:77b20c9b1933 32 (++) Erase function: Erase sector, erase all sectors
Ownasaurus 2:77b20c9b1933 33 (++) Program functions: byte, half word, word and double word
Ownasaurus 2:77b20c9b1933 34
Ownasaurus 2:77b20c9b1933 35 (#) Option Bytes Programming functions: this group includes all needed
Ownasaurus 2:77b20c9b1933 36 functions to manage the Option Bytes:
Ownasaurus 2:77b20c9b1933 37 (++) Set/Reset the write protection
Ownasaurus 2:77b20c9b1933 38 (++) Set the Read protection Level
Ownasaurus 2:77b20c9b1933 39 (++) Set the BOR level
Ownasaurus 2:77b20c9b1933 40 (++) Program the user Option Bytes
Ownasaurus 2:77b20c9b1933 41 (++) Launch the Option Bytes loader
Ownasaurus 2:77b20c9b1933 42
Ownasaurus 2:77b20c9b1933 43 (#) Interrupts and flags management functions: this group
Ownasaurus 2:77b20c9b1933 44 includes all needed functions to:
Ownasaurus 2:77b20c9b1933 45 (++) Enable/Disable the FLASH interrupt sources
Ownasaurus 2:77b20c9b1933 46 (++) Get flags status
Ownasaurus 2:77b20c9b1933 47 (++) Clear flags
Ownasaurus 2:77b20c9b1933 48 (++) Get FLASH operation status
Ownasaurus 2:77b20c9b1933 49 (++) Wait for last FLASH operation
Ownasaurus 2:77b20c9b1933 50 @endverbatim
Ownasaurus 2:77b20c9b1933 51 ******************************************************************************
Ownasaurus 2:77b20c9b1933 52 * @attention
Ownasaurus 2:77b20c9b1933 53 *
Ownasaurus 2:77b20c9b1933 54 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
Ownasaurus 2:77b20c9b1933 55 *
Ownasaurus 2:77b20c9b1933 56 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
Ownasaurus 2:77b20c9b1933 57 * You may not use this file except in compliance with the License.
Ownasaurus 2:77b20c9b1933 58 * You may obtain a copy of the License at:
Ownasaurus 2:77b20c9b1933 59 *
Ownasaurus 2:77b20c9b1933 60 * http://www.st.com/software_license_agreement_liberty_v2
Ownasaurus 2:77b20c9b1933 61 *
Ownasaurus 2:77b20c9b1933 62 * Unless required by applicable law or agreed to in writing, software
Ownasaurus 2:77b20c9b1933 63 * distributed under the License is distributed on an "AS IS" BASIS,
Ownasaurus 2:77b20c9b1933 64 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Ownasaurus 2:77b20c9b1933 65 * See the License for the specific language governing permissions and
Ownasaurus 2:77b20c9b1933 66 * limitations under the License.
Ownasaurus 2:77b20c9b1933 67 *
Ownasaurus 2:77b20c9b1933 68 ******************************************************************************
Ownasaurus 2:77b20c9b1933 69 */
Ownasaurus 2:77b20c9b1933 70
Ownasaurus 2:77b20c9b1933 71 /* Includes ------------------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 72 #include "stm32f4xx_flash.h"
Ownasaurus 2:77b20c9b1933 73
Ownasaurus 2:77b20c9b1933 74 /** @addtogroup STM32F4xx_StdPeriph_Driver
Ownasaurus 2:77b20c9b1933 75 * @{
Ownasaurus 2:77b20c9b1933 76 */
Ownasaurus 2:77b20c9b1933 77
Ownasaurus 2:77b20c9b1933 78 /** @defgroup FLASH
Ownasaurus 2:77b20c9b1933 79 * @brief FLASH driver modules
Ownasaurus 2:77b20c9b1933 80 * @{
Ownasaurus 2:77b20c9b1933 81 */
Ownasaurus 2:77b20c9b1933 82
Ownasaurus 2:77b20c9b1933 83 /* Private typedef -----------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 84 /* Private define ------------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 85 #define SECTOR_MASK ((uint32_t)0xFFFFFF07)
Ownasaurus 2:77b20c9b1933 86
Ownasaurus 2:77b20c9b1933 87 /* Private macro -------------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 88 /* Private variables ---------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 89 /* Private function prototypes -----------------------------------------------*/
Ownasaurus 2:77b20c9b1933 90 /* Private functions ---------------------------------------------------------*/
Ownasaurus 2:77b20c9b1933 91
Ownasaurus 2:77b20c9b1933 92 /** @defgroup FLASH_Private_Functions
Ownasaurus 2:77b20c9b1933 93 * @{
Ownasaurus 2:77b20c9b1933 94 */
Ownasaurus 2:77b20c9b1933 95
Ownasaurus 2:77b20c9b1933 96 /** @defgroup FLASH_Group1 FLASH Interface configuration functions
Ownasaurus 2:77b20c9b1933 97 * @brief FLASH Interface configuration functions
Ownasaurus 2:77b20c9b1933 98 *
Ownasaurus 2:77b20c9b1933 99
Ownasaurus 2:77b20c9b1933 100 @verbatim
Ownasaurus 2:77b20c9b1933 101 ===============================================================================
Ownasaurus 2:77b20c9b1933 102 ##### FLASH Interface configuration functions #####
Ownasaurus 2:77b20c9b1933 103 ===============================================================================
Ownasaurus 2:77b20c9b1933 104 [..]
Ownasaurus 2:77b20c9b1933 105 This group includes the following functions:
Ownasaurus 2:77b20c9b1933 106 (+) void FLASH_SetLatency(uint32_t FLASH_Latency)
Ownasaurus 2:77b20c9b1933 107 To correctly read data from FLASH memory, the number of wait states (LATENCY)
Ownasaurus 2:77b20c9b1933 108 must be correctly programmed according to the frequency of the CPU clock
Ownasaurus 2:77b20c9b1933 109 (HCLK) and the supply voltage of the device.
Ownasaurus 2:77b20c9b1933 110 [..]
Ownasaurus 2:77b20c9b1933 111 For STM32F405xx/07xx and STM32F415xx/17xx devices
Ownasaurus 2:77b20c9b1933 112 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 113 | Latency | HCLK clock frequency (MHz) |
Ownasaurus 2:77b20c9b1933 114 | |---------------------------------------------------------------------|
Ownasaurus 2:77b20c9b1933 115 | | voltage range | voltage range | voltage range | voltage range |
Ownasaurus 2:77b20c9b1933 116 | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
Ownasaurus 2:77b20c9b1933 117 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 118 |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
Ownasaurus 2:77b20c9b1933 119 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 120 |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
Ownasaurus 2:77b20c9b1933 121 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 122 |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
Ownasaurus 2:77b20c9b1933 123 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 124 |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88 |60 < HCLK <= 80 |
Ownasaurus 2:77b20c9b1933 125 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 126 |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
Ownasaurus 2:77b20c9b1933 127 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 128 |5WS(6CPU cycle)|150< HCLK <= 168|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
Ownasaurus 2:77b20c9b1933 129 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 130 |6WS(7CPU cycle)| NA |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
Ownasaurus 2:77b20c9b1933 131 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 132 |7WS(8CPU cycle)| NA | NA |154 < HCLK <= 168|140 < HCLK <= 160|
Ownasaurus 2:77b20c9b1933 133 +---------------|----------------|----------------|-----------------|-----------------+
Ownasaurus 2:77b20c9b1933 134
Ownasaurus 2:77b20c9b1933 135 [..]
Ownasaurus 2:77b20c9b1933 136 For STM32F42xxx/43xxx devices
Ownasaurus 2:77b20c9b1933 137 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 138 | Latency | HCLK clock frequency (MHz) |
Ownasaurus 2:77b20c9b1933 139 | |---------------------------------------------------------------------|
Ownasaurus 2:77b20c9b1933 140 | | voltage range | voltage range | voltage range | voltage range |
Ownasaurus 2:77b20c9b1933 141 | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
Ownasaurus 2:77b20c9b1933 142 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 143 |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
Ownasaurus 2:77b20c9b1933 144 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 145 |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
Ownasaurus 2:77b20c9b1933 146 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 147 |2WS(3CPU cycle)|60 < HCLK <= 90 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
Ownasaurus 2:77b20c9b1933 148 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 149 |3WS(4CPU cycle)|90 < HCLK <= 120|72 < HCLK <= 96 |66 < HCLK <= 88 |60 < HCLK <= 80 |
Ownasaurus 2:77b20c9b1933 150 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 151 |4WS(5CPU cycle)|120< HCLK <= 150|96 < HCLK <= 120|88 < HCLK <= 110 |80 < HCLK <= 100 |
Ownasaurus 2:77b20c9b1933 152 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 153 |5WS(6CPU cycle)|120< HCLK <= 180|120< HCLK <= 144|110 < HCLK <= 132|100 < HCLK <= 120|
Ownasaurus 2:77b20c9b1933 154 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 155 |6WS(7CPU cycle)| NA |144< HCLK <= 168|132 < HCLK <= 154|120 < HCLK <= 140|
Ownasaurus 2:77b20c9b1933 156 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 157 |7WS(8CPU cycle)| NA |168< HCLK <= 180|154 < HCLK <= 176|140 < HCLK <= 160|
Ownasaurus 2:77b20c9b1933 158 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 159 |8WS(9CPU cycle)| NA | NA |176 < HCLK <= 180|160 < HCLK <= 168|
Ownasaurus 2:77b20c9b1933 160 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 161
Ownasaurus 2:77b20c9b1933 162 [..]
Ownasaurus 2:77b20c9b1933 163 For STM32F401x devices
Ownasaurus 2:77b20c9b1933 164 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 165 | Latency | HCLK clock frequency (MHz) |
Ownasaurus 2:77b20c9b1933 166 | |---------------------------------------------------------------------|
Ownasaurus 2:77b20c9b1933 167 | | voltage range | voltage range | voltage range | voltage range |
Ownasaurus 2:77b20c9b1933 168 | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
Ownasaurus 2:77b20c9b1933 169 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 170 |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 22 |0 < HCLK <= 20 |
Ownasaurus 2:77b20c9b1933 171 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 172 |1WS(2CPU cycle)|30 < HCLK <= 60 |24 < HCLK <= 48 |22 < HCLK <= 44 |20 < HCLK <= 40 |
Ownasaurus 2:77b20c9b1933 173 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 174 |2WS(3CPU cycle)|60 < HCLK <= 84 |48 < HCLK <= 72 |44 < HCLK <= 66 |40 < HCLK <= 60 |
Ownasaurus 2:77b20c9b1933 175 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 176 |3WS(4CPU cycle)| NA |72 < HCLK <= 84 |66 < HCLK <= 84 |60 < HCLK <= 80 |
Ownasaurus 2:77b20c9b1933 177 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 178 |4WS(5CPU cycle)| NA | NA | NA |80 < HCLK <= 84 |
Ownasaurus 2:77b20c9b1933 179 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 180
Ownasaurus 2:77b20c9b1933 181 [..]
Ownasaurus 2:77b20c9b1933 182 For STM32F410xx/STM32F411xE devices
Ownasaurus 2:77b20c9b1933 183 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 184 | Latency | HCLK clock frequency (MHz) |
Ownasaurus 2:77b20c9b1933 185 | |---------------------------------------------------------------------|
Ownasaurus 2:77b20c9b1933 186 | | voltage range | voltage range | voltage range | voltage range |
Ownasaurus 2:77b20c9b1933 187 | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V |
Ownasaurus 2:77b20c9b1933 188 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 189 |0WS(1CPU cycle)|0 < HCLK <= 30 |0 < HCLK <= 24 |0 < HCLK <= 18 |0 < HCLK <= 16 |
Ownasaurus 2:77b20c9b1933 190 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 191 |1WS(2CPU cycle)|30 < HCLK <= 64 |24 < HCLK <= 48 |18 < HCLK <= 36 |16 < HCLK <= 32 |
Ownasaurus 2:77b20c9b1933 192 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 193 |2WS(3CPU cycle)|64 < HCLK <= 90 |48 < HCLK <= 72 |36 < HCLK <= 54 |32 < HCLK <= 48 |
Ownasaurus 2:77b20c9b1933 194 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 195 |3WS(4CPU cycle)|90 < HCLK <= 100|72 < HCLK <= 96 |54 < HCLK <= 72 |48 < HCLK <= 64 |
Ownasaurus 2:77b20c9b1933 196 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 197 |4WS(5CPU cycle)| NA |96 < HCLK <= 100|72 < HCLK <= 90 |64 < HCLK <= 80 |
Ownasaurus 2:77b20c9b1933 198 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 199 |5WS(6CPU cycle)| NA | NA |90 < HCLK <= 100 |80 < HCLK <= 96 |
Ownasaurus 2:77b20c9b1933 200 |---------------|----------------|----------------|-----------------|-----------------|
Ownasaurus 2:77b20c9b1933 201 |6WS(7CPU cycle)| NA | NA | NA |96 < HCLK <= 100 |
Ownasaurus 2:77b20c9b1933 202 +-------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 203
Ownasaurus 2:77b20c9b1933 204 [..]
Ownasaurus 2:77b20c9b1933 205 +-------------------------------------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 206 | | voltage range | voltage range | voltage range | voltage range | voltage range 2.7 V - 3.6 V |
Ownasaurus 2:77b20c9b1933 207 | | 2.7 V - 3.6 V | 2.4 V - 2.7 V | 2.1 V - 2.4 V | 1.8 V - 2.1 V | with External Vpp = 9V |
Ownasaurus 2:77b20c9b1933 208 |---------------|----------------|----------------|-----------------|-----------------|-----------------------------|
Ownasaurus 2:77b20c9b1933 209 |Max Parallelism| x32 | x16 | x8 | x64 |
Ownasaurus 2:77b20c9b1933 210 |---------------|----------------|----------------|-----------------|-----------------|-----------------------------|
Ownasaurus 2:77b20c9b1933 211 |PSIZE[1:0] | 10 | 01 | 00 | 11 |
Ownasaurus 2:77b20c9b1933 212 +-------------------------------------------------------------------------------------------------------------------+
Ownasaurus 2:77b20c9b1933 213
Ownasaurus 2:77b20c9b1933 214 -@- On STM32F405xx/407xx and STM32F415xx/417xx devices:
Ownasaurus 2:77b20c9b1933 215 (++) when VOS = '0' Scale 2 mode, the maximum value of fHCLK = 144MHz.
Ownasaurus 2:77b20c9b1933 216 (++) when VOS = '1' Scale 1 mode, the maximum value of fHCLK = 168MHz.
Ownasaurus 2:77b20c9b1933 217 [..]
Ownasaurus 2:77b20c9b1933 218 On STM32F42xxx/43xxx devices:
Ownasaurus 2:77b20c9b1933 219 (++) when VOS[1:0] = '0x01' Scale 3 mode, the maximum value of fHCLK is 120MHz.
Ownasaurus 2:77b20c9b1933 220 (++) when VOS[1:0] = '0x10' Scale 2 mode, the maximum value of fHCLK is 144MHz if OverDrive OFF and 168MHz if OverDrive ON.
Ownasaurus 2:77b20c9b1933 221 (++) when VOS[1:0] = '0x11' Scale 1 mode, the maximum value of fHCLK is 168MHz if OverDrive OFF and 180MHz if OverDrive ON.
Ownasaurus 2:77b20c9b1933 222 [..]
Ownasaurus 2:77b20c9b1933 223 On STM32F401x devices:
Ownasaurus 2:77b20c9b1933 224 (++) when VOS[1:0] = '0x01' Scale 3 mode, the maximum value of fHCLK is 60MHz.
Ownasaurus 2:77b20c9b1933 225 (++) when VOS[1:0] = '0x10' Scale 2 mode, the maximum value of fHCLK is 84MHz.
Ownasaurus 2:77b20c9b1933 226 [..]
Ownasaurus 2:77b20c9b1933 227 On STM32F410xx/STM32F411xE devices:
Ownasaurus 2:77b20c9b1933 228 (++) when VOS[1:0] = '0x01' Scale 3 mode, the maximum value of fHCLK is 64MHz.
Ownasaurus 2:77b20c9b1933 229 (++) when VOS[1:0] = '0x10' Scale 2 mode, the maximum value of fHCLK is 84MHz.
Ownasaurus 2:77b20c9b1933 230 (++) when VOS[1:0] = '0x11' Scale 1 mode, the maximum value of fHCLK is 100MHz.
Ownasaurus 2:77b20c9b1933 231
Ownasaurus 2:77b20c9b1933 232 For more details please refer product DataSheet
Ownasaurus 2:77b20c9b1933 233 You can use PWR_MainRegulatorModeConfig() function to control VOS bits.
Ownasaurus 2:77b20c9b1933 234
Ownasaurus 2:77b20c9b1933 235 (+) void FLASH_PrefetchBufferCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 236 (+) void FLASH_InstructionCacheCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 237 (+) void FLASH_DataCacheCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 238 (+) void FLASH_InstructionCacheReset(void)
Ownasaurus 2:77b20c9b1933 239 (+) void FLASH_DataCacheReset(void)
Ownasaurus 2:77b20c9b1933 240
Ownasaurus 2:77b20c9b1933 241 [..]
Ownasaurus 2:77b20c9b1933 242 The unlock sequence is not needed for these functions.
Ownasaurus 2:77b20c9b1933 243
Ownasaurus 2:77b20c9b1933 244 @endverbatim
Ownasaurus 2:77b20c9b1933 245 * @{
Ownasaurus 2:77b20c9b1933 246 */
Ownasaurus 2:77b20c9b1933 247
Ownasaurus 2:77b20c9b1933 248 /**
Ownasaurus 2:77b20c9b1933 249 * @brief Sets the code latency value.
Ownasaurus 2:77b20c9b1933 250 * @param FLASH_Latency: specifies the FLASH Latency value.
Ownasaurus 2:77b20c9b1933 251 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 252 * @arg FLASH_Latency_0: FLASH Zero Latency cycle
Ownasaurus 2:77b20c9b1933 253 * @arg FLASH_Latency_1: FLASH One Latency cycle
Ownasaurus 2:77b20c9b1933 254 * @arg FLASH_Latency_2: FLASH Two Latency cycles
Ownasaurus 2:77b20c9b1933 255 * @arg FLASH_Latency_3: FLASH Three Latency cycles
Ownasaurus 2:77b20c9b1933 256 * @arg FLASH_Latency_4: FLASH Four Latency cycles
Ownasaurus 2:77b20c9b1933 257 * @arg FLASH_Latency_5: FLASH Five Latency cycles
Ownasaurus 2:77b20c9b1933 258 * @arg FLASH_Latency_6: FLASH Six Latency cycles
Ownasaurus 2:77b20c9b1933 259 * @arg FLASH_Latency_7: FLASH Seven Latency cycles
Ownasaurus 2:77b20c9b1933 260 * @arg FLASH_Latency_8: FLASH Eight Latency cycles
Ownasaurus 2:77b20c9b1933 261 * @arg FLASH_Latency_9: FLASH Nine Latency cycles
Ownasaurus 2:77b20c9b1933 262 * @arg FLASH_Latency_10: FLASH Teen Latency cycles
Ownasaurus 2:77b20c9b1933 263 * @arg FLASH_Latency_11: FLASH Eleven Latency cycles
Ownasaurus 2:77b20c9b1933 264 * @arg FLASH_Latency_12: FLASH Twelve Latency cycles
Ownasaurus 2:77b20c9b1933 265 * @arg FLASH_Latency_13: FLASH Thirteen Latency cycles
Ownasaurus 2:77b20c9b1933 266 * @arg FLASH_Latency_14: FLASH Fourteen Latency cycles
Ownasaurus 2:77b20c9b1933 267 * @arg FLASH_Latency_15: FLASH Fifteen Latency cycles
Ownasaurus 2:77b20c9b1933 268 *
Ownasaurus 2:77b20c9b1933 269 * @note For STM32F405xx/407xx, STM32F415xx/417xx, STM32F401xx/411xE and STM32F412xG devices
Ownasaurus 2:77b20c9b1933 270 * this parameter can be a value between FLASH_Latency_0 and FLASH_Latency_7.
Ownasaurus 2:77b20c9b1933 271 *
Ownasaurus 2:77b20c9b1933 272 * @note For STM32F42xxx/43xxx devices this parameter can be a value between
Ownasaurus 2:77b20c9b1933 273 * FLASH_Latency_0 and FLASH_Latency_15.
Ownasaurus 2:77b20c9b1933 274 *
Ownasaurus 2:77b20c9b1933 275 * @retval None
Ownasaurus 2:77b20c9b1933 276 */
Ownasaurus 2:77b20c9b1933 277 void FLASH_SetLatency(uint32_t FLASH_Latency)
Ownasaurus 2:77b20c9b1933 278 {
Ownasaurus 2:77b20c9b1933 279 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 280 assert_param(IS_FLASH_LATENCY(FLASH_Latency));
Ownasaurus 2:77b20c9b1933 281
Ownasaurus 2:77b20c9b1933 282 /* Perform Byte access to FLASH_ACR[8:0] to set the Latency value */
Ownasaurus 2:77b20c9b1933 283 *(__IO uint8_t *)ACR_BYTE0_ADDRESS = (uint8_t)FLASH_Latency;
Ownasaurus 2:77b20c9b1933 284 }
Ownasaurus 2:77b20c9b1933 285
Ownasaurus 2:77b20c9b1933 286 /**
Ownasaurus 2:77b20c9b1933 287 * @brief Enables or disables the Prefetch Buffer.
Ownasaurus 2:77b20c9b1933 288 * @param NewState: new state of the Prefetch Buffer.
Ownasaurus 2:77b20c9b1933 289 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 290 * @retval None
Ownasaurus 2:77b20c9b1933 291 */
Ownasaurus 2:77b20c9b1933 292 void FLASH_PrefetchBufferCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 293 {
Ownasaurus 2:77b20c9b1933 294 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 295 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 296
Ownasaurus 2:77b20c9b1933 297 /* Enable or disable the Prefetch Buffer */
Ownasaurus 2:77b20c9b1933 298 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 299 {
Ownasaurus 2:77b20c9b1933 300 FLASH->ACR |= FLASH_ACR_PRFTEN;
Ownasaurus 2:77b20c9b1933 301 }
Ownasaurus 2:77b20c9b1933 302 else
Ownasaurus 2:77b20c9b1933 303 {
Ownasaurus 2:77b20c9b1933 304 FLASH->ACR &= (~FLASH_ACR_PRFTEN);
Ownasaurus 2:77b20c9b1933 305 }
Ownasaurus 2:77b20c9b1933 306 }
Ownasaurus 2:77b20c9b1933 307
Ownasaurus 2:77b20c9b1933 308 /**
Ownasaurus 2:77b20c9b1933 309 * @brief Enables or disables the Instruction Cache feature.
Ownasaurus 2:77b20c9b1933 310 * @param NewState: new state of the Instruction Cache.
Ownasaurus 2:77b20c9b1933 311 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 312 * @retval None
Ownasaurus 2:77b20c9b1933 313 */
Ownasaurus 2:77b20c9b1933 314 void FLASH_InstructionCacheCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 315 {
Ownasaurus 2:77b20c9b1933 316 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 317 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 318
Ownasaurus 2:77b20c9b1933 319 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 320 {
Ownasaurus 2:77b20c9b1933 321 FLASH->ACR |= FLASH_ACR_ICEN;
Ownasaurus 2:77b20c9b1933 322 }
Ownasaurus 2:77b20c9b1933 323 else
Ownasaurus 2:77b20c9b1933 324 {
Ownasaurus 2:77b20c9b1933 325 FLASH->ACR &= (~FLASH_ACR_ICEN);
Ownasaurus 2:77b20c9b1933 326 }
Ownasaurus 2:77b20c9b1933 327 }
Ownasaurus 2:77b20c9b1933 328
Ownasaurus 2:77b20c9b1933 329 /**
Ownasaurus 2:77b20c9b1933 330 * @brief Enables or disables the Data Cache feature.
Ownasaurus 2:77b20c9b1933 331 * @param NewState: new state of the Data Cache.
Ownasaurus 2:77b20c9b1933 332 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 333 * @retval None
Ownasaurus 2:77b20c9b1933 334 */
Ownasaurus 2:77b20c9b1933 335 void FLASH_DataCacheCmd(FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 336 {
Ownasaurus 2:77b20c9b1933 337 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 338 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 339
Ownasaurus 2:77b20c9b1933 340 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 341 {
Ownasaurus 2:77b20c9b1933 342 FLASH->ACR |= FLASH_ACR_DCEN;
Ownasaurus 2:77b20c9b1933 343 }
Ownasaurus 2:77b20c9b1933 344 else
Ownasaurus 2:77b20c9b1933 345 {
Ownasaurus 2:77b20c9b1933 346 FLASH->ACR &= (~FLASH_ACR_DCEN);
Ownasaurus 2:77b20c9b1933 347 }
Ownasaurus 2:77b20c9b1933 348 }
Ownasaurus 2:77b20c9b1933 349
Ownasaurus 2:77b20c9b1933 350 /**
Ownasaurus 2:77b20c9b1933 351 * @brief Resets the Instruction Cache.
Ownasaurus 2:77b20c9b1933 352 * @note This function must be used only when the Instruction Cache is disabled.
Ownasaurus 2:77b20c9b1933 353 * @param None
Ownasaurus 2:77b20c9b1933 354 * @retval None
Ownasaurus 2:77b20c9b1933 355 */
Ownasaurus 2:77b20c9b1933 356 void FLASH_InstructionCacheReset(void)
Ownasaurus 2:77b20c9b1933 357 {
Ownasaurus 2:77b20c9b1933 358 FLASH->ACR |= FLASH_ACR_ICRST;
Ownasaurus 2:77b20c9b1933 359 }
Ownasaurus 2:77b20c9b1933 360
Ownasaurus 2:77b20c9b1933 361 /**
Ownasaurus 2:77b20c9b1933 362 * @brief Resets the Data Cache.
Ownasaurus 2:77b20c9b1933 363 * @note This function must be used only when the Data Cache is disabled.
Ownasaurus 2:77b20c9b1933 364 * @param None
Ownasaurus 2:77b20c9b1933 365 * @retval None
Ownasaurus 2:77b20c9b1933 366 */
Ownasaurus 2:77b20c9b1933 367 void FLASH_DataCacheReset(void)
Ownasaurus 2:77b20c9b1933 368 {
Ownasaurus 2:77b20c9b1933 369 FLASH->ACR |= FLASH_ACR_DCRST;
Ownasaurus 2:77b20c9b1933 370 }
Ownasaurus 2:77b20c9b1933 371
Ownasaurus 2:77b20c9b1933 372 /**
Ownasaurus 2:77b20c9b1933 373 * @}
Ownasaurus 2:77b20c9b1933 374 */
Ownasaurus 2:77b20c9b1933 375
Ownasaurus 2:77b20c9b1933 376 /** @defgroup FLASH_Group2 FLASH Memory Programming functions
Ownasaurus 2:77b20c9b1933 377 * @brief FLASH Memory Programming functions
Ownasaurus 2:77b20c9b1933 378 *
Ownasaurus 2:77b20c9b1933 379 @verbatim
Ownasaurus 2:77b20c9b1933 380 ===============================================================================
Ownasaurus 2:77b20c9b1933 381 ##### FLASH Memory Programming functions #####
Ownasaurus 2:77b20c9b1933 382 ===============================================================================
Ownasaurus 2:77b20c9b1933 383 [..]
Ownasaurus 2:77b20c9b1933 384 This group includes the following functions:
Ownasaurus 2:77b20c9b1933 385 (+) void FLASH_Unlock(void)
Ownasaurus 2:77b20c9b1933 386 (+) void FLASH_Lock(void)
Ownasaurus 2:77b20c9b1933 387 (+) FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 388 (+) FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 389 (+) FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data)
Ownasaurus 2:77b20c9b1933 390 (+) FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Ownasaurus 2:77b20c9b1933 391 (+) FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
Ownasaurus 2:77b20c9b1933 392 (+) FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
Ownasaurus 2:77b20c9b1933 393 The following functions can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 394 (+) FLASH_Status FLASH_EraseAllBank1Sectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 395 (+) FLASH_Status FLASH_EraseAllBank2Sectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 396 [..]
Ownasaurus 2:77b20c9b1933 397 Any operation of erase or program should follow these steps:
Ownasaurus 2:77b20c9b1933 398 (#) Call the FLASH_Unlock() function to enable the FLASH control register access
Ownasaurus 2:77b20c9b1933 399
Ownasaurus 2:77b20c9b1933 400 (#) Call the desired function to erase sector(s) or program data
Ownasaurus 2:77b20c9b1933 401
Ownasaurus 2:77b20c9b1933 402 (#) Call the FLASH_Lock() function to disable the FLASH control register access
Ownasaurus 2:77b20c9b1933 403 (recommended to protect the FLASH memory against possible unwanted operation)
Ownasaurus 2:77b20c9b1933 404
Ownasaurus 2:77b20c9b1933 405 @endverbatim
Ownasaurus 2:77b20c9b1933 406 * @{
Ownasaurus 2:77b20c9b1933 407 */
Ownasaurus 2:77b20c9b1933 408
Ownasaurus 2:77b20c9b1933 409 /**
Ownasaurus 2:77b20c9b1933 410 * @brief Unlocks the FLASH control register access
Ownasaurus 2:77b20c9b1933 411 * @param None
Ownasaurus 2:77b20c9b1933 412 * @retval None
Ownasaurus 2:77b20c9b1933 413 */
Ownasaurus 2:77b20c9b1933 414 void FLASH_Unlock(void)
Ownasaurus 2:77b20c9b1933 415 {
Ownasaurus 2:77b20c9b1933 416 if((FLASH->CR & FLASH_CR_LOCK) != RESET)
Ownasaurus 2:77b20c9b1933 417 {
Ownasaurus 2:77b20c9b1933 418 /* Authorize the FLASH Registers access */
Ownasaurus 2:77b20c9b1933 419 FLASH->KEYR = FLASH_KEY1;
Ownasaurus 2:77b20c9b1933 420 FLASH->KEYR = FLASH_KEY2;
Ownasaurus 2:77b20c9b1933 421 }
Ownasaurus 2:77b20c9b1933 422 }
Ownasaurus 2:77b20c9b1933 423
Ownasaurus 2:77b20c9b1933 424 /**
Ownasaurus 2:77b20c9b1933 425 * @brief Locks the FLASH control register access
Ownasaurus 2:77b20c9b1933 426 * @param None
Ownasaurus 2:77b20c9b1933 427 * @retval None
Ownasaurus 2:77b20c9b1933 428 */
Ownasaurus 2:77b20c9b1933 429 void FLASH_Lock(void)
Ownasaurus 2:77b20c9b1933 430 {
Ownasaurus 2:77b20c9b1933 431 /* Set the LOCK Bit to lock the FLASH Registers access */
Ownasaurus 2:77b20c9b1933 432 FLASH->CR |= FLASH_CR_LOCK;
Ownasaurus 2:77b20c9b1933 433 }
Ownasaurus 2:77b20c9b1933 434
Ownasaurus 2:77b20c9b1933 435 /**
Ownasaurus 2:77b20c9b1933 436 * @brief Erases a specified FLASH Sector.
Ownasaurus 2:77b20c9b1933 437 *
Ownasaurus 2:77b20c9b1933 438 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 439 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 440 *
Ownasaurus 2:77b20c9b1933 441 * @param FLASH_Sector: The Sector number to be erased.
Ownasaurus 2:77b20c9b1933 442 *
Ownasaurus 2:77b20c9b1933 443 * @note For STM32F405xx/407xx and STM32F415xx/417xx devices this parameter can
Ownasaurus 2:77b20c9b1933 444 * be a value between FLASH_Sector_0 and FLASH_Sector_11.
Ownasaurus 2:77b20c9b1933 445 *
Ownasaurus 2:77b20c9b1933 446 * For STM32F42xxx/43xxx devices this parameter can be a value between
Ownasaurus 2:77b20c9b1933 447 * FLASH_Sector_0 and FLASH_Sector_23.
Ownasaurus 2:77b20c9b1933 448 *
Ownasaurus 2:77b20c9b1933 449 * For STM32F401xx devices this parameter can be a value between
Ownasaurus 2:77b20c9b1933 450 * FLASH_Sector_0 and FLASH_Sector_5.
Ownasaurus 2:77b20c9b1933 451 *
Ownasaurus 2:77b20c9b1933 452 * For STM32F411xE and STM32F412xG devices this parameter can be a value between
Ownasaurus 2:77b20c9b1933 453 * FLASH_Sector_0 and FLASH_Sector_7.
Ownasaurus 2:77b20c9b1933 454 *
Ownasaurus 2:77b20c9b1933 455 * For STM32F410xx devices this parameter can be a value between
Ownasaurus 2:77b20c9b1933 456 * FLASH_Sector_0 and FLASH_Sector_4.
Ownasaurus 2:77b20c9b1933 457 *
Ownasaurus 2:77b20c9b1933 458 * @param VoltageRange: The device voltage range which defines the erase parallelism.
Ownasaurus 2:77b20c9b1933 459 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 460 * @arg VoltageRange_1: when the device voltage range is 1.8V to 2.1V,
Ownasaurus 2:77b20c9b1933 461 * the operation will be done by byte (8-bit)
Ownasaurus 2:77b20c9b1933 462 * @arg VoltageRange_2: when the device voltage range is 2.1V to 2.7V,
Ownasaurus 2:77b20c9b1933 463 * the operation will be done by half word (16-bit)
Ownasaurus 2:77b20c9b1933 464 * @arg VoltageRange_3: when the device voltage range is 2.7V to 3.6V,
Ownasaurus 2:77b20c9b1933 465 * the operation will be done by word (32-bit)
Ownasaurus 2:77b20c9b1933 466 * @arg VoltageRange_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
Ownasaurus 2:77b20c9b1933 467 * the operation will be done by double word (64-bit)
Ownasaurus 2:77b20c9b1933 468 *
Ownasaurus 2:77b20c9b1933 469 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 470 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 471 */
Ownasaurus 2:77b20c9b1933 472 FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 473 {
Ownasaurus 2:77b20c9b1933 474 uint32_t tmp_psize = 0x0;
Ownasaurus 2:77b20c9b1933 475 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 476
Ownasaurus 2:77b20c9b1933 477 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 478 assert_param(IS_FLASH_SECTOR(FLASH_Sector));
Ownasaurus 2:77b20c9b1933 479 assert_param(IS_VOLTAGERANGE(VoltageRange));
Ownasaurus 2:77b20c9b1933 480
Ownasaurus 2:77b20c9b1933 481 if(VoltageRange == VoltageRange_1)
Ownasaurus 2:77b20c9b1933 482 {
Ownasaurus 2:77b20c9b1933 483 tmp_psize = FLASH_PSIZE_BYTE;
Ownasaurus 2:77b20c9b1933 484 }
Ownasaurus 2:77b20c9b1933 485 else if(VoltageRange == VoltageRange_2)
Ownasaurus 2:77b20c9b1933 486 {
Ownasaurus 2:77b20c9b1933 487 tmp_psize = FLASH_PSIZE_HALF_WORD;
Ownasaurus 2:77b20c9b1933 488 }
Ownasaurus 2:77b20c9b1933 489 else if(VoltageRange == VoltageRange_3)
Ownasaurus 2:77b20c9b1933 490 {
Ownasaurus 2:77b20c9b1933 491 tmp_psize = FLASH_PSIZE_WORD;
Ownasaurus 2:77b20c9b1933 492 }
Ownasaurus 2:77b20c9b1933 493 else
Ownasaurus 2:77b20c9b1933 494 {
Ownasaurus 2:77b20c9b1933 495 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
Ownasaurus 2:77b20c9b1933 496 }
Ownasaurus 2:77b20c9b1933 497 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 498 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 499
Ownasaurus 2:77b20c9b1933 500 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 501 {
Ownasaurus 2:77b20c9b1933 502 /* if the previous operation is completed, proceed to erase the sector */
Ownasaurus 2:77b20c9b1933 503 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 504 FLASH->CR |= tmp_psize;
Ownasaurus 2:77b20c9b1933 505 FLASH->CR &= SECTOR_MASK;
Ownasaurus 2:77b20c9b1933 506 FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
Ownasaurus 2:77b20c9b1933 507 FLASH->CR |= FLASH_CR_STRT;
Ownasaurus 2:77b20c9b1933 508
Ownasaurus 2:77b20c9b1933 509 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 510 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 511
Ownasaurus 2:77b20c9b1933 512 /* if the erase operation is completed, disable the SER Bit */
Ownasaurus 2:77b20c9b1933 513 FLASH->CR &= (~FLASH_CR_SER);
Ownasaurus 2:77b20c9b1933 514 FLASH->CR &= SECTOR_MASK;
Ownasaurus 2:77b20c9b1933 515 }
Ownasaurus 2:77b20c9b1933 516 /* Return the Erase Status */
Ownasaurus 2:77b20c9b1933 517 return status;
Ownasaurus 2:77b20c9b1933 518 }
Ownasaurus 2:77b20c9b1933 519
Ownasaurus 2:77b20c9b1933 520 /**
Ownasaurus 2:77b20c9b1933 521 * @brief Erases all FLASH Sectors.
Ownasaurus 2:77b20c9b1933 522 *
Ownasaurus 2:77b20c9b1933 523 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 524 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 525 *
Ownasaurus 2:77b20c9b1933 526 * @param VoltageRange: The device voltage range which defines the erase parallelism.
Ownasaurus 2:77b20c9b1933 527 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 528 * @arg VoltageRange_1: when the device voltage range is 1.8V to 2.1V,
Ownasaurus 2:77b20c9b1933 529 * the operation will be done by byte (8-bit)
Ownasaurus 2:77b20c9b1933 530 * @arg VoltageRange_2: when the device voltage range is 2.1V to 2.7V,
Ownasaurus 2:77b20c9b1933 531 * the operation will be done by half word (16-bit)
Ownasaurus 2:77b20c9b1933 532 * @arg VoltageRange_3: when the device voltage range is 2.7V to 3.6V,
Ownasaurus 2:77b20c9b1933 533 * the operation will be done by word (32-bit)
Ownasaurus 2:77b20c9b1933 534 * @arg VoltageRange_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
Ownasaurus 2:77b20c9b1933 535 * the operation will be done by double word (64-bit)
Ownasaurus 2:77b20c9b1933 536 *
Ownasaurus 2:77b20c9b1933 537 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 538 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 539 */
Ownasaurus 2:77b20c9b1933 540 FLASH_Status FLASH_EraseAllSectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 541 {
Ownasaurus 2:77b20c9b1933 542 uint32_t tmp_psize = 0x0;
Ownasaurus 2:77b20c9b1933 543 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 544
Ownasaurus 2:77b20c9b1933 545 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 546 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 547 assert_param(IS_VOLTAGERANGE(VoltageRange));
Ownasaurus 2:77b20c9b1933 548
Ownasaurus 2:77b20c9b1933 549 if(VoltageRange == VoltageRange_1)
Ownasaurus 2:77b20c9b1933 550 {
Ownasaurus 2:77b20c9b1933 551 tmp_psize = FLASH_PSIZE_BYTE;
Ownasaurus 2:77b20c9b1933 552 }
Ownasaurus 2:77b20c9b1933 553 else if(VoltageRange == VoltageRange_2)
Ownasaurus 2:77b20c9b1933 554 {
Ownasaurus 2:77b20c9b1933 555 tmp_psize = FLASH_PSIZE_HALF_WORD;
Ownasaurus 2:77b20c9b1933 556 }
Ownasaurus 2:77b20c9b1933 557 else if(VoltageRange == VoltageRange_3)
Ownasaurus 2:77b20c9b1933 558 {
Ownasaurus 2:77b20c9b1933 559 tmp_psize = FLASH_PSIZE_WORD;
Ownasaurus 2:77b20c9b1933 560 }
Ownasaurus 2:77b20c9b1933 561 else
Ownasaurus 2:77b20c9b1933 562 {
Ownasaurus 2:77b20c9b1933 563 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
Ownasaurus 2:77b20c9b1933 564 }
Ownasaurus 2:77b20c9b1933 565 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 566 {
Ownasaurus 2:77b20c9b1933 567 /* if the previous operation is completed, proceed to erase all sectors */
Ownasaurus 2:77b20c9b1933 568 #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F469_479xx)
Ownasaurus 2:77b20c9b1933 569 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 570 FLASH->CR |= tmp_psize;
Ownasaurus 2:77b20c9b1933 571 FLASH->CR |= (FLASH_CR_MER1 | FLASH_CR_MER2);
Ownasaurus 2:77b20c9b1933 572 FLASH->CR |= FLASH_CR_STRT;
Ownasaurus 2:77b20c9b1933 573
Ownasaurus 2:77b20c9b1933 574 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 575 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 576
Ownasaurus 2:77b20c9b1933 577 /* if the erase operation is completed, disable the MER Bit */
Ownasaurus 2:77b20c9b1933 578 FLASH->CR &= ~(FLASH_CR_MER1 | FLASH_CR_MER2);
Ownasaurus 2:77b20c9b1933 579 #endif /* STM32F427_437xx || STM32F429_439xx || STM32F469_479xx */
Ownasaurus 2:77b20c9b1933 580
Ownasaurus 2:77b20c9b1933 581 #if defined(STM32F40_41xxx) || defined(STM32F401xx) || defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F412xG) || defined(STM32F446xx)
Ownasaurus 2:77b20c9b1933 582 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 583 FLASH->CR |= tmp_psize;
Ownasaurus 2:77b20c9b1933 584 FLASH->CR |= FLASH_CR_MER;
Ownasaurus 2:77b20c9b1933 585 FLASH->CR |= FLASH_CR_STRT;
Ownasaurus 2:77b20c9b1933 586
Ownasaurus 2:77b20c9b1933 587 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 588 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 589
Ownasaurus 2:77b20c9b1933 590 /* if the erase operation is completed, disable the MER Bit */
Ownasaurus 2:77b20c9b1933 591 FLASH->CR &= (~FLASH_CR_MER);
Ownasaurus 2:77b20c9b1933 592 #endif /* STM32F40_41xxx || STM32F401xx || STM32F410xx || STM32F411xE || STM32F412xG || STM32F446xx */
Ownasaurus 2:77b20c9b1933 593
Ownasaurus 2:77b20c9b1933 594 }
Ownasaurus 2:77b20c9b1933 595 /* Return the Erase Status */
Ownasaurus 2:77b20c9b1933 596 return status;
Ownasaurus 2:77b20c9b1933 597 }
Ownasaurus 2:77b20c9b1933 598
Ownasaurus 2:77b20c9b1933 599 /**
Ownasaurus 2:77b20c9b1933 600 * @brief Erases all FLASH Sectors in Bank 1.
Ownasaurus 2:77b20c9b1933 601 *
Ownasaurus 2:77b20c9b1933 602 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 603 *
Ownasaurus 2:77b20c9b1933 604 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 605 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 606 *
Ownasaurus 2:77b20c9b1933 607 * @param VoltageRange: The device voltage range which defines the erase parallelism.
Ownasaurus 2:77b20c9b1933 608 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 609 * @arg VoltageRange_1: when the device voltage range is 1.8V to 2.1V,
Ownasaurus 2:77b20c9b1933 610 * the operation will be done by byte (8-bit)
Ownasaurus 2:77b20c9b1933 611 * @arg VoltageRange_2: when the device voltage range is 2.1V to 2.7V,
Ownasaurus 2:77b20c9b1933 612 * the operation will be done by half word (16-bit)
Ownasaurus 2:77b20c9b1933 613 * @arg VoltageRange_3: when the device voltage range is 2.7V to 3.6V,
Ownasaurus 2:77b20c9b1933 614 * the operation will be done by word (32-bit)
Ownasaurus 2:77b20c9b1933 615 * @arg VoltageRange_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
Ownasaurus 2:77b20c9b1933 616 * the operation will be done by double word (64-bit)
Ownasaurus 2:77b20c9b1933 617 *
Ownasaurus 2:77b20c9b1933 618 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 619 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 620 */
Ownasaurus 2:77b20c9b1933 621 FLASH_Status FLASH_EraseAllBank1Sectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 622 {
Ownasaurus 2:77b20c9b1933 623 uint32_t tmp_psize = 0x0;
Ownasaurus 2:77b20c9b1933 624 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 625
Ownasaurus 2:77b20c9b1933 626 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 627 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 628 assert_param(IS_VOLTAGERANGE(VoltageRange));
Ownasaurus 2:77b20c9b1933 629
Ownasaurus 2:77b20c9b1933 630 if(VoltageRange == VoltageRange_1)
Ownasaurus 2:77b20c9b1933 631 {
Ownasaurus 2:77b20c9b1933 632 tmp_psize = FLASH_PSIZE_BYTE;
Ownasaurus 2:77b20c9b1933 633 }
Ownasaurus 2:77b20c9b1933 634 else if(VoltageRange == VoltageRange_2)
Ownasaurus 2:77b20c9b1933 635 {
Ownasaurus 2:77b20c9b1933 636 tmp_psize = FLASH_PSIZE_HALF_WORD;
Ownasaurus 2:77b20c9b1933 637 }
Ownasaurus 2:77b20c9b1933 638 else if(VoltageRange == VoltageRange_3)
Ownasaurus 2:77b20c9b1933 639 {
Ownasaurus 2:77b20c9b1933 640 tmp_psize = FLASH_PSIZE_WORD;
Ownasaurus 2:77b20c9b1933 641 }
Ownasaurus 2:77b20c9b1933 642 else
Ownasaurus 2:77b20c9b1933 643 {
Ownasaurus 2:77b20c9b1933 644 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
Ownasaurus 2:77b20c9b1933 645 }
Ownasaurus 2:77b20c9b1933 646 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 647 {
Ownasaurus 2:77b20c9b1933 648 /* if the previous operation is completed, proceed to erase all sectors */
Ownasaurus 2:77b20c9b1933 649 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 650 FLASH->CR |= tmp_psize;
Ownasaurus 2:77b20c9b1933 651 FLASH->CR |= FLASH_CR_MER1;
Ownasaurus 2:77b20c9b1933 652 FLASH->CR |= FLASH_CR_STRT;
Ownasaurus 2:77b20c9b1933 653
Ownasaurus 2:77b20c9b1933 654 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 655 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 656
Ownasaurus 2:77b20c9b1933 657 /* if the erase operation is completed, disable the MER Bit */
Ownasaurus 2:77b20c9b1933 658 FLASH->CR &= (~FLASH_CR_MER1);
Ownasaurus 2:77b20c9b1933 659
Ownasaurus 2:77b20c9b1933 660 }
Ownasaurus 2:77b20c9b1933 661 /* Return the Erase Status */
Ownasaurus 2:77b20c9b1933 662 return status;
Ownasaurus 2:77b20c9b1933 663 }
Ownasaurus 2:77b20c9b1933 664
Ownasaurus 2:77b20c9b1933 665
Ownasaurus 2:77b20c9b1933 666 /**
Ownasaurus 2:77b20c9b1933 667 * @brief Erases all FLASH Sectors in Bank 2.
Ownasaurus 2:77b20c9b1933 668 *
Ownasaurus 2:77b20c9b1933 669 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 670 *
Ownasaurus 2:77b20c9b1933 671 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 672 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 673 *
Ownasaurus 2:77b20c9b1933 674 * @param VoltageRange: The device voltage range which defines the erase parallelism.
Ownasaurus 2:77b20c9b1933 675 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 676 * @arg VoltageRange_1: when the device voltage range is 1.8V to 2.1V,
Ownasaurus 2:77b20c9b1933 677 * the operation will be done by byte (8-bit)
Ownasaurus 2:77b20c9b1933 678 * @arg VoltageRange_2: when the device voltage range is 2.1V to 2.7V,
Ownasaurus 2:77b20c9b1933 679 * the operation will be done by half word (16-bit)
Ownasaurus 2:77b20c9b1933 680 * @arg VoltageRange_3: when the device voltage range is 2.7V to 3.6V,
Ownasaurus 2:77b20c9b1933 681 * the operation will be done by word (32-bit)
Ownasaurus 2:77b20c9b1933 682 * @arg VoltageRange_4: when the device voltage range is 2.7V to 3.6V + External Vpp,
Ownasaurus 2:77b20c9b1933 683 * the operation will be done by double word (64-bit)
Ownasaurus 2:77b20c9b1933 684 *
Ownasaurus 2:77b20c9b1933 685 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 686 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 687 */
Ownasaurus 2:77b20c9b1933 688 FLASH_Status FLASH_EraseAllBank2Sectors(uint8_t VoltageRange)
Ownasaurus 2:77b20c9b1933 689 {
Ownasaurus 2:77b20c9b1933 690 uint32_t tmp_psize = 0x0;
Ownasaurus 2:77b20c9b1933 691 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 692
Ownasaurus 2:77b20c9b1933 693 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 694 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 695 assert_param(IS_VOLTAGERANGE(VoltageRange));
Ownasaurus 2:77b20c9b1933 696
Ownasaurus 2:77b20c9b1933 697 if(VoltageRange == VoltageRange_1)
Ownasaurus 2:77b20c9b1933 698 {
Ownasaurus 2:77b20c9b1933 699 tmp_psize = FLASH_PSIZE_BYTE;
Ownasaurus 2:77b20c9b1933 700 }
Ownasaurus 2:77b20c9b1933 701 else if(VoltageRange == VoltageRange_2)
Ownasaurus 2:77b20c9b1933 702 {
Ownasaurus 2:77b20c9b1933 703 tmp_psize = FLASH_PSIZE_HALF_WORD;
Ownasaurus 2:77b20c9b1933 704 }
Ownasaurus 2:77b20c9b1933 705 else if(VoltageRange == VoltageRange_3)
Ownasaurus 2:77b20c9b1933 706 {
Ownasaurus 2:77b20c9b1933 707 tmp_psize = FLASH_PSIZE_WORD;
Ownasaurus 2:77b20c9b1933 708 }
Ownasaurus 2:77b20c9b1933 709 else
Ownasaurus 2:77b20c9b1933 710 {
Ownasaurus 2:77b20c9b1933 711 tmp_psize = FLASH_PSIZE_DOUBLE_WORD;
Ownasaurus 2:77b20c9b1933 712 }
Ownasaurus 2:77b20c9b1933 713 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 714 {
Ownasaurus 2:77b20c9b1933 715 /* if the previous operation is completed, proceed to erase all sectors */
Ownasaurus 2:77b20c9b1933 716 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 717 FLASH->CR |= tmp_psize;
Ownasaurus 2:77b20c9b1933 718 FLASH->CR |= FLASH_CR_MER2;
Ownasaurus 2:77b20c9b1933 719 FLASH->CR |= FLASH_CR_STRT;
Ownasaurus 2:77b20c9b1933 720
Ownasaurus 2:77b20c9b1933 721 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 722 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 723
Ownasaurus 2:77b20c9b1933 724 /* if the erase operation is completed, disable the MER Bit */
Ownasaurus 2:77b20c9b1933 725 FLASH->CR &= (~FLASH_CR_MER2);
Ownasaurus 2:77b20c9b1933 726
Ownasaurus 2:77b20c9b1933 727 }
Ownasaurus 2:77b20c9b1933 728 /* Return the Erase Status */
Ownasaurus 2:77b20c9b1933 729 return status;
Ownasaurus 2:77b20c9b1933 730 }
Ownasaurus 2:77b20c9b1933 731
Ownasaurus 2:77b20c9b1933 732 /**
Ownasaurus 2:77b20c9b1933 733 * @brief Programs a double word (64-bit) at a specified address.
Ownasaurus 2:77b20c9b1933 734 * @note This function must be used when the device voltage range is from
Ownasaurus 2:77b20c9b1933 735 * 2.7V to 3.6V and an External Vpp is present.
Ownasaurus 2:77b20c9b1933 736 *
Ownasaurus 2:77b20c9b1933 737 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 738 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 739 *
Ownasaurus 2:77b20c9b1933 740 * @param Address: specifies the address to be programmed.
Ownasaurus 2:77b20c9b1933 741 * @param Data: specifies the data to be programmed.
Ownasaurus 2:77b20c9b1933 742 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 743 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 744 */
Ownasaurus 2:77b20c9b1933 745 FLASH_Status FLASH_ProgramDoubleWord(uint32_t Address, uint64_t Data)
Ownasaurus 2:77b20c9b1933 746 {
Ownasaurus 2:77b20c9b1933 747 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 748
Ownasaurus 2:77b20c9b1933 749 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 750 assert_param(IS_FLASH_ADDRESS(Address));
Ownasaurus 2:77b20c9b1933 751
Ownasaurus 2:77b20c9b1933 752 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 753 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 754
Ownasaurus 2:77b20c9b1933 755 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 756 {
Ownasaurus 2:77b20c9b1933 757 /* if the previous operation is completed, proceed to program the new data */
Ownasaurus 2:77b20c9b1933 758 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 759 FLASH->CR |= FLASH_PSIZE_DOUBLE_WORD;
Ownasaurus 2:77b20c9b1933 760 FLASH->CR |= FLASH_CR_PG;
Ownasaurus 2:77b20c9b1933 761
Ownasaurus 2:77b20c9b1933 762 *(__IO uint64_t*)Address = Data;
Ownasaurus 2:77b20c9b1933 763
Ownasaurus 2:77b20c9b1933 764 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 765 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 766
Ownasaurus 2:77b20c9b1933 767 /* if the program operation is completed, disable the PG Bit */
Ownasaurus 2:77b20c9b1933 768 FLASH->CR &= (~FLASH_CR_PG);
Ownasaurus 2:77b20c9b1933 769 }
Ownasaurus 2:77b20c9b1933 770 /* Return the Program Status */
Ownasaurus 2:77b20c9b1933 771 return status;
Ownasaurus 2:77b20c9b1933 772 }
Ownasaurus 2:77b20c9b1933 773
Ownasaurus 2:77b20c9b1933 774 /**
Ownasaurus 2:77b20c9b1933 775 * @brief Programs a word (32-bit) at a specified address.
Ownasaurus 2:77b20c9b1933 776 *
Ownasaurus 2:77b20c9b1933 777 * @note This function must be used when the device voltage range is from 2.7V to 3.6V.
Ownasaurus 2:77b20c9b1933 778 *
Ownasaurus 2:77b20c9b1933 779 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 780 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 781 *
Ownasaurus 2:77b20c9b1933 782 * @param Address: specifies the address to be programmed.
Ownasaurus 2:77b20c9b1933 783 * This parameter can be any address in Program memory zone or in OTP zone.
Ownasaurus 2:77b20c9b1933 784 * @param Data: specifies the data to be programmed.
Ownasaurus 2:77b20c9b1933 785 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 786 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 787 */
Ownasaurus 2:77b20c9b1933 788 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Ownasaurus 2:77b20c9b1933 789 {
Ownasaurus 2:77b20c9b1933 790 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 791
Ownasaurus 2:77b20c9b1933 792 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 793 assert_param(IS_FLASH_ADDRESS(Address));
Ownasaurus 2:77b20c9b1933 794
Ownasaurus 2:77b20c9b1933 795 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 796 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 797
Ownasaurus 2:77b20c9b1933 798 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 799 {
Ownasaurus 2:77b20c9b1933 800 /* if the previous operation is completed, proceed to program the new data */
Ownasaurus 2:77b20c9b1933 801 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 802 FLASH->CR |= FLASH_PSIZE_WORD;
Ownasaurus 2:77b20c9b1933 803 FLASH->CR |= FLASH_CR_PG;
Ownasaurus 2:77b20c9b1933 804
Ownasaurus 2:77b20c9b1933 805 *(__IO uint32_t*)Address = Data;
Ownasaurus 2:77b20c9b1933 806
Ownasaurus 2:77b20c9b1933 807 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 808 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 809
Ownasaurus 2:77b20c9b1933 810 /* if the program operation is completed, disable the PG Bit */
Ownasaurus 2:77b20c9b1933 811 FLASH->CR &= (~FLASH_CR_PG);
Ownasaurus 2:77b20c9b1933 812 }
Ownasaurus 2:77b20c9b1933 813 /* Return the Program Status */
Ownasaurus 2:77b20c9b1933 814 return status;
Ownasaurus 2:77b20c9b1933 815 }
Ownasaurus 2:77b20c9b1933 816
Ownasaurus 2:77b20c9b1933 817 /**
Ownasaurus 2:77b20c9b1933 818 * @brief Programs a half word (16-bit) at a specified address.
Ownasaurus 2:77b20c9b1933 819 * @note This function must be used when the device voltage range is from 2.1V to 3.6V.
Ownasaurus 2:77b20c9b1933 820 *
Ownasaurus 2:77b20c9b1933 821 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 822 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 823 *
Ownasaurus 2:77b20c9b1933 824 * @param Address: specifies the address to be programmed.
Ownasaurus 2:77b20c9b1933 825 * This parameter can be any address in Program memory zone or in OTP zone.
Ownasaurus 2:77b20c9b1933 826 * @param Data: specifies the data to be programmed.
Ownasaurus 2:77b20c9b1933 827 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 828 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 829 */
Ownasaurus 2:77b20c9b1933 830 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
Ownasaurus 2:77b20c9b1933 831 {
Ownasaurus 2:77b20c9b1933 832 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 833
Ownasaurus 2:77b20c9b1933 834 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 835 assert_param(IS_FLASH_ADDRESS(Address));
Ownasaurus 2:77b20c9b1933 836
Ownasaurus 2:77b20c9b1933 837 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 838 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 839
Ownasaurus 2:77b20c9b1933 840 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 841 {
Ownasaurus 2:77b20c9b1933 842 /* if the previous operation is completed, proceed to program the new data */
Ownasaurus 2:77b20c9b1933 843 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 844 FLASH->CR |= FLASH_PSIZE_HALF_WORD;
Ownasaurus 2:77b20c9b1933 845 FLASH->CR |= FLASH_CR_PG;
Ownasaurus 2:77b20c9b1933 846
Ownasaurus 2:77b20c9b1933 847 *(__IO uint16_t*)Address = Data;
Ownasaurus 2:77b20c9b1933 848
Ownasaurus 2:77b20c9b1933 849 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 850 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 851
Ownasaurus 2:77b20c9b1933 852 /* if the program operation is completed, disable the PG Bit */
Ownasaurus 2:77b20c9b1933 853 FLASH->CR &= (~FLASH_CR_PG);
Ownasaurus 2:77b20c9b1933 854 }
Ownasaurus 2:77b20c9b1933 855 /* Return the Program Status */
Ownasaurus 2:77b20c9b1933 856 return status;
Ownasaurus 2:77b20c9b1933 857 }
Ownasaurus 2:77b20c9b1933 858
Ownasaurus 2:77b20c9b1933 859 /**
Ownasaurus 2:77b20c9b1933 860 * @brief Programs a byte (8-bit) at a specified address.
Ownasaurus 2:77b20c9b1933 861 * @note This function can be used within all the device supply voltage ranges.
Ownasaurus 2:77b20c9b1933 862 *
Ownasaurus 2:77b20c9b1933 863 * @note If an erase and a program operations are requested simultaneously,
Ownasaurus 2:77b20c9b1933 864 * the erase operation is performed before the program one.
Ownasaurus 2:77b20c9b1933 865 *
Ownasaurus 2:77b20c9b1933 866 * @param Address: specifies the address to be programmed.
Ownasaurus 2:77b20c9b1933 867 * This parameter can be any address in Program memory zone or in OTP zone.
Ownasaurus 2:77b20c9b1933 868 * @param Data: specifies the data to be programmed.
Ownasaurus 2:77b20c9b1933 869 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 870 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 871 */
Ownasaurus 2:77b20c9b1933 872 FLASH_Status FLASH_ProgramByte(uint32_t Address, uint8_t Data)
Ownasaurus 2:77b20c9b1933 873 {
Ownasaurus 2:77b20c9b1933 874 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 875
Ownasaurus 2:77b20c9b1933 876 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 877 assert_param(IS_FLASH_ADDRESS(Address));
Ownasaurus 2:77b20c9b1933 878
Ownasaurus 2:77b20c9b1933 879 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 880 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 881
Ownasaurus 2:77b20c9b1933 882 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 883 {
Ownasaurus 2:77b20c9b1933 884 /* if the previous operation is completed, proceed to program the new data */
Ownasaurus 2:77b20c9b1933 885 FLASH->CR &= CR_PSIZE_MASK;
Ownasaurus 2:77b20c9b1933 886 FLASH->CR |= FLASH_PSIZE_BYTE;
Ownasaurus 2:77b20c9b1933 887 FLASH->CR |= FLASH_CR_PG;
Ownasaurus 2:77b20c9b1933 888
Ownasaurus 2:77b20c9b1933 889 *(__IO uint8_t*)Address = Data;
Ownasaurus 2:77b20c9b1933 890
Ownasaurus 2:77b20c9b1933 891 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 892 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 893
Ownasaurus 2:77b20c9b1933 894 /* if the program operation is completed, disable the PG Bit */
Ownasaurus 2:77b20c9b1933 895 FLASH->CR &= (~FLASH_CR_PG);
Ownasaurus 2:77b20c9b1933 896 }
Ownasaurus 2:77b20c9b1933 897
Ownasaurus 2:77b20c9b1933 898 /* Return the Program Status */
Ownasaurus 2:77b20c9b1933 899 return status;
Ownasaurus 2:77b20c9b1933 900 }
Ownasaurus 2:77b20c9b1933 901
Ownasaurus 2:77b20c9b1933 902 /**
Ownasaurus 2:77b20c9b1933 903 * @}
Ownasaurus 2:77b20c9b1933 904 */
Ownasaurus 2:77b20c9b1933 905
Ownasaurus 2:77b20c9b1933 906 /** @defgroup FLASH_Group3 Option Bytes Programming functions
Ownasaurus 2:77b20c9b1933 907 * @brief Option Bytes Programming functions
Ownasaurus 2:77b20c9b1933 908 *
Ownasaurus 2:77b20c9b1933 909 @verbatim
Ownasaurus 2:77b20c9b1933 910 ===============================================================================
Ownasaurus 2:77b20c9b1933 911 ##### Option Bytes Programming functions #####
Ownasaurus 2:77b20c9b1933 912 ===============================================================================
Ownasaurus 2:77b20c9b1933 913 [..]
Ownasaurus 2:77b20c9b1933 914 This group includes the following functions:
Ownasaurus 2:77b20c9b1933 915 (+) void FLASH_OB_Unlock(void)
Ownasaurus 2:77b20c9b1933 916 (+) void FLASH_OB_Lock(void)
Ownasaurus 2:77b20c9b1933 917 (+) void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 918 (+) void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 919 (+) void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PCROPSelect)
Ownasaurus 2:77b20c9b1933 920 (+) void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 921 (+) void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 922 (+) void FLASH_OB_RDPConfig(uint8_t OB_RDP)
Ownasaurus 2:77b20c9b1933 923 (+) void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
Ownasaurus 2:77b20c9b1933 924 (+) void FLASH_OB_BORConfig(uint8_t OB_BOR)
Ownasaurus 2:77b20c9b1933 925 (+) FLASH_Status FLASH_ProgramOTP(uint32_t Address, uint32_t Data)
Ownasaurus 2:77b20c9b1933 926 (+) FLASH_Status FLASH_OB_Launch(void)
Ownasaurus 2:77b20c9b1933 927 (+) uint32_t FLASH_OB_GetUser(void)
Ownasaurus 2:77b20c9b1933 928 (+) uint8_t FLASH_OB_GetWRP(void)
Ownasaurus 2:77b20c9b1933 929 (+) uint8_t FLASH_OB_GetWRP1(void)
Ownasaurus 2:77b20c9b1933 930 (+) uint8_t FLASH_OB_GetPCROP(void)
Ownasaurus 2:77b20c9b1933 931 (+) uint8_t FLASH_OB_GetPCROP1(void)
Ownasaurus 2:77b20c9b1933 932 (+) uint8_t FLASH_OB_GetRDP(void)
Ownasaurus 2:77b20c9b1933 933 (+) uint8_t FLASH_OB_GetBOR(void)
Ownasaurus 2:77b20c9b1933 934 [..]
Ownasaurus 2:77b20c9b1933 935 The following function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 936 (+) void FLASH_OB_BootConfig(uint8_t OB_BOOT)
Ownasaurus 2:77b20c9b1933 937 [..]
Ownasaurus 2:77b20c9b1933 938 Any operation of erase or program should follow these steps:
Ownasaurus 2:77b20c9b1933 939 (#) Call the FLASH_OB_Unlock() function to enable the FLASH option control
Ownasaurus 2:77b20c9b1933 940 register access
Ownasaurus 2:77b20c9b1933 941
Ownasaurus 2:77b20c9b1933 942 (#) Call one or several functions to program the desired Option Bytes:
Ownasaurus 2:77b20c9b1933 943 (++) void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 944 => to Enable/Disable the desired sector write protection
Ownasaurus 2:77b20c9b1933 945 (++) void FLASH_OB_RDPConfig(uint8_t OB_RDP) => to set the desired read
Ownasaurus 2:77b20c9b1933 946 Protection Level
Ownasaurus 2:77b20c9b1933 947 (++) void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
Ownasaurus 2:77b20c9b1933 948 => to configure the user Option Bytes.
Ownasaurus 2:77b20c9b1933 949 (++) void FLASH_OB_BORConfig(uint8_t OB_BOR) => to set the BOR Level
Ownasaurus 2:77b20c9b1933 950
Ownasaurus 2:77b20c9b1933 951 (#) Once all needed Option Bytes to be programmed are correctly written,
Ownasaurus 2:77b20c9b1933 952 call the FLASH_OB_Launch() function to launch the Option Bytes
Ownasaurus 2:77b20c9b1933 953 programming process.
Ownasaurus 2:77b20c9b1933 954
Ownasaurus 2:77b20c9b1933 955 -@- When changing the IWDG mode from HW to SW or from SW to HW, a system
Ownasaurus 2:77b20c9b1933 956 reset is needed to make the change effective.
Ownasaurus 2:77b20c9b1933 957
Ownasaurus 2:77b20c9b1933 958 (#) Call the FLASH_OB_Lock() function to disable the FLASH option control
Ownasaurus 2:77b20c9b1933 959 register access (recommended to protect the Option Bytes against
Ownasaurus 2:77b20c9b1933 960 possible unwanted operations)
Ownasaurus 2:77b20c9b1933 961
Ownasaurus 2:77b20c9b1933 962 @endverbatim
Ownasaurus 2:77b20c9b1933 963 * @{
Ownasaurus 2:77b20c9b1933 964 */
Ownasaurus 2:77b20c9b1933 965
Ownasaurus 2:77b20c9b1933 966 /**
Ownasaurus 2:77b20c9b1933 967 * @brief Unlocks the FLASH Option Control Registers access.
Ownasaurus 2:77b20c9b1933 968 * @param None
Ownasaurus 2:77b20c9b1933 969 * @retval None
Ownasaurus 2:77b20c9b1933 970 */
Ownasaurus 2:77b20c9b1933 971 void FLASH_OB_Unlock(void)
Ownasaurus 2:77b20c9b1933 972 {
Ownasaurus 2:77b20c9b1933 973 if((FLASH->OPTCR & FLASH_OPTCR_OPTLOCK) != RESET)
Ownasaurus 2:77b20c9b1933 974 {
Ownasaurus 2:77b20c9b1933 975 /* Authorizes the Option Byte register programming */
Ownasaurus 2:77b20c9b1933 976 FLASH->OPTKEYR = FLASH_OPT_KEY1;
Ownasaurus 2:77b20c9b1933 977 FLASH->OPTKEYR = FLASH_OPT_KEY2;
Ownasaurus 2:77b20c9b1933 978 }
Ownasaurus 2:77b20c9b1933 979 }
Ownasaurus 2:77b20c9b1933 980
Ownasaurus 2:77b20c9b1933 981 /**
Ownasaurus 2:77b20c9b1933 982 * @brief Locks the FLASH Option Control Registers access.
Ownasaurus 2:77b20c9b1933 983 * @param None
Ownasaurus 2:77b20c9b1933 984 * @retval None
Ownasaurus 2:77b20c9b1933 985 */
Ownasaurus 2:77b20c9b1933 986 void FLASH_OB_Lock(void)
Ownasaurus 2:77b20c9b1933 987 {
Ownasaurus 2:77b20c9b1933 988 /* Set the OPTLOCK Bit to lock the FLASH Option Byte Registers access */
Ownasaurus 2:77b20c9b1933 989 FLASH->OPTCR |= FLASH_OPTCR_OPTLOCK;
Ownasaurus 2:77b20c9b1933 990 }
Ownasaurus 2:77b20c9b1933 991
Ownasaurus 2:77b20c9b1933 992 /**
Ownasaurus 2:77b20c9b1933 993 * @brief Enables or disables the write protection of the desired sectors, for the first
Ownasaurus 2:77b20c9b1933 994 * 1 Mb of the Flash
Ownasaurus 2:77b20c9b1933 995 *
Ownasaurus 2:77b20c9b1933 996 * @note When the memory read protection level is selected (RDP level = 1),
Ownasaurus 2:77b20c9b1933 997 * it is not possible to program or erase the flash sector i if CortexM4
Ownasaurus 2:77b20c9b1933 998 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
Ownasaurus 2:77b20c9b1933 999 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
Ownasaurus 2:77b20c9b1933 1000 *
Ownasaurus 2:77b20c9b1933 1001 * @param OB_WRP: specifies the sector(s) to be write protected or unprotected.
Ownasaurus 2:77b20c9b1933 1002 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1003 * @arg OB_WRP: A value between OB_WRP_Sector0 and OB_WRP_Sector11
Ownasaurus 2:77b20c9b1933 1004 * @arg OB_WRP_Sector_All
Ownasaurus 2:77b20c9b1933 1005 * @param Newstate: new state of the Write Protection.
Ownasaurus 2:77b20c9b1933 1006 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 1007 * @retval None
Ownasaurus 2:77b20c9b1933 1008 */
Ownasaurus 2:77b20c9b1933 1009 void FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 1010 {
Ownasaurus 2:77b20c9b1933 1011 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1012
Ownasaurus 2:77b20c9b1933 1013 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1014 assert_param(IS_OB_WRP(OB_WRP));
Ownasaurus 2:77b20c9b1933 1015 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 1016
Ownasaurus 2:77b20c9b1933 1017 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1018
Ownasaurus 2:77b20c9b1933 1019 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1020 {
Ownasaurus 2:77b20c9b1933 1021 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 1022 {
Ownasaurus 2:77b20c9b1933 1023 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~OB_WRP);
Ownasaurus 2:77b20c9b1933 1024 }
Ownasaurus 2:77b20c9b1933 1025 else
Ownasaurus 2:77b20c9b1933 1026 {
Ownasaurus 2:77b20c9b1933 1027 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)OB_WRP;
Ownasaurus 2:77b20c9b1933 1028 }
Ownasaurus 2:77b20c9b1933 1029 }
Ownasaurus 2:77b20c9b1933 1030 }
Ownasaurus 2:77b20c9b1933 1031
Ownasaurus 2:77b20c9b1933 1032 /**
Ownasaurus 2:77b20c9b1933 1033 * @brief Enables or disables the write protection of the desired sectors, for the second
Ownasaurus 2:77b20c9b1933 1034 * 1 Mb of the Flash
Ownasaurus 2:77b20c9b1933 1035 *
Ownasaurus 2:77b20c9b1933 1036 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 1037 *
Ownasaurus 2:77b20c9b1933 1038 * @note When the memory read out protection is selected (RDP level = 1),
Ownasaurus 2:77b20c9b1933 1039 * it is not possible to program or erase the flash sector i if CortexM4
Ownasaurus 2:77b20c9b1933 1040 * debug features are connected or boot code is executed in RAM, even if nWRPi = 1
Ownasaurus 2:77b20c9b1933 1041 * @note Active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
Ownasaurus 2:77b20c9b1933 1042 *
Ownasaurus 2:77b20c9b1933 1043 * @param OB_WRP: specifies the sector(s) to be write protected or unprotected.
Ownasaurus 2:77b20c9b1933 1044 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1045 * @arg OB_WRP: A value between OB_WRP_Sector12 and OB_WRP_Sector23
Ownasaurus 2:77b20c9b1933 1046 * @arg OB_WRP_Sector_All
Ownasaurus 2:77b20c9b1933 1047 * @param Newstate: new state of the Write Protection.
Ownasaurus 2:77b20c9b1933 1048 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 1049 * @retval None
Ownasaurus 2:77b20c9b1933 1050 */
Ownasaurus 2:77b20c9b1933 1051 void FLASH_OB_WRP1Config(uint32_t OB_WRP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 1052 {
Ownasaurus 2:77b20c9b1933 1053 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1054
Ownasaurus 2:77b20c9b1933 1055 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1056 assert_param(IS_OB_WRP(OB_WRP));
Ownasaurus 2:77b20c9b1933 1057 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 1058
Ownasaurus 2:77b20c9b1933 1059 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1060
Ownasaurus 2:77b20c9b1933 1061 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1062 {
Ownasaurus 2:77b20c9b1933 1063 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 1064 {
Ownasaurus 2:77b20c9b1933 1065 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~OB_WRP);
Ownasaurus 2:77b20c9b1933 1066 }
Ownasaurus 2:77b20c9b1933 1067 else
Ownasaurus 2:77b20c9b1933 1068 {
Ownasaurus 2:77b20c9b1933 1069 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)OB_WRP;
Ownasaurus 2:77b20c9b1933 1070 }
Ownasaurus 2:77b20c9b1933 1071 }
Ownasaurus 2:77b20c9b1933 1072 }
Ownasaurus 2:77b20c9b1933 1073
Ownasaurus 2:77b20c9b1933 1074 /**
Ownasaurus 2:77b20c9b1933 1075 * @brief Select the Protection Mode (SPRMOD).
Ownasaurus 2:77b20c9b1933 1076 *
Ownasaurus 2:77b20c9b1933 1077 * @note This function can be used only for STM32F42xxx/43xxx and STM32F401xx/411xE devices.
Ownasaurus 2:77b20c9b1933 1078 *
Ownasaurus 2:77b20c9b1933 1079 * @note After PCROP activation, Option Byte modification is not possible.
Ownasaurus 2:77b20c9b1933 1080 * Exception made for the global Read Out Protection modification level (level1 to level0)
Ownasaurus 2:77b20c9b1933 1081 * @note Once SPRMOD bit is active unprotection of a protected sector is not possible
Ownasaurus 2:77b20c9b1933 1082 *
Ownasaurus 2:77b20c9b1933 1083 * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag
Ownasaurus 2:77b20c9b1933 1084 *
Ownasaurus 2:77b20c9b1933 1085 * @note Some Precautions should be taken when activating the PCROP feature :
Ownasaurus 2:77b20c9b1933 1086 * The active value of nWRPi bits is inverted when PCROP mode is active, this means if SPRMOD = 1
Ownasaurus 2:77b20c9b1933 1087 * and WRPi = 1 (default value), then the user sector i is read/write protected.
Ownasaurus 2:77b20c9b1933 1088 * In order to avoid activation of PCROP Mode for undesired sectors, please follow the
Ownasaurus 2:77b20c9b1933 1089 * below safety sequence :
Ownasaurus 2:77b20c9b1933 1090 * - Disable PCROP for all Sectors using FLASH_OB_PCROPConfig(OB_PCROP_Sector_All, DISABLE) function
Ownasaurus 2:77b20c9b1933 1091 * for Bank1 or FLASH_OB_PCROP1Config(OB_PCROP_Sector_All, DISABLE) function for Bank2
Ownasaurus 2:77b20c9b1933 1092 * - Enable PCROP for the desired Sector i using FLASH_OB_PCROPConfig(Sector i, ENABLE) function
Ownasaurus 2:77b20c9b1933 1093 * - Activate the PCROP Mode FLASH_OB_PCROPSelectionConfig() function.
Ownasaurus 2:77b20c9b1933 1094 *
Ownasaurus 2:77b20c9b1933 1095 * @param OB_PCROP: Select the Protection Mode of nWPRi bits
Ownasaurus 2:77b20c9b1933 1096 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1097 * @arg OB_PcROP_Disable: nWRPi control the write protection of respective user sectors.
Ownasaurus 2:77b20c9b1933 1098 * @arg OB_PcROP_Enable: nWRPi control the read&write protection (PCROP) of respective user sectors.
Ownasaurus 2:77b20c9b1933 1099 * @retval None
Ownasaurus 2:77b20c9b1933 1100 */
Ownasaurus 2:77b20c9b1933 1101 void FLASH_OB_PCROPSelectionConfig(uint8_t OB_PcROP)
Ownasaurus 2:77b20c9b1933 1102 {
Ownasaurus 2:77b20c9b1933 1103 uint8_t optiontmp = 0xFF;
Ownasaurus 2:77b20c9b1933 1104
Ownasaurus 2:77b20c9b1933 1105 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1106 assert_param(IS_OB_PCROP_SELECT(OB_PcROP));
Ownasaurus 2:77b20c9b1933 1107
Ownasaurus 2:77b20c9b1933 1108 /* Mask SPRMOD bit */
Ownasaurus 2:77b20c9b1933 1109 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE3_ADDRESS) & (uint8_t)0x7F);
Ownasaurus 2:77b20c9b1933 1110 /* Update Option Byte */
Ownasaurus 2:77b20c9b1933 1111 *(__IO uint8_t *)OPTCR_BYTE3_ADDRESS = (uint8_t)(OB_PcROP | optiontmp);
Ownasaurus 2:77b20c9b1933 1112
Ownasaurus 2:77b20c9b1933 1113 }
Ownasaurus 2:77b20c9b1933 1114
Ownasaurus 2:77b20c9b1933 1115 /**
Ownasaurus 2:77b20c9b1933 1116 * @brief Enables or disables the read/write protection (PCROP) of the desired
Ownasaurus 2:77b20c9b1933 1117 * sectors, for the first 1 MB of the Flash.
Ownasaurus 2:77b20c9b1933 1118 *
Ownasaurus 2:77b20c9b1933 1119 * @note This function can be used only for STM32F42xxx/43xxx , STM32F401xx/411xE
Ownasaurus 2:77b20c9b1933 1120 * and STM32F412xG devices.
Ownasaurus 2:77b20c9b1933 1121 *
Ownasaurus 2:77b20c9b1933 1122 * @param OB_PCROP: specifies the sector(s) to be read/write protected or unprotected.
Ownasaurus 2:77b20c9b1933 1123 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1124 * @arg OB_PCROP: A value between OB_PCROP_Sector0 and OB_PCROP_Sector11 for
Ownasaurus 2:77b20c9b1933 1125 * STM32F42xxx/43xxx devices and between OB_PCROP_Sector0 and
Ownasaurus 2:77b20c9b1933 1126 * OB_PCROP_Sector5 for STM32F401xx/411xE devices.
Ownasaurus 2:77b20c9b1933 1127 * @arg OB_PCROP_Sector_All
Ownasaurus 2:77b20c9b1933 1128 * @param Newstate: new state of the Write Protection.
Ownasaurus 2:77b20c9b1933 1129 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 1130 * @retval None
Ownasaurus 2:77b20c9b1933 1131 */
Ownasaurus 2:77b20c9b1933 1132 void FLASH_OB_PCROPConfig(uint32_t OB_PCROP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 1133 {
Ownasaurus 2:77b20c9b1933 1134 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1135
Ownasaurus 2:77b20c9b1933 1136 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1137 assert_param(IS_OB_PCROP(OB_PCROP));
Ownasaurus 2:77b20c9b1933 1138 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 1139
Ownasaurus 2:77b20c9b1933 1140 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1141
Ownasaurus 2:77b20c9b1933 1142 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1143 {
Ownasaurus 2:77b20c9b1933 1144 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 1145 {
Ownasaurus 2:77b20c9b1933 1146 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS |= (uint16_t)OB_PCROP;
Ownasaurus 2:77b20c9b1933 1147 }
Ownasaurus 2:77b20c9b1933 1148 else
Ownasaurus 2:77b20c9b1933 1149 {
Ownasaurus 2:77b20c9b1933 1150 *(__IO uint16_t*)OPTCR_BYTE2_ADDRESS &= (~OB_PCROP);
Ownasaurus 2:77b20c9b1933 1151 }
Ownasaurus 2:77b20c9b1933 1152 }
Ownasaurus 2:77b20c9b1933 1153 }
Ownasaurus 2:77b20c9b1933 1154
Ownasaurus 2:77b20c9b1933 1155 /**
Ownasaurus 2:77b20c9b1933 1156 * @brief Enables or disables the read/write protection (PCROP) of the desired
Ownasaurus 2:77b20c9b1933 1157 * sectors
Ownasaurus 2:77b20c9b1933 1158 *
Ownasaurus 2:77b20c9b1933 1159 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 1160 *
Ownasaurus 2:77b20c9b1933 1161 * @param OB_PCROP: specifies the sector(s) to be read/write protected or unprotected.
Ownasaurus 2:77b20c9b1933 1162 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1163 * @arg OB_PCROP: A value between OB_PCROP_Sector12 and OB_PCROP_Sector23
Ownasaurus 2:77b20c9b1933 1164 * @arg OB_PCROP_Sector_All
Ownasaurus 2:77b20c9b1933 1165 * @param Newstate: new state of the Write Protection.
Ownasaurus 2:77b20c9b1933 1166 * This parameter can be: ENABLE or DISABLE.
Ownasaurus 2:77b20c9b1933 1167 * @retval None
Ownasaurus 2:77b20c9b1933 1168 */
Ownasaurus 2:77b20c9b1933 1169 void FLASH_OB_PCROP1Config(uint32_t OB_PCROP, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 1170 {
Ownasaurus 2:77b20c9b1933 1171 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1172
Ownasaurus 2:77b20c9b1933 1173 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1174 assert_param(IS_OB_PCROP(OB_PCROP));
Ownasaurus 2:77b20c9b1933 1175 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 1176
Ownasaurus 2:77b20c9b1933 1177 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1178
Ownasaurus 2:77b20c9b1933 1179 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1180 {
Ownasaurus 2:77b20c9b1933 1181 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 1182 {
Ownasaurus 2:77b20c9b1933 1183 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS |= (uint16_t)OB_PCROP;
Ownasaurus 2:77b20c9b1933 1184 }
Ownasaurus 2:77b20c9b1933 1185 else
Ownasaurus 2:77b20c9b1933 1186 {
Ownasaurus 2:77b20c9b1933 1187 *(__IO uint16_t*)OPTCR1_BYTE2_ADDRESS &= (~OB_PCROP);
Ownasaurus 2:77b20c9b1933 1188 }
Ownasaurus 2:77b20c9b1933 1189 }
Ownasaurus 2:77b20c9b1933 1190 }
Ownasaurus 2:77b20c9b1933 1191
Ownasaurus 2:77b20c9b1933 1192
Ownasaurus 2:77b20c9b1933 1193 /**
Ownasaurus 2:77b20c9b1933 1194 * @brief Sets the read protection level.
Ownasaurus 2:77b20c9b1933 1195 * @param OB_RDP: specifies the read protection level.
Ownasaurus 2:77b20c9b1933 1196 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1197 * @arg OB_RDP_Level_0: No protection
Ownasaurus 2:77b20c9b1933 1198 * @arg OB_RDP_Level_1: Read protection of the memory
Ownasaurus 2:77b20c9b1933 1199 * @arg OB_RDP_Level_2: Full chip protection
Ownasaurus 2:77b20c9b1933 1200 *
Ownasaurus 2:77b20c9b1933 1201 * /!\ Warning /!\ When enabling OB_RDP level 2 it's no more possible to go back to level 1 or 0
Ownasaurus 2:77b20c9b1933 1202 *
Ownasaurus 2:77b20c9b1933 1203 * @retval None
Ownasaurus 2:77b20c9b1933 1204 */
Ownasaurus 2:77b20c9b1933 1205 void FLASH_OB_RDPConfig(uint8_t OB_RDP)
Ownasaurus 2:77b20c9b1933 1206 {
Ownasaurus 2:77b20c9b1933 1207 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1208
Ownasaurus 2:77b20c9b1933 1209 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1210 assert_param(IS_OB_RDP(OB_RDP));
Ownasaurus 2:77b20c9b1933 1211
Ownasaurus 2:77b20c9b1933 1212 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1213
Ownasaurus 2:77b20c9b1933 1214 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1215 {
Ownasaurus 2:77b20c9b1933 1216 *(__IO uint8_t*)OPTCR_BYTE1_ADDRESS = OB_RDP;
Ownasaurus 2:77b20c9b1933 1217
Ownasaurus 2:77b20c9b1933 1218 }
Ownasaurus 2:77b20c9b1933 1219 }
Ownasaurus 2:77b20c9b1933 1220
Ownasaurus 2:77b20c9b1933 1221 /**
Ownasaurus 2:77b20c9b1933 1222 * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
Ownasaurus 2:77b20c9b1933 1223 * @param OB_IWDG: Selects the IWDG mode
Ownasaurus 2:77b20c9b1933 1224 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1225 * @arg OB_IWDG_SW: Software IWDG selected
Ownasaurus 2:77b20c9b1933 1226 * @arg OB_IWDG_HW: Hardware IWDG selected
Ownasaurus 2:77b20c9b1933 1227 * @param OB_STOP: Reset event when entering STOP mode.
Ownasaurus 2:77b20c9b1933 1228 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1229 * @arg OB_STOP_NoRST: No reset generated when entering in STOP
Ownasaurus 2:77b20c9b1933 1230 * @arg OB_STOP_RST: Reset generated when entering in STOP
Ownasaurus 2:77b20c9b1933 1231 * @param OB_STDBY: Reset event when entering Standby mode.
Ownasaurus 2:77b20c9b1933 1232 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1233 * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY
Ownasaurus 2:77b20c9b1933 1234 * @arg OB_STDBY_RST: Reset generated when entering in STANDBY
Ownasaurus 2:77b20c9b1933 1235 * @retval None
Ownasaurus 2:77b20c9b1933 1236 */
Ownasaurus 2:77b20c9b1933 1237 void FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY)
Ownasaurus 2:77b20c9b1933 1238 {
Ownasaurus 2:77b20c9b1933 1239 uint8_t optiontmp = 0xFF;
Ownasaurus 2:77b20c9b1933 1240 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1241
Ownasaurus 2:77b20c9b1933 1242 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1243 assert_param(IS_OB_IWDG_SOURCE(OB_IWDG));
Ownasaurus 2:77b20c9b1933 1244 assert_param(IS_OB_STOP_SOURCE(OB_STOP));
Ownasaurus 2:77b20c9b1933 1245 assert_param(IS_OB_STDBY_SOURCE(OB_STDBY));
Ownasaurus 2:77b20c9b1933 1246
Ownasaurus 2:77b20c9b1933 1247 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 1248 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1249
Ownasaurus 2:77b20c9b1933 1250 if(status == FLASH_COMPLETE2)
Ownasaurus 2:77b20c9b1933 1251 {
Ownasaurus 2:77b20c9b1933 1252 #if defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F469_479xx)
Ownasaurus 2:77b20c9b1933 1253 /* Mask OPTLOCK, OPTSTRT, BOR_LEV and BFB2 bits */
Ownasaurus 2:77b20c9b1933 1254 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x1F);
Ownasaurus 2:77b20c9b1933 1255 #endif /* STM32F427_437xx || STM32F429_439xx || STM32F469_479xx */
Ownasaurus 2:77b20c9b1933 1256
Ownasaurus 2:77b20c9b1933 1257 #if defined(STM32F40_41xxx) || defined(STM32F401xx) || defined(STM32F410xx) || defined(STM32F411xE) || defined(STM32F446xx)
Ownasaurus 2:77b20c9b1933 1258 /* Mask OPTLOCK, OPTSTRT and BOR_LEV bits */
Ownasaurus 2:77b20c9b1933 1259 optiontmp = (uint8_t)((*(__IO uint8_t *)OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0F);
Ownasaurus 2:77b20c9b1933 1260 #endif /* STM32F40_41xxx || STM32F401xx || STM32F410xx || STM32F411xE || STM32F446xx */
Ownasaurus 2:77b20c9b1933 1261
Ownasaurus 2:77b20c9b1933 1262 /* Update User Option Byte */
Ownasaurus 2:77b20c9b1933 1263 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS = OB_IWDG | (uint8_t)(OB_STDBY | (uint8_t)(OB_STOP | ((uint8_t)optiontmp)));
Ownasaurus 2:77b20c9b1933 1264 }
Ownasaurus 2:77b20c9b1933 1265 }
Ownasaurus 2:77b20c9b1933 1266
Ownasaurus 2:77b20c9b1933 1267 /**
Ownasaurus 2:77b20c9b1933 1268 * @brief Configure the Dual Bank Boot.
Ownasaurus 2:77b20c9b1933 1269 *
Ownasaurus 2:77b20c9b1933 1270 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 1271 *
Ownasaurus 2:77b20c9b1933 1272 * @param OB_BOOT: specifies the Dual Bank Boot Option byte.
Ownasaurus 2:77b20c9b1933 1273 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1274 * @arg OB_Dual_BootEnabled: Dual Bank Boot Enable
Ownasaurus 2:77b20c9b1933 1275 * @arg OB_Dual_BootDisabled: Dual Bank Boot Disabled
Ownasaurus 2:77b20c9b1933 1276 * @retval None
Ownasaurus 2:77b20c9b1933 1277 */
Ownasaurus 2:77b20c9b1933 1278 void FLASH_OB_BootConfig(uint8_t OB_BOOT)
Ownasaurus 2:77b20c9b1933 1279 {
Ownasaurus 2:77b20c9b1933 1280 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1281 assert_param(IS_OB_BOOT(OB_BOOT));
Ownasaurus 2:77b20c9b1933 1282
Ownasaurus 2:77b20c9b1933 1283 /* Set Dual Bank Boot */
Ownasaurus 2:77b20c9b1933 1284 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BFB2);
Ownasaurus 2:77b20c9b1933 1285 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= OB_BOOT;
Ownasaurus 2:77b20c9b1933 1286
Ownasaurus 2:77b20c9b1933 1287 }
Ownasaurus 2:77b20c9b1933 1288
Ownasaurus 2:77b20c9b1933 1289 /**
Ownasaurus 2:77b20c9b1933 1290 * @brief Sets the BOR Level.
Ownasaurus 2:77b20c9b1933 1291 * @param OB_BOR: specifies the Option Bytes BOR Reset Level.
Ownasaurus 2:77b20c9b1933 1292 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1293 * @arg OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V
Ownasaurus 2:77b20c9b1933 1294 * @arg OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V
Ownasaurus 2:77b20c9b1933 1295 * @arg OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V
Ownasaurus 2:77b20c9b1933 1296 * @arg OB_BOR_OFF: Supply voltage ranges from 1.62 to 2.1 V
Ownasaurus 2:77b20c9b1933 1297 * @retval None
Ownasaurus 2:77b20c9b1933 1298 */
Ownasaurus 2:77b20c9b1933 1299 void FLASH_OB_BORConfig(uint8_t OB_BOR)
Ownasaurus 2:77b20c9b1933 1300 {
Ownasaurus 2:77b20c9b1933 1301 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1302 assert_param(IS_OB_BOR(OB_BOR));
Ownasaurus 2:77b20c9b1933 1303
Ownasaurus 2:77b20c9b1933 1304 /* Set the BOR Level */
Ownasaurus 2:77b20c9b1933 1305 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS &= (~FLASH_OPTCR_BOR_LEV);
Ownasaurus 2:77b20c9b1933 1306 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= OB_BOR;
Ownasaurus 2:77b20c9b1933 1307
Ownasaurus 2:77b20c9b1933 1308 }
Ownasaurus 2:77b20c9b1933 1309
Ownasaurus 2:77b20c9b1933 1310 /**
Ownasaurus 2:77b20c9b1933 1311 * @brief Launch the option byte loading.
Ownasaurus 2:77b20c9b1933 1312 * @param None
Ownasaurus 2:77b20c9b1933 1313 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 1314 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 1315 */
Ownasaurus 2:77b20c9b1933 1316 FLASH_Status FLASH_OB_Launch(void)
Ownasaurus 2:77b20c9b1933 1317 {
Ownasaurus 2:77b20c9b1933 1318 FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1319
Ownasaurus 2:77b20c9b1933 1320 /* Set the OPTSTRT bit in OPTCR register */
Ownasaurus 2:77b20c9b1933 1321 *(__IO uint8_t *)OPTCR_BYTE0_ADDRESS |= FLASH_OPTCR_OPTSTRT;
Ownasaurus 2:77b20c9b1933 1322
Ownasaurus 2:77b20c9b1933 1323 /* Wait for last operation to be completed */
Ownasaurus 2:77b20c9b1933 1324 status = FLASH_WaitForLastOperation2();
Ownasaurus 2:77b20c9b1933 1325
Ownasaurus 2:77b20c9b1933 1326 return status;
Ownasaurus 2:77b20c9b1933 1327 }
Ownasaurus 2:77b20c9b1933 1328
Ownasaurus 2:77b20c9b1933 1329 /**
Ownasaurus 2:77b20c9b1933 1330 * @brief Returns the FLASH User Option Bytes values.
Ownasaurus 2:77b20c9b1933 1331 * @param None
Ownasaurus 2:77b20c9b1933 1332 * @retval The FLASH User Option Bytes values: IWDG_SW(Bit0), RST_STOP(Bit1)
Ownasaurus 2:77b20c9b1933 1333 * and RST_STDBY(Bit2).
Ownasaurus 2:77b20c9b1933 1334 */
Ownasaurus 2:77b20c9b1933 1335 uint8_t FLASH_OB_GetUser(void)
Ownasaurus 2:77b20c9b1933 1336 {
Ownasaurus 2:77b20c9b1933 1337 /* Return the User Option Byte */
Ownasaurus 2:77b20c9b1933 1338 return (uint8_t)(FLASH->OPTCR >> 5);
Ownasaurus 2:77b20c9b1933 1339 }
Ownasaurus 2:77b20c9b1933 1340
Ownasaurus 2:77b20c9b1933 1341 /**
Ownasaurus 2:77b20c9b1933 1342 * @brief Returns the FLASH Write Protection Option Bytes value.
Ownasaurus 2:77b20c9b1933 1343 * @param None
Ownasaurus 2:77b20c9b1933 1344 * @retval The FLASH Write Protection Option Bytes value
Ownasaurus 2:77b20c9b1933 1345 */
Ownasaurus 2:77b20c9b1933 1346 uint16_t FLASH_OB_GetWRP(void)
Ownasaurus 2:77b20c9b1933 1347 {
Ownasaurus 2:77b20c9b1933 1348 /* Return the FLASH write protection Register value */
Ownasaurus 2:77b20c9b1933 1349 return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
Ownasaurus 2:77b20c9b1933 1350 }
Ownasaurus 2:77b20c9b1933 1351
Ownasaurus 2:77b20c9b1933 1352 /**
Ownasaurus 2:77b20c9b1933 1353 * @brief Returns the FLASH Write Protection Option Bytes value.
Ownasaurus 2:77b20c9b1933 1354 *
Ownasaurus 2:77b20c9b1933 1355 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 1356 *
Ownasaurus 2:77b20c9b1933 1357 * @param None
Ownasaurus 2:77b20c9b1933 1358 * @retval The FLASH Write Protection Option Bytes value
Ownasaurus 2:77b20c9b1933 1359 */
Ownasaurus 2:77b20c9b1933 1360 uint16_t FLASH_OB_GetWRP1(void)
Ownasaurus 2:77b20c9b1933 1361 {
Ownasaurus 2:77b20c9b1933 1362 /* Return the FLASH write protection Register value */
Ownasaurus 2:77b20c9b1933 1363 return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
Ownasaurus 2:77b20c9b1933 1364 }
Ownasaurus 2:77b20c9b1933 1365
Ownasaurus 2:77b20c9b1933 1366 /**
Ownasaurus 2:77b20c9b1933 1367 * @brief Returns the FLASH PC Read/Write Protection Option Bytes value.
Ownasaurus 2:77b20c9b1933 1368 *
Ownasaurus 2:77b20c9b1933 1369 * @note This function can be used only for STM32F42xxx/43xxx devices and STM32F401xx/411xE devices.
Ownasaurus 2:77b20c9b1933 1370 *
Ownasaurus 2:77b20c9b1933 1371 * @param None
Ownasaurus 2:77b20c9b1933 1372 * @retval The FLASH PC Read/Write Protection Option Bytes value
Ownasaurus 2:77b20c9b1933 1373 */
Ownasaurus 2:77b20c9b1933 1374 uint16_t FLASH_OB_GetPCROP(void)
Ownasaurus 2:77b20c9b1933 1375 {
Ownasaurus 2:77b20c9b1933 1376 /* Return the FLASH PC Read/write protection Register value */
Ownasaurus 2:77b20c9b1933 1377 return (*(__IO uint16_t *)(OPTCR_BYTE2_ADDRESS));
Ownasaurus 2:77b20c9b1933 1378 }
Ownasaurus 2:77b20c9b1933 1379
Ownasaurus 2:77b20c9b1933 1380 /**
Ownasaurus 2:77b20c9b1933 1381 * @brief Returns the FLASH PC Read/Write Protection Option Bytes value.
Ownasaurus 2:77b20c9b1933 1382 *
Ownasaurus 2:77b20c9b1933 1383 * @note This function can be used only for STM32F42xxx/43xxx devices.
Ownasaurus 2:77b20c9b1933 1384 *
Ownasaurus 2:77b20c9b1933 1385 * @param None
Ownasaurus 2:77b20c9b1933 1386 * @retval The FLASH PC Read/Write Protection Option Bytes value
Ownasaurus 2:77b20c9b1933 1387 */
Ownasaurus 2:77b20c9b1933 1388 uint16_t FLASH_OB_GetPCROP1(void)
Ownasaurus 2:77b20c9b1933 1389 {
Ownasaurus 2:77b20c9b1933 1390 /* Return the FLASH write protection Register value */
Ownasaurus 2:77b20c9b1933 1391 return (*(__IO uint16_t *)(OPTCR1_BYTE2_ADDRESS));
Ownasaurus 2:77b20c9b1933 1392 }
Ownasaurus 2:77b20c9b1933 1393
Ownasaurus 2:77b20c9b1933 1394 /**
Ownasaurus 2:77b20c9b1933 1395 * @brief Returns the FLASH Read Protection level.
Ownasaurus 2:77b20c9b1933 1396 * @param None
Ownasaurus 2:77b20c9b1933 1397 * @retval FLASH ReadOut Protection Status:
Ownasaurus 2:77b20c9b1933 1398 * - SET, when OB_RDP_Level_1 or OB_RDP_Level_2 is set
Ownasaurus 2:77b20c9b1933 1399 * - RESET, when OB_RDP_Level_0 is set
Ownasaurus 2:77b20c9b1933 1400 */
Ownasaurus 2:77b20c9b1933 1401 FlagStatus FLASH_OB_GetRDP(void)
Ownasaurus 2:77b20c9b1933 1402 {
Ownasaurus 2:77b20c9b1933 1403 FlagStatus readstatus = RESET;
Ownasaurus 2:77b20c9b1933 1404
Ownasaurus 2:77b20c9b1933 1405 if ((*(__IO uint8_t*)(OPTCR_BYTE1_ADDRESS) != (uint8_t)OB_RDP_Level_0))
Ownasaurus 2:77b20c9b1933 1406 {
Ownasaurus 2:77b20c9b1933 1407 readstatus = SET;
Ownasaurus 2:77b20c9b1933 1408 }
Ownasaurus 2:77b20c9b1933 1409 else
Ownasaurus 2:77b20c9b1933 1410 {
Ownasaurus 2:77b20c9b1933 1411 readstatus = RESET;
Ownasaurus 2:77b20c9b1933 1412 }
Ownasaurus 2:77b20c9b1933 1413 return readstatus;
Ownasaurus 2:77b20c9b1933 1414 }
Ownasaurus 2:77b20c9b1933 1415
Ownasaurus 2:77b20c9b1933 1416 /**
Ownasaurus 2:77b20c9b1933 1417 * @brief Returns the FLASH BOR level.
Ownasaurus 2:77b20c9b1933 1418 * @param None
Ownasaurus 2:77b20c9b1933 1419 * @retval The FLASH BOR level:
Ownasaurus 2:77b20c9b1933 1420 * - OB_BOR_LEVEL3: Supply voltage ranges from 2.7 to 3.6 V
Ownasaurus 2:77b20c9b1933 1421 * - OB_BOR_LEVEL2: Supply voltage ranges from 2.4 to 2.7 V
Ownasaurus 2:77b20c9b1933 1422 * - OB_BOR_LEVEL1: Supply voltage ranges from 2.1 to 2.4 V
Ownasaurus 2:77b20c9b1933 1423 * - OB_BOR_OFF : Supply voltage ranges from 1.62 to 2.1 V
Ownasaurus 2:77b20c9b1933 1424 */
Ownasaurus 2:77b20c9b1933 1425 uint8_t FLASH_OB_GetBOR(void)
Ownasaurus 2:77b20c9b1933 1426 {
Ownasaurus 2:77b20c9b1933 1427 /* Return the FLASH BOR level */
Ownasaurus 2:77b20c9b1933 1428 return (uint8_t)(*(__IO uint8_t *)(OPTCR_BYTE0_ADDRESS) & (uint8_t)0x0C);
Ownasaurus 2:77b20c9b1933 1429 }
Ownasaurus 2:77b20c9b1933 1430
Ownasaurus 2:77b20c9b1933 1431 /**
Ownasaurus 2:77b20c9b1933 1432 * @}
Ownasaurus 2:77b20c9b1933 1433 */
Ownasaurus 2:77b20c9b1933 1434
Ownasaurus 2:77b20c9b1933 1435 /** @defgroup FLASH_Group4 Interrupts and flags management functions
Ownasaurus 2:77b20c9b1933 1436 * @brief Interrupts and flags management functions
Ownasaurus 2:77b20c9b1933 1437 *
Ownasaurus 2:77b20c9b1933 1438 @verbatim
Ownasaurus 2:77b20c9b1933 1439 ===============================================================================
Ownasaurus 2:77b20c9b1933 1440 ##### Interrupts and flags management functions #####
Ownasaurus 2:77b20c9b1933 1441 ===============================================================================
Ownasaurus 2:77b20c9b1933 1442 @endverbatim
Ownasaurus 2:77b20c9b1933 1443 * @{
Ownasaurus 2:77b20c9b1933 1444 */
Ownasaurus 2:77b20c9b1933 1445
Ownasaurus 2:77b20c9b1933 1446 /**
Ownasaurus 2:77b20c9b1933 1447 * @brief Enables or disables the specified FLASH interrupts.
Ownasaurus 2:77b20c9b1933 1448 * @param FLASH_IT: specifies the FLASH interrupt sources to be enabled or disabled.
Ownasaurus 2:77b20c9b1933 1449 * This parameter can be any combination of the following values:
Ownasaurus 2:77b20c9b1933 1450 * @arg FLASH_IT_ERR: FLASH Error Interrupt
Ownasaurus 2:77b20c9b1933 1451 * @arg FLASH_IT_EOP: FLASH end of operation Interrupt
Ownasaurus 2:77b20c9b1933 1452 * @retval None
Ownasaurus 2:77b20c9b1933 1453 */
Ownasaurus 2:77b20c9b1933 1454 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
Ownasaurus 2:77b20c9b1933 1455 {
Ownasaurus 2:77b20c9b1933 1456 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1457 assert_param(IS_FLASH_IT(FLASH_IT));
Ownasaurus 2:77b20c9b1933 1458 assert_param(IS_FUNCTIONAL_STATE(NewState));
Ownasaurus 2:77b20c9b1933 1459
Ownasaurus 2:77b20c9b1933 1460 if(NewState != DISABLE)
Ownasaurus 2:77b20c9b1933 1461 {
Ownasaurus 2:77b20c9b1933 1462 /* Enable the interrupt sources */
Ownasaurus 2:77b20c9b1933 1463 FLASH->CR |= FLASH_IT;
Ownasaurus 2:77b20c9b1933 1464 }
Ownasaurus 2:77b20c9b1933 1465 else
Ownasaurus 2:77b20c9b1933 1466 {
Ownasaurus 2:77b20c9b1933 1467 /* Disable the interrupt sources */
Ownasaurus 2:77b20c9b1933 1468 FLASH->CR &= ~(uint32_t)FLASH_IT;
Ownasaurus 2:77b20c9b1933 1469 }
Ownasaurus 2:77b20c9b1933 1470 }
Ownasaurus 2:77b20c9b1933 1471
Ownasaurus 2:77b20c9b1933 1472 /**
Ownasaurus 2:77b20c9b1933 1473 * @brief Checks whether the specified FLASH flag is set or not.
Ownasaurus 2:77b20c9b1933 1474 * @param FLASH_FLAG: specifies the FLASH flag to check.
Ownasaurus 2:77b20c9b1933 1475 * This parameter can be one of the following values:
Ownasaurus 2:77b20c9b1933 1476 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
Ownasaurus 2:77b20c9b1933 1477 * @arg FLASH_FLAG_OPERR: FLASH operation Error flag
Ownasaurus 2:77b20c9b1933 1478 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
Ownasaurus 2:77b20c9b1933 1479 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
Ownasaurus 2:77b20c9b1933 1480 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
Ownasaurus 2:77b20c9b1933 1481 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
Ownasaurus 2:77b20c9b1933 1482 * @arg FLASH_FLAG_RDERR: FLASH (PCROP) Read Protection error flag (STM32F42xx/43xxx and STM32F401xx/411xE devices)
Ownasaurus 2:77b20c9b1933 1483 * @arg FLASH_FLAG_BSY: FLASH Busy flag
Ownasaurus 2:77b20c9b1933 1484 * @retval The new state of FLASH_FLAG (SET or RESET).
Ownasaurus 2:77b20c9b1933 1485 */
Ownasaurus 2:77b20c9b1933 1486 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
Ownasaurus 2:77b20c9b1933 1487 {
Ownasaurus 2:77b20c9b1933 1488 FlagStatus bitstatus = RESET;
Ownasaurus 2:77b20c9b1933 1489 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1490 assert_param(IS_FLASH_GET_FLAG(FLASH_FLAG));
Ownasaurus 2:77b20c9b1933 1491
Ownasaurus 2:77b20c9b1933 1492 if((FLASH->SR & FLASH_FLAG) != (uint32_t)RESET)
Ownasaurus 2:77b20c9b1933 1493 {
Ownasaurus 2:77b20c9b1933 1494 bitstatus = SET;
Ownasaurus 2:77b20c9b1933 1495 }
Ownasaurus 2:77b20c9b1933 1496 else
Ownasaurus 2:77b20c9b1933 1497 {
Ownasaurus 2:77b20c9b1933 1498 bitstatus = RESET;
Ownasaurus 2:77b20c9b1933 1499 }
Ownasaurus 2:77b20c9b1933 1500 /* Return the new state of FLASH_FLAG (SET or RESET) */
Ownasaurus 2:77b20c9b1933 1501 return bitstatus;
Ownasaurus 2:77b20c9b1933 1502 }
Ownasaurus 2:77b20c9b1933 1503
Ownasaurus 2:77b20c9b1933 1504 /**
Ownasaurus 2:77b20c9b1933 1505 * @brief Clears the FLASH's pending flags.
Ownasaurus 2:77b20c9b1933 1506 * @param FLASH_FLAG: specifies the FLASH flags to clear.
Ownasaurus 2:77b20c9b1933 1507 * This parameter can be any combination of the following values:
Ownasaurus 2:77b20c9b1933 1508 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
Ownasaurus 2:77b20c9b1933 1509 * @arg FLASH_FLAG_OPERR: FLASH operation Error flag
Ownasaurus 2:77b20c9b1933 1510 * @arg FLASH_FLAG_WRPERR: FLASH Write protected error flag
Ownasaurus 2:77b20c9b1933 1511 * @arg FLASH_FLAG_PGAERR: FLASH Programming Alignment error flag
Ownasaurus 2:77b20c9b1933 1512 * @arg FLASH_FLAG_PGPERR: FLASH Programming Parallelism error flag
Ownasaurus 2:77b20c9b1933 1513 * @arg FLASH_FLAG_PGSERR: FLASH Programming Sequence error flag
Ownasaurus 2:77b20c9b1933 1514 * @arg FLASH_FLAG_RDERR: FLASH Read Protection error flag (STM32F42xx/43xxx and STM32F401xx/411xE devices)
Ownasaurus 2:77b20c9b1933 1515 * @retval None
Ownasaurus 2:77b20c9b1933 1516 */
Ownasaurus 2:77b20c9b1933 1517 void FLASH_ClearFlag(uint32_t FLASH_FLAG)
Ownasaurus 2:77b20c9b1933 1518 {
Ownasaurus 2:77b20c9b1933 1519 /* Check the parameters */
Ownasaurus 2:77b20c9b1933 1520 assert_param(IS_FLASH_CLEAR_FLAG(FLASH_FLAG));
Ownasaurus 2:77b20c9b1933 1521
Ownasaurus 2:77b20c9b1933 1522 /* Clear the flags */
Ownasaurus 2:77b20c9b1933 1523 FLASH->SR = FLASH_FLAG;
Ownasaurus 2:77b20c9b1933 1524 }
Ownasaurus 2:77b20c9b1933 1525
Ownasaurus 2:77b20c9b1933 1526 /**
Ownasaurus 2:77b20c9b1933 1527 * @brief Returns the FLASH Status.
Ownasaurus 2:77b20c9b1933 1528 * @param None
Ownasaurus 2:77b20c9b1933 1529 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 1530 * FLASH_ERROR_WRP2, FLASH_ERROR_RD2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 1531 */
Ownasaurus 2:77b20c9b1933 1532 FLASH_Status FLASH_GetStatus(void)
Ownasaurus 2:77b20c9b1933 1533 {
Ownasaurus 2:77b20c9b1933 1534 FLASH_Status flashstatus = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1535
Ownasaurus 2:77b20c9b1933 1536 if((FLASH->SR & FLASH_FLAG_BSY) == FLASH_FLAG_BSY)
Ownasaurus 2:77b20c9b1933 1537 {
Ownasaurus 2:77b20c9b1933 1538 flashstatus = FLASH_BUSY2;
Ownasaurus 2:77b20c9b1933 1539 }
Ownasaurus 2:77b20c9b1933 1540 else
Ownasaurus 2:77b20c9b1933 1541 {
Ownasaurus 2:77b20c9b1933 1542 if((FLASH->SR & FLASH_FLAG_WRPERR) != (uint32_t)0x00)
Ownasaurus 2:77b20c9b1933 1543 {
Ownasaurus 2:77b20c9b1933 1544 flashstatus = FLASH_ERROR_WRP2;
Ownasaurus 2:77b20c9b1933 1545 }
Ownasaurus 2:77b20c9b1933 1546 else
Ownasaurus 2:77b20c9b1933 1547 {
Ownasaurus 2:77b20c9b1933 1548 if((FLASH->SR & FLASH_FLAG_RDERR) != (uint32_t)0x00)
Ownasaurus 2:77b20c9b1933 1549 {
Ownasaurus 2:77b20c9b1933 1550 flashstatus = FLASH_ERROR_RD2;
Ownasaurus 2:77b20c9b1933 1551 }
Ownasaurus 2:77b20c9b1933 1552 else
Ownasaurus 2:77b20c9b1933 1553 {
Ownasaurus 2:77b20c9b1933 1554 if((FLASH->SR & (uint32_t)0xE0) != (uint32_t)0x00)
Ownasaurus 2:77b20c9b1933 1555 {
Ownasaurus 2:77b20c9b1933 1556 flashstatus = FLASH_ERROR_PROGRAM2;
Ownasaurus 2:77b20c9b1933 1557 }
Ownasaurus 2:77b20c9b1933 1558 else
Ownasaurus 2:77b20c9b1933 1559 {
Ownasaurus 2:77b20c9b1933 1560 if((FLASH->SR & FLASH_FLAG_OPERR) != (uint32_t)0x00)
Ownasaurus 2:77b20c9b1933 1561 {
Ownasaurus 2:77b20c9b1933 1562 flashstatus = FLASH_ERROR_OPERATION2;
Ownasaurus 2:77b20c9b1933 1563 }
Ownasaurus 2:77b20c9b1933 1564 else
Ownasaurus 2:77b20c9b1933 1565 {
Ownasaurus 2:77b20c9b1933 1566 flashstatus = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1567 }
Ownasaurus 2:77b20c9b1933 1568 }
Ownasaurus 2:77b20c9b1933 1569 }
Ownasaurus 2:77b20c9b1933 1570 }
Ownasaurus 2:77b20c9b1933 1571 }
Ownasaurus 2:77b20c9b1933 1572 /* Return the FLASH Status */
Ownasaurus 2:77b20c9b1933 1573 return flashstatus;
Ownasaurus 2:77b20c9b1933 1574 }
Ownasaurus 2:77b20c9b1933 1575
Ownasaurus 2:77b20c9b1933 1576 /**
Ownasaurus 2:77b20c9b1933 1577 * @brief Waits for a FLASH operation to complete.
Ownasaurus 2:77b20c9b1933 1578 * @param None
Ownasaurus 2:77b20c9b1933 1579 * @retval FLASH Status: The returned value can be: FLASH_BUSY2, FLASH_ERROR_PROGRAM2,
Ownasaurus 2:77b20c9b1933 1580 * FLASH_ERROR_WRP2, FLASH_ERROR_OPERATION2 or FLASH_COMPLETE2.
Ownasaurus 2:77b20c9b1933 1581 */
Ownasaurus 2:77b20c9b1933 1582 FLASH_Status FLASH_WaitForLastOperation2(void)
Ownasaurus 2:77b20c9b1933 1583 {
Ownasaurus 2:77b20c9b1933 1584 __IO FLASH_Status status = FLASH_COMPLETE2;
Ownasaurus 2:77b20c9b1933 1585
Ownasaurus 2:77b20c9b1933 1586 /* Check for the FLASH Status */
Ownasaurus 2:77b20c9b1933 1587 status = FLASH_GetStatus();
Ownasaurus 2:77b20c9b1933 1588
Ownasaurus 2:77b20c9b1933 1589 /* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
Ownasaurus 2:77b20c9b1933 1590 Even if the FLASH operation fails, the BUSY flag will be reset and an error
Ownasaurus 2:77b20c9b1933 1591 flag will be set */
Ownasaurus 2:77b20c9b1933 1592 while(status == FLASH_BUSY2)
Ownasaurus 2:77b20c9b1933 1593 {
Ownasaurus 2:77b20c9b1933 1594 status = FLASH_GetStatus();
Ownasaurus 2:77b20c9b1933 1595 }
Ownasaurus 2:77b20c9b1933 1596 /* Return the operation status */
Ownasaurus 2:77b20c9b1933 1597 return status;
Ownasaurus 2:77b20c9b1933 1598 }
Ownasaurus 2:77b20c9b1933 1599
Ownasaurus 2:77b20c9b1933 1600 /**
Ownasaurus 2:77b20c9b1933 1601 * @}
Ownasaurus 2:77b20c9b1933 1602 */
Ownasaurus 2:77b20c9b1933 1603
Ownasaurus 2:77b20c9b1933 1604 /**
Ownasaurus 2:77b20c9b1933 1605 * @}
Ownasaurus 2:77b20c9b1933 1606 */
Ownasaurus 2:77b20c9b1933 1607
Ownasaurus 2:77b20c9b1933 1608 /**
Ownasaurus 2:77b20c9b1933 1609 * @}
Ownasaurus 2:77b20c9b1933 1610 */
Ownasaurus 2:77b20c9b1933 1611
Ownasaurus 2:77b20c9b1933 1612 /**
Ownasaurus 2:77b20c9b1933 1613 * @}
Ownasaurus 2:77b20c9b1933 1614 */
Ownasaurus 2:77b20c9b1933 1615
Ownasaurus 2:77b20c9b1933 1616 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Ownasaurus 2:77b20c9b1933 1617