STM8S/A Standard Peripherals Drivers
|
stm8s_flash.h
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm8s_flash.h 00004 * @author MCD Application Team 00005 * @version V2.3.0 00006 * @date 16-June-2017 00007 * @brief This file contains all functions prototype and macros for the FLASH peripheral. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> 00012 * 00013 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00014 * You may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at: 00016 * 00017 * http://www.st.com/software_license_agreement_liberty_v2 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 * 00025 ****************************************************************************** 00026 */ 00027 00028 /* Define to prevent recursive inclusion -------------------------------------*/ 00029 #ifndef __STM8S_FLASH_H 00030 #define __STM8S_FLASH_H 00031 00032 /* Includes ------------------------------------------------------------------*/ 00033 #include "stm8s.h" 00034 00035 /* Exported constants --------------------------------------------------------*/ 00036 00037 /** @addtogroup FLASH_Exported_Constants 00038 * @{ 00039 */ 00040 00041 #define FLASH_PROG_START_PHYSICAL_ADDRESS ((uint32_t)0x008000) /*!< Program memory: start address */ 00042 00043 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined (STM8AF52Ax) || defined (STM8AF62Ax) 00044 #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0x027FFF) /*!< Program memory: end address */ 00045 #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)1024) /*!< Program memory: total number of blocks */ 00046 #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 00047 #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x0047FF) /*!< Data EEPROM memory: end address */ 00048 #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)16) /*!< Data EEPROM memory: total number of blocks */ 00049 #define FLASH_BLOCK_SIZE ((uint8_t)128) /*!< Number of bytes in a block (common for Program and Data memories) */ 00050 #endif /* STM8S208, STM8S207, STM8S007, STM8AF52Ax, STM8AF62Ax */ 00051 00052 #if defined(STM8S105) || defined(STM8S005) || defined(STM8AF626x) 00053 #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0xFFFF) /*!< Program memory: end address */ 00054 #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)256) /*!< Program memory: total number of blocks */ 00055 #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 00056 #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x0043FF) /*!< Data EEPROM memory: end address */ 00057 #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)8) /*!< Data EEPROM memory: total number of blocks */ 00058 #define FLASH_BLOCK_SIZE ((uint8_t)128) /*!< Number of bytes in a block (common for Program and Data memories) */ 00059 #endif /* STM8S105 or STM8AF626x */ 00060 00061 #if defined(STM8S103) || defined(STM8S003) || defined(STM8S001) || defined(STM8S903) || defined(STM8AF622x) 00062 #define FLASH_PROG_END_PHYSICAL_ADDRESS ((uint32_t)0x9FFF) /*!< Program memory: end address */ 00063 #define FLASH_PROG_BLOCKS_NUMBER ((uint16_t)128) /*!< Program memory: total number of blocks */ 00064 #define FLASH_DATA_START_PHYSICAL_ADDRESS ((uint32_t)0x004000) /*!< Data EEPROM memory: start address */ 00065 #define FLASH_DATA_END_PHYSICAL_ADDRESS ((uint32_t)0x00427F) /*!< Data EEPROM memory: end address */ 00066 #define FLASH_DATA_BLOCKS_NUMBER ((uint16_t)10) /*!< Data EEPROM memory: total number of blocks */ 00067 #define FLASH_BLOCK_SIZE ((uint8_t)64) /*!< Number of bytes in a block (common for Program and Data memories) */ 00068 #endif /* STM8S103 or STM8S003 or STM8S001 or STM8S903 or STM8AF622x*/ 00069 00070 #define FLASH_RASS_KEY1 ((uint8_t)0x56) /*!< First RASS key */ 00071 #define FLASH_RASS_KEY2 ((uint8_t)0xAE) /*!< Second RASS key */ 00072 00073 #define OPTION_BYTE_START_PHYSICAL_ADDRESS ((uint16_t)0x4800) 00074 #define OPTION_BYTE_END_PHYSICAL_ADDRESS ((uint16_t)0x487F) 00075 #define FLASH_OPTIONBYTE_ERROR ((uint16_t)0x5555) /*!< Error code option byte 00076 (if value read is not equal to complement value read) */ 00077 /** 00078 * @} 00079 */ 00080 00081 /* Exported types ------------------------------------------------------------*/ 00082 00083 /** @addtogroup FLASH_Exported_Types 00084 * @{ 00085 */ 00086 00087 /** 00088 * @brief FLASH Memory types 00089 */ 00090 typedef enum { 00091 FLASH_MEMTYPE_PROG = (uint8_t)0xFD, /*!< Program memory */ 00092 FLASH_MEMTYPE_DATA = (uint8_t)0xF7 /*!< Data EEPROM memory */ 00093 } FLASH_MemType_TypeDef; 00094 00095 /** 00096 * @brief FLASH programming modes 00097 */ 00098 typedef enum { 00099 FLASH_PROGRAMMODE_STANDARD = (uint8_t)0x00, /*!< Standard programming mode */ 00100 FLASH_PROGRAMMODE_FAST = (uint8_t)0x10 /*!< Fast programming mode */ 00101 } FLASH_ProgramMode_TypeDef; 00102 00103 /** 00104 * @brief FLASH fixed programming time 00105 */ 00106 typedef enum { 00107 FLASH_PROGRAMTIME_STANDARD = (uint8_t)0x00, /*!< Standard programming time fixed at 1/2 tprog */ 00108 FLASH_PROGRAMTIME_TPROG = (uint8_t)0x01 /*!< Programming time fixed at tprog */ 00109 } FLASH_ProgramTime_TypeDef; 00110 00111 /** 00112 * @brief FLASH Low Power mode select 00113 */ 00114 typedef enum { 00115 FLASH_LPMODE_POWERDOWN = (uint8_t)0x04, /*!< HALT: Power-Down / ACTIVE-HALT: Power-Down */ 00116 FLASH_LPMODE_STANDBY = (uint8_t)0x08, /*!< HALT: Standby / ACTIVE-HALT: Standby */ 00117 FLASH_LPMODE_POWERDOWN_STANDBY = (uint8_t)0x00, /*!< HALT: Power-Down / ACTIVE-HALT: Standby */ 00118 FLASH_LPMODE_STANDBY_POWERDOWN = (uint8_t)0x0C /*!< HALT: Standby / ACTIVE-HALT: Power-Down */ 00119 } 00120 FLASH_LPMode_TypeDef; 00121 00122 /** 00123 * @brief FLASH status of the last operation 00124 */ 00125 typedef enum { 00126 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 00127 defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 00128 FLASH_STATUS_END_HIGH_VOLTAGE = (uint8_t)0x40, /*!< End of high voltage */ 00129 #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 00130 FLASH_STATUS_SUCCESSFUL_OPERATION = (uint8_t)0x04, /*!< End of operation flag */ 00131 FLASH_STATUS_TIMEOUT = (uint8_t)0x02, /*!< Time out error */ 00132 FLASH_STATUS_WRITE_PROTECTION_ERROR = (uint8_t)0x01 /*!< Write attempted to protected page */ 00133 } FLASH_Status_TypeDef; 00134 00135 /** 00136 * @brief FLASH flags definition 00137 * - Warning : FLAG value = mapping position register 00138 */ 00139 typedef enum { 00140 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 00141 defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 00142 FLASH_FLAG_HVOFF = (uint8_t)0x40, /*!< End of high voltage flag */ 00143 #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 00144 FLASH_FLAG_DUL = (uint8_t)0x08, /*!< Data EEPROM unlocked flag */ 00145 FLASH_FLAG_EOP = (uint8_t)0x04, /*!< End of programming (write or erase operation) flag */ 00146 FLASH_FLAG_PUL = (uint8_t)0x02, /*!< Flash Program memory unlocked flag */ 00147 FLASH_FLAG_WR_PG_DIS = (uint8_t)0x01 /*!< Write attempted to protected page flag */ 00148 } FLASH_Flag_TypeDef; 00149 00150 /** 00151 * @} 00152 */ 00153 00154 /* Private macros ------------------------------------------------------------*/ 00155 00156 /** 00157 * @brief Macros used by the assert function in order to check the different functions parameters. 00158 * @addtogroup FLASH_Private_Macros 00159 * @{ 00160 */ 00161 00162 /** 00163 * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program Address 00164 */ 00165 00166 #define IS_FLASH_PROG_ADDRESS_OK(ADDRESS) (((ADDRESS) >= FLASH_PROG_START_PHYSICAL_ADDRESS) && \ 00167 ((ADDRESS) <= FLASH_PROG_END_PHYSICAL_ADDRESS)) 00168 00169 /** 00170 * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom Address 00171 */ 00172 00173 #define IS_FLASH_DATA_ADDRESS_OK(ADDRESS) (((ADDRESS) >= FLASH_DATA_START_PHYSICAL_ADDRESS) && \ 00174 ((ADDRESS) <= FLASH_DATA_END_PHYSICAL_ADDRESS)) 00175 00176 /** 00177 * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom and flash program Address 00178 */ 00179 #define IS_FLASH_ADDRESS_OK(ADDRESS)((((ADDRESS) >= FLASH_PROG_START_PHYSICAL_ADDRESS) && ((ADDRESS) <= FLASH_PROG_END_PHYSICAL_ADDRESS)) || \ 00180 (((ADDRESS) >= FLASH_DATA_START_PHYSICAL_ADDRESS) && ((ADDRESS) <= FLASH_DATA_END_PHYSICAL_ADDRESS))) 00181 00182 /** 00183 * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program Block number 00184 */ 00185 #define IS_FLASH_PROG_BLOCK_NUMBER_OK(BLOCKNUM) ((BLOCKNUM) < FLASH_PROG_BLOCKS_NUMBER) 00186 00187 /** 00188 * @brief Macro used by the assert function in order to check the different sensitivity values for the data eeprom Block number 00189 */ 00190 #define IS_FLASH_DATA_BLOCK_NUMBER_OK(BLOCKNUM) ((BLOCKNUM) < FLASH_DATA_BLOCKS_NUMBER) 00191 00192 /** 00193 * @brief Macro used by the assert function in order to check the different sensitivity values for the flash memory type 00194 */ 00195 00196 #define IS_MEMORY_TYPE_OK(MEMTYPE) (((MEMTYPE) == FLASH_MEMTYPE_PROG) || \ 00197 ((MEMTYPE) == FLASH_MEMTYPE_DATA)) 00198 00199 /** 00200 * @brief Macro used by the assert function in order to check the different sensitivity values for the flash program mode 00201 */ 00202 00203 #define IS_FLASH_PROGRAM_MODE_OK(MODE) (((MODE) == FLASH_PROGRAMMODE_STANDARD) || \ 00204 ((MODE) == FLASH_PROGRAMMODE_FAST)) 00205 00206 /** 00207 * @brief Macro used by the assert function in order to check the program time mode 00208 */ 00209 00210 #define IS_FLASH_PROGRAM_TIME_OK(TIME) (((TIME) == FLASH_PROGRAMTIME_STANDARD) || \ 00211 ((TIME) == FLASH_PROGRAMTIME_TPROG)) 00212 00213 /** 00214 * @brief Macro used by the assert function in order to check the different 00215 * sensitivity values for the low power mode 00216 */ 00217 00218 #define IS_FLASH_LOW_POWER_MODE_OK(LPMODE) (((LPMODE) == FLASH_LPMODE_POWERDOWN) || \ 00219 ((LPMODE) == FLASH_LPMODE_STANDBY) || \ 00220 ((LPMODE) == FLASH_LPMODE_POWERDOWN_STANDBY) || \ 00221 ((LPMODE) == FLASH_LPMODE_STANDBY_POWERDOWN)) 00222 00223 /** 00224 * @brief Macro used by the assert function in order to check the different 00225 * sensitivity values for the option bytes Address 00226 */ 00227 #define IS_OPTION_BYTE_ADDRESS_OK(ADDRESS) (((ADDRESS) >= OPTION_BYTE_START_PHYSICAL_ADDRESS) && \ 00228 ((ADDRESS) <= OPTION_BYTE_END_PHYSICAL_ADDRESS)) 00229 00230 00231 /** 00232 * @brief Macro used by the assert function in order to check the different flags values 00233 */ 00234 #if defined (STM8S208) || defined(STM8S207) || defined(STM8S007) || defined(STM8S105) || \ 00235 defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined(STM8AF626x) 00236 #define IS_FLASH_FLAGS_OK(FLAG) (((FLAG) == FLASH_FLAG_HVOFF) || \ 00237 ((FLAG) == FLASH_FLAG_DUL) || \ 00238 ((FLAG) == FLASH_FLAG_EOP) || \ 00239 ((FLAG) == FLASH_FLAG_PUL) || \ 00240 ((FLAG) == FLASH_FLAG_WR_PG_DIS)) 00241 #else /* STM8S103, STM8S001, STM8S903, STM8AF622x */ 00242 #define IS_FLASH_FLAGS_OK(FLAG) (((FLAG) == FLASH_FLAG_DUL) || \ 00243 ((FLAG) == FLASH_FLAG_EOP) || \ 00244 ((FLAG) == FLASH_FLAG_PUL) || \ 00245 ((FLAG) == FLASH_FLAG_WR_PG_DIS)) 00246 #endif /* STM8S208, STM8S207, STM8S105, STM8AF62Ax, STM8AF52Ax, STM8AF626x */ 00247 /** 00248 * @} 00249 */ 00250 00251 /* Exported functions ------------------------------------------------------- */ 00252 00253 /** @addtogroup FLASH_Exported_Functions 00254 * @{ 00255 */ 00256 void FLASH_Unlock(FLASH_MemType_TypeDef FLASH_MemType); 00257 void FLASH_Lock(FLASH_MemType_TypeDef FLASH_MemType); 00258 void FLASH_DeInit(void); 00259 void FLASH_ITConfig(FunctionalState NewState); 00260 void FLASH_EraseByte(uint32_t Address); 00261 void FLASH_ProgramByte(uint32_t Address, uint8_t Data); 00262 uint8_t FLASH_ReadByte(uint32_t Address); 00263 void FLASH_ProgramWord(uint32_t Address, uint32_t Data); 00264 uint16_t FLASH_ReadOptionByte(uint16_t Address); 00265 void FLASH_ProgramOptionByte(uint16_t Address, uint8_t Data); 00266 void FLASH_EraseOptionByte(uint16_t Address); 00267 void FLASH_SetLowPowerMode(FLASH_LPMode_TypeDef FLASH_LPMode); 00268 void FLASH_SetProgrammingTime(FLASH_ProgramTime_TypeDef FLASH_ProgTime); 00269 FLASH_LPMode_TypeDef FLASH_GetLowPowerMode(void); 00270 FLASH_ProgramTime_TypeDef FLASH_GetProgrammingTime(void); 00271 uint32_t FLASH_GetBootSize(void); 00272 FlagStatus FLASH_GetFlagStatus(FLASH_Flag_TypeDef FLASH_FLAG); 00273 00274 /** 00275 @code 00276 All the functions declared below must be executed from RAM exclusively, except 00277 for the FLASH_WaitForLastOperation function which can be executed from Flash. 00278 00279 Steps of the execution from RAM differs from one toolchain to another. 00280 for more details refer to stm8s_flash.c file. 00281 00282 To enable execution from RAM you can either uncomment the following define 00283 in the stm8s.h file or define it in your toolchain compiler preprocessor 00284 - #define RAM_EXECUTION (1) 00285 00286 @endcode 00287 */ 00288 IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType)); 00289 IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType, 00290 FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer)); 00291 IN_RAM(FLASH_Status_TypeDef FLASH_WaitForLastOperation(FLASH_MemType_TypeDef FLASH_MemType)); 00292 00293 /** 00294 * @} 00295 */ 00296 00297 #endif /*__STM8S_FLASH_H */ 00298 00299 00300 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/