stm32f103rb_hal_blink

Non-blocking, event triggered blink example using HAL library
Index Commits Files Refs README
Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h (8820B)
   1 /**
   2   ******************************************************************************
   3   * @file    stm32f1xx_hal_flash.h
   4   * @author  MCD Application Team
   5   * @brief   Header file of Flash HAL module.
   6   ******************************************************************************
   7   * @attention
   8   *
   9   * Copyright (c) 2016 STMicroelectronics.
  10   * All rights reserved.
  11   *
  12   * This software is licensed under terms that can be found in the LICENSE file in
  13   * the root directory of this software component.
  14   * If no LICENSE file comes with this software, it is provided AS-IS.
  15   ******************************************************************************
  16   */
  17 
  18 /* Define to prevent recursive inclusion -------------------------------------*/
  19 #ifndef __STM32F1xx_HAL_FLASH_H
  20 #define __STM32F1xx_HAL_FLASH_H
  21 
  22 #ifdef __cplusplus
  23  extern "C" {
  24 #endif
  25 
  26 /* Includes ------------------------------------------------------------------*/
  27 #include "stm32f1xx_hal_def.h"
  28    
  29 /** @addtogroup STM32F1xx_HAL_Driver
  30   * @{
  31   */
  32 
  33 /** @addtogroup FLASH
  34   * @{
  35   */
  36   
  37 /** @addtogroup FLASH_Private_Constants
  38   * @{
  39   */
  40 #define FLASH_TIMEOUT_VALUE              50000U /* 50 s */
  41 /**
  42   * @}
  43   */
  44 
  45 /** @addtogroup FLASH_Private_Macros
  46   * @{
  47   */
  48 
  49 #define IS_FLASH_TYPEPROGRAM(VALUE)  (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  50                                       ((VALUE) == FLASH_TYPEPROGRAM_WORD)     || \
  51                                       ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))  
  52 
  53 #if   defined(FLASH_ACR_LATENCY)
  54 #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  55                                        ((__LATENCY__) == FLASH_LATENCY_1) || \
  56                                        ((__LATENCY__) == FLASH_LATENCY_2))
  57 
  58 #else
  59 #define IS_FLASH_LATENCY(__LATENCY__)   ((__LATENCY__) == FLASH_LATENCY_0)
  60 #endif /* FLASH_ACR_LATENCY */
  61 /**
  62   * @}
  63   */  
  64 
  65 /* Exported types ------------------------------------------------------------*/ 
  66 /** @defgroup FLASH_Exported_Types FLASH Exported Types
  67   * @{
  68   */  
  69 
  70 /**
  71   * @brief  FLASH Procedure structure definition
  72   */
  73 typedef enum 
  74 {
  75   FLASH_PROC_NONE              = 0U, 
  76   FLASH_PROC_PAGEERASE         = 1U,
  77   FLASH_PROC_MASSERASE         = 2U,
  78   FLASH_PROC_PROGRAMHALFWORD   = 3U,
  79   FLASH_PROC_PROGRAMWORD       = 4U,
  80   FLASH_PROC_PROGRAMDOUBLEWORD = 5U
  81 } FLASH_ProcedureTypeDef;
  82 
  83 /** 
  84   * @brief  FLASH handle Structure definition  
  85   */
  86 typedef struct
  87 {
  88   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  89   
  90   __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
  91 
  92   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
  93 
  94   __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
  95 
  96   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
  97 
  98   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
  99                                                      This parameter can be a value of @ref FLASH_Error_Codes  */
 100 } FLASH_ProcessTypeDef;
 101 
 102 /**
 103   * @}
 104   */
 105 
 106 /* Exported constants --------------------------------------------------------*/
 107 /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
 108   * @{
 109   */  
 110 
 111 /** @defgroup FLASH_Error_Codes FLASH Error Codes
 112   * @{
 113   */
 114 
 115 #define HAL_FLASH_ERROR_NONE      0x00U  /*!< No error */
 116 #define HAL_FLASH_ERROR_PROG      0x01U  /*!< Programming error */
 117 #define HAL_FLASH_ERROR_WRP       0x02U  /*!< Write protection error */
 118 #define HAL_FLASH_ERROR_OPTV      0x04U  /*!< Option validity error */
 119 
 120 /**
 121   * @}
 122   */
 123 
 124 /** @defgroup FLASH_Type_Program FLASH Type Program
 125   * @{
 126   */ 
 127 #define FLASH_TYPEPROGRAM_HALFWORD             0x01U  /*!<Program a half-word (16-bit) at a specified address.*/
 128 #define FLASH_TYPEPROGRAM_WORD                 0x02U  /*!<Program a word (32-bit) at a specified address.*/
 129 #define FLASH_TYPEPROGRAM_DOUBLEWORD           0x03U  /*!<Program a double word (64-bit) at a specified address*/
 130 
 131 /**
 132   * @}
 133   */
 134 
 135 #if   defined(FLASH_ACR_LATENCY)
 136 /** @defgroup FLASH_Latency FLASH Latency
 137   * @{
 138   */
 139 #define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
 140 #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
 141 #define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
 142 
 143 /**
 144   * @}
 145   */
 146 
 147 #else
 148 /** @defgroup FLASH_Latency FLASH Latency
 149   * @{
 150   */
 151 #define FLASH_LATENCY_0            0x00000000U    /*!< FLASH Zero Latency cycle */
 152 
 153 /**
 154   * @}
 155   */
 156 
 157 #endif /* FLASH_ACR_LATENCY */
 158 /**
 159   * @}
 160   */  
 161   
 162 /* Exported macro ------------------------------------------------------------*/
 163 
 164 /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
 165  *  @brief macros to control FLASH features 
 166  *  @{
 167  */
 168  
 169 /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
 170  *  @brief macros to handle FLASH half cycle
 171  * @{
 172  */
 173 
 174 /**
 175   * @brief  Enable the FLASH half cycle access.
 176   * @note   half cycle access can only be used with a low-frequency clock of less than
 177             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
 178   * @retval None
 179   */
 180 #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE()  (FLASH->ACR |= FLASH_ACR_HLFCYA)
 181 
 182 /**
 183   * @brief  Disable the FLASH half cycle access.
 184   * @note   half cycle access can only be used with a low-frequency clock of less than
 185             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
 186   * @retval None
 187   */
 188 #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
 189 
 190 /**
 191   * @}
 192   */
 193 
 194 #if defined(FLASH_ACR_LATENCY)
 195 /** @defgroup FLASH_EM_Latency FLASH Latency
 196  *  @brief macros to handle FLASH Latency
 197  * @{
 198  */ 
 199   
 200 /**
 201   * @brief  Set the FLASH Latency.
 202   * @param  __LATENCY__ FLASH Latency                   
 203   *         The value of this parameter depend on device used within the same series
 204   * @retval None
 205   */ 
 206 #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
 207 
 208 
 209 /**
 210   * @brief  Get the FLASH Latency.
 211   * @retval FLASH Latency                   
 212   *         The value of this parameter depend on device used within the same series
 213   */ 
 214 #define __HAL_FLASH_GET_LATENCY()     (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
 215 
 216 /**
 217   * @}
 218   */
 219 
 220 #endif /* FLASH_ACR_LATENCY */
 221 /** @defgroup FLASH_Prefetch FLASH Prefetch
 222  *  @brief macros to handle FLASH Prefetch buffer
 223  * @{
 224  */   
 225 /**
 226   * @brief  Enable the FLASH prefetch buffer.
 227   * @retval None
 228   */ 
 229 #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
 230 
 231 /**
 232   * @brief  Disable the FLASH prefetch buffer.
 233   * @retval None
 234   */
 235 #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
 236 
 237 /**
 238   * @}
 239   */
 240   
 241 /**
 242   * @}
 243   */ 
 244 
 245 /* Include FLASH HAL Extended module */
 246 #include "stm32f1xx_hal_flash_ex.h"  
 247 
 248 /* Exported functions --------------------------------------------------------*/
 249 /** @addtogroup FLASH_Exported_Functions
 250   * @{
 251   */
 252   
 253 /** @addtogroup FLASH_Exported_Functions_Group1
 254   * @{
 255   */
 256 /* IO operation functions *****************************************************/
 257 HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
 258 HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
 259 
 260 /* FLASH IRQ handler function */
 261 void       HAL_FLASH_IRQHandler(void);
 262 /* Callbacks in non blocking modes */ 
 263 void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
 264 void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
 265 
 266 /**
 267   * @}
 268   */
 269 
 270 /** @addtogroup FLASH_Exported_Functions_Group2
 271   * @{
 272   */
 273 /* Peripheral Control functions ***********************************************/
 274 HAL_StatusTypeDef HAL_FLASH_Unlock(void);
 275 HAL_StatusTypeDef HAL_FLASH_Lock(void);
 276 HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
 277 HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
 278 void HAL_FLASH_OB_Launch(void);
 279 
 280 /**
 281   * @}
 282   */
 283 
 284 /** @addtogroup FLASH_Exported_Functions_Group3
 285   * @{
 286   */
 287 /* Peripheral State and Error functions ***************************************/
 288 uint32_t HAL_FLASH_GetError(void);
 289 
 290 /**
 291   * @}
 292   */
 293 
 294 /**
 295   * @}
 296   */
 297 
 298 /* Private function -------------------------------------------------*/
 299 /** @addtogroup FLASH_Private_Functions
 300  * @{
 301  */
 302 HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
 303 #if defined(FLASH_BANK2_END)
 304 HAL_StatusTypeDef       FLASH_WaitForLastOperationBank2(uint32_t Timeout);
 305 #endif /* FLASH_BANK2_END */
 306 
 307 /**
 308   * @}
 309   */
 310 
 311 /**
 312   * @}
 313   */
 314 
 315 /**
 316   * @}
 317   */
 318 
 319 #ifdef __cplusplus
 320 }
 321 #endif
 322 
 323 #endif /* __STM32F1xx_HAL_FLASH_H */
 324 
 325