Subversion Repositories LedShow

Rev

Go to most recent revision | Blame | Compare with Previous | 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</center></h2>
  10.   *
  11.   * Redistribution and use in source and binary forms, with or without modification,
  12.   * are permitted provided that the following conditions are met:
  13.   *   1. Redistributions of source code must retain the above copyright notice,
  14.   *      this list of conditions and the following disclaimer.
  15.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  16.   *      this list of conditions and the following disclaimer in the documentation
  17.   *      and/or other materials provided with the distribution.
  18.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  19.   *      may be used to endorse or promote products derived from this software
  20.   *      without specific prior written permission.
  21.   *
  22.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.   *
  33.   ******************************************************************************  
  34.   */
  35.  
  36. /* Define to prevent recursive inclusion -------------------------------------*/
  37. #ifndef __STM32F1xx_HAL_FLASH_H
  38. #define __STM32F1xx_HAL_FLASH_H
  39.  
  40. #ifdef __cplusplus
  41.  extern "C" {
  42. #endif
  43.  
  44. /* Includes ------------------------------------------------------------------*/
  45. #include "stm32f1xx_hal_def.h"
  46.    
  47. /** @addtogroup STM32F1xx_HAL_Driver
  48.   * @{
  49.   */
  50.  
  51. /** @addtogroup FLASH
  52.   * @{
  53.   */
  54.  
  55. /** @addtogroup FLASH_Private_Constants
  56.   * @{
  57.   */
  58. #define FLASH_TIMEOUT_VALUE              50000U /* 50 s */
  59. /**
  60.   * @}
  61.   */
  62.  
  63. /** @addtogroup FLASH_Private_Macros
  64.   * @{
  65.   */
  66.  
  67. #define IS_FLASH_TYPEPROGRAM(VALUE)  (((VALUE) == FLASH_TYPEPROGRAM_HALFWORD) || \
  68.                                       ((VALUE) == FLASH_TYPEPROGRAM_WORD)     || \
  69.                                       ((VALUE) == FLASH_TYPEPROGRAM_DOUBLEWORD))  
  70.  
  71. #if   defined(FLASH_ACR_LATENCY)
  72. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  73.                                        ((__LATENCY__) == FLASH_LATENCY_1) || \
  74.                                        ((__LATENCY__) == FLASH_LATENCY_2))
  75.  
  76. #else
  77. #define IS_FLASH_LATENCY(__LATENCY__)   ((__LATENCY__) == FLASH_LATENCY_0)
  78. #endif /* FLASH_ACR_LATENCY */
  79. /**
  80.   * @}
  81.   */  
  82.  
  83. /* Exported types ------------------------------------------------------------*/
  84. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  85.   * @{
  86.   */  
  87.  
  88. /**
  89.   * @brief  FLASH Procedure structure definition
  90.   */
  91. typedef enum
  92. {
  93.   FLASH_PROC_NONE              = 0U,
  94.   FLASH_PROC_PAGEERASE         = 1U,
  95.   FLASH_PROC_MASSERASE         = 2U,
  96.   FLASH_PROC_PROGRAMHALFWORD   = 3U,
  97.   FLASH_PROC_PROGRAMWORD       = 4U,
  98.   FLASH_PROC_PROGRAMDOUBLEWORD = 5U
  99. } FLASH_ProcedureTypeDef;
  100.  
  101. /**
  102.   * @brief  FLASH handle Structure definition  
  103.   */
  104. typedef struct
  105. {
  106.   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  107.  
  108.   __IO uint32_t               DataRemaining;    /*!< Internal variable to save the remaining pages to erase or half-word to program in IT context */
  109.  
  110.   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
  111.  
  112.   __IO uint64_t               Data;             /*!< Internal variable to save data to be programmed */
  113.  
  114.   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
  115.  
  116.   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
  117.                                                      This parameter can be a value of @ref FLASH_Error_Codes  */
  118. } FLASH_ProcessTypeDef;
  119.  
  120. /**
  121.   * @}
  122.   */
  123.  
  124. /* Exported constants --------------------------------------------------------*/
  125. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  126.   * @{
  127.   */  
  128.  
  129. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  130.   * @{
  131.   */
  132.  
  133. #define HAL_FLASH_ERROR_NONE      0x00U  /*!< No error */
  134. #define HAL_FLASH_ERROR_PROG      0x01U  /*!< Programming error */
  135. #define HAL_FLASH_ERROR_WRP       0x02U  /*!< Write protection error */
  136. #define HAL_FLASH_ERROR_OPTV      0x04U  /*!< Option validity error */
  137.  
  138. /**
  139.   * @}
  140.   */
  141.  
  142. /** @defgroup FLASH_Type_Program FLASH Type Program
  143.   * @{
  144.   */
  145. #define FLASH_TYPEPROGRAM_HALFWORD             0x01U  /*!<Program a half-word (16-bit) at a specified address.*/
  146. #define FLASH_TYPEPROGRAM_WORD                 0x02U  /*!<Program a word (32-bit) at a specified address.*/
  147. #define FLASH_TYPEPROGRAM_DOUBLEWORD           0x03U  /*!<Program a double word (64-bit) at a specified address*/
  148.  
  149. /**
  150.   * @}
  151.   */
  152.  
  153. #if   defined(FLASH_ACR_LATENCY)
  154. /** @defgroup FLASH_Latency FLASH Latency
  155.   * @{
  156.   */
  157. #define FLASH_LATENCY_0            0x00000000U               /*!< FLASH Zero Latency cycle */
  158. #define FLASH_LATENCY_1            FLASH_ACR_LATENCY_0       /*!< FLASH One Latency cycle */
  159. #define FLASH_LATENCY_2            FLASH_ACR_LATENCY_1       /*!< FLASH Two Latency cycles */
  160.  
  161. /**
  162.   * @}
  163.   */
  164.  
  165. #else
  166. /** @defgroup FLASH_Latency FLASH Latency
  167.   * @{
  168.   */
  169. #define FLASH_LATENCY_0            0x00000000U    /*!< FLASH Zero Latency cycle */
  170.  
  171. /**
  172.   * @}
  173.   */
  174.  
  175. #endif /* FLASH_ACR_LATENCY */
  176. /**
  177.   * @}
  178.   */  
  179.  
  180. /* Exported macro ------------------------------------------------------------*/
  181.  
  182. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  183.  *  @brief macros to control FLASH features
  184.  *  @{
  185.  */
  186.  
  187. /** @defgroup FLASH_Half_Cycle FLASH Half Cycle
  188.  *  @brief macros to handle FLASH half cycle
  189.  * @{
  190.  */
  191.  
  192. /**
  193.   * @brief  Enable the FLASH half cycle access.
  194.   * @note   half cycle access can only be used with a low-frequency clock of less than
  195.             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
  196.   * @retval None
  197.   */
  198. #define __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE()  (FLASH->ACR |= FLASH_ACR_HLFCYA)
  199.  
  200. /**
  201.   * @brief  Disable the FLASH half cycle access.
  202.   * @note   half cycle access can only be used with a low-frequency clock of less than
  203.             8 MHz that can be obtained with the use of HSI or HSE but not of PLL.
  204.   * @retval None
  205.   */
  206. #define __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE() (FLASH->ACR &= (~FLASH_ACR_HLFCYA))
  207.  
  208. /**
  209.   * @}
  210.   */
  211.  
  212. #if defined(FLASH_ACR_LATENCY)
  213. /** @defgroup FLASH_EM_Latency FLASH Latency
  214.  *  @brief macros to handle FLASH Latency
  215.  * @{
  216.  */
  217.  
  218. /**
  219.   * @brief  Set the FLASH Latency.
  220.   * @param  __LATENCY__ FLASH Latency                  
  221.   *         The value of this parameter depend on device used within the same series
  222.   * @retval None
  223.   */
  224. #define __HAL_FLASH_SET_LATENCY(__LATENCY__)    (FLASH->ACR = (FLASH->ACR&(~FLASH_ACR_LATENCY)) | (__LATENCY__))
  225.  
  226.  
  227. /**
  228.   * @brief  Get the FLASH Latency.
  229.   * @retval FLASH Latency                  
  230.   *         The value of this parameter depend on device used within the same series
  231.   */
  232. #define __HAL_FLASH_GET_LATENCY()     (READ_BIT((FLASH->ACR), FLASH_ACR_LATENCY))
  233.  
  234. /**
  235.   * @}
  236.   */
  237.  
  238. #endif /* FLASH_ACR_LATENCY */
  239. /** @defgroup FLASH_Prefetch FLASH Prefetch
  240.  *  @brief macros to handle FLASH Prefetch buffer
  241.  * @{
  242.  */  
  243. /**
  244.   * @brief  Enable the FLASH prefetch buffer.
  245.   * @retval None
  246.   */
  247. #define __HAL_FLASH_PREFETCH_BUFFER_ENABLE()    (FLASH->ACR |= FLASH_ACR_PRFTBE)
  248.  
  249. /**
  250.   * @brief  Disable the FLASH prefetch buffer.
  251.   * @retval None
  252.   */
  253. #define __HAL_FLASH_PREFETCH_BUFFER_DISABLE()   (FLASH->ACR &= (~FLASH_ACR_PRFTBE))
  254.  
  255. /**
  256.   * @}
  257.   */
  258.  
  259. /**
  260.   * @}
  261.   */
  262.  
  263. /* Include FLASH HAL Extended module */
  264. #include "stm32f1xx_hal_flash_ex.h"  
  265.  
  266. /* Exported functions --------------------------------------------------------*/
  267. /** @addtogroup FLASH_Exported_Functions
  268.   * @{
  269.   */
  270.  
  271. /** @addtogroup FLASH_Exported_Functions_Group1
  272.   * @{
  273.   */
  274. /* IO operation functions *****************************************************/
  275. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  276. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data);
  277.  
  278. /* FLASH IRQ handler function */
  279. void       HAL_FLASH_IRQHandler(void);
  280. /* Callbacks in non blocking modes */
  281. void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  282. void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  283.  
  284. /**
  285.   * @}
  286.   */
  287.  
  288. /** @addtogroup FLASH_Exported_Functions_Group2
  289.   * @{
  290.   */
  291. /* Peripheral Control functions ***********************************************/
  292. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  293. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  294. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  295. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  296. void HAL_FLASH_OB_Launch(void);
  297.  
  298. /**
  299.   * @}
  300.   */
  301.  
  302. /** @addtogroup FLASH_Exported_Functions_Group3
  303.   * @{
  304.   */
  305. /* Peripheral State and Error functions ***************************************/
  306. uint32_t HAL_FLASH_GetError(void);
  307.  
  308. /**
  309.   * @}
  310.   */
  311.  
  312. /**
  313.   * @}
  314.   */
  315.  
  316. /* Private function -------------------------------------------------*/
  317. /** @addtogroup FLASH_Private_Functions
  318.  * @{
  319.  */
  320. HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
  321. #if defined(FLASH_BANK2_END)
  322. HAL_StatusTypeDef       FLASH_WaitForLastOperationBank2(uint32_t Timeout);
  323. #endif /* FLASH_BANK2_END */
  324.  
  325. /**
  326.   * @}
  327.   */
  328.  
  329. /**
  330.   * @}
  331.   */
  332.  
  333. /**
  334.   * @}
  335.   */
  336.  
  337. #ifdef __cplusplus
  338. }
  339. #endif
  340.  
  341. #endif /* __STM32F1xx_HAL_FLASH_H */
  342.  
  343. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  344.  
  345.