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