The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Jun 21 17:31:38 2017 +0100
Revision:
145:64910690c574
Parent:
128:9bcdf88f62b0
Release 145 of the mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 122:f9eeca106725 1 /**
Kojto 122:f9eeca106725 2 ******************************************************************************
Kojto 122:f9eeca106725 3 * @file stm32l4xx_hal_flash.h
Kojto 122:f9eeca106725 4 * @author MCD Application Team
AnnaBridge 145:64910690c574 5 * @version V1.7.1
AnnaBridge 145:64910690c574 6 * @date 21-April-2017
Kojto 122:f9eeca106725 7 * @brief Header file of FLASH HAL module.
Kojto 122:f9eeca106725 8 ******************************************************************************
Kojto 122:f9eeca106725 9 * @attention
Kojto 122:f9eeca106725 10 *
AnnaBridge 145:64910690c574 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Kojto 122:f9eeca106725 12 *
Kojto 122:f9eeca106725 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 122:f9eeca106725 14 * are permitted provided that the following conditions are met:
Kojto 122:f9eeca106725 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 122:f9eeca106725 16 * this list of conditions and the following disclaimer.
Kojto 122:f9eeca106725 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 122:f9eeca106725 18 * this list of conditions and the following disclaimer in the documentation
Kojto 122:f9eeca106725 19 * and/or other materials provided with the distribution.
Kojto 122:f9eeca106725 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 122:f9eeca106725 21 * may be used to endorse or promote products derived from this software
Kojto 122:f9eeca106725 22 * without specific prior written permission.
Kojto 122:f9eeca106725 23 *
Kojto 122:f9eeca106725 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 122:f9eeca106725 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 122:f9eeca106725 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 122:f9eeca106725 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 122:f9eeca106725 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 122:f9eeca106725 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 122:f9eeca106725 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 122:f9eeca106725 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 122:f9eeca106725 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 122:f9eeca106725 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 122:f9eeca106725 34 *
Kojto 122:f9eeca106725 35 ******************************************************************************
Kojto 122:f9eeca106725 36 */
Kojto 122:f9eeca106725 37
Kojto 122:f9eeca106725 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 122:f9eeca106725 39 #ifndef __STM32L4xx_HAL_FLASH_H
Kojto 122:f9eeca106725 40 #define __STM32L4xx_HAL_FLASH_H
Kojto 122:f9eeca106725 41
Kojto 122:f9eeca106725 42 #ifdef __cplusplus
Kojto 122:f9eeca106725 43 extern "C" {
Kojto 122:f9eeca106725 44 #endif
Kojto 122:f9eeca106725 45
Kojto 122:f9eeca106725 46 /* Includes ------------------------------------------------------------------*/
Kojto 122:f9eeca106725 47 #include "stm32l4xx_hal_def.h"
Kojto 122:f9eeca106725 48
Kojto 122:f9eeca106725 49 /** @addtogroup STM32L4xx_HAL_Driver
Kojto 122:f9eeca106725 50 * @{
Kojto 122:f9eeca106725 51 */
Kojto 122:f9eeca106725 52
Kojto 122:f9eeca106725 53 /** @addtogroup FLASH
Kojto 122:f9eeca106725 54 * @{
Kojto 122:f9eeca106725 55 */
Kojto 122:f9eeca106725 56
Kojto 122:f9eeca106725 57 /* Exported types ------------------------------------------------------------*/
Kojto 122:f9eeca106725 58 /** @defgroup FLASH_Exported_Types FLASH Exported Types
Kojto 122:f9eeca106725 59 * @{
Kojto 122:f9eeca106725 60 */
Kojto 122:f9eeca106725 61
Kojto 122:f9eeca106725 62 /**
Kojto 122:f9eeca106725 63 * @brief FLASH Erase structure definition
Kojto 122:f9eeca106725 64 */
Kojto 122:f9eeca106725 65 typedef struct
Kojto 122:f9eeca106725 66 {
Kojto 122:f9eeca106725 67 uint32_t TypeErase; /*!< Mass erase or page erase.
Kojto 122:f9eeca106725 68 This parameter can be a value of @ref FLASH_Type_Erase */
Kojto 122:f9eeca106725 69 uint32_t Banks; /*!< Select bank to erase.
Kojto 122:f9eeca106725 70 This parameter must be a value of @ref FLASH_Banks
Kojto 122:f9eeca106725 71 (FLASH_BANK_BOTH should be used only for mass erase) */
Kojto 122:f9eeca106725 72 uint32_t Page; /*!< Initial Flash page to erase when page erase is disabled
Kojto 122:f9eeca106725 73 This parameter must be a value between 0 and (max number of pages in the bank - 1)
Kojto 122:f9eeca106725 74 (eg : 255 for 1MB dual bank) */
Kojto 122:f9eeca106725 75 uint32_t NbPages; /*!< Number of pages to be erased.
Kojto 122:f9eeca106725 76 This parameter must be a value between 1 and (max number of pages in the bank - value of initial page)*/
Kojto 122:f9eeca106725 77 } FLASH_EraseInitTypeDef;
Kojto 122:f9eeca106725 78
Kojto 122:f9eeca106725 79 /**
Kojto 122:f9eeca106725 80 * @brief FLASH Option Bytes Program structure definition
Kojto 122:f9eeca106725 81 */
Kojto 122:f9eeca106725 82 typedef struct
Kojto 122:f9eeca106725 83 {
Kojto 122:f9eeca106725 84 uint32_t OptionType; /*!< Option byte to be configured.
Kojto 122:f9eeca106725 85 This parameter can be a combination of the values of @ref FLASH_OB_Type */
Kojto 122:f9eeca106725 86 uint32_t WRPArea; /*!< Write protection area to be programmed (used for OPTIONBYTE_WRP).
Kojto 122:f9eeca106725 87 Only one WRP area could be programmed at the same time.
Kojto 122:f9eeca106725 88 This parameter can be value of @ref FLASH_OB_WRP_Area */
Kojto 122:f9eeca106725 89 uint32_t WRPStartOffset; /*!< Write protection start offset (used for OPTIONBYTE_WRP).
Kojto 122:f9eeca106725 90 This parameter must be a value between 0 and (max number of pages in the bank - 1)
Kojto 122:f9eeca106725 91 (eg : 25 for 1MB dual bank) */
Kojto 122:f9eeca106725 92 uint32_t WRPEndOffset; /*!< Write protection end offset (used for OPTIONBYTE_WRP).
Kojto 122:f9eeca106725 93 This parameter must be a value between WRPStartOffset and (max number of pages in the bank - 1) */
Kojto 122:f9eeca106725 94 uint32_t RDPLevel; /*!< Set the read protection level.. (used for OPTIONBYTE_RDP).
Kojto 122:f9eeca106725 95 This parameter can be a value of @ref FLASH_OB_Read_Protection */
Kojto 122:f9eeca106725 96 uint32_t USERType; /*!< User option byte(s) to be configured (used for OPTIONBYTE_USER).
Kojto 122:f9eeca106725 97 This parameter can be a combination of @ref FLASH_OB_USER_Type */
Kojto 122:f9eeca106725 98 uint32_t USERConfig; /*!< Value of the user option byte (used for OPTIONBYTE_USER).
Kojto 122:f9eeca106725 99 This parameter can be a combination of @ref FLASH_OB_USER_BOR_LEVEL,
Kojto 122:f9eeca106725 100 @ref FLASH_OB_USER_nRST_STOP, @ref FLASH_OB_USER_nRST_STANDBY,
Kojto 122:f9eeca106725 101 @ref FLASH_OB_USER_nRST_SHUTDOWN, @ref FLASH_OB_USER_IWDG_SW,
Kojto 122:f9eeca106725 102 @ref FLASH_OB_USER_IWDG_STOP, @ref FLASH_OB_USER_IWDG_STANDBY,
Kojto 122:f9eeca106725 103 @ref FLASH_OB_USER_WWDG_SW, @ref FLASH_OB_USER_BFB2,
Kojto 122:f9eeca106725 104 @ref FLASH_OB_USER_DUALBANK, @ref FLASH_OB_USER_nBOOT1,
Kojto 122:f9eeca106725 105 @ref FLASH_OB_USER_SRAM2_PE and @ref FLASH_OB_USER_SRAM2_RST */
Kojto 122:f9eeca106725 106 uint32_t PCROPConfig; /*!< Configuration of the PCROP (used for OPTIONBYTE_PCROP).
Kojto 122:f9eeca106725 107 This parameter must be a combination of @ref FLASH_Banks (except FLASH_BANK_BOTH)
Kojto 122:f9eeca106725 108 and @ref FLASH_OB_PCROP_RDP */
Kojto 122:f9eeca106725 109 uint32_t PCROPStartAddr; /*!< PCROP Start address (used for OPTIONBYTE_PCROP).
Kojto 122:f9eeca106725 110 This parameter must be a value between begin and end of bank
Kojto 122:f9eeca106725 111 => Be careful of the bank swapping for the address */
Kojto 122:f9eeca106725 112 uint32_t PCROPEndAddr; /*!< PCROP End address (used for OPTIONBYTE_PCROP).
Kojto 122:f9eeca106725 113 This parameter must be a value between PCROP Start address and end of bank */
Kojto 122:f9eeca106725 114 } FLASH_OBProgramInitTypeDef;
Kojto 122:f9eeca106725 115
Kojto 122:f9eeca106725 116 /**
Kojto 122:f9eeca106725 117 * @brief FLASH Procedure structure definition
Kojto 122:f9eeca106725 118 */
Kojto 122:f9eeca106725 119 typedef enum
Kojto 122:f9eeca106725 120 {
Kojto 122:f9eeca106725 121 FLASH_PROC_NONE = 0,
Kojto 122:f9eeca106725 122 FLASH_PROC_PAGE_ERASE,
Kojto 122:f9eeca106725 123 FLASH_PROC_MASS_ERASE,
Kojto 122:f9eeca106725 124 FLASH_PROC_PROGRAM,
Kojto 122:f9eeca106725 125 FLASH_PROC_PROGRAM_LAST
Kojto 122:f9eeca106725 126 } FLASH_ProcedureTypeDef;
Kojto 122:f9eeca106725 127
AnnaBridge 145:64910690c574 128 /**
AnnaBridge 145:64910690c574 129 * @brief FLASH Cache structure definition
AnnaBridge 145:64910690c574 130 */
AnnaBridge 145:64910690c574 131 typedef enum
AnnaBridge 145:64910690c574 132 {
AnnaBridge 145:64910690c574 133 FLASH_CACHE_DISABLED = 0,
AnnaBridge 145:64910690c574 134 FLASH_CACHE_ICACHE_ENABLED,
AnnaBridge 145:64910690c574 135 FLASH_CACHE_DCACHE_ENABLED,
AnnaBridge 145:64910690c574 136 FLASH_CACHE_ICACHE_DCACHE_ENABLED
AnnaBridge 145:64910690c574 137 } FLASH_CacheTypeDef;
AnnaBridge 145:64910690c574 138
Kojto 122:f9eeca106725 139 /**
Kojto 122:f9eeca106725 140 * @brief FLASH handle Structure definition
Kojto 122:f9eeca106725 141 */
Kojto 122:f9eeca106725 142 typedef struct
Kojto 122:f9eeca106725 143 {
Kojto 122:f9eeca106725 144 HAL_LockTypeDef Lock; /* FLASH locking object */
Kojto 122:f9eeca106725 145 __IO uint32_t ErrorCode; /* FLASH error code */
Kojto 122:f9eeca106725 146 __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /* Internal variable to indicate which procedure is ongoing or not in IT context */
Kojto 122:f9eeca106725 147 __IO uint32_t Address; /* Internal variable to save address selected for program in IT context */
Kojto 122:f9eeca106725 148 __IO uint32_t Bank; /* Internal variable to save current bank selected during erase in IT context */
Kojto 122:f9eeca106725 149 __IO uint32_t Page; /* Internal variable to define the current page which is erasing in IT context */
Kojto 122:f9eeca106725 150 __IO uint32_t NbPagesToErase; /* Internal variable to save the remaining pages to erase in IT context */
AnnaBridge 145:64910690c574 151 __IO FLASH_CacheTypeDef CacheToReactivate; /* Internal variable to indicate which caches should be reactivated */
Kojto 122:f9eeca106725 152 }FLASH_ProcessTypeDef;
Kojto 122:f9eeca106725 153
Kojto 122:f9eeca106725 154 /**
Kojto 122:f9eeca106725 155 * @}
Kojto 122:f9eeca106725 156 */
Kojto 122:f9eeca106725 157
Kojto 122:f9eeca106725 158 /* Exported constants --------------------------------------------------------*/
Kojto 122:f9eeca106725 159 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
Kojto 122:f9eeca106725 160 * @{
Kojto 122:f9eeca106725 161 */
Kojto 122:f9eeca106725 162
Kojto 122:f9eeca106725 163 /** @defgroup FLASH_Error FLASH Error
Kojto 122:f9eeca106725 164 * @{
Kojto 122:f9eeca106725 165 */
Kojto 122:f9eeca106725 166 #define HAL_FLASH_ERROR_NONE ((uint32_t)0x00000000)
Kojto 122:f9eeca106725 167 #define HAL_FLASH_ERROR_OP ((uint32_t)0x00000001)
Kojto 122:f9eeca106725 168 #define HAL_FLASH_ERROR_PROG ((uint32_t)0x00000002)
Kojto 122:f9eeca106725 169 #define HAL_FLASH_ERROR_WRP ((uint32_t)0x00000004)
Kojto 122:f9eeca106725 170 #define HAL_FLASH_ERROR_PGA ((uint32_t)0x00000008)
Kojto 122:f9eeca106725 171 #define HAL_FLASH_ERROR_SIZ ((uint32_t)0x00000010)
Kojto 122:f9eeca106725 172 #define HAL_FLASH_ERROR_PGS ((uint32_t)0x00000020)
Kojto 122:f9eeca106725 173 #define HAL_FLASH_ERROR_MIS ((uint32_t)0x00000040)
Kojto 122:f9eeca106725 174 #define HAL_FLASH_ERROR_FAST ((uint32_t)0x00000080)
Kojto 122:f9eeca106725 175 #define HAL_FLASH_ERROR_RD ((uint32_t)0x00000100)
Kojto 122:f9eeca106725 176 #define HAL_FLASH_ERROR_OPTV ((uint32_t)0x00000200)
Kojto 122:f9eeca106725 177 #define HAL_FLASH_ERROR_ECCD ((uint32_t)0x00000400)
AnnaBridge 145:64910690c574 178 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
AnnaBridge 145:64910690c574 179 defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 180 #define HAL_FLASH_ERROR_PEMPTY ((uint32_t)0x00000800)
Kojto 122:f9eeca106725 181 #endif
Kojto 122:f9eeca106725 182 /**
Kojto 122:f9eeca106725 183 * @}
Kojto 122:f9eeca106725 184 */
Kojto 122:f9eeca106725 185
Kojto 122:f9eeca106725 186 /** @defgroup FLASH_Type_Erase FLASH Erase Type
Kojto 122:f9eeca106725 187 * @{
Kojto 122:f9eeca106725 188 */
Kojto 122:f9eeca106725 189 #define FLASH_TYPEERASE_PAGES ((uint32_t)0x00) /*!<Pages erase only*/
Kojto 122:f9eeca106725 190 #define FLASH_TYPEERASE_MASSERASE ((uint32_t)0x01) /*!<Flash mass erase activation*/
Kojto 122:f9eeca106725 191 /**
Kojto 122:f9eeca106725 192 * @}
Kojto 122:f9eeca106725 193 */
Kojto 122:f9eeca106725 194
Kojto 122:f9eeca106725 195 /** @defgroup FLASH_Banks FLASH Banks
Kojto 122:f9eeca106725 196 * @{
Kojto 122:f9eeca106725 197 */
Kojto 122:f9eeca106725 198 #define FLASH_BANK_1 ((uint32_t)0x01) /*!< Bank 1 */
AnnaBridge 145:64910690c574 199 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 200 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 201 #define FLASH_BANK_2 ((uint32_t)0x02) /*!< Bank 2 */
Kojto 122:f9eeca106725 202 #define FLASH_BANK_BOTH ((uint32_t)(FLASH_BANK_1 | FLASH_BANK_2)) /*!< Bank1 and Bank2 */
Kojto 122:f9eeca106725 203 #else
Kojto 122:f9eeca106725 204 #define FLASH_BANK_BOTH ((uint32_t)(FLASH_BANK_1)) /*!< Bank 1 */
Kojto 122:f9eeca106725 205 #endif
Kojto 122:f9eeca106725 206 /**
Kojto 122:f9eeca106725 207 * @}
Kojto 122:f9eeca106725 208 */
Kojto 122:f9eeca106725 209
Kojto 122:f9eeca106725 210
Kojto 122:f9eeca106725 211 /** @defgroup FLASH_Type_Program FLASH Program Type
Kojto 122:f9eeca106725 212 * @{
Kojto 122:f9eeca106725 213 */
Kojto 122:f9eeca106725 214 #define FLASH_TYPEPROGRAM_DOUBLEWORD ((uint32_t)0x00) /*!<Program a double-word (64-bit) at a specified address.*/
Kojto 122:f9eeca106725 215 #define FLASH_TYPEPROGRAM_FAST ((uint32_t)0x01) /*!<Fast program a 32 row double-word (64-bit) at a specified address.
Kojto 122:f9eeca106725 216 And another 32 row double-word (64-bit) will be programmed */
Kojto 122:f9eeca106725 217 #define FLASH_TYPEPROGRAM_FAST_AND_LAST ((uint32_t)0x02) /*!<Fast program a 32 row double-word (64-bit) at a specified address.
Kojto 122:f9eeca106725 218 And this is the last 32 row double-word (64-bit) programmed */
Kojto 122:f9eeca106725 219 /**
Kojto 122:f9eeca106725 220 * @}
Kojto 122:f9eeca106725 221 */
Kojto 122:f9eeca106725 222
Kojto 122:f9eeca106725 223 /** @defgroup FLASH_OB_Type FLASH Option Bytes Type
Kojto 122:f9eeca106725 224 * @{
Kojto 122:f9eeca106725 225 */
Kojto 122:f9eeca106725 226 #define OPTIONBYTE_WRP ((uint32_t)0x01) /*!< WRP option byte configuration */
Kojto 122:f9eeca106725 227 #define OPTIONBYTE_RDP ((uint32_t)0x02) /*!< RDP option byte configuration */
Kojto 122:f9eeca106725 228 #define OPTIONBYTE_USER ((uint32_t)0x04) /*!< USER option byte configuration */
Kojto 122:f9eeca106725 229 #define OPTIONBYTE_PCROP ((uint32_t)0x08) /*!< PCROP option byte configuration */
Kojto 122:f9eeca106725 230 /**
Kojto 122:f9eeca106725 231 * @}
Kojto 122:f9eeca106725 232 */
Kojto 122:f9eeca106725 233
Kojto 122:f9eeca106725 234 /** @defgroup FLASH_OB_WRP_Area FLASH WRP Area
Kojto 122:f9eeca106725 235 * @{
Kojto 122:f9eeca106725 236 */
Kojto 122:f9eeca106725 237 #define OB_WRPAREA_BANK1_AREAA ((uint32_t)0x00) /*!< Flash Bank 1 Area A */
Kojto 122:f9eeca106725 238 #define OB_WRPAREA_BANK1_AREAB ((uint32_t)0x01) /*!< Flash Bank 1 Area B */
AnnaBridge 145:64910690c574 239 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 240 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 241 #define OB_WRPAREA_BANK2_AREAA ((uint32_t)0x02) /*!< Flash Bank 2 Area A */
Kojto 122:f9eeca106725 242 #define OB_WRPAREA_BANK2_AREAB ((uint32_t)0x04) /*!< Flash Bank 2 Area B */
Kojto 122:f9eeca106725 243 #endif
Kojto 122:f9eeca106725 244 /**
Kojto 122:f9eeca106725 245 * @}
Kojto 122:f9eeca106725 246 */
Kojto 122:f9eeca106725 247
Kojto 122:f9eeca106725 248 /** @defgroup FLASH_OB_Read_Protection FLASH Option Bytes Read Protection
Kojto 122:f9eeca106725 249 * @{
Kojto 122:f9eeca106725 250 */
Kojto 122:f9eeca106725 251 #define OB_RDP_LEVEL_0 ((uint32_t)0xAA)
Kojto 122:f9eeca106725 252 #define OB_RDP_LEVEL_1 ((uint32_t)0xBB)
Kojto 122:f9eeca106725 253 #define OB_RDP_LEVEL_2 ((uint32_t)0xCC) /*!< Warning: When enabling read protection level 2
Kojto 122:f9eeca106725 254 it's no more possible to go back to level 1 or 0 */
Kojto 122:f9eeca106725 255 /**
Kojto 122:f9eeca106725 256 * @}
Kojto 122:f9eeca106725 257 */
Kojto 122:f9eeca106725 258
Kojto 122:f9eeca106725 259 /** @defgroup FLASH_OB_USER_Type FLASH Option Bytes User Type
Kojto 122:f9eeca106725 260 * @{
Kojto 122:f9eeca106725 261 */
Kojto 122:f9eeca106725 262 #define OB_USER_BOR_LEV ((uint32_t)0x0001) /*!< BOR reset Level */
Kojto 122:f9eeca106725 263 #define OB_USER_nRST_STOP ((uint32_t)0x0002) /*!< Reset generated when entering the stop mode */
Kojto 122:f9eeca106725 264 #define OB_USER_nRST_STDBY ((uint32_t)0x0004) /*!< Reset generated when entering the standby mode */
Kojto 122:f9eeca106725 265 #define OB_USER_IWDG_SW ((uint32_t)0x0008) /*!< Independent watchdog selection */
Kojto 122:f9eeca106725 266 #define OB_USER_IWDG_STOP ((uint32_t)0x0010) /*!< Independent watchdog counter freeze in stop mode */
Kojto 122:f9eeca106725 267 #define OB_USER_IWDG_STDBY ((uint32_t)0x0020) /*!< Independent watchdog counter freeze in standby mode */
Kojto 122:f9eeca106725 268 #define OB_USER_WWDG_SW ((uint32_t)0x0040) /*!< Window watchdog selection */
AnnaBridge 145:64910690c574 269 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 270 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 271 #define OB_USER_BFB2 ((uint32_t)0x0080) /*!< Dual-bank boot */
Kojto 122:f9eeca106725 272 #define OB_USER_DUALBANK ((uint32_t)0x0100) /*!< Dual-Bank on 512KB or 256KB Flash memory devices */
Kojto 122:f9eeca106725 273 #endif
Kojto 122:f9eeca106725 274 #define OB_USER_nBOOT1 ((uint32_t)0x0200) /*!< Boot configuration */
Kojto 122:f9eeca106725 275 #define OB_USER_SRAM2_PE ((uint32_t)0x0400) /*!< SRAM2 parity check enable */
Kojto 122:f9eeca106725 276 #define OB_USER_SRAM2_RST ((uint32_t)0x0800) /*!< SRAM2 Erase when system reset */
Kojto 122:f9eeca106725 277 #define OB_USER_nRST_SHDW ((uint32_t)0x1000) /*!< Reset generated when entering the shutdown mode */
AnnaBridge 145:64910690c574 278 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || \
AnnaBridge 145:64910690c574 279 defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
AnnaBridge 145:64910690c574 280 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 281 #define OB_USER_nSWBOOT0 ((uint32_t)0x2000) /*!< Software BOOT0 */
Kojto 122:f9eeca106725 282 #define OB_USER_nBOOT0 ((uint32_t)0x4000) /*!< nBOOT0 option bit */
Kojto 122:f9eeca106725 283 #endif
Kojto 122:f9eeca106725 284 /**
Kojto 122:f9eeca106725 285 * @}
Kojto 122:f9eeca106725 286 */
Kojto 122:f9eeca106725 287
Kojto 122:f9eeca106725 288 /** @defgroup FLASH_OB_USER_BOR_LEVEL FLASH Option Bytes User BOR Level
Kojto 122:f9eeca106725 289 * @{
Kojto 122:f9eeca106725 290 */
Kojto 122:f9eeca106725 291 #define OB_BOR_LEVEL_0 ((uint32_t)FLASH_OPTR_BOR_LEV_0) /*!< Reset level threshold is around 1.7V */
Kojto 122:f9eeca106725 292 #define OB_BOR_LEVEL_1 ((uint32_t)FLASH_OPTR_BOR_LEV_1) /*!< Reset level threshold is around 2.0V */
Kojto 122:f9eeca106725 293 #define OB_BOR_LEVEL_2 ((uint32_t)FLASH_OPTR_BOR_LEV_2) /*!< Reset level threshold is around 2.2V */
Kojto 122:f9eeca106725 294 #define OB_BOR_LEVEL_3 ((uint32_t)FLASH_OPTR_BOR_LEV_3) /*!< Reset level threshold is around 2.5V */
Kojto 122:f9eeca106725 295 #define OB_BOR_LEVEL_4 ((uint32_t)FLASH_OPTR_BOR_LEV_4) /*!< Reset level threshold is around 2.8V */
Kojto 122:f9eeca106725 296 /**
Kojto 122:f9eeca106725 297 * @}
Kojto 122:f9eeca106725 298 */
Kojto 122:f9eeca106725 299
Kojto 122:f9eeca106725 300 /** @defgroup FLASH_OB_USER_nRST_STOP FLASH Option Bytes User Reset On Stop
Kojto 122:f9eeca106725 301 * @{
Kojto 122:f9eeca106725 302 */
Kojto 122:f9eeca106725 303 #define OB_STOP_RST ((uint32_t)0x0000) /*!< Reset generated when entering the stop mode */
Kojto 122:f9eeca106725 304 #define OB_STOP_NORST ((uint32_t)FLASH_OPTR_nRST_STOP) /*!< No reset generated when entering the stop mode */
Kojto 122:f9eeca106725 305 /**
Kojto 122:f9eeca106725 306 * @}
Kojto 122:f9eeca106725 307 */
Kojto 122:f9eeca106725 308
Kojto 122:f9eeca106725 309 /** @defgroup FLASH_OB_USER_nRST_STANDBY FLASH Option Bytes User Reset On Standby
Kojto 122:f9eeca106725 310 * @{
Kojto 122:f9eeca106725 311 */
Kojto 122:f9eeca106725 312 #define OB_STANDBY_RST ((uint32_t)0x0000) /*!< Reset generated when entering the standby mode */
Kojto 122:f9eeca106725 313 #define OB_STANDBY_NORST ((uint32_t)FLASH_OPTR_nRST_STDBY) /*!< No reset generated when entering the standby mode */
Kojto 122:f9eeca106725 314 /**
Kojto 122:f9eeca106725 315 * @}
Kojto 122:f9eeca106725 316 */
Kojto 122:f9eeca106725 317
Kojto 122:f9eeca106725 318 /** @defgroup FLASH_OB_USER_nRST_SHUTDOWN FLASH Option Bytes User Reset On Shutdown
Kojto 122:f9eeca106725 319 * @{
Kojto 122:f9eeca106725 320 */
Kojto 122:f9eeca106725 321 #define OB_SHUTDOWN_RST ((uint32_t)0x0000) /*!< Reset generated when entering the shutdown mode */
Kojto 122:f9eeca106725 322 #define OB_SHUTDOWN_NORST ((uint32_t)FLASH_OPTR_nRST_SHDW) /*!< No reset generated when entering the shutdown mode */
Kojto 122:f9eeca106725 323 /**
Kojto 122:f9eeca106725 324 * @}
Kojto 122:f9eeca106725 325 */
Kojto 122:f9eeca106725 326
Kojto 122:f9eeca106725 327 /** @defgroup FLASH_OB_USER_IWDG_SW FLASH Option Bytes User IWDG Type
Kojto 122:f9eeca106725 328 * @{
Kojto 122:f9eeca106725 329 */
Kojto 122:f9eeca106725 330 #define OB_IWDG_HW ((uint32_t)0x00000) /*!< Hardware independent watchdog */
Kojto 122:f9eeca106725 331 #define OB_IWDG_SW ((uint32_t)FLASH_OPTR_IWDG_SW) /*!< Software independent watchdog */
Kojto 122:f9eeca106725 332 /**
Kojto 122:f9eeca106725 333 * @}
Kojto 122:f9eeca106725 334 */
Kojto 122:f9eeca106725 335
Kojto 122:f9eeca106725 336 /** @defgroup FLASH_OB_USER_IWDG_STOP FLASH Option Bytes User IWDG Mode On Stop
Kojto 122:f9eeca106725 337 * @{
Kojto 122:f9eeca106725 338 */
Kojto 122:f9eeca106725 339 #define OB_IWDG_STOP_FREEZE ((uint32_t)0x00000) /*!< Independent watchdog counter is frozen in Stop mode */
Kojto 122:f9eeca106725 340 #define OB_IWDG_STOP_RUN ((uint32_t)FLASH_OPTR_IWDG_STOP) /*!< Independent watchdog counter is running in Stop mode */
Kojto 122:f9eeca106725 341 /**
Kojto 122:f9eeca106725 342 * @}
Kojto 122:f9eeca106725 343 */
Kojto 122:f9eeca106725 344
Kojto 122:f9eeca106725 345 /** @defgroup FLASH_OB_USER_IWDG_STANDBY FLASH Option Bytes User IWDG Mode On Standby
Kojto 122:f9eeca106725 346 * @{
Kojto 122:f9eeca106725 347 */
Kojto 122:f9eeca106725 348 #define OB_IWDG_STDBY_FREEZE ((uint32_t)0x00000) /*!< Independent watchdog counter is frozen in Standby mode */
Kojto 122:f9eeca106725 349 #define OB_IWDG_STDBY_RUN ((uint32_t)FLASH_OPTR_IWDG_STDBY) /*!< Independent watchdog counter is running in Standby mode */
Kojto 122:f9eeca106725 350 /**
Kojto 122:f9eeca106725 351 * @}
Kojto 122:f9eeca106725 352 */
Kojto 122:f9eeca106725 353
Kojto 122:f9eeca106725 354 /** @defgroup FLASH_OB_USER_WWDG_SW FLASH Option Bytes User WWDG Type
Kojto 122:f9eeca106725 355 * @{
Kojto 122:f9eeca106725 356 */
Kojto 122:f9eeca106725 357 #define OB_WWDG_HW ((uint32_t)0x00000) /*!< Hardware window watchdog */
Kojto 122:f9eeca106725 358 #define OB_WWDG_SW ((uint32_t)FLASH_OPTR_WWDG_SW) /*!< Software window watchdog */
Kojto 122:f9eeca106725 359 /**
Kojto 122:f9eeca106725 360 * @}
Kojto 122:f9eeca106725 361 */
Kojto 122:f9eeca106725 362
AnnaBridge 145:64910690c574 363 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 364 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 365 /** @defgroup FLASH_OB_USER_BFB2 FLASH Option Bytes User BFB2 Mode
Kojto 122:f9eeca106725 366 * @{
Kojto 122:f9eeca106725 367 */
Kojto 122:f9eeca106725 368 #define OB_BFB2_DISABLE ((uint32_t)0x000000) /*!< Dual-bank boot disable */
Kojto 122:f9eeca106725 369 #define OB_BFB2_ENABLE ((uint32_t)FLASH_OPTR_BFB2) /*!< Dual-bank boot enable */
Kojto 122:f9eeca106725 370 /**
Kojto 122:f9eeca106725 371 * @}
Kojto 122:f9eeca106725 372 */
Kojto 122:f9eeca106725 373 /** @defgroup FLASH_OB_USER_DUALBANK FLASH Option Bytes User Dual-bank Type
Kojto 122:f9eeca106725 374 * @{
Kojto 122:f9eeca106725 375 */
Kojto 122:f9eeca106725 376 #define OB_DUALBANK_SINGLE ((uint32_t)0x000000) /*!< 256 KB/512 KB Single-bank Flash */
Kojto 122:f9eeca106725 377 #define OB_DUALBANK_DUAL ((uint32_t)FLASH_OPTR_DUALBANK) /*!< 256 KB/512 KB Dual-bank Flash */
Kojto 122:f9eeca106725 378 /**
Kojto 122:f9eeca106725 379 * @}
Kojto 122:f9eeca106725 380 */
Kojto 122:f9eeca106725 381 #endif
Kojto 122:f9eeca106725 382
Kojto 122:f9eeca106725 383 /** @defgroup FLASH_OB_USER_nBOOT1 FLASH Option Bytes User BOOT1 Type
Kojto 122:f9eeca106725 384 * @{
Kojto 122:f9eeca106725 385 */
Kojto 122:f9eeca106725 386 #define OB_BOOT1_SRAM ((uint32_t)0x000000) /*!< Embedded SRAM1 is selected as boot space (if BOOT0=1) */
Kojto 122:f9eeca106725 387 #define OB_BOOT1_SYSTEM ((uint32_t)FLASH_OPTR_nBOOT1) /*!< System memory is selected as boot space (if BOOT0=1) */
Kojto 122:f9eeca106725 388 /**
Kojto 122:f9eeca106725 389 * @}
Kojto 122:f9eeca106725 390 */
Kojto 122:f9eeca106725 391
Kojto 122:f9eeca106725 392 /** @defgroup FLASH_OB_USER_SRAM2_PE FLASH Option Bytes User SRAM2 Parity Check Type
Kojto 122:f9eeca106725 393 * @{
Kojto 122:f9eeca106725 394 */
Kojto 122:f9eeca106725 395 #define OB_SRAM2_PARITY_ENABLE ((uint32_t)0x0000000) /*!< SRAM2 parity check enable */
Kojto 122:f9eeca106725 396 #define OB_SRAM2_PARITY_DISABLE ((uint32_t)FLASH_OPTR_SRAM2_PE) /*!< SRAM2 parity check disable */
Kojto 122:f9eeca106725 397 /**
Kojto 122:f9eeca106725 398 * @}
Kojto 122:f9eeca106725 399 */
Kojto 122:f9eeca106725 400
Kojto 122:f9eeca106725 401 /** @defgroup FLASH_OB_USER_SRAM2_RST FLASH Option Bytes User SRAM2 Erase On Reset Type
Kojto 122:f9eeca106725 402 * @{
Kojto 122:f9eeca106725 403 */
Kojto 122:f9eeca106725 404 #define OB_SRAM2_RST_ERASE ((uint32_t)0x0000000) /*!< SRAM2 erased when a system reset occurs */
Kojto 122:f9eeca106725 405 #define OB_SRAM2_RST_NOT_ERASE ((uint32_t)FLASH_OPTR_SRAM2_RST) /*!< SRAM2 is not erased when a system reset occurs */
Kojto 122:f9eeca106725 406 /**
Kojto 122:f9eeca106725 407 * @}
Kojto 122:f9eeca106725 408 */
Kojto 122:f9eeca106725 409
AnnaBridge 145:64910690c574 410 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || \
AnnaBridge 145:64910690c574 411 defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
AnnaBridge 145:64910690c574 412 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 413 /** @defgroup OB_USER_nSWBOOT0 FLASH Option Bytes User Software BOOT0
Kojto 122:f9eeca106725 414 * @{
Kojto 122:f9eeca106725 415 */
Kojto 122:f9eeca106725 416 #define OB_BOOT0_FROM_OB ((uint32_t)0x0000000) /*!< BOOT0 taken from the option bit nBOOT0 */
Kojto 122:f9eeca106725 417 #define OB_BOOT0_FROM_PIN ((uint32_t)FLASH_OPTR_nSWBOOT0) /*!< BOOT0 taken from PH3/BOOT0 pin */
Kojto 122:f9eeca106725 418 /**
Kojto 122:f9eeca106725 419 * @}
Kojto 122:f9eeca106725 420 */
Kojto 122:f9eeca106725 421
Kojto 122:f9eeca106725 422 /** @defgroup OB_USER_nBOOT0 FLASH Option Bytes User nBOOT0 option bit
Kojto 122:f9eeca106725 423 * @{
Kojto 122:f9eeca106725 424 */
Kojto 122:f9eeca106725 425 #define OB_BOOT0_RESET ((uint32_t)0x0000000) /*!< nBOOT0 = 0 */
Kojto 122:f9eeca106725 426 #define OB_BOOT0_SET ((uint32_t)FLASH_OPTR_nBOOT0) /*!< nBOOT0 = 1 */
Kojto 122:f9eeca106725 427 /**
Kojto 122:f9eeca106725 428 * @}
Kojto 122:f9eeca106725 429 */
Kojto 122:f9eeca106725 430 #endif
Kojto 122:f9eeca106725 431
Kojto 122:f9eeca106725 432 /** @defgroup FLASH_OB_PCROP_RDP FLASH Option Bytes PCROP On RDP Level Type
Kojto 122:f9eeca106725 433 * @{
Kojto 122:f9eeca106725 434 */
Kojto 122:f9eeca106725 435 #define OB_PCROP_RDP_NOT_ERASE ((uint32_t)0x00000000) /*!< PCROP area is not erased when the RDP level
Kojto 122:f9eeca106725 436 is decreased from Level 1 to Level 0 */
Kojto 122:f9eeca106725 437 #define OB_PCROP_RDP_ERASE ((uint32_t)FLASH_PCROP1ER_PCROP_RDP) /*!< PCROP area is erased when the RDP level is
Kojto 122:f9eeca106725 438 decreased from Level 1 to Level 0 (full mass erase) */
Kojto 122:f9eeca106725 439 /**
Kojto 122:f9eeca106725 440 * @}
Kojto 122:f9eeca106725 441 */
Kojto 122:f9eeca106725 442
Kojto 122:f9eeca106725 443 /** @defgroup FLASH_Latency FLASH Latency
Kojto 122:f9eeca106725 444 * @{
Kojto 122:f9eeca106725 445 */
Kojto 122:f9eeca106725 446 #define FLASH_LATENCY_0 FLASH_ACR_LATENCY_0WS /*!< FLASH Zero wait state */
Kojto 122:f9eeca106725 447 #define FLASH_LATENCY_1 FLASH_ACR_LATENCY_1WS /*!< FLASH One wait state */
Kojto 122:f9eeca106725 448 #define FLASH_LATENCY_2 FLASH_ACR_LATENCY_2WS /*!< FLASH Two wait states */
Kojto 122:f9eeca106725 449 #define FLASH_LATENCY_3 FLASH_ACR_LATENCY_3WS /*!< FLASH Three wait states */
Kojto 122:f9eeca106725 450 #define FLASH_LATENCY_4 FLASH_ACR_LATENCY_4WS /*!< FLASH Four wait states */
Kojto 122:f9eeca106725 451 /**
Kojto 122:f9eeca106725 452 * @}
Kojto 122:f9eeca106725 453 */
Kojto 122:f9eeca106725 454
Kojto 122:f9eeca106725 455 /** @defgroup FLASH_Keys FLASH Keys
Kojto 122:f9eeca106725 456 * @{
Kojto 122:f9eeca106725 457 */
Kojto 122:f9eeca106725 458 #define FLASH_KEY1 ((uint32_t)0x45670123U) /*!< Flash key1 */
Kojto 122:f9eeca106725 459 #define FLASH_KEY2 ((uint32_t)0xCDEF89ABU) /*!< Flash key2: used with FLASH_KEY1
Kojto 122:f9eeca106725 460 to unlock the FLASH registers access */
Kojto 122:f9eeca106725 461
Kojto 122:f9eeca106725 462 #define FLASH_PDKEY1 ((uint32_t)0x04152637U) /*!< Flash power down key1 */
Kojto 122:f9eeca106725 463 #define FLASH_PDKEY2 ((uint32_t)0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1
Kojto 122:f9eeca106725 464 to unlock the RUN_PD bit in FLASH_ACR */
Kojto 122:f9eeca106725 465
Kojto 122:f9eeca106725 466 #define FLASH_OPTKEY1 ((uint32_t)0x08192A3BU) /*!< Flash option byte key1 */
Kojto 122:f9eeca106725 467 #define FLASH_OPTKEY2 ((uint32_t)0x4C5D6E7FU) /*!< Flash option byte key2: used with FLASH_OPTKEY1
Kojto 122:f9eeca106725 468 to allow option bytes operations */
Kojto 122:f9eeca106725 469 /**
Kojto 122:f9eeca106725 470 * @}
Kojto 122:f9eeca106725 471 */
Kojto 122:f9eeca106725 472
Kojto 122:f9eeca106725 473 /** @defgroup FLASH_Flags FLASH Flags Definition
Kojto 122:f9eeca106725 474 * @{
Kojto 122:f9eeca106725 475 */
Kojto 122:f9eeca106725 476 #define FLASH_FLAG_EOP FLASH_SR_EOP /*!< FLASH End of operation flag */
Kojto 122:f9eeca106725 477 #define FLASH_FLAG_OPERR FLASH_SR_OPERR /*!< FLASH Operation error flag */
Kojto 122:f9eeca106725 478 #define FLASH_FLAG_PROGERR FLASH_SR_PROGERR /*!< FLASH Programming error flag */
Kojto 122:f9eeca106725 479 #define FLASH_FLAG_WRPERR FLASH_SR_WRPERR /*!< FLASH Write protection error flag */
Kojto 122:f9eeca106725 480 #define FLASH_FLAG_PGAERR FLASH_SR_PGAERR /*!< FLASH Programming alignment error flag */
Kojto 122:f9eeca106725 481 #define FLASH_FLAG_SIZERR FLASH_SR_SIZERR /*!< FLASH Size error flag */
Kojto 122:f9eeca106725 482 #define FLASH_FLAG_PGSERR FLASH_SR_PGSERR /*!< FLASH Programming sequence error flag */
Kojto 122:f9eeca106725 483 #define FLASH_FLAG_MISERR FLASH_SR_MISERR /*!< FLASH Fast programming data miss error flag */
Kojto 122:f9eeca106725 484 #define FLASH_FLAG_FASTERR FLASH_SR_FASTERR /*!< FLASH Fast programming error flag */
Kojto 122:f9eeca106725 485 #define FLASH_FLAG_RDERR FLASH_SR_RDERR /*!< FLASH PCROP read error flag */
Kojto 122:f9eeca106725 486 #define FLASH_FLAG_OPTVERR FLASH_SR_OPTVERR /*!< FLASH Option validity error flag */
Kojto 122:f9eeca106725 487 #define FLASH_FLAG_BSY FLASH_SR_BSY /*!< FLASH Busy flag */
AnnaBridge 145:64910690c574 488 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || defined (STM32L443xx) || \
AnnaBridge 145:64910690c574 489 defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 490 #define FLASH_FLAG_PEMPTY FLASH_SR_PEMPTY /*!< FLASH Program empty */
Kojto 122:f9eeca106725 491 #endif
Kojto 122:f9eeca106725 492 #define FLASH_FLAG_ECCC FLASH_ECCR_ECCC /*!< FLASH ECC correction */
Kojto 122:f9eeca106725 493 #define FLASH_FLAG_ECCD FLASH_ECCR_ECCD /*!< FLASH ECC detection */
Kojto 122:f9eeca106725 494
Kojto 122:f9eeca106725 495 #define FLASH_FLAG_ALL_ERRORS (FLASH_FLAG_OPERR | FLASH_FLAG_PROGERR | FLASH_FLAG_WRPERR | \
Kojto 122:f9eeca106725 496 FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_PGSERR | \
Kojto 122:f9eeca106725 497 FLASH_FLAG_MISERR | FLASH_FLAG_FASTERR | FLASH_FLAG_RDERR | \
Kojto 122:f9eeca106725 498 FLASH_FLAG_OPTVERR | FLASH_FLAG_ECCD)
Kojto 122:f9eeca106725 499 /**
Kojto 122:f9eeca106725 500 * @}
Kojto 122:f9eeca106725 501 */
Kojto 122:f9eeca106725 502
Kojto 122:f9eeca106725 503 /** @defgroup FLASH_Interrupt_definition FLASH Interrupts Definition
Kojto 122:f9eeca106725 504 * @brief FLASH Interrupt definition
Kojto 122:f9eeca106725 505 * @{
Kojto 122:f9eeca106725 506 */
Kojto 122:f9eeca106725 507 #define FLASH_IT_EOP FLASH_CR_EOPIE /*!< End of FLASH Operation Interrupt source */
Kojto 122:f9eeca106725 508 #define FLASH_IT_OPERR FLASH_CR_ERRIE /*!< Error Interrupt source */
Kojto 122:f9eeca106725 509 #define FLASH_IT_RDERR FLASH_CR_RDERRIE /*!< PCROP Read Error Interrupt source*/
Kojto 122:f9eeca106725 510 #define FLASH_IT_ECCC (FLASH_ECCR_ECCIE >> 24) /*!< ECC Correction Interrupt source */
Kojto 122:f9eeca106725 511 /**
Kojto 122:f9eeca106725 512 * @}
Kojto 122:f9eeca106725 513 */
Kojto 122:f9eeca106725 514
Kojto 122:f9eeca106725 515 /**
Kojto 122:f9eeca106725 516 * @}
Kojto 122:f9eeca106725 517 */
Kojto 122:f9eeca106725 518
Kojto 122:f9eeca106725 519 /* Exported macros -----------------------------------------------------------*/
Kojto 122:f9eeca106725 520 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
Kojto 122:f9eeca106725 521 * @brief macros to control FLASH features
Kojto 122:f9eeca106725 522 * @{
Kojto 122:f9eeca106725 523 */
Kojto 122:f9eeca106725 524
Kojto 122:f9eeca106725 525 /**
Kojto 122:f9eeca106725 526 * @brief Set the FLASH Latency.
Kojto 122:f9eeca106725 527 * @param __LATENCY__: FLASH Latency
Kojto 122:f9eeca106725 528 * This parameter can be one of the following values :
Kojto 122:f9eeca106725 529 * @arg FLASH_LATENCY_0: FLASH Zero wait state
Kojto 122:f9eeca106725 530 * @arg FLASH_LATENCY_1: FLASH One wait state
Kojto 122:f9eeca106725 531 * @arg FLASH_LATENCY_2: FLASH Two wait states
Kojto 122:f9eeca106725 532 * @arg FLASH_LATENCY_3: FLASH Three wait states
Kojto 122:f9eeca106725 533 * @arg FLASH_LATENCY_4: FLASH Four wait states
Kojto 122:f9eeca106725 534 * @retval None
Kojto 122:f9eeca106725 535 */
Kojto 122:f9eeca106725 536 #define __HAL_FLASH_SET_LATENCY(__LATENCY__) (MODIFY_REG(FLASH->ACR, FLASH_ACR_LATENCY, (__LATENCY__)))
Kojto 122:f9eeca106725 537
Kojto 122:f9eeca106725 538 /**
Kojto 122:f9eeca106725 539 * @brief Get the FLASH Latency.
Kojto 122:f9eeca106725 540 * @retval FLASH Latency
Kojto 122:f9eeca106725 541 * This parameter can be one of the following values :
Kojto 122:f9eeca106725 542 * @arg FLASH_LATENCY_0: FLASH Zero wait state
Kojto 122:f9eeca106725 543 * @arg FLASH_LATENCY_1: FLASH One wait state
Kojto 122:f9eeca106725 544 * @arg FLASH_LATENCY_2: FLASH Two wait states
Kojto 122:f9eeca106725 545 * @arg FLASH_LATENCY_3: FLASH Three wait states
Kojto 122:f9eeca106725 546 * @arg FLASH_LATENCY_4: FLASH Four wait states
Kojto 122:f9eeca106725 547 */
Kojto 122:f9eeca106725 548 #define __HAL_FLASH_GET_LATENCY() READ_BIT(FLASH->ACR, FLASH_ACR_LATENCY)
Kojto 122:f9eeca106725 549
Kojto 122:f9eeca106725 550 /**
Kojto 122:f9eeca106725 551 * @brief Enable the FLASH prefetch buffer.
Kojto 122:f9eeca106725 552 * @retval None
Kojto 122:f9eeca106725 553 */
Kojto 122:f9eeca106725 554 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_PRFTEN)
Kojto 122:f9eeca106725 555
Kojto 122:f9eeca106725 556 /**
Kojto 122:f9eeca106725 557 * @brief Disable the FLASH prefetch buffer.
Kojto 122:f9eeca106725 558 * @retval None
Kojto 122:f9eeca106725 559 */
Kojto 122:f9eeca106725 560 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_PRFTEN)
Kojto 122:f9eeca106725 561
Kojto 122:f9eeca106725 562 /**
Kojto 122:f9eeca106725 563 * @brief Enable the FLASH instruction cache.
Kojto 122:f9eeca106725 564 * @retval none
Kojto 122:f9eeca106725 565 */
Kojto 122:f9eeca106725 566 #define __HAL_FLASH_INSTRUCTION_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_ICEN)
Kojto 122:f9eeca106725 567
Kojto 122:f9eeca106725 568 /**
Kojto 122:f9eeca106725 569 * @brief Disable the FLASH instruction cache.
Kojto 122:f9eeca106725 570 * @retval none
Kojto 122:f9eeca106725 571 */
Kojto 122:f9eeca106725 572 #define __HAL_FLASH_INSTRUCTION_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICEN)
Kojto 122:f9eeca106725 573
Kojto 122:f9eeca106725 574 /**
Kojto 122:f9eeca106725 575 * @brief Enable the FLASH data cache.
Kojto 122:f9eeca106725 576 * @retval none
Kojto 122:f9eeca106725 577 */
Kojto 122:f9eeca106725 578 #define __HAL_FLASH_DATA_CACHE_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_DCEN)
Kojto 122:f9eeca106725 579
Kojto 122:f9eeca106725 580 /**
Kojto 122:f9eeca106725 581 * @brief Disable the FLASH data cache.
Kojto 122:f9eeca106725 582 * @retval none
Kojto 122:f9eeca106725 583 */
Kojto 122:f9eeca106725 584 #define __HAL_FLASH_DATA_CACHE_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_DCEN)
Kojto 122:f9eeca106725 585
Kojto 122:f9eeca106725 586 /**
Kojto 122:f9eeca106725 587 * @brief Reset the FLASH instruction Cache.
Kojto 122:f9eeca106725 588 * @note This function must be used only when the Instruction Cache is disabled.
Kojto 122:f9eeca106725 589 * @retval None
Kojto 122:f9eeca106725 590 */
Kojto 122:f9eeca106725 591 #define __HAL_FLASH_INSTRUCTION_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_ICRST); \
Kojto 122:f9eeca106725 592 CLEAR_BIT(FLASH->ACR, FLASH_ACR_ICRST); \
Kojto 122:f9eeca106725 593 } while (0)
Kojto 122:f9eeca106725 594
Kojto 122:f9eeca106725 595 /**
Kojto 122:f9eeca106725 596 * @brief Reset the FLASH data Cache.
Kojto 122:f9eeca106725 597 * @note This function must be used only when the data Cache is disabled.
Kojto 122:f9eeca106725 598 * @retval None
Kojto 122:f9eeca106725 599 */
Kojto 122:f9eeca106725 600 #define __HAL_FLASH_DATA_CACHE_RESET() do { SET_BIT(FLASH->ACR, FLASH_ACR_DCRST); \
Kojto 122:f9eeca106725 601 CLEAR_BIT(FLASH->ACR, FLASH_ACR_DCRST); \
Kojto 122:f9eeca106725 602 } while (0)
Kojto 122:f9eeca106725 603
Kojto 122:f9eeca106725 604 /**
Kojto 122:f9eeca106725 605 * @brief Enable the FLASH power down during Low-power run mode.
Kojto 122:f9eeca106725 606 * @note Writing this bit to 0 this bit, automatically the keys are
Kojto 122:f9eeca106725 607 * loss and a new unlock sequence is necessary to re-write it to 1.
Kojto 122:f9eeca106725 608 */
Kojto 122:f9eeca106725 609 #define __HAL_FLASH_POWER_DOWN_ENABLE() do { WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY1); \
Kojto 122:f9eeca106725 610 WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY2); \
Kojto 122:f9eeca106725 611 SET_BIT(FLASH->ACR, FLASH_ACR_RUN_PD); \
Kojto 122:f9eeca106725 612 } while (0)
Kojto 122:f9eeca106725 613
Kojto 122:f9eeca106725 614 /**
Kojto 122:f9eeca106725 615 * @brief Disable the FLASH power down during Low-power run mode.
Kojto 122:f9eeca106725 616 * @note Writing this bit to 0 this bit, automatically the keys are
Kojto 122:f9eeca106725 617 * loss and a new unlock sequence is necessary to re-write it to 1.
Kojto 122:f9eeca106725 618 */
Kojto 122:f9eeca106725 619 #define __HAL_FLASH_POWER_DOWN_DISABLE() do { WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY1); \
Kojto 122:f9eeca106725 620 WRITE_REG(FLASH->PDKEYR, FLASH_PDKEY2); \
Kojto 122:f9eeca106725 621 CLEAR_BIT(FLASH->ACR, FLASH_ACR_RUN_PD); \
Kojto 122:f9eeca106725 622 } while (0)
Kojto 122:f9eeca106725 623
Kojto 122:f9eeca106725 624 /**
Kojto 122:f9eeca106725 625 * @brief Enable the FLASH power down during Low-Power sleep mode
Kojto 122:f9eeca106725 626 * @retval none
Kojto 122:f9eeca106725 627 */
Kojto 122:f9eeca106725 628 #define __HAL_FLASH_SLEEP_POWERDOWN_ENABLE() SET_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
Kojto 122:f9eeca106725 629
Kojto 122:f9eeca106725 630 /**
Kojto 122:f9eeca106725 631 * @brief Disable the FLASH power down during Low-Power sleep mode
Kojto 122:f9eeca106725 632 * @retval none
Kojto 122:f9eeca106725 633 */
Kojto 122:f9eeca106725 634 #define __HAL_FLASH_SLEEP_POWERDOWN_DISABLE() CLEAR_BIT(FLASH->ACR, FLASH_ACR_SLEEP_PD)
Kojto 122:f9eeca106725 635
Kojto 122:f9eeca106725 636 /**
Kojto 122:f9eeca106725 637 * @}
Kojto 122:f9eeca106725 638 */
Kojto 122:f9eeca106725 639
Kojto 122:f9eeca106725 640 /** @defgroup FLASH_Interrupt FLASH Interrupts Macros
Kojto 122:f9eeca106725 641 * @brief macros to handle FLASH interrupts
Kojto 122:f9eeca106725 642 * @{
Kojto 122:f9eeca106725 643 */
Kojto 122:f9eeca106725 644
Kojto 122:f9eeca106725 645 /**
Kojto 122:f9eeca106725 646 * @brief Enable the specified FLASH interrupt.
Kojto 122:f9eeca106725 647 * @param __INTERRUPT__: FLASH interrupt
Kojto 122:f9eeca106725 648 * This parameter can be any combination of the following values:
Kojto 122:f9eeca106725 649 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
Kojto 122:f9eeca106725 650 * @arg FLASH_IT_OPERR: Error Interrupt
Kojto 122:f9eeca106725 651 * @arg FLASH_IT_RDERR: PCROP Read Error Interrupt
Kojto 122:f9eeca106725 652 * @arg FLASH_IT_ECCC: ECC Correction Interrupt
Kojto 122:f9eeca106725 653 * @retval none
Kojto 122:f9eeca106725 654 */
Kojto 122:f9eeca106725 655 #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__) do { if((__INTERRUPT__) & FLASH_IT_ECCC) { SET_BIT(FLASH->ECCR, FLASH_ECCR_ECCIE); }\
Kojto 122:f9eeca106725 656 if((__INTERRUPT__) & (~FLASH_IT_ECCC)) { SET_BIT(FLASH->CR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); }\
Kojto 122:f9eeca106725 657 } while(0)
Kojto 122:f9eeca106725 658
Kojto 122:f9eeca106725 659 /**
Kojto 122:f9eeca106725 660 * @brief Disable the specified FLASH interrupt.
Kojto 122:f9eeca106725 661 * @param __INTERRUPT__: FLASH interrupt
Kojto 122:f9eeca106725 662 * This parameter can be any combination of the following values:
Kojto 122:f9eeca106725 663 * @arg FLASH_IT_EOP: End of FLASH Operation Interrupt
Kojto 122:f9eeca106725 664 * @arg FLASH_IT_OPERR: Error Interrupt
Kojto 122:f9eeca106725 665 * @arg FLASH_IT_RDERR: PCROP Read Error Interrupt
Kojto 122:f9eeca106725 666 * @arg FLASH_IT_ECCC: ECC Correction Interrupt
Kojto 122:f9eeca106725 667 * @retval none
Kojto 122:f9eeca106725 668 */
Kojto 122:f9eeca106725 669 #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__) do { if((__INTERRUPT__) & FLASH_IT_ECCC) { CLEAR_BIT(FLASH->ECCR, FLASH_ECCR_ECCIE); }\
Kojto 122:f9eeca106725 670 if((__INTERRUPT__) & (~FLASH_IT_ECCC)) { CLEAR_BIT(FLASH->CR, ((__INTERRUPT__) & (~FLASH_IT_ECCC))); }\
Kojto 122:f9eeca106725 671 } while(0)
Kojto 122:f9eeca106725 672
Kojto 122:f9eeca106725 673 /**
Kojto 122:f9eeca106725 674 * @brief Check whether the specified FLASH flag is set or not.
Kojto 122:f9eeca106725 675 * @param __FLAG__: specifies the FLASH flag to check.
Kojto 122:f9eeca106725 676 * This parameter can be one of the following values:
Kojto 122:f9eeca106725 677 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
Kojto 122:f9eeca106725 678 * @arg FLASH_FLAG_OPERR: FLASH Operation error flag
Kojto 122:f9eeca106725 679 * @arg FLASH_FLAG_PROGERR: FLASH Programming error flag
Kojto 122:f9eeca106725 680 * @arg FLASH_FLAG_WRPERR: FLASH Write protection error flag
Kojto 122:f9eeca106725 681 * @arg FLASH_FLAG_PGAERR: FLASH Programming alignment error flag
Kojto 122:f9eeca106725 682 * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
Kojto 122:f9eeca106725 683 * @arg FLASH_FLAG_PGSERR: FLASH Programming sequence error flag
Kojto 122:f9eeca106725 684 * @arg FLASH_FLAG_MISERR: FLASH Fast programming data miss error flag
Kojto 122:f9eeca106725 685 * @arg FLASH_FLAG_FASTERR: FLASH Fast programming error flag
Kojto 122:f9eeca106725 686 * @arg FLASH_FLAG_RDERR: FLASH PCROP read error flag
Kojto 122:f9eeca106725 687 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
Kojto 122:f9eeca106725 688 * @arg FLASH_FLAG_BSY: FLASH write/erase operations in progress flag
Kojto 122:f9eeca106725 689 * @arg FLASH_FLAG_PEMPTY : FLASH Boot from not programmed flash (apply only for STM32L43x/STM32L44x devices)
Kojto 122:f9eeca106725 690 * @arg FLASH_FLAG_ECCC: FLASH one ECC error has been detected and corrected
Kojto 122:f9eeca106725 691 * @arg FLASH_FLAG_ECCD: FLASH two ECC errors have been detected
Kojto 122:f9eeca106725 692 * @retval The new state of FLASH_FLAG (SET or RESET).
Kojto 122:f9eeca106725 693 */
Kojto 122:f9eeca106725 694 #define __HAL_FLASH_GET_FLAG(__FLAG__) (((__FLAG__) & (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)) ? \
Kojto 122:f9eeca106725 695 (READ_BIT(FLASH->ECCR, (__FLAG__)) == (__FLAG__)) : \
Kojto 122:f9eeca106725 696 (READ_BIT(FLASH->SR, (__FLAG__)) == (__FLAG__)))
Kojto 122:f9eeca106725 697
Kojto 122:f9eeca106725 698 /**
Kojto 122:f9eeca106725 699 * @brief Clear the FLASH's pending flags.
Kojto 122:f9eeca106725 700 * @param __FLAG__: specifies the FLASH flags to clear.
Kojto 122:f9eeca106725 701 * This parameter can be any combination of the following values:
Kojto 122:f9eeca106725 702 * @arg FLASH_FLAG_EOP: FLASH End of Operation flag
Kojto 122:f9eeca106725 703 * @arg FLASH_FLAG_OPERR: FLASH Operation error flag
Kojto 122:f9eeca106725 704 * @arg FLASH_FLAG_PROGERR: FLASH Programming error flag
Kojto 122:f9eeca106725 705 * @arg FLASH_FLAG_WRPERR: FLASH Write protection error flag
Kojto 122:f9eeca106725 706 * @arg FLASH_FLAG_PGAERR: FLASH Programming alignment error flag
Kojto 122:f9eeca106725 707 * @arg FLASH_FLAG_SIZERR: FLASH Size error flag
Kojto 122:f9eeca106725 708 * @arg FLASH_FLAG_PGSERR: FLASH Programming sequence error flag
Kojto 122:f9eeca106725 709 * @arg FLASH_FLAG_MISERR: FLASH Fast programming data miss error flag
Kojto 122:f9eeca106725 710 * @arg FLASH_FLAG_FASTERR: FLASH Fast programming error flag
Kojto 122:f9eeca106725 711 * @arg FLASH_FLAG_RDERR: FLASH PCROP read error flag
Kojto 122:f9eeca106725 712 * @arg FLASH_FLAG_OPTVERR: FLASH Option validity error flag
Kojto 122:f9eeca106725 713 * @arg FLASH_FLAG_ECCC: FLASH one ECC error has been detected and corrected
Kojto 122:f9eeca106725 714 * @arg FLASH_FLAG_ECCD: FLASH two ECC errors have been detected
Kojto 122:f9eeca106725 715 * @arg FLASH_FLAG_ALL_ERRORS: FLASH All errors flags
Kojto 122:f9eeca106725 716 * @retval None
Kojto 122:f9eeca106725 717 */
Kojto 122:f9eeca106725 718 #define __HAL_FLASH_CLEAR_FLAG(__FLAG__) do { if((__FLAG__) & (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)) { SET_BIT(FLASH->ECCR, ((__FLAG__) & (FLASH_FLAG_ECCC | FLASH_FLAG_ECCD))); }\
Kojto 122:f9eeca106725 719 if((__FLAG__) & ~(FLASH_FLAG_ECCC | FLASH_FLAG_ECCD)) { WRITE_REG(FLASH->SR, ((__FLAG__) & ~(FLASH_FLAG_ECCC | FLASH_FLAG_ECCD))); }\
Kojto 122:f9eeca106725 720 } while(0)
Kojto 122:f9eeca106725 721 /**
Kojto 122:f9eeca106725 722 * @}
Kojto 122:f9eeca106725 723 */
Kojto 122:f9eeca106725 724
Kojto 122:f9eeca106725 725 /* Include FLASH HAL Extended module */
Kojto 122:f9eeca106725 726 #include "stm32l4xx_hal_flash_ex.h"
Kojto 122:f9eeca106725 727 #include "stm32l4xx_hal_flash_ramfunc.h"
Kojto 122:f9eeca106725 728
Kojto 122:f9eeca106725 729 /* Exported functions --------------------------------------------------------*/
Kojto 122:f9eeca106725 730 /** @addtogroup FLASH_Exported_Functions
Kojto 122:f9eeca106725 731 * @{
Kojto 122:f9eeca106725 732 */
Kojto 122:f9eeca106725 733
Kojto 122:f9eeca106725 734 /* Program operation functions ***********************************************/
Kojto 122:f9eeca106725 735 /** @addtogroup FLASH_Exported_Functions_Group1
Kojto 122:f9eeca106725 736 * @{
Kojto 122:f9eeca106725 737 */
Kojto 122:f9eeca106725 738 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
Kojto 122:f9eeca106725 739 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
Kojto 122:f9eeca106725 740 /* FLASH IRQ handler method */
Kojto 122:f9eeca106725 741 void HAL_FLASH_IRQHandler(void);
Kojto 122:f9eeca106725 742 /* Callbacks in non blocking modes */
Kojto 122:f9eeca106725 743 void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
Kojto 122:f9eeca106725 744 void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
Kojto 122:f9eeca106725 745 /**
Kojto 122:f9eeca106725 746 * @}
Kojto 122:f9eeca106725 747 */
Kojto 122:f9eeca106725 748
Kojto 122:f9eeca106725 749 /* Peripheral Control functions **********************************************/
Kojto 122:f9eeca106725 750 /** @addtogroup FLASH_Exported_Functions_Group2
Kojto 122:f9eeca106725 751 * @{
Kojto 122:f9eeca106725 752 */
Kojto 122:f9eeca106725 753 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
Kojto 122:f9eeca106725 754 HAL_StatusTypeDef HAL_FLASH_Lock(void);
Kojto 122:f9eeca106725 755 /* Option bytes control */
Kojto 122:f9eeca106725 756 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
Kojto 122:f9eeca106725 757 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
Kojto 122:f9eeca106725 758 HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
Kojto 122:f9eeca106725 759 /**
Kojto 122:f9eeca106725 760 * @}
Kojto 122:f9eeca106725 761 */
Kojto 122:f9eeca106725 762
Kojto 122:f9eeca106725 763 /* Peripheral State functions ************************************************/
Kojto 122:f9eeca106725 764 /** @addtogroup FLASH_Exported_Functions_Group3
Kojto 122:f9eeca106725 765 * @{
Kojto 122:f9eeca106725 766 */
Kojto 122:f9eeca106725 767 uint32_t HAL_FLASH_GetError(void);
Kojto 122:f9eeca106725 768 /**
Kojto 122:f9eeca106725 769 * @}
Kojto 122:f9eeca106725 770 */
Kojto 122:f9eeca106725 771
Kojto 122:f9eeca106725 772 /**
Kojto 122:f9eeca106725 773 * @}
Kojto 122:f9eeca106725 774 */
Kojto 122:f9eeca106725 775
Kojto 122:f9eeca106725 776 /* Private constants --------------------------------------------------------*/
Kojto 122:f9eeca106725 777 /** @defgroup FLASH_Private_Constants FLASH Private Constants
Kojto 122:f9eeca106725 778 * @{
Kojto 122:f9eeca106725 779 */
Kojto 122:f9eeca106725 780 #define FLASH_SIZE_DATA_REGISTER ((uint32_t)0x1FFF75E0)
Kojto 122:f9eeca106725 781
AnnaBridge 145:64910690c574 782 #if defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
AnnaBridge 145:64910690c574 783 #define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFF)) ? (0x200 << 10) : \
AnnaBridge 145:64910690c574 784 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) << 10))
AnnaBridge 145:64910690c574 785 #else
Kojto 122:f9eeca106725 786 #define FLASH_SIZE ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) == 0xFFFF)) ? (0x400 << 10) : \
Kojto 122:f9eeca106725 787 (((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) << 10))
AnnaBridge 145:64910690c574 788 #endif
Kojto 122:f9eeca106725 789
AnnaBridge 145:64910690c574 790 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 791 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 792 #define FLASH_BANK_SIZE (FLASH_SIZE >> 1)
Kojto 122:f9eeca106725 793 #else
Kojto 122:f9eeca106725 794 #define FLASH_BANK_SIZE (FLASH_SIZE)
Kojto 122:f9eeca106725 795 #endif
Kojto 122:f9eeca106725 796
Kojto 122:f9eeca106725 797 #define FLASH_PAGE_SIZE ((uint32_t)0x800)
Kojto 122:f9eeca106725 798
Kojto 122:f9eeca106725 799 #define FLASH_TIMEOUT_VALUE ((uint32_t)50000)/* 50 s */
Kojto 122:f9eeca106725 800 /**
Kojto 122:f9eeca106725 801 * @}
Kojto 122:f9eeca106725 802 */
Kojto 122:f9eeca106725 803
Kojto 122:f9eeca106725 804 /* Private macros ------------------------------------------------------------*/
Kojto 122:f9eeca106725 805 /** @defgroup FLASH_Private_Macros FLASH Private Macros
Kojto 122:f9eeca106725 806 * @{
Kojto 122:f9eeca106725 807 */
Kojto 122:f9eeca106725 808
Kojto 122:f9eeca106725 809 #define IS_FLASH_TYPEERASE(VALUE) (((VALUE) == FLASH_TYPEERASE_PAGES) || \
Kojto 122:f9eeca106725 810 ((VALUE) == FLASH_TYPEERASE_MASSERASE))
Kojto 122:f9eeca106725 811
AnnaBridge 145:64910690c574 812 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 813 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 814 #define IS_FLASH_BANK(BANK) (((BANK) == FLASH_BANK_1) || \
Kojto 122:f9eeca106725 815 ((BANK) == FLASH_BANK_2) || \
Kojto 122:f9eeca106725 816 ((BANK) == FLASH_BANK_BOTH))
Kojto 122:f9eeca106725 817
Kojto 122:f9eeca106725 818 #define IS_FLASH_BANK_EXCLUSIVE(BANK) (((BANK) == FLASH_BANK_1) || \
Kojto 122:f9eeca106725 819 ((BANK) == FLASH_BANK_2))
Kojto 122:f9eeca106725 820 #else
Kojto 122:f9eeca106725 821 #define IS_FLASH_BANK(BANK) ((BANK) == FLASH_BANK_1)
Kojto 122:f9eeca106725 822
Kojto 122:f9eeca106725 823 #define IS_FLASH_BANK_EXCLUSIVE(BANK) ((BANK) == FLASH_BANK_1)
Kojto 122:f9eeca106725 824 #endif
Kojto 122:f9eeca106725 825
Kojto 122:f9eeca106725 826 #define IS_FLASH_TYPEPROGRAM(VALUE) (((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD) || \
Kojto 122:f9eeca106725 827 ((VALUE) == FLASH_TYPEPROGRAM_FAST) || \
Kojto 122:f9eeca106725 828 ((VALUE) == FLASH_TYPEPROGRAM_FAST_AND_LAST))
Kojto 122:f9eeca106725 829
Kojto 122:f9eeca106725 830 #define IS_FLASH_MAIN_MEM_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_BASE) && ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x400) ? \
Kojto 122:f9eeca106725 831 ((ADDRESS) <= FLASH_BASE+0xFFFFF) : ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x200) ? \
Kojto 122:f9eeca106725 832 ((ADDRESS) <= FLASH_BASE+0x7FFFF) : ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x100) ? \
Kojto 122:f9eeca106725 833 ((ADDRESS) <= FLASH_BASE+0x3FFFF) : ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x80) ? \
Kojto 122:f9eeca106725 834 ((ADDRESS) <= FLASH_BASE+0x1FFFF) : ((ADDRESS) <= FLASH_BASE+0xFFFFF))))))
Kojto 122:f9eeca106725 835
Kojto 122:f9eeca106725 836 #define IS_FLASH_OTP_ADDRESS(ADDRESS) (((ADDRESS) >= 0x1FFF7000) && ((ADDRESS) <= 0x1FFF73FF))
Kojto 122:f9eeca106725 837
Kojto 122:f9eeca106725 838 #define IS_FLASH_PROGRAM_ADDRESS(ADDRESS) (IS_FLASH_MAIN_MEM_ADDRESS(ADDRESS) || IS_FLASH_OTP_ADDRESS(ADDRESS))
Kojto 122:f9eeca106725 839
AnnaBridge 145:64910690c574 840 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
Kojto 122:f9eeca106725 841 #define IS_FLASH_PAGE(PAGE) (((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x400) ? ((PAGE) < 256) : \
Kojto 122:f9eeca106725 842 ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x200) ? ((PAGE) < 128) : \
Kojto 122:f9eeca106725 843 ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x100) ? ((PAGE) < 64) : \
Kojto 122:f9eeca106725 844 ((PAGE) < 256)))))
AnnaBridge 145:64910690c574 845 #elif defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx)
AnnaBridge 145:64910690c574 846 #define IS_FLASH_PAGE(PAGE) (((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x200) ? ((PAGE) < 256) : \
AnnaBridge 145:64910690c574 847 ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x100) ? ((PAGE) < 128) : \
AnnaBridge 145:64910690c574 848 ((PAGE) < 256))))
Kojto 122:f9eeca106725 849 #else
Kojto 122:f9eeca106725 850 #define IS_FLASH_PAGE(PAGE) (((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x100) ? ((PAGE) < 128) : \
Kojto 122:f9eeca106725 851 ((((*((uint16_t *)FLASH_SIZE_DATA_REGISTER)) & (0x0FFF)) == 0x80) ? ((PAGE) < 64) : \
Kojto 122:f9eeca106725 852 ((PAGE) < 128))))
Kojto 122:f9eeca106725 853 #endif
Kojto 122:f9eeca106725 854
Kojto 122:f9eeca106725 855 #define IS_OPTIONBYTE(VALUE) (((VALUE) <= (OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER | OPTIONBYTE_PCROP)))
Kojto 122:f9eeca106725 856
AnnaBridge 145:64910690c574 857 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 858 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 859 #define IS_OB_WRPAREA(VALUE) (((VALUE) == OB_WRPAREA_BANK1_AREAA) || ((VALUE) == OB_WRPAREA_BANK1_AREAB) || \
Kojto 122:f9eeca106725 860 ((VALUE) == OB_WRPAREA_BANK2_AREAA) || ((VALUE) == OB_WRPAREA_BANK2_AREAB))
Kojto 122:f9eeca106725 861 #else
Kojto 122:f9eeca106725 862 #define IS_OB_WRPAREA(VALUE) (((VALUE) == OB_WRPAREA_BANK1_AREAA) || ((VALUE) == OB_WRPAREA_BANK1_AREAB))
Kojto 122:f9eeca106725 863 #endif
Kojto 122:f9eeca106725 864
Kojto 122:f9eeca106725 865 #define IS_OB_RDP_LEVEL(LEVEL) (((LEVEL) == OB_RDP_LEVEL_0) ||\
Kojto 122:f9eeca106725 866 ((LEVEL) == OB_RDP_LEVEL_1)/* ||\
Kojto 122:f9eeca106725 867 ((LEVEL) == OB_RDP_LEVEL_2)*/)
Kojto 122:f9eeca106725 868
AnnaBridge 145:64910690c574 869 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) || defined(STM32L496xx) || defined(STM32L4A6xx)
Kojto 122:f9eeca106725 870 #define IS_OB_USER_TYPE(TYPE) (((TYPE) <= (uint32_t)0x1FFF) && ((TYPE) != 0))
Kojto 122:f9eeca106725 871 #else
Kojto 122:f9eeca106725 872 #define IS_OB_USER_TYPE(TYPE) (((TYPE) <= (uint32_t)0x7E7F) && ((TYPE) != 0) && (((TYPE)&0x0180) == 0))
Kojto 122:f9eeca106725 873 #endif
Kojto 122:f9eeca106725 874
Kojto 122:f9eeca106725 875 #define IS_OB_USER_BOR_LEVEL(LEVEL) (((LEVEL) == OB_BOR_LEVEL_0) || ((LEVEL) == OB_BOR_LEVEL_1) || \
Kojto 122:f9eeca106725 876 ((LEVEL) == OB_BOR_LEVEL_2) || ((LEVEL) == OB_BOR_LEVEL_3) || \
Kojto 122:f9eeca106725 877 ((LEVEL) == OB_BOR_LEVEL_4))
Kojto 122:f9eeca106725 878
Kojto 122:f9eeca106725 879 #define IS_OB_USER_STOP(VALUE) (((VALUE) == OB_STOP_RST) || ((VALUE) == OB_STOP_NORST))
Kojto 122:f9eeca106725 880
Kojto 122:f9eeca106725 881 #define IS_OB_USER_STANDBY(VALUE) (((VALUE) == OB_STANDBY_RST) || ((VALUE) == OB_STANDBY_NORST))
Kojto 122:f9eeca106725 882
Kojto 122:f9eeca106725 883 #define IS_OB_USER_SHUTDOWN(VALUE) (((VALUE) == OB_SHUTDOWN_RST) || ((VALUE) == OB_SHUTDOWN_NORST))
Kojto 122:f9eeca106725 884
Kojto 122:f9eeca106725 885 #define IS_OB_USER_IWDG(VALUE) (((VALUE) == OB_IWDG_HW) || ((VALUE) == OB_IWDG_SW))
Kojto 122:f9eeca106725 886
Kojto 122:f9eeca106725 887 #define IS_OB_USER_IWDG_STOP(VALUE) (((VALUE) == OB_IWDG_STOP_FREEZE) || ((VALUE) == OB_IWDG_STOP_RUN))
Kojto 122:f9eeca106725 888
Kojto 122:f9eeca106725 889 #define IS_OB_USER_IWDG_STDBY(VALUE) (((VALUE) == OB_IWDG_STDBY_FREEZE) || ((VALUE) == OB_IWDG_STDBY_RUN))
Kojto 122:f9eeca106725 890
Kojto 122:f9eeca106725 891 #define IS_OB_USER_WWDG(VALUE) (((VALUE) == OB_WWDG_HW) || ((VALUE) == OB_WWDG_SW))
Kojto 122:f9eeca106725 892
AnnaBridge 145:64910690c574 893 #if defined (STM32L471xx) || defined (STM32L475xx) || defined (STM32L476xx) || defined (STM32L485xx) || defined (STM32L486xx) || \
AnnaBridge 145:64910690c574 894 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 895 #define IS_OB_USER_BFB2(VALUE) (((VALUE) == OB_BFB2_DISABLE) || ((VALUE) == OB_BFB2_ENABLE))
Kojto 122:f9eeca106725 896
Kojto 122:f9eeca106725 897 #define IS_OB_USER_DUALBANK(VALUE) (((VALUE) == OB_DUALBANK_SINGLE) || ((VALUE) == OB_DUALBANK_DUAL))
Kojto 122:f9eeca106725 898 #endif
Kojto 122:f9eeca106725 899
Kojto 122:f9eeca106725 900 #define IS_OB_USER_BOOT1(VALUE) (((VALUE) == OB_BOOT1_SRAM) || ((VALUE) == OB_BOOT1_SYSTEM))
Kojto 122:f9eeca106725 901
Kojto 122:f9eeca106725 902 #define IS_OB_USER_SRAM2_PARITY(VALUE) (((VALUE) == OB_SRAM2_PARITY_ENABLE) || ((VALUE) == OB_SRAM2_PARITY_DISABLE))
Kojto 122:f9eeca106725 903
Kojto 122:f9eeca106725 904 #define IS_OB_USER_SRAM2_RST(VALUE) (((VALUE) == OB_SRAM2_RST_ERASE) || ((VALUE) == OB_SRAM2_RST_NOT_ERASE))
Kojto 122:f9eeca106725 905
AnnaBridge 145:64910690c574 906 #if defined (STM32L431xx) || defined (STM32L432xx) || defined (STM32L433xx) || defined (STM32L442xx) || \
AnnaBridge 145:64910690c574 907 defined (STM32L443xx) || defined (STM32L451xx) || defined (STM32L452xx) || defined (STM32L462xx) || \
AnnaBridge 145:64910690c574 908 defined (STM32L496xx) || defined (STM32L4A6xx)
Kojto 122:f9eeca106725 909 #define IS_OB_USER_SWBOOT0(VALUE) (((VALUE) == OB_BOOT0_FROM_OB) || ((VALUE) == OB_BOOT0_FROM_PIN))
Kojto 122:f9eeca106725 910
Kojto 122:f9eeca106725 911 #define IS_OB_USER_BOOT0(VALUE) (((VALUE) == OB_BOOT0_RESET) || ((VALUE) == OB_BOOT0_SET))
Kojto 122:f9eeca106725 912 #endif
Kojto 122:f9eeca106725 913
Kojto 122:f9eeca106725 914 #define IS_OB_PCROP_RDP(VALUE) (((VALUE) == OB_PCROP_RDP_NOT_ERASE) || ((VALUE) == OB_PCROP_RDP_ERASE))
Kojto 122:f9eeca106725 915
Kojto 122:f9eeca106725 916 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_LATENCY_0) || \
Kojto 122:f9eeca106725 917 ((LATENCY) == FLASH_LATENCY_1) || \
Kojto 122:f9eeca106725 918 ((LATENCY) == FLASH_LATENCY_2) || \
Kojto 122:f9eeca106725 919 ((LATENCY) == FLASH_LATENCY_3) || \
Kojto 122:f9eeca106725 920 ((LATENCY) == FLASH_LATENCY_4))
Kojto 122:f9eeca106725 921 /**
Kojto 122:f9eeca106725 922 * @}
Kojto 122:f9eeca106725 923 */
Kojto 122:f9eeca106725 924
Kojto 122:f9eeca106725 925 /**
Kojto 122:f9eeca106725 926 * @}
Kojto 122:f9eeca106725 927 */
Kojto 122:f9eeca106725 928
Kojto 122:f9eeca106725 929 /**
Kojto 122:f9eeca106725 930 * @}
Kojto 122:f9eeca106725 931 */
Kojto 122:f9eeca106725 932
Kojto 122:f9eeca106725 933 #ifdef __cplusplus
Kojto 122:f9eeca106725 934 }
Kojto 122:f9eeca106725 935 #endif
Kojto 122:f9eeca106725 936
Kojto 122:f9eeca106725 937 #endif /* __STM32L4xx_HAL_FLASH_H */
Kojto 122:f9eeca106725 938
Kojto 122:f9eeca106725 939 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/