Subversion Repositories CharLCD

Rev

Blame | Last modification | View Log | Download | RSS feed

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