Subversion Repositories EngineBay2

Rev

Rev 35 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32l1xx_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) 2017 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 __STM32L1xx_HAL_FLASH_H
  22. #define __STM32L1xx_HAL_FLASH_H
  23.  
  24. #ifdef __cplusplus
  25.  extern "C" {
  26. #endif
  27.  
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32l1xx_hal_def.h"
  30.    
  31. /** @addtogroup STM32L1xx_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_WORD)
  52.  
  53. #define IS_FLASH_LATENCY(__LATENCY__) (((__LATENCY__) == FLASH_LATENCY_0) || \
  54.                                        ((__LATENCY__) == FLASH_LATENCY_1))
  55.  
  56. /**
  57.   * @}
  58.   */  
  59.  
  60. /* Exported types ------------------------------------------------------------*/
  61. /** @defgroup FLASH_Exported_Types FLASH Exported Types
  62.   * @{
  63.   */  
  64.  
  65. /**
  66.   * @brief  FLASH Procedure structure definition
  67.   */
  68. typedef enum
  69. {
  70.   FLASH_PROC_NONE              = 0U,
  71.   FLASH_PROC_PAGEERASE         = 1U,
  72.   FLASH_PROC_PROGRAM           = 2U,
  73. } FLASH_ProcedureTypeDef;
  74.  
  75. /**
  76.   * @brief  FLASH handle Structure definition  
  77.   */
  78. typedef struct
  79. {
  80.   __IO FLASH_ProcedureTypeDef ProcedureOnGoing; /*!< Internal variable to indicate which procedure is ongoing or not in IT context */
  81.  
  82.   __IO uint32_t               NbPagesToErase;   /*!< Internal variable to save the remaining sectors to erase in IT context*/
  83.  
  84.   __IO uint32_t               Address;          /*!< Internal variable to save address selected for program or erase */
  85.  
  86.   __IO uint32_t               Page;             /*!< Internal variable to define the current page which is erasing */
  87.  
  88.   HAL_LockTypeDef             Lock;             /*!< FLASH locking object                */
  89.  
  90.   __IO uint32_t               ErrorCode;        /*!< FLASH error code                    
  91.                                                      This parameter can be a value of @ref FLASH_Error_Codes  */
  92. } FLASH_ProcessTypeDef;
  93.  
  94. /**
  95.   * @}
  96.   */
  97.  
  98. /* Exported constants --------------------------------------------------------*/
  99. /** @defgroup FLASH_Exported_Constants FLASH Exported Constants
  100.   * @{
  101.   */  
  102.  
  103. /** @defgroup FLASH_Error_Codes FLASH Error Codes
  104.   * @{
  105.   */
  106.  
  107. #define HAL_FLASH_ERROR_NONE      0x00U  /*!< No error */
  108. #define HAL_FLASH_ERROR_PGA       0x01U  /*!< Programming alignment error */
  109. #define HAL_FLASH_ERROR_WRP       0x02U  /*!< Write protection error */
  110. #define HAL_FLASH_ERROR_OPTV      0x04U  /*!< Option validity error */
  111. #define HAL_FLASH_ERROR_SIZE      0x08U  /*!<  */
  112. #define HAL_FLASH_ERROR_RD        0x10U  /*!< Read protected error */
  113. #define HAL_FLASH_ERROR_OPTVUSR   0x20U  /*!< Option UserValidity Error. */
  114. #define HAL_FLASH_ERROR_OPERATION 0x40U  /*!< Not used */
  115.  
  116. /**
  117.   * @}
  118.   */
  119.  
  120. /** @defgroup FLASH_Page_Size FLASH size information
  121.   * @{
  122.   */
  123.  
  124. #define FLASH_SIZE                (uint32_t)((*((uint32_t *)FLASHSIZE_BASE)&0xFFFFU) * 1024U)
  125. #define FLASH_PAGE_SIZE           (256U)  /*!< FLASH Page Size in bytes */
  126.  
  127. /**
  128.   * @}
  129.   */
  130.  
  131. /** @defgroup FLASH_Type_Program FLASH Type Program
  132.   * @{
  133.   */
  134. #define FLASH_TYPEPROGRAM_WORD       (0x02U)  /*!<Program a word (32-bit) at a specified address.*/
  135.  
  136. /**
  137.   * @}
  138.   */
  139.  
  140. /** @defgroup FLASH_Latency FLASH Latency
  141.   * @{
  142.   */
  143. #define FLASH_LATENCY_0            (0x00000000U)    /*!< FLASH Zero Latency cycle */
  144. #define FLASH_LATENCY_1            FLASH_ACR_LATENCY         /*!< FLASH One Latency cycle */
  145.  
  146. /**
  147.   * @}
  148.   */
  149.  
  150. /** @defgroup FLASH_Interrupts FLASH Interrupts
  151.   * @{
  152.   */
  153.  
  154. #define FLASH_IT_EOP               FLASH_PECR_EOPIE  /*!< End of programming interrupt source */
  155. #define FLASH_IT_ERR               FLASH_PECR_ERRIE  /*!< Error interrupt source */
  156. /**
  157.   * @}
  158.   */
  159.  
  160. /** @defgroup FLASH_Flags FLASH Flags
  161.   * @{
  162.   */
  163.  
  164. #define FLASH_FLAG_BSY             FLASH_SR_BSY        /*!< FLASH Busy flag */
  165. #define FLASH_FLAG_EOP             FLASH_SR_EOP        /*!< FLASH End of Programming flag */
  166. #define FLASH_FLAG_ENDHV           FLASH_SR_ENDHV      /*!< FLASH End of High Voltage flag */
  167. #define FLASH_FLAG_READY           FLASH_SR_READY      /*!< FLASH Ready flag after low power mode */
  168. #define FLASH_FLAG_WRPERR          FLASH_SR_WRPERR     /*!< FLASH Write protected error flag */
  169. #define FLASH_FLAG_PGAERR          FLASH_SR_PGAERR     /*!< FLASH Programming Alignment error flag */
  170. #define FLASH_FLAG_SIZERR          FLASH_SR_SIZERR     /*!< FLASH Size error flag  */
  171. #define FLASH_FLAG_OPTVERR         FLASH_SR_OPTVERR    /*!< FLASH Option Validity error flag  */
  172. /* Cat2 & Cat3*/
  173. #if defined(FLASH_SR_RDERR)
  174. #define FLASH_FLAG_RDERR           FLASH_SR_RDERR    /*!< Read protected error flag  */
  175. #endif /* FLASH_SR_RDERR */
  176. /* Cat3, Cat4 & Cat5*/
  177. #if defined(FLASH_SR_OPTVERRUSR)
  178. #define FLASH_FLAG_OPTVERRUSR      FLASH_SR_OPTVERRUSR /*!< FLASH Option User Validity error flag  */
  179. #endif /* FLASH_SR_OPTVERRUSR */
  180.  
  181. /**
  182.   * @}
  183.   */
  184.  
  185. /** @defgroup FLASH_Keys FLASH Keys
  186.   * @{
  187.   */
  188.  
  189. #define FLASH_PDKEY1               (0x04152637U) /*!< Flash power down key1 */
  190. #define FLASH_PDKEY2               (0xFAFBFCFDU) /*!< Flash power down key2: used with FLASH_PDKEY1
  191.                                                               to unlock the RUN_PD bit in FLASH_ACR */
  192.  
  193. #define FLASH_PEKEY1               (0x89ABCDEFU) /*!< Flash program erase key1 */
  194. #define FLASH_PEKEY2               (0x02030405U) /*!< Flash program erase key: used with FLASH_PEKEY2
  195.                                                                to unlock the write access to the FLASH_PECR register and
  196.                                                                data EEPROM */
  197.  
  198. #define FLASH_PRGKEY1              (0x8C9DAEBFU) /*!< Flash program memory key1 */
  199. #define FLASH_PRGKEY2              (0x13141516U) /*!< Flash program memory key2: used with FLASH_PRGKEY2
  200.                                                                to unlock the program memory */
  201.  
  202. #define FLASH_OPTKEY1              (0xFBEAD9C8U) /*!< Flash option key1 */
  203. #define FLASH_OPTKEY2              (0x24252627U) /*!< Flash option key2: used with FLASH_OPTKEY1 to
  204.                                                               unlock the write access to the option byte block */
  205. /**
  206.   * @}
  207.   */
  208. /**
  209.   * @}
  210.   */  
  211.  
  212. /* Exported macro ------------------------------------------------------------*/
  213.  
  214. /** @defgroup FLASH_Exported_Macros FLASH Exported Macros
  215.  *  @brief macros to control FLASH features
  216.  *  @{
  217.  */
  218.  
  219.  
  220. /** @defgroup FLASH_Interrupt FLASH Interrupts
  221.  *  @brief macros to handle FLASH interrupts
  222.  * @{
  223.  */
  224.  
  225. /**
  226.   * @brief  Enable the specified FLASH interrupt.
  227.   * @param  __INTERRUPT__  FLASH interrupt
  228.   *         This parameter can be any combination of the following values:
  229.   *     @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  230.   *     @arg @ref FLASH_IT_ERR Error Interrupt    
  231.   * @retval none
  232.   */  
  233. #define __HAL_FLASH_ENABLE_IT(__INTERRUPT__)  SET_BIT((FLASH->PECR), (__INTERRUPT__))
  234.  
  235. /**
  236.   * @brief  Disable the specified FLASH interrupt.
  237.   * @param  __INTERRUPT__  FLASH interrupt
  238.   *         This parameter can be any combination of the following values:
  239.   *     @arg @ref FLASH_IT_EOP End of FLASH Operation Interrupt
  240.   *     @arg @ref FLASH_IT_ERR Error Interrupt    
  241.   * @retval none
  242.   */  
  243. #define __HAL_FLASH_DISABLE_IT(__INTERRUPT__)  CLEAR_BIT((FLASH->PECR), (uint32_t)(__INTERRUPT__))
  244.  
  245. /**
  246.   * @brief  Get the specified FLASH flag status.
  247.   * @param  __FLAG__ specifies the FLASH flag to check.
  248.   *          This parameter can be one of the following values:
  249.   *            @arg @ref FLASH_FLAG_BSY         FLASH Busy flag
  250.   *            @arg @ref FLASH_FLAG_EOP         FLASH End of Operation flag
  251.   *            @arg @ref FLASH_FLAG_ENDHV       FLASH End of High Voltage flag
  252.   *            @arg @ref FLASH_FLAG_READY       FLASH Ready flag after low power mode
  253.   *            @arg @ref FLASH_FLAG_PGAERR      FLASH Programming Alignment error flag
  254.   *            @arg @ref FLASH_FLAG_SIZERR      FLASH Size error flag
  255.   *            @arg @ref FLASH_FLAG_OPTVERR     FLASH Option validity error error flag
  256. @if STM32L100xB
  257. @elif STM32L100xBA
  258.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  259. @elif STM32L151xB
  260. @elif STM32L151xBA
  261.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  262. @elif STM32L152xB
  263. @elif STM32L152xBA
  264.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  265. @elif STM32L100xC
  266.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  267.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  268. @elif STM32L151xC
  269.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  270.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  271. @elif STM32L152xC
  272.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  273.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  274. @elif STM32L162xC
  275.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  276.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  277. @else
  278.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  279. @endif
  280.   *            @arg @ref FLASH_FLAG_WRPERR      FLASH Write protected error flag
  281.   * @retval The new state of __FLAG__ (SET or RESET).
  282.   */
  283. #define __HAL_FLASH_GET_FLAG(__FLAG__)   (((FLASH->SR) & (__FLAG__)) == (__FLAG__))
  284.  
  285. /**
  286.   * @brief  Clear the specified FLASH flag.
  287.   * @param  __FLAG__ specifies the FLASH flags to clear.
  288.   *          This parameter can be any combination of the following values:
  289.   *            @arg @ref FLASH_FLAG_EOP         FLASH End of Operation flag
  290.   *            @arg @ref FLASH_FLAG_PGAERR      FLASH Programming Alignment error flag
  291.   *            @arg @ref FLASH_FLAG_SIZERR      FLASH Size error flag
  292.   *            @arg @ref FLASH_FLAG_OPTVERR     FLASH Option validity error error flag
  293. @if STM32L100xB
  294. @elif STM32L100xBA
  295.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  296. @elif STM32L151xB
  297. @elif STM32L151xBA
  298.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  299. @elif STM32L152xB
  300. @elif STM32L152xBA
  301.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  302. @elif STM32L100xC
  303.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  304.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  305. @elif STM32L151xC
  306.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  307.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  308. @elif STM32L152xC
  309.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  310.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  311. @elif STM32L162xC
  312.   *            @arg @ref FLASH_FLAG_RDERR       FLASH Read Protection error flag (PCROP)
  313.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  314. @else
  315.   *            @arg @ref FLASH_FLAG_OPTVERRUSR  FLASH Option User validity error
  316. @endif
  317.   *            @arg @ref FLASH_FLAG_WRPERR      FLASH Write protected error flag
  318.   * @retval none
  319.   */
  320. #define __HAL_FLASH_CLEAR_FLAG(__FLAG__)   ((FLASH->SR) = (__FLAG__))
  321.  
  322. /**
  323.   * @}
  324.   */
  325.  
  326. /**
  327.   * @}
  328.   */
  329.  
  330. /* Include FLASH HAL Extended module */
  331. #include "stm32l1xx_hal_flash_ex.h"  
  332. #include "stm32l1xx_hal_flash_ramfunc.h"  
  333.  
  334. /* Exported functions --------------------------------------------------------*/
  335. /** @addtogroup FLASH_Exported_Functions
  336.   * @{
  337.   */
  338.  
  339. /** @addtogroup FLASH_Exported_Functions_Group1
  340.   * @{
  341.   */
  342. /* IO operation functions *****************************************************/
  343. HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  344. HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint32_t Data);
  345.  
  346. /* FLASH IRQ handler function */
  347. void       HAL_FLASH_IRQHandler(void);
  348. /* Callbacks in non blocking modes */
  349. void       HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue);
  350. void       HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue);
  351.  
  352. /**
  353.   * @}
  354.   */
  355.  
  356. /** @addtogroup FLASH_Exported_Functions_Group2
  357.   * @{
  358.   */
  359. /* Peripheral Control functions ***********************************************/
  360. HAL_StatusTypeDef HAL_FLASH_Unlock(void);
  361. HAL_StatusTypeDef HAL_FLASH_Lock(void);
  362. HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void);
  363. HAL_StatusTypeDef HAL_FLASH_OB_Lock(void);
  364. HAL_StatusTypeDef HAL_FLASH_OB_Launch(void);
  365.  
  366. /**
  367.   * @}
  368.   */
  369.  
  370. /** @addtogroup FLASH_Exported_Functions_Group3
  371.   * @{
  372.   */
  373. /* Peripheral State and Error functions ***************************************/
  374. uint32_t HAL_FLASH_GetError(void);
  375.  
  376. /**
  377.   * @}
  378.   */
  379.  
  380. /**
  381.   * @}
  382.   */
  383.  
  384. /* Private function -------------------------------------------------*/
  385. /** @addtogroup FLASH_Private_Functions
  386.  * @{
  387.  */
  388. HAL_StatusTypeDef       FLASH_WaitForLastOperation(uint32_t Timeout);
  389.  
  390. /**
  391.   * @}
  392.   */
  393.  
  394. /**
  395.   * @}
  396.   */
  397.  
  398. /**
  399.   * @}
  400.   */
  401.  
  402. #ifdef __cplusplus
  403. }
  404. #endif
  405.  
  406. #endif /* __STM32L1xx_HAL_FLASH_H */
  407.  
  408. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  409.  
  410.