mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_L053R8/stm32l0xx_hal_flash_ex.c@323:9e901b0a5aa1, 2014-09-13 (annotated)
- Committer:
- shaoziyang
- Date:
- Sat Sep 13 14:25:46 2014 +0000
- Revision:
- 323:9e901b0a5aa1
- Parent:
- 181:a4cbdfbbd2f4
test with CLOCK_SETUP = 0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 181:a4cbdfbbd2f4 | 1 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 2 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 3 | * @file stm32l0xx_hal_flash_ex.c |
mbed_official | 181:a4cbdfbbd2f4 | 4 | * @author MCD Application Team |
mbed_official | 181:a4cbdfbbd2f4 | 5 | * @version V1.0.0 |
mbed_official | 181:a4cbdfbbd2f4 | 6 | * @date 22-April-2014 |
mbed_official | 181:a4cbdfbbd2f4 | 7 | * @brief FLASH HAL module driver. |
mbed_official | 181:a4cbdfbbd2f4 | 8 | * This file provides firmware functions to manage the following |
mbed_official | 181:a4cbdfbbd2f4 | 9 | * functionalities of the internal FLASH memory: |
mbed_official | 181:a4cbdfbbd2f4 | 10 | * + FLASH Interface configuration |
mbed_official | 181:a4cbdfbbd2f4 | 11 | * + FLASH Memory Programming |
mbed_official | 181:a4cbdfbbd2f4 | 12 | * + DATA EEPROM Programming |
mbed_official | 181:a4cbdfbbd2f4 | 13 | * + Option Bytes Programming |
mbed_official | 181:a4cbdfbbd2f4 | 14 | * + Interrupts and flags management |
mbed_official | 181:a4cbdfbbd2f4 | 15 | * |
mbed_official | 181:a4cbdfbbd2f4 | 16 | * @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 17 | ============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 18 | ##### Flash peripheral Extended features ##### |
mbed_official | 181:a4cbdfbbd2f4 | 19 | ============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 20 | |
mbed_official | 181:a4cbdfbbd2f4 | 21 | [..] Comparing to other products, the FLASH interface for STM32L0xx |
mbed_official | 181:a4cbdfbbd2f4 | 22 | devices contains the following additional features |
mbed_official | 181:a4cbdfbbd2f4 | 23 | (+) DATA_EEPROM memory management |
mbed_official | 181:a4cbdfbbd2f4 | 24 | (+) BOOT option bit configuration |
mbed_official | 181:a4cbdfbbd2f4 | 25 | (+) PCROP protection for all sectors |
mbed_official | 181:a4cbdfbbd2f4 | 26 | |
mbed_official | 181:a4cbdfbbd2f4 | 27 | ##### How to use this driver ##### |
mbed_official | 181:a4cbdfbbd2f4 | 28 | ============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 29 | [..] This driver provides functions to configure and program the FLASH memory |
mbed_official | 181:a4cbdfbbd2f4 | 30 | of all STM32L0xx. It includes: |
mbed_official | 181:a4cbdfbbd2f4 | 31 | (+) Full DATA_EEPROM erase and program management |
mbed_official | 181:a4cbdfbbd2f4 | 32 | (+) Boot activation |
mbed_official | 181:a4cbdfbbd2f4 | 33 | (+) PCROP protection configuration and control for all pages |
mbed_official | 181:a4cbdfbbd2f4 | 34 | |
mbed_official | 181:a4cbdfbbd2f4 | 35 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 36 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 37 | * @attention |
mbed_official | 181:a4cbdfbbd2f4 | 38 | * |
mbed_official | 181:a4cbdfbbd2f4 | 39 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 181:a4cbdfbbd2f4 | 40 | * |
mbed_official | 181:a4cbdfbbd2f4 | 41 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 181:a4cbdfbbd2f4 | 42 | * are permitted provided that the following conditions are met: |
mbed_official | 181:a4cbdfbbd2f4 | 43 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 44 | * this list of conditions and the following disclaimer. |
mbed_official | 181:a4cbdfbbd2f4 | 45 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 181:a4cbdfbbd2f4 | 46 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 181:a4cbdfbbd2f4 | 47 | * and/or other materials provided with the distribution. |
mbed_official | 181:a4cbdfbbd2f4 | 48 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 181:a4cbdfbbd2f4 | 49 | * may be used to endorse or promote products derived from this software |
mbed_official | 181:a4cbdfbbd2f4 | 50 | * without specific prior written permission. |
mbed_official | 181:a4cbdfbbd2f4 | 51 | * |
mbed_official | 181:a4cbdfbbd2f4 | 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 181:a4cbdfbbd2f4 | 53 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 181:a4cbdfbbd2f4 | 54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 181:a4cbdfbbd2f4 | 55 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 181:a4cbdfbbd2f4 | 56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 181:a4cbdfbbd2f4 | 57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 181:a4cbdfbbd2f4 | 58 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 181:a4cbdfbbd2f4 | 59 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 181:a4cbdfbbd2f4 | 60 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 181:a4cbdfbbd2f4 | 61 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 181:a4cbdfbbd2f4 | 62 | * |
mbed_official | 181:a4cbdfbbd2f4 | 63 | ****************************************************************************** |
mbed_official | 181:a4cbdfbbd2f4 | 64 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 65 | |
mbed_official | 181:a4cbdfbbd2f4 | 66 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 67 | #include "stm32l0xx_hal.h" |
mbed_official | 181:a4cbdfbbd2f4 | 68 | /** @addtogroup STM32L0XX_HAL_Driver |
mbed_official | 181:a4cbdfbbd2f4 | 69 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 70 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 71 | |
mbed_official | 181:a4cbdfbbd2f4 | 72 | /** @defgroup FLASHEx HAL FLASH Driver |
mbed_official | 181:a4cbdfbbd2f4 | 73 | * @brief FLASH HAL Extension module driver |
mbed_official | 181:a4cbdfbbd2f4 | 74 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 75 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 76 | |
mbed_official | 181:a4cbdfbbd2f4 | 77 | #ifdef HAL_FLASH_MODULE_ENABLED |
mbed_official | 181:a4cbdfbbd2f4 | 78 | |
mbed_official | 181:a4cbdfbbd2f4 | 79 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 80 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 81 | #define HAL_FLASH_TIMEOUT_VALUE ((uint32_t)0x50000 |
mbed_official | 181:a4cbdfbbd2f4 | 82 | #define WRP01_MASK ((uint32_t)0x0000FFFF) |
mbed_official | 181:a4cbdfbbd2f4 | 83 | #define PAGESIZE ((uint32_t)0x00000080) |
mbed_official | 181:a4cbdfbbd2f4 | 84 | |
mbed_official | 181:a4cbdfbbd2f4 | 85 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 86 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 87 | /*Variables used for Erase sectors under interruption*/ |
mbed_official | 181:a4cbdfbbd2f4 | 88 | extern FLASH_ProcessTypeDef pFlash; |
mbed_official | 181:a4cbdfbbd2f4 | 89 | |
mbed_official | 181:a4cbdfbbd2f4 | 90 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 91 | static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 181:a4cbdfbbd2f4 | 92 | static HAL_StatusTypeDef FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP); |
mbed_official | 181:a4cbdfbbd2f4 | 93 | static HAL_StatusTypeDef FLASH_OB_BootConfig(uint16_t OB_BOOT); |
mbed_official | 181:a4cbdfbbd2f4 | 94 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 95 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 96 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 97 | static HAL_StatusTypeDef DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 98 | static HAL_StatusTypeDef DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 99 | static HAL_StatusTypeDef DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data); |
mbed_official | 181:a4cbdfbbd2f4 | 100 | static uint8_t FLASH_OB_GetUser(void); |
mbed_official | 181:a4cbdfbbd2f4 | 101 | static uint32_t FLASH_OB_GetWRP(void); |
mbed_official | 181:a4cbdfbbd2f4 | 102 | static FlagStatus FLASH_OB_GetRDP(void); |
mbed_official | 181:a4cbdfbbd2f4 | 103 | static uint8_t FLASH_OB_GetBOR(void); |
mbed_official | 181:a4cbdfbbd2f4 | 104 | static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState); |
mbed_official | 181:a4cbdfbbd2f4 | 105 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint8_t OB_RDP); |
mbed_official | 181:a4cbdfbbd2f4 | 106 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY); |
mbed_official | 181:a4cbdfbbd2f4 | 107 | static HAL_StatusTypeDef FLASH_OB_BORConfig(uint8_t OB_BOR); |
mbed_official | 181:a4cbdfbbd2f4 | 108 | |
mbed_official | 181:a4cbdfbbd2f4 | 109 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 181:a4cbdfbbd2f4 | 110 | |
mbed_official | 181:a4cbdfbbd2f4 | 111 | /** @defgroup Extended_FLASHEx_Private_Functions Extended FLASH Private functions |
mbed_official | 181:a4cbdfbbd2f4 | 112 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 113 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 114 | |
mbed_official | 181:a4cbdfbbd2f4 | 115 | /** @defgroup HAL_FLASHEx_Group1 Peripheral extended features functions |
mbed_official | 181:a4cbdfbbd2f4 | 116 | * @brief Data transfers functions |
mbed_official | 181:a4cbdfbbd2f4 | 117 | * |
mbed_official | 181:a4cbdfbbd2f4 | 118 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 119 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 120 | ##### Extended Features functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 121 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 122 | [..] |
mbed_official | 181:a4cbdfbbd2f4 | 123 | This subsection provides a set of functions allowing to manage the FLASH data |
mbed_official | 181:a4cbdfbbd2f4 | 124 | transfers. |
mbed_official | 181:a4cbdfbbd2f4 | 125 | |
mbed_official | 181:a4cbdfbbd2f4 | 126 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 127 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 128 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 129 | |
mbed_official | 181:a4cbdfbbd2f4 | 130 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 131 | * @brief Program option bytes |
mbed_official | 181:a4cbdfbbd2f4 | 132 | * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
mbed_official | 181:a4cbdfbbd2f4 | 133 | * contains the configuration information for the programming. |
mbed_official | 181:a4cbdfbbd2f4 | 134 | * |
mbed_official | 181:a4cbdfbbd2f4 | 135 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 136 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 137 | HAL_StatusTypeDef HAL_FLASHEx_AdvOBProgram (FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
mbed_official | 181:a4cbdfbbd2f4 | 138 | { |
mbed_official | 181:a4cbdfbbd2f4 | 139 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 140 | |
mbed_official | 181:a4cbdfbbd2f4 | 141 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 142 | assert_param(IS_OBEX(pAdvOBInit->OptionType)); |
mbed_official | 181:a4cbdfbbd2f4 | 143 | |
mbed_official | 181:a4cbdfbbd2f4 | 144 | /*Program PCROP option byte*/ |
mbed_official | 181:a4cbdfbbd2f4 | 145 | if ((pAdvOBInit->OptionType&OBEX_PCROP) == OBEX_PCROP) |
mbed_official | 181:a4cbdfbbd2f4 | 146 | { |
mbed_official | 181:a4cbdfbbd2f4 | 147 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 148 | assert_param(IS_PCROPSTATE(pAdvOBInit->PCROPState)); |
mbed_official | 181:a4cbdfbbd2f4 | 149 | if (pAdvOBInit->PCROPState == PCROPSTATE_ENABLE) |
mbed_official | 181:a4cbdfbbd2f4 | 150 | { |
mbed_official | 181:a4cbdfbbd2f4 | 151 | /*Enable of Write protection on the selected Sector*/ |
mbed_official | 181:a4cbdfbbd2f4 | 152 | status = FLASH_OB_PCROPConfig(pAdvOBInit->Pages, ENABLE); |
mbed_official | 181:a4cbdfbbd2f4 | 153 | status = FLASH_OB_PCROPSelectionConfig(OB_PCROP_SELECTED); |
mbed_official | 181:a4cbdfbbd2f4 | 154 | } |
mbed_official | 181:a4cbdfbbd2f4 | 155 | else |
mbed_official | 181:a4cbdfbbd2f4 | 156 | { |
mbed_official | 181:a4cbdfbbd2f4 | 157 | /*Disable of Write protection on the selected Sector*/ |
mbed_official | 181:a4cbdfbbd2f4 | 158 | status = FLASH_OB_PCROPConfig(pAdvOBInit->Pages, DISABLE); |
mbed_official | 181:a4cbdfbbd2f4 | 159 | status = FLASH_OB_PCROPSelectionConfig(OB_PCROP_DESELECTED); |
mbed_official | 181:a4cbdfbbd2f4 | 160 | } |
mbed_official | 181:a4cbdfbbd2f4 | 161 | } |
mbed_official | 181:a4cbdfbbd2f4 | 162 | /*Program BOOT config option byte*/ |
mbed_official | 181:a4cbdfbbd2f4 | 163 | if ((pAdvOBInit->OptionType&OBEX_BOOTCONFIG) == OBEX_BOOTCONFIG) |
mbed_official | 181:a4cbdfbbd2f4 | 164 | { |
mbed_official | 181:a4cbdfbbd2f4 | 165 | status = FLASH_OB_BootConfig(pAdvOBInit->BootConfig); |
mbed_official | 181:a4cbdfbbd2f4 | 166 | } |
mbed_official | 181:a4cbdfbbd2f4 | 167 | |
mbed_official | 181:a4cbdfbbd2f4 | 168 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 169 | } |
mbed_official | 181:a4cbdfbbd2f4 | 170 | |
mbed_official | 181:a4cbdfbbd2f4 | 171 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 172 | * @brief Get the OBEX byte configuration |
mbed_official | 181:a4cbdfbbd2f4 | 173 | * @param pAdvOBInit: pointer to an FLASH_AdvOBProgramInitTypeDef structure that |
mbed_official | 181:a4cbdfbbd2f4 | 174 | * contains the configuration information for the programming. |
mbed_official | 181:a4cbdfbbd2f4 | 175 | * |
mbed_official | 181:a4cbdfbbd2f4 | 176 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 177 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 178 | void HAL_FLASHEx_AdvOBGetConfig(FLASH_AdvOBProgramInitTypeDef *pAdvOBInit) |
mbed_official | 181:a4cbdfbbd2f4 | 179 | { |
mbed_official | 181:a4cbdfbbd2f4 | 180 | pAdvOBInit->OptionType = OBEX_PCROP| OBEX_BOOTCONFIG; |
mbed_official | 181:a4cbdfbbd2f4 | 181 | /*Get PCROP state */ |
mbed_official | 181:a4cbdfbbd2f4 | 182 | pAdvOBInit->PCROPState = (FLASH->OBR & 0x00000100) >> 8; |
mbed_official | 181:a4cbdfbbd2f4 | 183 | /*Get PCROP protected Pages */ |
mbed_official | 181:a4cbdfbbd2f4 | 184 | pAdvOBInit->Pages = FLASH->WRPR; |
mbed_official | 181:a4cbdfbbd2f4 | 185 | /*Get Boot config OB*/ |
mbed_official | 181:a4cbdfbbd2f4 | 186 | pAdvOBInit->BootConfig = (FLASH->OBR & 0x80000000) >> 24; |
mbed_official | 181:a4cbdfbbd2f4 | 187 | } |
mbed_official | 181:a4cbdfbbd2f4 | 188 | |
mbed_official | 181:a4cbdfbbd2f4 | 189 | /** @defgroup HAL_FLASHEx_Group2 DATA EEPROM Programming functions |
mbed_official | 181:a4cbdfbbd2f4 | 190 | * @brief DATA EEPROM Programming functions |
mbed_official | 181:a4cbdfbbd2f4 | 191 | * |
mbed_official | 181:a4cbdfbbd2f4 | 192 | @verbatim |
mbed_official | 181:a4cbdfbbd2f4 | 193 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 194 | ##### DATA EEPROM Programming functions ##### |
mbed_official | 181:a4cbdfbbd2f4 | 195 | =============================================================================== |
mbed_official | 181:a4cbdfbbd2f4 | 196 | |
mbed_official | 181:a4cbdfbbd2f4 | 197 | [..] The DATA_EEPROM Programming_Functions, includes the following functions: |
mbed_official | 181:a4cbdfbbd2f4 | 198 | (+) HAL_DATA_EEPROMEx_Unlock(void); |
mbed_official | 181:a4cbdfbbd2f4 | 199 | (+) HAL_DATA_EEPROMEx_Lock(void); |
mbed_official | 181:a4cbdfbbd2f4 | 200 | (+) HAL_DATA_EEPROMEx_Erase(uint32_t Address) |
mbed_official | 181:a4cbdfbbd2f4 | 201 | (+) HAL_DATA_EEPROMEx_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 202 | |
mbed_official | 181:a4cbdfbbd2f4 | 203 | [..] Any operation of erase or program should follow these steps: |
mbed_official | 181:a4cbdfbbd2f4 | 204 | (#) Call the HAL_DATA_EEPROMEx_Unlock() function to enable the data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 205 | and Flash program erase control register access. |
mbed_official | 181:a4cbdfbbd2f4 | 206 | (#) Call the desired function to erase or program data. |
mbed_official | 181:a4cbdfbbd2f4 | 207 | (#) Call the HAL_DATA_EEPROMEx_Lock() to disable the data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 208 | and Flash program erase control register access(recommended |
mbed_official | 181:a4cbdfbbd2f4 | 209 | to protect the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 210 | |
mbed_official | 181:a4cbdfbbd2f4 | 211 | @endverbatim |
mbed_official | 181:a4cbdfbbd2f4 | 212 | * @{ |
mbed_official | 181:a4cbdfbbd2f4 | 213 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 214 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 215 | * @brief Unlocks the data memory and FLASH_PECR register access. |
mbed_official | 181:a4cbdfbbd2f4 | 216 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 217 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 218 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 219 | HAL_StatusTypeDef HAL_DATA_EEPROMEx_Unlock(void) |
mbed_official | 181:a4cbdfbbd2f4 | 220 | { |
mbed_official | 181:a4cbdfbbd2f4 | 221 | if((FLASH->PECR & FLASH_PECR_PELOCK) != RESET) |
mbed_official | 181:a4cbdfbbd2f4 | 222 | { |
mbed_official | 181:a4cbdfbbd2f4 | 223 | /* Unlocking the Data memory and FLASH_PECR register access*/ |
mbed_official | 181:a4cbdfbbd2f4 | 224 | FLASH->PEKEYR = FLASH_PEKEY1; |
mbed_official | 181:a4cbdfbbd2f4 | 225 | FLASH->PEKEYR = FLASH_PEKEY2; |
mbed_official | 181:a4cbdfbbd2f4 | 226 | } |
mbed_official | 181:a4cbdfbbd2f4 | 227 | else |
mbed_official | 181:a4cbdfbbd2f4 | 228 | { |
mbed_official | 181:a4cbdfbbd2f4 | 229 | return HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 230 | } |
mbed_official | 181:a4cbdfbbd2f4 | 231 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 232 | } |
mbed_official | 181:a4cbdfbbd2f4 | 233 | |
mbed_official | 181:a4cbdfbbd2f4 | 234 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 235 | * @brief Locks the Data memory and FLASH_PECR register access. |
mbed_official | 181:a4cbdfbbd2f4 | 236 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 237 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 238 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 239 | HAL_StatusTypeDef HAL_DATA_EEPROMEx_Lock(void) |
mbed_official | 181:a4cbdfbbd2f4 | 240 | { |
mbed_official | 181:a4cbdfbbd2f4 | 241 | /* Set the PELOCK Bit to lock the data memory and FLASH_PECR register access */ |
mbed_official | 181:a4cbdfbbd2f4 | 242 | FLASH->PECR |= FLASH_PECR_PELOCK; |
mbed_official | 181:a4cbdfbbd2f4 | 243 | |
mbed_official | 181:a4cbdfbbd2f4 | 244 | return HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 245 | } |
mbed_official | 181:a4cbdfbbd2f4 | 246 | |
mbed_official | 181:a4cbdfbbd2f4 | 247 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 248 | * @brief Erase a word in data memory. |
mbed_official | 181:a4cbdfbbd2f4 | 249 | * @param Address: specifies the address to be erased. |
mbed_official | 181:a4cbdfbbd2f4 | 250 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 251 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 252 | * Call the DATA_EEPROM_Lock() to the data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 253 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 254 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 255 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 256 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 257 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 258 | HAL_StatusTypeDef HAL_DATA_EEPROMEx_Erase(uint32_t Address) |
mbed_official | 181:a4cbdfbbd2f4 | 259 | { |
mbed_official | 181:a4cbdfbbd2f4 | 260 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 261 | |
mbed_official | 181:a4cbdfbbd2f4 | 262 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 263 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 264 | |
mbed_official | 181:a4cbdfbbd2f4 | 265 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 266 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 267 | |
mbed_official | 181:a4cbdfbbd2f4 | 268 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 269 | { |
mbed_official | 181:a4cbdfbbd2f4 | 270 | /* Write "00000000h" to valid address in the data memory" */ |
mbed_official | 181:a4cbdfbbd2f4 | 271 | *(__IO uint32_t *) Address = 0x00000000; |
mbed_official | 181:a4cbdfbbd2f4 | 272 | } |
mbed_official | 181:a4cbdfbbd2f4 | 273 | |
mbed_official | 181:a4cbdfbbd2f4 | 274 | /* Return the erase status */ |
mbed_official | 181:a4cbdfbbd2f4 | 275 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 276 | } |
mbed_official | 181:a4cbdfbbd2f4 | 277 | |
mbed_official | 181:a4cbdfbbd2f4 | 278 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 279 | * @brief Program word at a specified address |
mbed_official | 181:a4cbdfbbd2f4 | 280 | * @param TypeProgram: Indicate the way to program at a specified address. |
mbed_official | 181:a4cbdfbbd2f4 | 281 | * This parameter can be a value of @ref FLASH_Type_Program |
mbed_official | 181:a4cbdfbbd2f4 | 282 | * @param Address: specifies the address to be programmed. |
mbed_official | 181:a4cbdfbbd2f4 | 283 | * @param Data: specifies the data to be programmed |
mbed_official | 181:a4cbdfbbd2f4 | 284 | * |
mbed_official | 181:a4cbdfbbd2f4 | 285 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 286 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 287 | |
mbed_official | 181:a4cbdfbbd2f4 | 288 | HAL_StatusTypeDef HAL_DATA_EEPROMEx_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 289 | { |
mbed_official | 181:a4cbdfbbd2f4 | 290 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 291 | |
mbed_official | 181:a4cbdfbbd2f4 | 292 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 293 | __HAL_LOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 294 | |
mbed_official | 181:a4cbdfbbd2f4 | 295 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 296 | assert_param(IS_TYPEPROGRAM(TypeProgram)); |
mbed_official | 181:a4cbdfbbd2f4 | 297 | |
mbed_official | 181:a4cbdfbbd2f4 | 298 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 299 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 300 | |
mbed_official | 181:a4cbdfbbd2f4 | 301 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 302 | { |
mbed_official | 181:a4cbdfbbd2f4 | 303 | if(TypeProgram == TYPEPROGRAM_FASTBYTE) |
mbed_official | 181:a4cbdfbbd2f4 | 304 | { |
mbed_official | 181:a4cbdfbbd2f4 | 305 | /*Program word (8-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 306 | DATA_EEPROM_FastProgramByte(Address, (uint8_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 307 | |
mbed_official | 181:a4cbdfbbd2f4 | 308 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 309 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 310 | } |
mbed_official | 181:a4cbdfbbd2f4 | 311 | |
mbed_official | 181:a4cbdfbbd2f4 | 312 | if(TypeProgram == TYPEPROGRAM_FASTHALFWORD) |
mbed_official | 181:a4cbdfbbd2f4 | 313 | { |
mbed_official | 181:a4cbdfbbd2f4 | 314 | /*Program word (16-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 315 | DATA_EEPROM_FastProgramHalfWord(Address, (uint16_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 316 | |
mbed_official | 181:a4cbdfbbd2f4 | 317 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 318 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 319 | } |
mbed_official | 181:a4cbdfbbd2f4 | 320 | if(TypeProgram == TYPEPROGRAM_FASTWORD) |
mbed_official | 181:a4cbdfbbd2f4 | 321 | { |
mbed_official | 181:a4cbdfbbd2f4 | 322 | /*Program word (32-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 323 | DATA_EEPROM_FastProgramWord(Address, (uint32_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 324 | |
mbed_official | 181:a4cbdfbbd2f4 | 325 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 326 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 327 | } |
mbed_official | 181:a4cbdfbbd2f4 | 328 | if(TypeProgram == TYPEPROGRAM_WORD) |
mbed_official | 181:a4cbdfbbd2f4 | 329 | { |
mbed_official | 181:a4cbdfbbd2f4 | 330 | /*Program word (32-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 331 | DATA_EEPROM_ProgramWord(Address, (uint32_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 332 | |
mbed_official | 181:a4cbdfbbd2f4 | 333 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 334 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 335 | } |
mbed_official | 181:a4cbdfbbd2f4 | 336 | |
mbed_official | 181:a4cbdfbbd2f4 | 337 | if(TypeProgram == TYPEPROGRAM_HALFWORD) |
mbed_official | 181:a4cbdfbbd2f4 | 338 | { |
mbed_official | 181:a4cbdfbbd2f4 | 339 | /*Program word (16-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 340 | DATA_EEPROM_ProgramHalfWord(Address, (uint16_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 341 | |
mbed_official | 181:a4cbdfbbd2f4 | 342 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 343 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 344 | } |
mbed_official | 181:a4cbdfbbd2f4 | 345 | |
mbed_official | 181:a4cbdfbbd2f4 | 346 | if(TypeProgram == TYPEPROGRAM_BYTE) |
mbed_official | 181:a4cbdfbbd2f4 | 347 | { |
mbed_official | 181:a4cbdfbbd2f4 | 348 | /*Program word (8-bit) at a specified address.*/ |
mbed_official | 181:a4cbdfbbd2f4 | 349 | DATA_EEPROM_ProgramByte(Address, (uint8_t) Data); |
mbed_official | 181:a4cbdfbbd2f4 | 350 | |
mbed_official | 181:a4cbdfbbd2f4 | 351 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 352 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 353 | } |
mbed_official | 181:a4cbdfbbd2f4 | 354 | } |
mbed_official | 181:a4cbdfbbd2f4 | 355 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 356 | __HAL_UNLOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 357 | |
mbed_official | 181:a4cbdfbbd2f4 | 358 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 359 | } |
mbed_official | 181:a4cbdfbbd2f4 | 360 | |
mbed_official | 181:a4cbdfbbd2f4 | 361 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 362 | * @brief Erase the specified FLASH memory Pages |
mbed_official | 181:a4cbdfbbd2f4 | 363 | * @param[in] pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 181:a4cbdfbbd2f4 | 364 | * contains the configuration information for the erasing. |
mbed_official | 181:a4cbdfbbd2f4 | 365 | * |
mbed_official | 181:a4cbdfbbd2f4 | 366 | * @param[out] PageError: pointer to variable that |
mbed_official | 181:a4cbdfbbd2f4 | 367 | * contains the configuration information on faulty sector in case of error |
mbed_official | 181:a4cbdfbbd2f4 | 368 | * (0xFFFFFFFF means that all the sectors have been correctly erased) |
mbed_official | 181:a4cbdfbbd2f4 | 369 | * |
mbed_official | 181:a4cbdfbbd2f4 | 370 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 371 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 372 | HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) |
mbed_official | 181:a4cbdfbbd2f4 | 373 | { |
mbed_official | 181:a4cbdfbbd2f4 | 374 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 375 | uint32_t index = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 376 | |
mbed_official | 181:a4cbdfbbd2f4 | 377 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 378 | __HAL_LOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 379 | |
mbed_official | 181:a4cbdfbbd2f4 | 380 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 381 | assert_param(IS_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 181:a4cbdfbbd2f4 | 382 | |
mbed_official | 181:a4cbdfbbd2f4 | 383 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 384 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 385 | |
mbed_official | 181:a4cbdfbbd2f4 | 386 | if (status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 387 | { |
mbed_official | 181:a4cbdfbbd2f4 | 388 | /*Initialization of PageError variable*/ |
mbed_official | 181:a4cbdfbbd2f4 | 389 | *PageError = 0xFFFFFFFF; |
mbed_official | 181:a4cbdfbbd2f4 | 390 | |
mbed_official | 181:a4cbdfbbd2f4 | 391 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 392 | assert_param(IS_NBPAGES(pEraseInit->NbPages + pEraseInit->Page)); |
mbed_official | 181:a4cbdfbbd2f4 | 393 | |
mbed_official | 181:a4cbdfbbd2f4 | 394 | /* Erase by sector by sector to be done*/ |
mbed_official | 181:a4cbdfbbd2f4 | 395 | for(index = pEraseInit->Page; index < ((pEraseInit->NbPages*PAGESIZE)+ pEraseInit->Page); index+=PAGESIZE) |
mbed_official | 181:a4cbdfbbd2f4 | 396 | { |
mbed_official | 181:a4cbdfbbd2f4 | 397 | FLASH_Erase_Page(index); |
mbed_official | 181:a4cbdfbbd2f4 | 398 | |
mbed_official | 181:a4cbdfbbd2f4 | 399 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 400 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 401 | |
mbed_official | 181:a4cbdfbbd2f4 | 402 | /* If the erase operation is completed, disable the ERASE Bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 403 | FLASH->PECR &= (~FLASH_PECR_PROG); |
mbed_official | 181:a4cbdfbbd2f4 | 404 | FLASH->PECR &= (~FLASH_PECR_ERASE); |
mbed_official | 181:a4cbdfbbd2f4 | 405 | |
mbed_official | 181:a4cbdfbbd2f4 | 406 | if (status != HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 407 | { |
mbed_official | 181:a4cbdfbbd2f4 | 408 | /* In case of error, stop erase procedure and return the faulty sector*/ |
mbed_official | 181:a4cbdfbbd2f4 | 409 | *PageError = index; |
mbed_official | 181:a4cbdfbbd2f4 | 410 | break; |
mbed_official | 181:a4cbdfbbd2f4 | 411 | } |
mbed_official | 181:a4cbdfbbd2f4 | 412 | } |
mbed_official | 181:a4cbdfbbd2f4 | 413 | } |
mbed_official | 181:a4cbdfbbd2f4 | 414 | |
mbed_official | 181:a4cbdfbbd2f4 | 415 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 416 | __HAL_UNLOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 417 | |
mbed_official | 181:a4cbdfbbd2f4 | 418 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 419 | } |
mbed_official | 181:a4cbdfbbd2f4 | 420 | |
mbed_official | 181:a4cbdfbbd2f4 | 421 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 422 | * @brief Perform a page erase of the specified FLASH memory pages with interrupt enabled |
mbed_official | 181:a4cbdfbbd2f4 | 423 | * @param pEraseInit: pointer to an FLASH_EraseInitTypeDef structure that |
mbed_official | 181:a4cbdfbbd2f4 | 424 | * contains the configuration information for the erasing. |
mbed_official | 181:a4cbdfbbd2f4 | 425 | * |
mbed_official | 181:a4cbdfbbd2f4 | 426 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 427 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 428 | HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) |
mbed_official | 181:a4cbdfbbd2f4 | 429 | { |
mbed_official | 181:a4cbdfbbd2f4 | 430 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 431 | |
mbed_official | 181:a4cbdfbbd2f4 | 432 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 433 | __HAL_LOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 434 | |
mbed_official | 181:a4cbdfbbd2f4 | 435 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 436 | assert_param(IS_TYPEERASE(pEraseInit->TypeErase)); |
mbed_official | 181:a4cbdfbbd2f4 | 437 | |
mbed_official | 181:a4cbdfbbd2f4 | 438 | /* Enable End of FLASH Operation interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 439 | __HAL_FLASH_ENABLE_IT(FLASH_IT_EOP); |
mbed_official | 181:a4cbdfbbd2f4 | 440 | |
mbed_official | 181:a4cbdfbbd2f4 | 441 | /* Enable Error source interrupt */ |
mbed_official | 181:a4cbdfbbd2f4 | 442 | __HAL_FLASH_ENABLE_IT(FLASH_IT_ERR); |
mbed_official | 181:a4cbdfbbd2f4 | 443 | |
mbed_official | 181:a4cbdfbbd2f4 | 444 | /* Clear pending flags (if any) */ |
mbed_official | 181:a4cbdfbbd2f4 | 445 | __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_ENDHV | FLASH_FLAG_WRPERR |\ |
mbed_official | 181:a4cbdfbbd2f4 | 446 | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR| FLASH_FLAG_OPTVERR |\ |
mbed_official | 181:a4cbdfbbd2f4 | 447 | FLASH_FLAG_RDERR | FLASH_FLAG_NOTZEROERR); |
mbed_official | 181:a4cbdfbbd2f4 | 448 | |
mbed_official | 181:a4cbdfbbd2f4 | 449 | if (pEraseInit->TypeErase == TYPEERASE_PAGEERASE) |
mbed_official | 181:a4cbdfbbd2f4 | 450 | { |
mbed_official | 181:a4cbdfbbd2f4 | 451 | /* Erase by sector to be done*/ |
mbed_official | 181:a4cbdfbbd2f4 | 452 | |
mbed_official | 181:a4cbdfbbd2f4 | 453 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 454 | assert_param(IS_NBPAGES(pEraseInit->NbPages + pEraseInit->Page)); |
mbed_official | 181:a4cbdfbbd2f4 | 455 | |
mbed_official | 181:a4cbdfbbd2f4 | 456 | pFlash.ProcedureOnGoing = FLASH_PROC_PAGEERASE; |
mbed_official | 181:a4cbdfbbd2f4 | 457 | pFlash.NbPagesToErase = pEraseInit->NbPages; |
mbed_official | 181:a4cbdfbbd2f4 | 458 | pFlash.Page = pEraseInit->Page; |
mbed_official | 181:a4cbdfbbd2f4 | 459 | |
mbed_official | 181:a4cbdfbbd2f4 | 460 | /*Erase 1st page and wait for IT*/ |
mbed_official | 181:a4cbdfbbd2f4 | 461 | FLASH_Erase_Page(pEraseInit->Page); |
mbed_official | 181:a4cbdfbbd2f4 | 462 | } |
mbed_official | 181:a4cbdfbbd2f4 | 463 | |
mbed_official | 181:a4cbdfbbd2f4 | 464 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 465 | } |
mbed_official | 181:a4cbdfbbd2f4 | 466 | |
mbed_official | 181:a4cbdfbbd2f4 | 467 | |
mbed_official | 181:a4cbdfbbd2f4 | 468 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 469 | * @brief Program option bytes |
mbed_official | 181:a4cbdfbbd2f4 | 470 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 181:a4cbdfbbd2f4 | 471 | * contains the configuration information for the programming. |
mbed_official | 181:a4cbdfbbd2f4 | 472 | * |
mbed_official | 181:a4cbdfbbd2f4 | 473 | * @retval HAL_StatusTypeDef HAL Status |
mbed_official | 181:a4cbdfbbd2f4 | 474 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 475 | HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 181:a4cbdfbbd2f4 | 476 | { |
mbed_official | 181:a4cbdfbbd2f4 | 477 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 478 | |
mbed_official | 181:a4cbdfbbd2f4 | 479 | /* Process Locked */ |
mbed_official | 181:a4cbdfbbd2f4 | 480 | __HAL_LOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 481 | |
mbed_official | 181:a4cbdfbbd2f4 | 482 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 483 | assert_param(IS_OPTIONBYTE(pOBInit->OptionType)); |
mbed_official | 181:a4cbdfbbd2f4 | 484 | |
mbed_official | 181:a4cbdfbbd2f4 | 485 | /*Write protection configuration*/ |
mbed_official | 181:a4cbdfbbd2f4 | 486 | if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) |
mbed_official | 181:a4cbdfbbd2f4 | 487 | { |
mbed_official | 181:a4cbdfbbd2f4 | 488 | assert_param(IS_WRPSTATE(pOBInit->WRPState)); |
mbed_official | 181:a4cbdfbbd2f4 | 489 | if (pOBInit->WRPState == WRPSTATE_ENABLE) |
mbed_official | 181:a4cbdfbbd2f4 | 490 | { |
mbed_official | 181:a4cbdfbbd2f4 | 491 | /*Enable of Write protection on the selected Sector*/ |
mbed_official | 181:a4cbdfbbd2f4 | 492 | status = FLASH_OB_WRPConfig(pOBInit->WRPSector, ENABLE); |
mbed_official | 181:a4cbdfbbd2f4 | 493 | } |
mbed_official | 181:a4cbdfbbd2f4 | 494 | else |
mbed_official | 181:a4cbdfbbd2f4 | 495 | { |
mbed_official | 181:a4cbdfbbd2f4 | 496 | /*Disable of Write protection on the selected Sector*/ |
mbed_official | 181:a4cbdfbbd2f4 | 497 | status = FLASH_OB_WRPConfig(pOBInit->WRPSector, DISABLE); |
mbed_official | 181:a4cbdfbbd2f4 | 498 | } |
mbed_official | 181:a4cbdfbbd2f4 | 499 | } |
mbed_official | 181:a4cbdfbbd2f4 | 500 | |
mbed_official | 181:a4cbdfbbd2f4 | 501 | /* Read protection configuration*/ |
mbed_official | 181:a4cbdfbbd2f4 | 502 | if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) |
mbed_official | 181:a4cbdfbbd2f4 | 503 | { |
mbed_official | 181:a4cbdfbbd2f4 | 504 | status = FLASH_OB_RDPConfig(pOBInit->RDPLevel); |
mbed_official | 181:a4cbdfbbd2f4 | 505 | } |
mbed_official | 181:a4cbdfbbd2f4 | 506 | |
mbed_official | 181:a4cbdfbbd2f4 | 507 | /* USER configuration*/ |
mbed_official | 181:a4cbdfbbd2f4 | 508 | if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) |
mbed_official | 181:a4cbdfbbd2f4 | 509 | { |
mbed_official | 181:a4cbdfbbd2f4 | 510 | status = FLASH_OB_UserConfig(pOBInit->USERConfig&OB_IWDG_SW, |
mbed_official | 181:a4cbdfbbd2f4 | 511 | pOBInit->USERConfig&OB_STOP_NoRST, |
mbed_official | 181:a4cbdfbbd2f4 | 512 | pOBInit->USERConfig&OB_STDBY_NoRST); |
mbed_official | 181:a4cbdfbbd2f4 | 513 | } |
mbed_official | 181:a4cbdfbbd2f4 | 514 | |
mbed_official | 181:a4cbdfbbd2f4 | 515 | /* BOR Level configuration*/ |
mbed_official | 181:a4cbdfbbd2f4 | 516 | if((pOBInit->OptionType & OPTIONBYTE_BOR) == OPTIONBYTE_BOR) |
mbed_official | 181:a4cbdfbbd2f4 | 517 | { |
mbed_official | 181:a4cbdfbbd2f4 | 518 | status = FLASH_OB_BORConfig(pOBInit->BORLevel); |
mbed_official | 181:a4cbdfbbd2f4 | 519 | } |
mbed_official | 181:a4cbdfbbd2f4 | 520 | /* Process Unlocked */ |
mbed_official | 181:a4cbdfbbd2f4 | 521 | __HAL_UNLOCK(&pFlash); |
mbed_official | 181:a4cbdfbbd2f4 | 522 | |
mbed_official | 181:a4cbdfbbd2f4 | 523 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 524 | } |
mbed_official | 181:a4cbdfbbd2f4 | 525 | |
mbed_official | 181:a4cbdfbbd2f4 | 526 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 527 | * @brief Get the Option byte configuration |
mbed_official | 181:a4cbdfbbd2f4 | 528 | * @param pOBInit: pointer to an FLASH_OBInitStruct structure that |
mbed_official | 181:a4cbdfbbd2f4 | 529 | * contains the configuration information for the programming. |
mbed_official | 181:a4cbdfbbd2f4 | 530 | * |
mbed_official | 181:a4cbdfbbd2f4 | 531 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 532 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 533 | void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) |
mbed_official | 181:a4cbdfbbd2f4 | 534 | { |
mbed_official | 181:a4cbdfbbd2f4 | 535 | pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_BOR; |
mbed_official | 181:a4cbdfbbd2f4 | 536 | |
mbed_official | 181:a4cbdfbbd2f4 | 537 | /*Get WRP*/ |
mbed_official | 181:a4cbdfbbd2f4 | 538 | pOBInit->WRPSector = FLASH_OB_GetWRP(); |
mbed_official | 181:a4cbdfbbd2f4 | 539 | |
mbed_official | 181:a4cbdfbbd2f4 | 540 | /*Get RDP Level*/ |
mbed_official | 181:a4cbdfbbd2f4 | 541 | pOBInit->RDPLevel = FLASH_OB_GetRDP(); |
mbed_official | 181:a4cbdfbbd2f4 | 542 | |
mbed_official | 181:a4cbdfbbd2f4 | 543 | /*Get USER*/ |
mbed_official | 181:a4cbdfbbd2f4 | 544 | pOBInit->USERConfig = FLASH_OB_GetUser(); |
mbed_official | 181:a4cbdfbbd2f4 | 545 | |
mbed_official | 181:a4cbdfbbd2f4 | 546 | /*Get BOR Level*/ |
mbed_official | 181:a4cbdfbbd2f4 | 547 | pOBInit->BORLevel = FLASH_OB_GetBOR(); |
mbed_official | 181:a4cbdfbbd2f4 | 548 | } |
mbed_official | 181:a4cbdfbbd2f4 | 549 | |
mbed_official | 181:a4cbdfbbd2f4 | 550 | |
mbed_official | 181:a4cbdfbbd2f4 | 551 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 552 | * @brief Returns the FLASH User Option Bytes values. |
mbed_official | 181:a4cbdfbbd2f4 | 553 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 554 | * @retval The FLASH User Option Bytes. |
mbed_official | 181:a4cbdfbbd2f4 | 555 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 556 | static uint8_t FLASH_OB_GetUser(void) |
mbed_official | 181:a4cbdfbbd2f4 | 557 | { |
mbed_official | 181:a4cbdfbbd2f4 | 558 | /* Return the User Option Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 559 | return (uint8_t)(FLASH->OBR >> 20); |
mbed_official | 181:a4cbdfbbd2f4 | 560 | } |
mbed_official | 181:a4cbdfbbd2f4 | 561 | |
mbed_official | 181:a4cbdfbbd2f4 | 562 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 563 | * @brief Returns the FLASH Write Protection Option Bytes value. |
mbed_official | 181:a4cbdfbbd2f4 | 564 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 565 | * @retval The FLASH Write Protection Option Bytes value. |
mbed_official | 181:a4cbdfbbd2f4 | 566 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 567 | static uint32_t FLASH_OB_GetWRP(void) |
mbed_official | 181:a4cbdfbbd2f4 | 568 | { |
mbed_official | 181:a4cbdfbbd2f4 | 569 | /* Return the FLASH write protection Register value */ |
mbed_official | 181:a4cbdfbbd2f4 | 570 | return (uint32_t)(FLASH->WRPR); |
mbed_official | 181:a4cbdfbbd2f4 | 571 | } |
mbed_official | 181:a4cbdfbbd2f4 | 572 | |
mbed_official | 181:a4cbdfbbd2f4 | 573 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 574 | * @brief Checks whether the FLASH Read out Protection Status is set or not. |
mbed_official | 181:a4cbdfbbd2f4 | 575 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 576 | * @retval FLASH ReadOut Protection Status(SET or RESET). |
mbed_official | 181:a4cbdfbbd2f4 | 577 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 578 | static FlagStatus FLASH_OB_GetRDP(void) |
mbed_official | 181:a4cbdfbbd2f4 | 579 | { |
mbed_official | 181:a4cbdfbbd2f4 | 580 | FlagStatus readstatus = RESET; |
mbed_official | 181:a4cbdfbbd2f4 | 581 | |
mbed_official | 181:a4cbdfbbd2f4 | 582 | if ((uint8_t)(FLASH->OBR) != (uint8_t)OB_RDP_Level_0) |
mbed_official | 181:a4cbdfbbd2f4 | 583 | { |
mbed_official | 181:a4cbdfbbd2f4 | 584 | readstatus = SET; |
mbed_official | 181:a4cbdfbbd2f4 | 585 | } |
mbed_official | 181:a4cbdfbbd2f4 | 586 | else |
mbed_official | 181:a4cbdfbbd2f4 | 587 | { |
mbed_official | 181:a4cbdfbbd2f4 | 588 | readstatus = RESET; |
mbed_official | 181:a4cbdfbbd2f4 | 589 | } |
mbed_official | 181:a4cbdfbbd2f4 | 590 | return readstatus; |
mbed_official | 181:a4cbdfbbd2f4 | 591 | } |
mbed_official | 181:a4cbdfbbd2f4 | 592 | |
mbed_official | 181:a4cbdfbbd2f4 | 593 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 594 | * @brief Returns the FLASH BOR level. |
mbed_official | 181:a4cbdfbbd2f4 | 595 | * @param None |
mbed_official | 181:a4cbdfbbd2f4 | 596 | * @retval The FLASH User Option Bytes. |
mbed_official | 181:a4cbdfbbd2f4 | 597 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 598 | static uint8_t FLASH_OB_GetBOR(void) |
mbed_official | 181:a4cbdfbbd2f4 | 599 | { |
mbed_official | 181:a4cbdfbbd2f4 | 600 | /* Return the BOR level */ |
mbed_official | 181:a4cbdfbbd2f4 | 601 | return (uint8_t)((FLASH->OBR & (uint32_t)0x000F0000) >> 16); |
mbed_official | 181:a4cbdfbbd2f4 | 602 | } |
mbed_official | 181:a4cbdfbbd2f4 | 603 | |
mbed_official | 181:a4cbdfbbd2f4 | 604 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 605 | * @brief Write protects the desired pages of the first 64KB of the Flash. |
mbed_official | 181:a4cbdfbbd2f4 | 606 | * @param OB_WRP: specifies the address of the pages to be write protected. |
mbed_official | 181:a4cbdfbbd2f4 | 607 | * This parameter can be: |
mbed_official | 181:a4cbdfbbd2f4 | 608 | * @arg value between OB_WRP_Pages0to31 and OB_WRP_Pages480to511 |
mbed_official | 181:a4cbdfbbd2f4 | 609 | * @arg OB_WRP_AllPages |
mbed_official | 181:a4cbdfbbd2f4 | 610 | * @param NewState: new state of the specified FLASH Pages Wtite protection. |
mbed_official | 181:a4cbdfbbd2f4 | 611 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 181:a4cbdfbbd2f4 | 612 | * @retval HAL_StatusTypeDef |
mbed_official | 181:a4cbdfbbd2f4 | 613 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 614 | static HAL_StatusTypeDef FLASH_OB_WRPConfig(uint32_t OB_WRP, FunctionalState NewState) |
mbed_official | 181:a4cbdfbbd2f4 | 615 | { |
mbed_official | 181:a4cbdfbbd2f4 | 616 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 617 | uint32_t WRP01_Data = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 618 | uint32_t tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 619 | |
mbed_official | 181:a4cbdfbbd2f4 | 620 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 621 | assert_param(IS_OB_WRP(OB_WRP)); |
mbed_official | 181:a4cbdfbbd2f4 | 622 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 181:a4cbdfbbd2f4 | 623 | |
mbed_official | 181:a4cbdfbbd2f4 | 624 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 625 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 626 | |
mbed_official | 181:a4cbdfbbd2f4 | 627 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 628 | { |
mbed_official | 181:a4cbdfbbd2f4 | 629 | if (NewState != DISABLE) |
mbed_official | 181:a4cbdfbbd2f4 | 630 | { |
mbed_official | 181:a4cbdfbbd2f4 | 631 | WRP01_Data = (uint16_t)(((OB_WRP & WRP01_MASK) | OB->WRP01)); |
mbed_official | 181:a4cbdfbbd2f4 | 632 | tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 181:a4cbdfbbd2f4 | 633 | OB->WRP01 = tmp1; |
mbed_official | 181:a4cbdfbbd2f4 | 634 | } |
mbed_official | 181:a4cbdfbbd2f4 | 635 | else |
mbed_official | 181:a4cbdfbbd2f4 | 636 | { |
mbed_official | 181:a4cbdfbbd2f4 | 637 | WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01)); |
mbed_official | 181:a4cbdfbbd2f4 | 638 | tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 181:a4cbdfbbd2f4 | 639 | OB->WRP01 = tmp1; |
mbed_official | 181:a4cbdfbbd2f4 | 640 | } |
mbed_official | 181:a4cbdfbbd2f4 | 641 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 642 | status = FLASH_WaitForLastOperation(HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 643 | } |
mbed_official | 181:a4cbdfbbd2f4 | 644 | |
mbed_official | 181:a4cbdfbbd2f4 | 645 | /* Return the write protection operation Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 646 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 647 | } |
mbed_official | 181:a4cbdfbbd2f4 | 648 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 649 | * @brief Enables or disables the read out protection. |
mbed_official | 181:a4cbdfbbd2f4 | 650 | * @note To correctly run this function, the FLASH_OB_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 651 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 652 | * @param FLASH_ReadProtection_Level: specifies the read protection level. |
mbed_official | 181:a4cbdfbbd2f4 | 653 | * This parameter can be: |
mbed_official | 181:a4cbdfbbd2f4 | 654 | * @arg OB_RDP_Level_0: No protection |
mbed_official | 181:a4cbdfbbd2f4 | 655 | * @arg OB_RDP_Level_1: Read protection of the memory |
mbed_official | 181:a4cbdfbbd2f4 | 656 | * @arg OB_RDP_Level_2: Chip protection |
mbed_official | 181:a4cbdfbbd2f4 | 657 | * |
mbed_official | 181:a4cbdfbbd2f4 | 658 | * !!!Warning!!! When enabling OB_RDP_Level_2 it's no more possible to go back to level 1 or 0 |
mbed_official | 181:a4cbdfbbd2f4 | 659 | * |
mbed_official | 181:a4cbdfbbd2f4 | 660 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 661 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 662 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 663 | static HAL_StatusTypeDef FLASH_OB_RDPConfig(uint8_t OB_RDP) |
mbed_official | 181:a4cbdfbbd2f4 | 664 | { |
mbed_official | 181:a4cbdfbbd2f4 | 665 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 666 | uint8_t tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 667 | uint32_t tmp2 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 668 | |
mbed_official | 181:a4cbdfbbd2f4 | 669 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 670 | assert_param(IS_OB_RDP(OB_RDP)); |
mbed_official | 181:a4cbdfbbd2f4 | 671 | status = FLASH_WaitForLastOperation(HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 672 | |
mbed_official | 181:a4cbdfbbd2f4 | 673 | /* calculate the option byte to write */ |
mbed_official | 181:a4cbdfbbd2f4 | 674 | tmp1 = (uint8_t)(~(OB_RDP )); |
mbed_official | 181:a4cbdfbbd2f4 | 675 | tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)OB_RDP)); |
mbed_official | 181:a4cbdfbbd2f4 | 676 | |
mbed_official | 181:a4cbdfbbd2f4 | 677 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 678 | { |
mbed_official | 181:a4cbdfbbd2f4 | 679 | /* program read protection level */ |
mbed_official | 181:a4cbdfbbd2f4 | 680 | OB->RDP = tmp2; |
mbed_official | 181:a4cbdfbbd2f4 | 681 | } |
mbed_official | 181:a4cbdfbbd2f4 | 682 | |
mbed_official | 181:a4cbdfbbd2f4 | 683 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 684 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 685 | |
mbed_official | 181:a4cbdfbbd2f4 | 686 | /* Return the Read protection operation Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 687 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 688 | } |
mbed_official | 181:a4cbdfbbd2f4 | 689 | |
mbed_official | 181:a4cbdfbbd2f4 | 690 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 691 | * @brief Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY. |
mbed_official | 181:a4cbdfbbd2f4 | 692 | * @param OB_IWDG: Selects the WDG mode. |
mbed_official | 181:a4cbdfbbd2f4 | 693 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 694 | * @arg OB_IWDG_SW: Software WDG selected |
mbed_official | 181:a4cbdfbbd2f4 | 695 | * @arg OB_IWDG_HW: Hardware WDG selected |
mbed_official | 181:a4cbdfbbd2f4 | 696 | * @param OB_STOP: Reset event when entering STOP mode. |
mbed_official | 181:a4cbdfbbd2f4 | 697 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 698 | * @arg OB_STOP_NoRST: No reset generated when entering in STOP |
mbed_official | 181:a4cbdfbbd2f4 | 699 | * @arg OB_STOP_RST: Reset generated when entering in STOP |
mbed_official | 181:a4cbdfbbd2f4 | 700 | * @param OB_STDBY: Reset event when entering Standby mode. |
mbed_official | 181:a4cbdfbbd2f4 | 701 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 702 | * @arg OB_STDBY_NoRST: No reset generated when entering in STANDBY |
mbed_official | 181:a4cbdfbbd2f4 | 703 | * @arg OB_STDBY_RST: Reset generated when entering in STANDBY |
mbed_official | 181:a4cbdfbbd2f4 | 704 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 705 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 706 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 707 | static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t OB_IWDG, uint8_t OB_STOP, uint8_t OB_STDBY) |
mbed_official | 181:a4cbdfbbd2f4 | 708 | { |
mbed_official | 181:a4cbdfbbd2f4 | 709 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 710 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 711 | |
mbed_official | 181:a4cbdfbbd2f4 | 712 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 713 | assert_param(IS_OB_IWDG_SOURCE(OB_IWDG)); |
mbed_official | 181:a4cbdfbbd2f4 | 714 | assert_param(IS_OB_STOP_SOURCE(OB_STOP)); |
mbed_official | 181:a4cbdfbbd2f4 | 715 | assert_param(IS_OB_STDBY_SOURCE(OB_STDBY)); |
mbed_official | 181:a4cbdfbbd2f4 | 716 | |
mbed_official | 181:a4cbdfbbd2f4 | 717 | /* Get the User Option byte register */ |
mbed_official | 181:a4cbdfbbd2f4 | 718 | tmp1 = (FLASH->OBR & 0x800F0000) >> 16; |
mbed_official | 181:a4cbdfbbd2f4 | 719 | |
mbed_official | 181:a4cbdfbbd2f4 | 720 | /* Calculate the user option byte to write */ |
mbed_official | 181:a4cbdfbbd2f4 | 721 | tmp = (uint32_t)(((uint32_t)~((uint32_t)((uint32_t)(OB_IWDG) | (uint32_t)(OB_STOP) | (uint32_t)(OB_STDBY) | tmp1))) << 16); |
mbed_official | 181:a4cbdfbbd2f4 | 722 | tmp |= ((uint32_t)(OB_IWDG) | ((uint32_t)OB_STOP) | (uint32_t)(OB_STDBY) | tmp1); |
mbed_official | 181:a4cbdfbbd2f4 | 723 | |
mbed_official | 181:a4cbdfbbd2f4 | 724 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 725 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 726 | |
mbed_official | 181:a4cbdfbbd2f4 | 727 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 728 | { |
mbed_official | 181:a4cbdfbbd2f4 | 729 | /* Write the User Option Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 730 | OB->USER = tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 731 | } |
mbed_official | 181:a4cbdfbbd2f4 | 732 | |
mbed_official | 181:a4cbdfbbd2f4 | 733 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 734 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 735 | |
mbed_official | 181:a4cbdfbbd2f4 | 736 | /* Return the Option Byte program Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 737 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 738 | } |
mbed_official | 181:a4cbdfbbd2f4 | 739 | |
mbed_official | 181:a4cbdfbbd2f4 | 740 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 741 | * @brief Programs the FLASH brownout reset threshold level Option Byte. |
mbed_official | 181:a4cbdfbbd2f4 | 742 | * @param OB_BOR: Selects the brownout reset threshold level. |
mbed_official | 181:a4cbdfbbd2f4 | 743 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 744 | * @arg OB_BOR_OFF: BOR is disabled at power down, the reset is asserted when the VDD |
mbed_official | 181:a4cbdfbbd2f4 | 745 | * power supply reaches the PDR(Power Down Reset) threshold (1.5V) |
mbed_official | 181:a4cbdfbbd2f4 | 746 | * @arg OB_BOR_LEVEL1: BOR Reset threshold levels for 1.7V - 1.8V VDD power supply |
mbed_official | 181:a4cbdfbbd2f4 | 747 | * @arg OB_BOR_LEVEL2: BOR Reset threshold levels for 1.9V - 2.0V VDD power supply |
mbed_official | 181:a4cbdfbbd2f4 | 748 | * @arg OB_BOR_LEVEL3: BOR Reset threshold levels for 2.3V - 2.4V VDD power supply |
mbed_official | 181:a4cbdfbbd2f4 | 749 | * @arg OB_BOR_LEVEL4: BOR Reset threshold levels for 2.55V - 2.65V VDD power supply |
mbed_official | 181:a4cbdfbbd2f4 | 750 | * @arg OB_BOR_LEVEL5: BOR Reset threshold levels for 2.8V - 2.9V VDD power supply |
mbed_official | 181:a4cbdfbbd2f4 | 751 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 752 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 753 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 754 | static HAL_StatusTypeDef FLASH_OB_BORConfig(uint8_t OB_BOR) |
mbed_official | 181:a4cbdfbbd2f4 | 755 | { |
mbed_official | 181:a4cbdfbbd2f4 | 756 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 757 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 758 | |
mbed_official | 181:a4cbdfbbd2f4 | 759 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 760 | assert_param(IS_OB_BOR_LEVEL(OB_BOR)); |
mbed_official | 181:a4cbdfbbd2f4 | 761 | |
mbed_official | 181:a4cbdfbbd2f4 | 762 | /* Get the User Option byte register */ |
mbed_official | 181:a4cbdfbbd2f4 | 763 | tmp1 = (FLASH->OBR & 0x000F0000) >> 16; |
mbed_official | 181:a4cbdfbbd2f4 | 764 | |
mbed_official | 181:a4cbdfbbd2f4 | 765 | /* Calculate the option byte to write */ |
mbed_official | 181:a4cbdfbbd2f4 | 766 | tmp = (uint32_t)~(OB_BOR | tmp1)<<16; |
mbed_official | 181:a4cbdfbbd2f4 | 767 | tmp |= (OB_BOR | tmp1); |
mbed_official | 181:a4cbdfbbd2f4 | 768 | |
mbed_official | 181:a4cbdfbbd2f4 | 769 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 770 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 771 | |
mbed_official | 181:a4cbdfbbd2f4 | 772 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 773 | { |
mbed_official | 181:a4cbdfbbd2f4 | 774 | /* Write the BOR Option Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 775 | OB->USER = tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 776 | } |
mbed_official | 181:a4cbdfbbd2f4 | 777 | |
mbed_official | 181:a4cbdfbbd2f4 | 778 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 779 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 780 | |
mbed_official | 181:a4cbdfbbd2f4 | 781 | /* Return the Option Byte program Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 782 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 783 | } |
mbed_official | 181:a4cbdfbbd2f4 | 784 | |
mbed_official | 181:a4cbdfbbd2f4 | 785 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 786 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 787 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 788 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 789 | * @brief Enables or disables the read/write protection (PCROP) of the desired |
mbed_official | 181:a4cbdfbbd2f4 | 790 | * sectors, for the first 64KB of the Flash. |
mbed_official | 181:a4cbdfbbd2f4 | 791 | * @param OB_WRP: specifies the address of the pages to be write protected. |
mbed_official | 181:a4cbdfbbd2f4 | 792 | * This parameter can be: |
mbed_official | 181:a4cbdfbbd2f4 | 793 | * @arg value between OB_WRP_Pages0to31 and OB_WRP_Pages480to511 |
mbed_official | 181:a4cbdfbbd2f4 | 794 | * @arg OB_WRP_AllPages |
mbed_official | 181:a4cbdfbbd2f4 | 795 | * @param NewState: new state of the specified FLASH Pages Write protection. |
mbed_official | 181:a4cbdfbbd2f4 | 796 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 181:a4cbdfbbd2f4 | 797 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 798 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 799 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 800 | static HAL_StatusTypeDef FLASH_OB_PCROPConfig(uint32_t OB_WRP, FunctionalState NewState) |
mbed_official | 181:a4cbdfbbd2f4 | 801 | { |
mbed_official | 181:a4cbdfbbd2f4 | 802 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 803 | uint32_t WRP01_Data = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 804 | uint32_t tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 805 | |
mbed_official | 181:a4cbdfbbd2f4 | 806 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 807 | assert_param(IS_OB_WRP(OB_WRP)); |
mbed_official | 181:a4cbdfbbd2f4 | 808 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 181:a4cbdfbbd2f4 | 809 | |
mbed_official | 181:a4cbdfbbd2f4 | 810 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 811 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 812 | |
mbed_official | 181:a4cbdfbbd2f4 | 813 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 814 | { |
mbed_official | 181:a4cbdfbbd2f4 | 815 | if (NewState != DISABLE) |
mbed_official | 181:a4cbdfbbd2f4 | 816 | { |
mbed_official | 181:a4cbdfbbd2f4 | 817 | WRP01_Data = (uint16_t)(~OB_WRP & (WRP01_MASK & OB->WRP01)); |
mbed_official | 181:a4cbdfbbd2f4 | 818 | |
mbed_official | 181:a4cbdfbbd2f4 | 819 | tmp1 = (uint32_t)((~WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 181:a4cbdfbbd2f4 | 820 | OB->WRP01 = tmp1; |
mbed_official | 181:a4cbdfbbd2f4 | 821 | } |
mbed_official | 181:a4cbdfbbd2f4 | 822 | |
mbed_official | 181:a4cbdfbbd2f4 | 823 | else |
mbed_official | 181:a4cbdfbbd2f4 | 824 | { |
mbed_official | 181:a4cbdfbbd2f4 | 825 | WRP01_Data = (uint16_t)((OB_WRP & WRP01_MASK) | OB->WRP01); |
mbed_official | 181:a4cbdfbbd2f4 | 826 | |
mbed_official | 181:a4cbdfbbd2f4 | 827 | tmp1 = (uint32_t)(~(WRP01_Data) << 16)|(WRP01_Data); |
mbed_official | 181:a4cbdfbbd2f4 | 828 | OB->WRP01 = tmp1; |
mbed_official | 181:a4cbdfbbd2f4 | 829 | } |
mbed_official | 181:a4cbdfbbd2f4 | 830 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 831 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 832 | } |
mbed_official | 181:a4cbdfbbd2f4 | 833 | |
mbed_official | 181:a4cbdfbbd2f4 | 834 | /* Return the write protection operation Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 835 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 836 | } |
mbed_official | 181:a4cbdfbbd2f4 | 837 | |
mbed_official | 181:a4cbdfbbd2f4 | 838 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 839 | * @brief Select the Protection Mode (SPRMOD). |
mbed_official | 181:a4cbdfbbd2f4 | 840 | * @note Once SPRMOD bit is active, unprotection of a protected sector is not possible |
mbed_official | 181:a4cbdfbbd2f4 | 841 | * @note Read a protected sector will set RDERR Flag and write a protected sector will set WRPERR Flag |
mbed_official | 181:a4cbdfbbd2f4 | 842 | * @param OB_PcROP: Select the Protection Mode of WPR bits. |
mbed_official | 181:a4cbdfbbd2f4 | 843 | * This parameter can be: |
mbed_official | 181:a4cbdfbbd2f4 | 844 | * @arg OB_PCROP_SELECTED: nWRP control the read&write protection (PcROP) of respective user sectors. |
mbed_official | 181:a4cbdfbbd2f4 | 845 | * @arg OB_PCROP_DESELECTED: nWRP control the write protection of respective user sectors. |
mbed_official | 181:a4cbdfbbd2f4 | 846 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 847 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 848 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 849 | static HAL_StatusTypeDef FLASH_OB_PCROPSelectionConfig(uint16_t OB_PcROP) |
mbed_official | 181:a4cbdfbbd2f4 | 850 | { |
mbed_official | 181:a4cbdfbbd2f4 | 851 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 852 | uint16_t tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 853 | uint32_t tmp2 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 854 | uint8_t optiontmp = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 855 | uint16_t optiontmp2 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 856 | |
mbed_official | 181:a4cbdfbbd2f4 | 857 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 858 | assert_param(IS_OB_PCROP_SELECT(OB_PcROP)); |
mbed_official | 181:a4cbdfbbd2f4 | 859 | |
mbed_official | 181:a4cbdfbbd2f4 | 860 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 861 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 862 | |
mbed_official | 181:a4cbdfbbd2f4 | 863 | /* Mask RDP Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 864 | optiontmp = (uint8_t)(*(__IO uint8_t *)(OB_BASE)); |
mbed_official | 181:a4cbdfbbd2f4 | 865 | |
mbed_official | 181:a4cbdfbbd2f4 | 866 | /* Update Option Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 867 | optiontmp2 = (uint16_t)(OB_PcROP | optiontmp); |
mbed_official | 181:a4cbdfbbd2f4 | 868 | |
mbed_official | 181:a4cbdfbbd2f4 | 869 | |
mbed_official | 181:a4cbdfbbd2f4 | 870 | /* calculate the option byte to write */ |
mbed_official | 181:a4cbdfbbd2f4 | 871 | tmp1 = (uint16_t)(~(optiontmp2 )); |
mbed_official | 181:a4cbdfbbd2f4 | 872 | tmp2 = (uint32_t)(((uint32_t)((uint32_t)(tmp1) << 16)) | ((uint32_t)optiontmp2)); |
mbed_official | 181:a4cbdfbbd2f4 | 873 | |
mbed_official | 181:a4cbdfbbd2f4 | 874 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 875 | { |
mbed_official | 181:a4cbdfbbd2f4 | 876 | /* program PCRop */ |
mbed_official | 181:a4cbdfbbd2f4 | 877 | OB->RDP = tmp2; |
mbed_official | 181:a4cbdfbbd2f4 | 878 | } |
mbed_official | 181:a4cbdfbbd2f4 | 879 | |
mbed_official | 181:a4cbdfbbd2f4 | 880 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 881 | status = FLASH_WaitForLastOperation(HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 882 | |
mbed_official | 181:a4cbdfbbd2f4 | 883 | /* Return the Read protection operation Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 884 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 885 | } |
mbed_official | 181:a4cbdfbbd2f4 | 886 | |
mbed_official | 181:a4cbdfbbd2f4 | 887 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 888 | * @brief Sets or resets the BOOT1 option bit. |
mbed_official | 181:a4cbdfbbd2f4 | 889 | * @param OB_BOOT1: Set or Reset the BOOT1 option bit. |
mbed_official | 181:a4cbdfbbd2f4 | 890 | * This parameter can be one of the following values: |
mbed_official | 181:a4cbdfbbd2f4 | 891 | * @arg OB_BOOT1_RESET: BOOT1 option bit reset |
mbed_official | 181:a4cbdfbbd2f4 | 892 | * @arg OB_BOOT1_SET: BOOT1 option bit set |
mbed_official | 181:a4cbdfbbd2f4 | 893 | * @retval None |
mbed_official | 181:a4cbdfbbd2f4 | 894 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 895 | static HAL_StatusTypeDef FLASH_OB_BootConfig(uint16_t OB_BOOT) |
mbed_official | 181:a4cbdfbbd2f4 | 896 | { |
mbed_official | 181:a4cbdfbbd2f4 | 897 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 181:a4cbdfbbd2f4 | 898 | uint32_t tmp = 0, tmp1 = 0; |
mbed_official | 181:a4cbdfbbd2f4 | 899 | |
mbed_official | 181:a4cbdfbbd2f4 | 900 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 901 | assert_param(IS_OB_BOOT1(OB_BOOT)); |
mbed_official | 181:a4cbdfbbd2f4 | 902 | |
mbed_official | 181:a4cbdfbbd2f4 | 903 | /* Get the User Option byte register */ |
mbed_official | 181:a4cbdfbbd2f4 | 904 | tmp1 = (FLASH->OBR & 0x007F0000) >> 16; |
mbed_official | 181:a4cbdfbbd2f4 | 905 | |
mbed_official | 181:a4cbdfbbd2f4 | 906 | /* Calculate the option byte to write */ |
mbed_official | 181:a4cbdfbbd2f4 | 907 | tmp = (uint32_t)~(OB_BOOT | tmp1)<<16; |
mbed_official | 181:a4cbdfbbd2f4 | 908 | tmp |= (OB_BOOT | tmp1); |
mbed_official | 181:a4cbdfbbd2f4 | 909 | |
mbed_official | 181:a4cbdfbbd2f4 | 910 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 911 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 912 | |
mbed_official | 181:a4cbdfbbd2f4 | 913 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 914 | { |
mbed_official | 181:a4cbdfbbd2f4 | 915 | /* Write the BOOT Option Byte */ |
mbed_official | 181:a4cbdfbbd2f4 | 916 | OB->USER = tmp; |
mbed_official | 181:a4cbdfbbd2f4 | 917 | } |
mbed_official | 181:a4cbdfbbd2f4 | 918 | |
mbed_official | 181:a4cbdfbbd2f4 | 919 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 920 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 921 | |
mbed_official | 181:a4cbdfbbd2f4 | 922 | /* Return the Option Byte program Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 923 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 924 | } |
mbed_official | 181:a4cbdfbbd2f4 | 925 | |
mbed_official | 181:a4cbdfbbd2f4 | 926 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 927 | * @brief Write a Byte at a specified address in data memory. |
mbed_official | 181:a4cbdfbbd2f4 | 928 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 929 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 930 | * Call the DATA_EEPROM_Lock() to the data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 931 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 932 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 933 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 934 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 935 | * @note This function assumes that data word is already erased. |
mbed_official | 181:a4cbdfbbd2f4 | 936 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 937 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 938 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 939 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramByte(uint32_t Address, uint8_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 940 | { |
mbed_official | 181:a4cbdfbbd2f4 | 941 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 942 | |
mbed_official | 181:a4cbdfbbd2f4 | 943 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 944 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 945 | |
mbed_official | 181:a4cbdfbbd2f4 | 946 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 947 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 948 | |
mbed_official | 181:a4cbdfbbd2f4 | 949 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 950 | { |
mbed_official | 181:a4cbdfbbd2f4 | 951 | /* Clear the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 952 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 181:a4cbdfbbd2f4 | 953 | |
mbed_official | 181:a4cbdfbbd2f4 | 954 | /* If the previous operation is completed, proceed to write the new Data */ |
mbed_official | 181:a4cbdfbbd2f4 | 955 | *(__IO uint8_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 956 | |
mbed_official | 181:a4cbdfbbd2f4 | 957 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 958 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 959 | } |
mbed_official | 181:a4cbdfbbd2f4 | 960 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 961 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 962 | } |
mbed_official | 181:a4cbdfbbd2f4 | 963 | |
mbed_official | 181:a4cbdfbbd2f4 | 964 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 965 | * @brief Writes a half word at a specified address in data memory. |
mbed_official | 181:a4cbdfbbd2f4 | 966 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 967 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 968 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 969 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 970 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 971 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 972 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 973 | * @note This function assumes that the is data word is already erased. |
mbed_official | 181:a4cbdfbbd2f4 | 974 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 975 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 976 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 977 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramHalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 978 | { |
mbed_official | 181:a4cbdfbbd2f4 | 979 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 980 | |
mbed_official | 181:a4cbdfbbd2f4 | 981 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 982 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 983 | |
mbed_official | 181:a4cbdfbbd2f4 | 984 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 985 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 986 | |
mbed_official | 181:a4cbdfbbd2f4 | 987 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 988 | { |
mbed_official | 181:a4cbdfbbd2f4 | 989 | /* Clear the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 990 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 181:a4cbdfbbd2f4 | 991 | |
mbed_official | 181:a4cbdfbbd2f4 | 992 | /* If the previous operation is completed, proceed to write the new data */ |
mbed_official | 181:a4cbdfbbd2f4 | 993 | *(__IO uint16_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 994 | |
mbed_official | 181:a4cbdfbbd2f4 | 995 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 996 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 997 | } |
mbed_official | 181:a4cbdfbbd2f4 | 998 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 999 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 1000 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1001 | |
mbed_official | 181:a4cbdfbbd2f4 | 1002 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1003 | * @brief Programs a word at a specified address in data memory. |
mbed_official | 181:a4cbdfbbd2f4 | 1004 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 1005 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 1006 | * Call the DATA_EEPROM_Lock() to the data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 1007 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 1008 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 1009 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1010 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1011 | * @note This function assumes that the is data word is already erased. |
mbed_official | 181:a4cbdfbbd2f4 | 1012 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 1013 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 1014 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1015 | static HAL_StatusTypeDef DATA_EEPROM_FastProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 1016 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1017 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 1018 | |
mbed_official | 181:a4cbdfbbd2f4 | 1019 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1020 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 1021 | |
mbed_official | 181:a4cbdfbbd2f4 | 1022 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1023 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1024 | |
mbed_official | 181:a4cbdfbbd2f4 | 1025 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1026 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1027 | /* Clear the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 1028 | FLASH->PECR &= (uint32_t)(~((uint32_t)FLASH_PECR_FTDW)); |
mbed_official | 181:a4cbdfbbd2f4 | 1029 | |
mbed_official | 181:a4cbdfbbd2f4 | 1030 | /* If the previous operation is completed, proceed to program the new data */ |
mbed_official | 181:a4cbdfbbd2f4 | 1031 | *(__IO uint32_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 1032 | |
mbed_official | 181:a4cbdfbbd2f4 | 1033 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1034 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1035 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1036 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 1037 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 1038 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1039 | |
mbed_official | 181:a4cbdfbbd2f4 | 1040 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1041 | * @brief Write a Byte at a specified address in data memory without erase. |
mbed_official | 181:a4cbdfbbd2f4 | 1042 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 1043 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 1044 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 1045 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 1046 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 1047 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 181:a4cbdfbbd2f4 | 1048 | * this function to configure the Fixed Time Programming. |
mbed_official | 181:a4cbdfbbd2f4 | 1049 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1050 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1051 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 1052 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 1053 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1054 | static HAL_StatusTypeDef DATA_EEPROM_ProgramByte(uint32_t Address, uint8_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 1055 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1056 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 1057 | |
mbed_official | 181:a4cbdfbbd2f4 | 1058 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1059 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 1060 | |
mbed_official | 181:a4cbdfbbd2f4 | 1061 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1062 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1063 | |
mbed_official | 181:a4cbdfbbd2f4 | 1064 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1065 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1066 | /* Set the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 1067 | FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW; |
mbed_official | 181:a4cbdfbbd2f4 | 1068 | |
mbed_official | 181:a4cbdfbbd2f4 | 1069 | *(__IO uint8_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 1070 | |
mbed_official | 181:a4cbdfbbd2f4 | 1071 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1072 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1073 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1074 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 1075 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 1076 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1077 | |
mbed_official | 181:a4cbdfbbd2f4 | 1078 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1079 | * @brief Writes a half word at a specified address in data memory without erase. |
mbed_official | 181:a4cbdfbbd2f4 | 1080 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 1081 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 1082 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 1083 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 1084 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 1085 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 181:a4cbdfbbd2f4 | 1086 | * this function to configure the Fixed Time Programming |
mbed_official | 181:a4cbdfbbd2f4 | 1087 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1088 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1089 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 1090 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 1091 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1092 | static HAL_StatusTypeDef DATA_EEPROM_ProgramHalfWord(uint32_t Address, uint16_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 1093 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1094 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 1095 | |
mbed_official | 181:a4cbdfbbd2f4 | 1096 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1097 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 1098 | |
mbed_official | 181:a4cbdfbbd2f4 | 1099 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1100 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1101 | |
mbed_official | 181:a4cbdfbbd2f4 | 1102 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1103 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1104 | /* Set the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 1105 | FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW; |
mbed_official | 181:a4cbdfbbd2f4 | 1106 | |
mbed_official | 181:a4cbdfbbd2f4 | 1107 | *(__IO uint16_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 1108 | |
mbed_official | 181:a4cbdfbbd2f4 | 1109 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1110 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1111 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1112 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 1113 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 1114 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1115 | |
mbed_official | 181:a4cbdfbbd2f4 | 1116 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1117 | * @brief Programs a word at a specified address in data memory without erase. |
mbed_official | 181:a4cbdfbbd2f4 | 1118 | * @note To correctly run this function, the DATA_EEPROM_Unlock() function |
mbed_official | 181:a4cbdfbbd2f4 | 1119 | * must be called before. |
mbed_official | 181:a4cbdfbbd2f4 | 1120 | * Call the DATA_EEPROM_Lock() to he data EEPROM access |
mbed_official | 181:a4cbdfbbd2f4 | 1121 | * and Flash program erase control register access(recommended to protect |
mbed_official | 181:a4cbdfbbd2f4 | 1122 | * the DATA_EEPROM against possible unwanted operation). |
mbed_official | 181:a4cbdfbbd2f4 | 1123 | * @note The function DATA_EEPROM_FixedTimeProgramCmd() can be called before |
mbed_official | 181:a4cbdfbbd2f4 | 1124 | * this function to configure the Fixed Time Programming. |
mbed_official | 181:a4cbdfbbd2f4 | 1125 | * @param Address: specifies the address to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1126 | * @param Data: specifies the data to be written. |
mbed_official | 181:a4cbdfbbd2f4 | 1127 | * @retval FLASH Status: The returned value can be: |
mbed_official | 181:a4cbdfbbd2f4 | 1128 | * FLASH_ERROR_PROGRAM, FLASH_ERROR_WRP, FLASH_COMPLETE or FLASH_TIMEOUT. |
mbed_official | 181:a4cbdfbbd2f4 | 1129 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1130 | static HAL_StatusTypeDef DATA_EEPROM_ProgramWord(uint32_t Address, uint32_t Data) |
mbed_official | 181:a4cbdfbbd2f4 | 1131 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1132 | HAL_StatusTypeDef status = HAL_ERROR; |
mbed_official | 181:a4cbdfbbd2f4 | 1133 | |
mbed_official | 181:a4cbdfbbd2f4 | 1134 | /* Check the parameters */ |
mbed_official | 181:a4cbdfbbd2f4 | 1135 | assert_param(IS_FLASH_DATA_ADDRESS(Address)); |
mbed_official | 181:a4cbdfbbd2f4 | 1136 | |
mbed_official | 181:a4cbdfbbd2f4 | 1137 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1138 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1139 | |
mbed_official | 181:a4cbdfbbd2f4 | 1140 | if(status == HAL_OK) |
mbed_official | 181:a4cbdfbbd2f4 | 1141 | { |
mbed_official | 181:a4cbdfbbd2f4 | 1142 | /* Set the FTDW bit */ |
mbed_official | 181:a4cbdfbbd2f4 | 1143 | FLASH->PECR |= (uint32_t)FLASH_PECR_FTDW; |
mbed_official | 181:a4cbdfbbd2f4 | 1144 | |
mbed_official | 181:a4cbdfbbd2f4 | 1145 | *(__IO uint32_t *)Address = Data; |
mbed_official | 181:a4cbdfbbd2f4 | 1146 | |
mbed_official | 181:a4cbdfbbd2f4 | 1147 | /* Wait for last operation to be completed */ |
mbed_official | 181:a4cbdfbbd2f4 | 1148 | status = FLASH_WaitForLastOperation((uint32_t)HAL_FLASH_TIMEOUT_VALUE)); |
mbed_official | 181:a4cbdfbbd2f4 | 1149 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1150 | /* Return the Write Status */ |
mbed_official | 181:a4cbdfbbd2f4 | 1151 | return status; |
mbed_official | 181:a4cbdfbbd2f4 | 1152 | } |
mbed_official | 181:a4cbdfbbd2f4 | 1153 | |
mbed_official | 181:a4cbdfbbd2f4 | 1154 | |
mbed_official | 181:a4cbdfbbd2f4 | 1155 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1156 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1157 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1158 | |
mbed_official | 181:a4cbdfbbd2f4 | 1159 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1160 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1161 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1162 | #endif /* HAL_FLASH_MODULE_ENABLED */ |
mbed_official | 181:a4cbdfbbd2f4 | 1163 | |
mbed_official | 181:a4cbdfbbd2f4 | 1164 | |
mbed_official | 181:a4cbdfbbd2f4 | 1165 | |
mbed_official | 181:a4cbdfbbd2f4 | 1166 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1167 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1168 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1169 | |
mbed_official | 181:a4cbdfbbd2f4 | 1170 | /** |
mbed_official | 181:a4cbdfbbd2f4 | 1171 | * @} |
mbed_official | 181:a4cbdfbbd2f4 | 1172 | */ |
mbed_official | 181:a4cbdfbbd2f4 | 1173 | |
mbed_official | 181:a4cbdfbbd2f4 | 1174 | |
mbed_official | 181:a4cbdfbbd2f4 | 1175 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
mbed_official | 181:a4cbdfbbd2f4 | 1176 | |
mbed_official | 181:a4cbdfbbd2f4 | 1177 |