STM8L15x Standard Peripherals Drivers
|
stm8l15x_flash.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm8l15x_flash.h 00004 * @author MCD Application Team 00005 * @version V1.5.0 00006 * @date 13-May-2011 00007 * @brief This file contains all the functions prototypes for the FLASH firmware 00008 * library. 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00013 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00014 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00015 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00016 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00017 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00018 * 00019 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> 00020 ****************************************************************************** 00021 */ 00022 00023 /* Define to prevent recursive inclusion -------------------------------------*/ 00024 #ifndef __STM8L15x_FLASH_H__ 00025 #define __STM8L15x_FLASH_H__ 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm8l15x.h" 00029 00030 /** @addtogroup STM8L15x_StdPeriph_Driver 00031 * @{ 00032 */ 00033 00034 /** @addtogroup FLASH 00035 * @{ 00036 */ 00037 00038 /* Exported constants --------------------------------------------------------*/ 00039 00040 /** @addtogroup FLASH_Exported_Constants 00041 * @{ 00042 */ 00043 #define FLASH_PROGRAM_START_PHYSICAL_ADDRESS ((uint32_t)0x00008000) /*!< Flash: start address */ 00044 #define FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS ((uint32_t)0x00001000) /*!< Data Eeprom: start address */ 00045 00046 /* STM8L15x High density devices */ 00047 #ifdef STM8L15X_HD 00048 #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x00017FFF) /*!< Flash: end address */ 00049 #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000017FF) /*!< Data Eeprom: end address */ 00050 #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x200) /*!< Flash memory: total number of Block */ 00051 #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x10) /*!< Data EEprom: total number of Block */ 00052 #define FLASH_BLOCK_SIZE ((uint8_t)0x80) /*!< Number of bytes in a Block 00053 (common for Program and Data EEprom memories) */ 00054 00055 /* STM8L15x Medium density and Medium density plus devices */ 00056 #elif defined (STM8L15X_MD) || defined (STM8L15X_MDP) 00057 #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x0000FFFF) /*!< Flash: end address */ 00058 #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000013FF) /*!< Data Eeprom: end address */ 00059 #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x100) /*!< Flash memory: total number of Block */ 00060 #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x8) /*!< Data EEprom: total number of Block */ 00061 #define FLASH_BLOCK_SIZE ((uint8_t)0x80) /*!< Number of bytes in a Block 00062 (common for Program and Data EEprom memories) */ 00063 00064 /* STM8L15x Low density devices */ 00065 #elif defined (STM8L15X_LD) 00066 #define FLASH_PROGRAM_END_PHYSICAL_ADDRESS ((uint32_t)0x00009FFF) /*!< Flash: end address */ 00067 #define FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS ((uint32_t)0x000010FF) /*!< Data Eeprom: end address */ 00068 #define FLASH_PROGRAM_BLOCKS_NUMBER ((uint16_t)0x80) /*!< Flash memory: total number of Block */ 00069 #define FLASH_DATA_EEPROM_BLOCKS_NUMBER ((uint8_t)0x4) /*!< Data EEprom: total number of Block */ 00070 #define FLASH_BLOCK_SIZE ((uint8_t)0x40) /*!< Number of bytes in a Block 00071 (common for Program and Data EEprom memories) */ 00072 #endif /* STM8L15X_HD */ 00073 00074 /*Common defines for all STM8L15x devices */ 00075 #define FLASH_OPTION_BYTES_START_PHYSICAL_ADDRESS ((uint32_t)0x00004800) /*!< Option bytes: start address */ 00076 #define FLASH_OPTION_BYTES_END_PHYSICAL_ADDRESS ((uint32_t)0x0000480A) /*!< Option bytes: end address */ 00077 #define FLASH_RASS_KEY1 ((uint8_t)0x56) /*!< First RASS key */ 00078 #define FLASH_RASS_KEY2 ((uint8_t)0xAE) /*!< Second RASS key */ 00079 #define FLASH_READOUTPROTECTION_KEY ((uint8_t)0xAA) /*!< Read out protection key */ 00080 00081 /** 00082 * @} 00083 */ 00084 00085 /* Exported types ------------------------------------------------------------*/ 00086 00087 /** @addtogroup FLASH_Exported_Types 00088 * @{ 00089 */ 00090 00091 /** @defgroup FLASH_Memory_Type 00092 * @{ 00093 */ 00094 typedef enum 00095 { 00096 FLASH_MemType_Program = (uint8_t)0xFD, /*!< Program memory */ 00097 FLASH_MemType_Data = (uint8_t)0xF7 /*!< Data EEPROM memory */ 00098 } FLASH_MemType_TypeDef; 00099 00100 /** 00101 * @} 00102 */ 00103 00104 /** @defgroup FLASH_Programming_Mode 00105 * @{ 00106 */ 00107 typedef enum 00108 { 00109 FLASH_ProgramMode_Standard = (uint8_t)0x00, /*!< Standard programming mode */ 00110 FLASH_ProgramMode_Fast = (uint8_t)0x10 /*!< Fast programming mode */ 00111 } FLASH_ProgramMode_TypeDef; 00112 00113 /** 00114 * @} 00115 */ 00116 00117 /** @defgroup FLASH_Programming_Time 00118 * @{ 00119 */ 00120 typedef enum 00121 { 00122 FLASH_ProgramTime_Standard = (uint8_t)0x00, /*!< Standard programming time fixed at 1/2 tprog */ 00123 FLASH_ProgramTime_TProg = (uint8_t)0x01 /*!< Programming time fixed at tprog */ 00124 } FLASH_ProgramTime_TypeDef; 00125 00126 /** 00127 * @} 00128 */ 00129 00130 /** @defgroup FLASH_Power_Mode 00131 * @{ 00132 */ 00133 typedef enum 00134 { 00135 FLASH_Power_IDDQ = (uint8_t)0x00, /*!< Flash program and data EEPROM in IDDQ */ 00136 FLASH_Power_On = (uint8_t)0x01 /*!< Flash program and data EEPROM not in IDDQ */ 00137 } FLASH_Power_TypeDef; 00138 00139 /** 00140 * @} 00141 */ 00142 00143 /** @defgroup FLASH_Status 00144 * @{ 00145 */ 00146 typedef enum 00147 { 00148 FLASH_Status_Write_Protection_Error = (uint8_t)0x01, /*!< Write attempted to protected Block */ 00149 FLASH_Status_TimeOut = (uint8_t)0x02, /*!< Time out error */ 00150 FLASH_Status_Successful_Operation = (uint8_t)0x04 /*!< End of operation flag */ 00151 } FLASH_Status_TypeDef; 00152 00153 /** 00154 * @} 00155 */ 00156 00157 /** @defgroup FLASH_Power_Status 00158 * @{ 00159 */ 00160 typedef enum 00161 { 00162 FLASH_PowerStatus_IDDQDuringWaitMode = (uint8_t)0x04, /*!< Flash program and data EEPROM 00163 in IDDQ during Wait mode*/ 00164 FLASH_PowerStatus_IDDQDuringRunMode = (uint8_t)0x08, /*!< Flash program and data EEPROM 00165 in IDDQ mode during Run mode*/ 00166 FLASH_PowerStatus_IDDQDuringWaitAndRunModes = (uint8_t)0x0C, /*!<Flash program and data EEPROM 00167 in IDDQ during Wait and run modes*/ 00168 FLASH_PowerStatus_On = (uint8_t)0x00 /*!< Flash program and data EEPROM 00169 is powered on during Wait and Run modes */ 00170 } FLASH_PowerStatus_TypeDef; 00171 00172 /** 00173 * @} 00174 */ 00175 00176 /** @defgroup FLASH_Flags 00177 * @{ 00178 */ 00179 typedef enum { 00180 FLASH_FLAG_HVOFF = (uint8_t)0x40, /*!< End of high voltage flag */ 00181 FLASH_FLAG_DUL = (uint8_t)0x08, /*!< Data EEPROM unlocked flag */ 00182 FLASH_FLAG_EOP = (uint8_t)0x04, /*!< End of programming (write or erase operation) flag */ 00183 FLASH_FLAG_PUL = (uint8_t)0x02, /*!< Flash Program memory unlocked flag */ 00184 FLASH_FLAG_WR_PG_DIS = (uint8_t)0x01 /*!< Write attempted to protected page flag */ 00185 } FLASH_FLAG_TypeDef; 00186 00187 /** 00188 * @} 00189 */ 00190 00191 /** 00192 * @} 00193 */ 00194 00195 /* Exported macros -----------------------------------------------------------*/ 00196 00197 /** @addtogroup FLASH_Exported_Macros 00198 * @{ 00199 */ 00200 00201 /** 00202 * @brief Macro used by the assert function in order to check the different 00203 * sensitivity values for the flash Address 00204 */ 00205 00206 #define IS_FLASH_PROGRAM_ADDRESS(Address) (((Address) >= FLASH_PROGRAM_START_PHYSICAL_ADDRESS) && \ 00207 ((Address) <= FLASH_PROGRAM_END_PHYSICAL_ADDRESS)) 00208 00209 00210 /** 00211 * @brief Macro used by the assert function in order to check the different 00212 * sensitivity values for the data Eeprom Address 00213 */ 00214 00215 #define IS_FLASH_DATA_EEPROM_ADDRESS(Address) (((Address) >= FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS) && \ 00216 ((Address) <= FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS)) 00217 00218 /** 00219 * @brief Macro used by the assert function in order to check the different 00220 * sensitivity values for the data eeprom and flash program Address 00221 */ 00222 #define IS_FLASH_ADDRESS(Address)((((Address) >= FLASH_PROGRAM_START_PHYSICAL_ADDRESS) && ((Address) <= FLASH_PROGRAM_END_PHYSICAL_ADDRESS)) || \ 00223 (((Address) >= FLASH_DATA_EEPROM_START_PHYSICAL_ADDRESS) && ((Address) <= FLASH_DATA_EEPROM_END_PHYSICAL_ADDRESS))) 00224 00225 /** 00226 * @brief Macro used by the assert function in order to check the different 00227 * sensitivity values for the option bytes Address 00228 */ 00229 #define IS_OPTION_BYTE_ADDRESS(ADDRESS) (((ADDRESS) >= FLASH_OPTION_BYTES_START_PHYSICAL_ADDRESS) && \ 00230 ((ADDRESS) <= FLASH_OPTION_BYTES_END_PHYSICAL_ADDRESS)) 00231 00232 /** 00233 * @brief Macro used by the assert function in order to check the different 00234 * sensitivity values for the flash Block number 00235 */ 00236 #define IS_FLASH_PROGRAM_BLOCK_NUMBER(BlockNum) ((BlockNum) < FLASH_PROGRAM_BLOCKS_NUMBER) 00237 00238 /** 00239 * @brief Macro used by the assert function in order to check the different 00240 * sensitivity values for the data eeprom Block number 00241 */ 00242 #define IS_FLASH_DATA_EEPROM_BLOCK_NUMBER(BlockNum) ((BlockNum) < FLASH_DATA_EEPROM_BLOCKS_NUMBER) 00243 00244 /** 00245 * @brief Macro used by the assert function in order to check the different 00246 * sensitivity values for the flash memory type 00247 */ 00248 #define IS_FLASH_MEMORY_TYPE(MemType) (((MemType) == FLASH_MemType_Program) || \ 00249 ((MemType) == FLASH_MemType_Data)) 00250 00251 /** 00252 * @brief Macro used by the assert function in order to check the different 00253 * sensitivity values for the flash program block mode 00254 */ 00255 #define IS_FLASH_PROGRAM_MODE(Mode) (((Mode) == FLASH_ProgramMode_Standard) || \ 00256 ((Mode) == FLASH_ProgramMode_Fast)) 00257 00258 /** 00259 * @brief Macro used by the assert function in order to check the program time mode 00260 */ 00261 #define IS_FLASH_PROGRAM_TIME(Time) (((Time) == FLASH_ProgramTime_Standard) || \ 00262 ((Time) == FLASH_ProgramTime_TProg)) 00263 00264 /** 00265 * @brief Macro used by the assert function in order to check the power mode 00266 */ 00267 #define IS_FLASH_POWER(Power) (((Power) == FLASH_Power_IDDQ) || \ 00268 ((Power) == FLASH_Power_On)) 00269 00270 /** 00271 * @brief Macro used by the assert function in order to check the power status during wait and run modes 00272 */ 00273 #define IS_FLASH_POWERSTATUS(PowerStatus) (((PowerStatus) == FLASH_PowerStatus_IDDQDuringWaitMode) || \ 00274 ((PowerStatus) == FLASH_PowerStatus_IDDQDuringRunMode ) || \ 00275 ((PowerStatus) == FLASH_PowerStatus_IDDQDuringWaitAndRunModes) || \ 00276 ((PowerStatus) == FLASH_Power_On)) 00277 00278 /** 00279 * @brief Macro used by the assert function in order to check the different flags values 00280 */ 00281 #define IS_FLASH_FLAGS(FLAG) (((FLAG) == FLASH_FLAG_HVOFF) || \ 00282 ((FLAG) == FLASH_FLAG_DUL) || \ 00283 ((FLAG) == FLASH_FLAG_EOP) || \ 00284 ((FLAG) == FLASH_FLAG_PUL) || \ 00285 ((FLAG) == FLASH_FLAG_WR_PG_DIS)) 00286 00287 /** 00288 * @} 00289 */ 00290 00291 /* Exported functions ------------------------------------------------------- */ 00292 /* FLASH program and Data EEPROM memories interface configuration functions ***/ 00293 FLASH_ProgramTime_TypeDef FLASH_GetProgrammingTime(void); 00294 void FLASH_SetProgrammingTime(FLASH_ProgramTime_TypeDef FLASH_ProgTime); 00295 void FLASH_PowerWaitModeConfig(FLASH_Power_TypeDef FLASH_Power); 00296 00297 /* FLASH program and Data EEPROM memories Programming functions ***************/ 00298 void FLASH_DeInit(void); 00299 void FLASH_Unlock(FLASH_MemType_TypeDef FLASH_MemType); 00300 void FLASH_Lock(FLASH_MemType_TypeDef FLASH_MemType); 00301 void FLASH_ProgramByte(uint32_t Address, uint8_t Data); 00302 void FLASH_EraseByte(uint32_t Address); 00303 void FLASH_ProgramWord(uint32_t Address, uint32_t Data); 00304 uint8_t FLASH_ReadByte(uint32_t Address); 00305 00306 /* Option Bytes Programming functions *****************************************/ 00307 uint16_t FLASH_GetBootSize(void); 00308 uint16_t FLASH_GetCodeSize(void); 00309 FunctionalState FLASH_GetReadOutProtectionStatus(void); 00310 void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data); 00311 void FLASH_EraseOptionByte(uint16_t Address); 00312 00313 /* Interrupts and flags management functions **********************************/ 00314 void FLASH_ITConfig(FunctionalState NewState); 00315 FlagStatus FLASH_GetFlagStatus(FLASH_FLAG_TypeDef FLASH_FLAG); 00316 00317 /* Functions to be executed from RAM ******************************************/ 00318 00319 /** 00320 @code 00321 All the functions declared below must be executed from RAM exclusively, except 00322 for the FLASH_WaitForLastOperation function which can be executed from Flash. 00323 00324 Steps of the execution from RAM differs from one toolchain to another. 00325 for more details refer to stm8l15x_flash.c file. 00326 00327 To enable execution from RAM you can either uncomment the following define 00328 in the stm8s.h file or define it in your toolchain compiler preprocessor 00329 - #define RAM_EXECUTION (1) 00330 00331 @endcode 00332 */ 00333 00334 IN_RAM(void FLASH_PowerRunModeConfig(FLASH_Power_TypeDef FLASH_Power)); 00335 IN_RAM(FLASH_PowerStatus_TypeDef FLASH_GetPowerStatus(void)); 00336 00337 IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType, 00338 FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer)); 00339 IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType)); 00340 00341 IN_RAM(FLASH_Status_TypeDef FLASH_WaitForLastOperation(FLASH_MemType_TypeDef FLASH_MemType)); 00342 00343 #endif /*__STM8L15x_FLASH_H__*/ 00344 00345 /** 00346 * @} 00347 */ 00348 00349 /** 00350 * @} 00351 */ 00352 00353 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/