stm8l15x_flash.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_flash.h
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions prototypes for the FLASH firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM8L15x_FLASH_H
  30. #define __STM8L15x_FLASH_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup FLASH
  37. * @{
  38. */
  39. /* Exported constants --------------------------------------------------------*/
  40. /** @addtogroup FLASH_Exported_Constants
  41. * @{
  42. */
  43. #define FLASH_PROGRAM_START_PHYSICAL_ADDRESS ((uint32_t)0x00008000) /*!< Flash: start address */
  44. #define FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS ((uint32_t)0x00001000) /*!< Data Eeprom: start address */
  45. /* STM8L15x High density devices */
  46. #if defined (STM8L15X_HD) || defined (STM8L05X_HD_VL)
  47. #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x00017FFF) /*!< Flash: end address */
  48. #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000017FF) /*!< Data Eeprom: end address */
  49. #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x200) /*!< Flash memory: total number of Block */
  50. #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x10) /*!< Data EEprom: total number of Block */
  51. #define FLASH_BLOCK_SIZE ((uint8_t)0x80) /*!< Number of bytes in a Block
  52. (common for Program and Data EEprom memories) */
  53. /* STM8L15x Medium density and Medium density plus devices */
  54. #elif defined (STM8L15X_MD) || defined (STM8L15X_MDP) || defined (STM8AL31_L_MD) || defined (STM8L05X_MD_VL)
  55. #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x0000FFFF) /*!< Flash: end address */
  56. #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000013FF) /*!< Data Eeprom: end address */
  57. #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x100) /*!< Flash memory: total number of Block */
  58. #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x8) /*!< Data EEprom: total number of Block */
  59. #define FLASH_BLOCK_SIZE ((uint8_t)0x80) /*!< Number of bytes in a Block
  60. (common for Program and Data EEprom memories) */
  61. /* STM8L15x Low density devices */
  62. #elif defined (STM8L15X_LD) || defined (STM8L05X_LD_VL)
  63. #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x00009FFF) /*!< Flash: end address */
  64. #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000010FF) /*!< Data Eeprom: end address */
  65. #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x80) /*!< Flash memory: total number of Block */
  66. #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x4) /*!< Data EEprom: total number of Block */
  67. #define FLASH_BLOCK_SIZE ((uint8_t)0x40) /*!< Number of bytes in a Block
  68. (common for Program and Data EEprom memories) */
  69. #endif /* STM8L15X_HD or STM8L05X_HD_VL*/
  70. /*Common defines for all STM8L15x devices */
  71. #define FLASH_OPTION_BYTES_START_PHYSICAL_ADDRESS ((uint32_t)0x00004800) /*!< Option bytes: start address */
  72. #define FLASH_OPTION_BYTES_END_PHYSICAL_ADDRESS ((uint32_t)0x0000480A) /*!< Option bytes: end address */
  73. #define FLASH_RASS_KEY1 ((uint8_t)0x56) /*!< First RASS key */
  74. #define FLASH_RASS_KEY2 ((uint8_t)0xAE) /*!< Second RASS key */
  75. #define FLASH_READOUTPROTECTION_KEY ((uint8_t)0xAA) /*!< Read out protection key */
  76. /**
  77. * @}
  78. */
  79. /* Exported types ------------------------------------------------------------*/
  80. /** @addtogroup FLASH_Exported_Types
  81. * @{
  82. */
  83. /** @defgroup FLASH_Memory_Type
  84. * @{
  85. */
  86. typedef enum
  87. {
  88. FLASH_MemType_Program = (uint8_t)0xFD, /*!< Program memory */
  89. FLASH_MemType_Data = (uint8_t)0xF7 /*!< Data EEPROM memory */
  90. } FLASH_MemType_TypeDef;
  91. /**
  92. * @}
  93. */
  94. /** @defgroup FLASH_Programming_Mode
  95. * @{
  96. */
  97. typedef enum
  98. {
  99. FLASH_ProgramMode_Standard = (uint8_t)0x00, /*!< Standard programming mode */
  100. FLASH_ProgramMode_Fast = (uint8_t)0x10 /*!< Fast programming mode */
  101. } FLASH_ProgramMode_TypeDef;
  102. /**
  103. * @}
  104. */
  105. /** @defgroup FLASH_Programming_Time
  106. * @{
  107. */
  108. typedef enum
  109. {
  110. FLASH_ProgramTime_Standard = (uint8_t)0x00, /*!< Standard programming time fixed at 1/2 tprog */
  111. FLASH_ProgramTime_TProg = (uint8_t)0x01 /*!< Programming time fixed at tprog */
  112. } FLASH_ProgramTime_TypeDef;
  113. /**
  114. * @}
  115. */
  116. /** @defgroup FLASH_Power_Mode
  117. * @{
  118. */
  119. typedef enum
  120. {
  121. FLASH_Power_IDDQ = (uint8_t)0x00, /*!< Flash program and data EEPROM in IDDQ */
  122. FLASH_Power_On = (uint8_t)0x01 /*!< Flash program and data EEPROM not in IDDQ */
  123. } FLASH_Power_TypeDef;
  124. /**
  125. * @}
  126. */
  127. /** @defgroup FLASH_Status
  128. * @{
  129. */
  130. typedef enum
  131. {
  132. FLASH_Status_Write_Protection_Error = (uint8_t)0x01, /*!< Write attempted to protected Block */
  133. FLASH_Status_TimeOut = (uint8_t)0x02, /*!< Time out error */
  134. FLASH_Status_Successful_Operation = (uint8_t)0x04 /*!< End of operation flag */
  135. } FLASH_Status_TypeDef;
  136. /**
  137. * @}
  138. */
  139. /** @defgroup FLASH_Power_Status
  140. * @{
  141. */
  142. typedef enum
  143. {
  144. FLASH_PowerStatus_IDDQDuringWaitMode = (uint8_t)0x04, /*!< Flash program and data EEPROM
  145. in IDDQ during Wait mode*/
  146. FLASH_PowerStatus_IDDQDuringRunMode = (uint8_t)0x08, /*!< Flash program and data EEPROM
  147. in IDDQ mode during Run mode*/
  148. FLASH_PowerStatus_IDDQDuringWaitAndRunModes = (uint8_t)0x0C, /*!<Flash program and data EEPROM
  149. in IDDQ during Wait and run modes*/
  150. FLASH_PowerStatus_On = (uint8_t)0x00 /*!< Flash program and data EEPROM
  151. is powered on during Wait and Run modes */
  152. } FLASH_PowerStatus_TypeDef;
  153. /**
  154. * @}
  155. */
  156. /** @defgroup FLASH_Flags
  157. * @{
  158. */
  159. typedef enum {
  160. FLASH_FLAG_HVOFF = (uint8_t)0x40, /*!< End of high voltage flag */
  161. FLASH_FLAG_DUL = (uint8_t)0x08, /*!< Data EEPROM unlocked flag */
  162. FLASH_FLAG_EOP = (uint8_t)0x04, /*!< End of programming (write or erase operation) flag */
  163. FLASH_FLAG_PUL = (uint8_t)0x02, /*!< Flash Program memory unlocked flag */
  164. FLASH_FLAG_WR_PG_DIS = (uint8_t)0x01 /*!< Write attempted to protected page flag */
  165. } FLASH_FLAG_TypeDef;
  166. /**
  167. * @}
  168. */
  169. /**
  170. * @}
  171. */
  172. /* Exported macros -----------------------------------------------------------*/
  173. /** @addtogroup FLASH_Exported_Macros
  174. * @{
  175. */
  176. /**
  177. * @brief Macro used by the assert function in order to check the different
  178. * sensitivity values for the flash Address
  179. */
  180. #define IS_FLASH_PROGRAM_ADDRESS(Address) (((Address) >= FLASH_PROGRAM_START_PHYSICAL_ADDRESS) && \
  181. ((Address) <= FLASH_PROGRAM_END_PHYSICAL_ADDRESS))
  182. /**
  183. * @brief Macro used by the assert function in order to check the different
  184. * sensitivity values for the data Eeprom Address
  185. */
  186. #define IS_FLASH_DATA_EEPROM_ADDRESS(Address) (((Address) >= FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS) && \
  187. ((Address) <= FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS))
  188. /**
  189. * @brief Macro used by the assert function in order to check the different
  190. * sensitivity values for the data eeprom and flash program Address
  191. */
  192. #define IS_FLASH_ADDRESS(Address)((((Address) >= FLASH_PROGRAM_START_PHYSICAL_ADDRESS) && ((Address) <= FLASH_PROGRAM_END_PHYSICAL_ADDRESS)) || \
  193. (((Address) >= FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS) && ((Address) <= FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS)))
  194. /**
  195. * @brief Macro used by the assert function in order to check the different
  196. * sensitivity values for the option bytes Address
  197. */
  198. #define IS_OPTION_BYTE_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_OPTION_BYTES_START_PHYSICAL_ADDRESS) && \
  199. ((ADDRESS) <= FLASH_OPTION_BYTES_END_PHYSICAL_ADDRESS))
  200. /**
  201. * @brief Macro used by the assert function in order to check the different
  202. * sensitivity values for the flash Block number
  203. */
  204. #define IS_FLASH_PROGRAM_BLOCK_NUMBER(BlockNum) ((BlockNum) < FLASH_PROGRAM_BLOCKS_NUMBER)
  205. /**
  206. * @brief Macro used by the assert function in order to check the different
  207. * sensitivity values for the data eeprom Block number
  208. */
  209. #define IS_FLASH_DATA_EEPROM_BLOCK_NUMBER(BlockNum) ((BlockNum) < FLASH_DATA_EEPROM_BLOCKS_NUMBER)
  210. /**
  211. * @brief Macro used by the assert function in order to check the different
  212. * sensitivity values for the flash memory type
  213. */
  214. #define IS_FLASH_MEMORY_TYPE(MemType) (((MemType) == FLASH_MemType_Program) || \
  215. ((MemType) == FLASH_MemType_Data))
  216. /**
  217. * @brief Macro used by the assert function in order to check the different
  218. * sensitivity values for the flash program block mode
  219. */
  220. #define IS_FLASH_PROGRAM_MODE(Mode) (((Mode) == FLASH_ProgramMode_Standard) || \
  221. ((Mode) == FLASH_ProgramMode_Fast))
  222. /**
  223. * @brief Macro used by the assert function in order to check the program time mode
  224. */
  225. #define IS_FLASH_PROGRAM_TIME(Time) (((Time) == FLASH_ProgramTime_Standard) || \
  226. ((Time) == FLASH_ProgramTime_TProg))
  227. /**
  228. * @brief Macro used by the assert function in order to check the power mode
  229. */
  230. #define IS_FLASH_POWER(Power) (((Power) == FLASH_Power_IDDQ) || \
  231. ((Power) == FLASH_Power_On))
  232. /**
  233. * @brief Macro used by the assert function in order to check the power status during wait and run modes
  234. */
  235. #define IS_FLASH_POWERSTATUS(PowerStatus) (((PowerStatus) == FLASH_PowerStatus_IDDQDuringWaitMode) || \
  236. ((PowerStatus) == FLASH_PowerStatus_IDDQDuringRunMode ) || \
  237. ((PowerStatus) == FLASH_PowerStatus_IDDQDuringWaitAndRunModes) || \
  238. ((PowerStatus) == FLASH_Power_On))
  239. /**
  240. * @brief Macro used by the assert function in order to check the different flags values
  241. */
  242. #define IS_FLASH_FLAGS(FLAG) (((FLAG) == FLASH_FLAG_HVOFF) || \
  243. ((FLAG) == FLASH_FLAG_DUL) || \
  244. ((FLAG) == FLASH_FLAG_EOP) || \
  245. ((FLAG) == FLASH_FLAG_PUL) || \
  246. ((FLAG) == FLASH_FLAG_WR_PG_DIS))
  247. /**
  248. * @}
  249. */
  250. /* Exported functions ------------------------------------------------------- */
  251. /* FLASH program and Data EEPROM memories interface configuration functions ***/
  252. FLASH_ProgramTime_TypeDef FLASH_GetProgrammingTime(void);
  253. void FLASH_SetProgrammingTime(FLASH_ProgramTime_TypeDef FLASH_ProgTime);
  254. void FLASH_PowerWaitModeConfig(FLASH_Power_TypeDef FLASH_Power);
  255. /* FLASH program and Data EEPROM memories Programming functions ***************/
  256. void FLASH_DeInit(void);
  257. void FLASH_Unlock(FLASH_MemType_TypeDef FLASH_MemType);
  258. void FLASH_Lock(FLASH_MemType_TypeDef FLASH_MemType);
  259. void FLASH_ProgramByte(uint32_t Address, uint8_t Data);
  260. void FLASH_EraseByte(uint32_t Address);
  261. void FLASH_ProgramWord(uint32_t Address, uint32_t Data);
  262. uint8_t FLASH_ReadByte(uint32_t Address);
  263. /* Option Bytes Programming functions *****************************************/
  264. uint16_t FLASH_GetBootSize(void);
  265. uint16_t FLASH_GetCodeSize(void);
  266. FunctionalState FLASH_GetReadOutProtectionStatus(void);
  267. void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data);
  268. void FLASH_EraseOptionByte(uint16_t Address);
  269. /* Interrupts and flags management functions **********************************/
  270. void FLASH_ITConfig(FunctionalState NewState);
  271. FlagStatus FLASH_GetFlagStatus(FLASH_FLAG_TypeDef FLASH_FLAG);
  272. /* Functions to be executed from RAM ******************************************/
  273. /**
  274. @code
  275. All the functions declared below must be executed from RAM exclusively, except
  276. for the FLASH_WaitForLastOperation function which can be executed from Flash.
  277. Steps of the execution from RAM differs from one toolchain to another.
  278. for more details refer to stm8l15x_flash.c file.
  279. To enable execution from RAM you can either uncomment the following define
  280. in the stm8s.h file or define it in your toolchain compiler preprocessor
  281. - #define RAM_EXECUTION (1)
  282. @endcode
  283. */
  284. IN_RAM(void FLASH_PowerRunModeConfig(FLASH_Power_TypeDef FLASH_Power));
  285. IN_RAM(FLASH_PowerStatus_TypeDef FLASH_GetPowerStatus(void));
  286. IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType,
  287. FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer));
  288. IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType));
  289. IN_RAM(FLASH_Status_TypeDef FLASH_WaitForLastOperation(FLASH_MemType_TypeDef FLASH_MemType));
  290. #endif /*__STM8L15x_FLASH_H*/
  291. /**
  292. * @}
  293. */
  294. /**
  295. * @}
  296. */
  297. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/