1 /*! 2 * @file apm32s10x_fmc.h 3 * 4 * @brief This file contains all the functions prototypes for the FMC firmware library 5 * 6 * @version V1.0.1 7 * 8 * @date 2022-12-31 9 * 10 * @attention 11 * 12 * Copyright (C) 2022-2023 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be usefull and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 /* Define to prevent recursive inclusion */ 27 #ifndef __APM32S10X_FMC_H 28 #define __APM32S10X_FMC_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* Includes */ 35 #include "apm32s10x.h" 36 37 /** @addtogroup APM32S10x_StdPeriphDriver 38 @{ 39 */ 40 41 /** @addtogroup FMC_Driver FMC Driver 42 @{ 43 */ 44 45 /** @defgroup FMC_Macros Macros 46 @{ 47 */ 48 49 /* Macros description */ 50 51 /* Values for APM32 Medium-density devices */ 52 #define FLASH_WRP_PAGE_0_3 ((uint32_t)BIT0) /*!< Write protection of page 0 to 3 */ 53 #define FLASH_WRP_PAGE_4_7 ((uint32_t)BIT1) /*!< Write protection of page 4 to 7 */ 54 #define FLASH_WRP_PAGE_8_11 ((uint32_t)BIT2) /*!< Write protection of page 8 to 11 */ 55 #define FLASH_WRP_PAGE_12_15 ((uint32_t)BIT3) /*!< Write protection of page 12 to 15 */ 56 #define FLASH_WRP_PAGE_16_19 ((uint32_t)BIT4) /*!< Write protection of page 16 to 19 */ 57 #define FLASH_WRP_PAGE_20_23 ((uint32_t)BIT5) /*!< Write protection of page 20 to 23 */ 58 #define FLASH_WRP_PAGE_24_27 ((uint32_t)BIT6) /*!< Write protection of page 24 to 27 */ 59 #define FLASH_WRP_PAGE_28_31 ((uint32_t)BIT7) /*!< Write protection of page 28 to 31 */ 60 #define FLASH_WRP_PAGE_32_35 ((uint32_t)BIT8) /*!< Write protection of page 32 to 35 */ 61 #define FLASH_WRP_PAGE_36_39 ((uint32_t)BIT9) /*!< Write protection of page 36 to 39 */ 62 #define FLASH_WRP_PAGE_40_43 ((uint32_t)BIT10) /*!< Write protection of page 40 to 43 */ 63 #define FLASH_WRP_PAGE_44_47 ((uint32_t)BIT11) /*!< Write protection of page 44 to 47 */ 64 #define FLASH_WRP_PAGE_48_51 ((uint32_t)BIT12) /*!< Write protection of page 48 to 51 */ 65 #define FLASH_WRP_PAGE_52_55 ((uint32_t)BIT13) /*!< Write protection of page 52 to 55 */ 66 #define FLASH_WRP_PAGE_56_59 ((uint32_t)BIT14) /*!< Write protection of page 56 to 59 */ 67 #define FLASH_WRP_PAGE_60_63 ((uint32_t)BIT15) /*!< Write protection of page 60 to 63 */ 68 #define FLASH_WRP_PAGE_64_67 ((uint32_t)BIT16) /*!< Write protection of page 64 to 67 */ 69 #define FLASH_WRP_PAGE_68_71 ((uint32_t)BIT17) /*!< Write protection of page 68 to 71 */ 70 #define FLASH_WRP_PAGE_72_75 ((uint32_t)BIT18) /*!< Write protection of page 72 to 75 */ 71 #define FLASH_WRP_PAGE_76_79 ((uint32_t)BIT19) /*!< Write protection of page 76 to 79 */ 72 #define FLASH_WRP_PAGE_80_83 ((uint32_t)BIT20) /*!< Write protection of page 80 to 83 */ 73 #define FLASH_WRP_PAGE_84_87 ((uint32_t)BIT21) /*!< Write protection of page 84 to 87 */ 74 #define FLASH_WRP_PAGE_88_91 ((uint32_t)BIT22) /*!< Write protection of page 88 to 91 */ 75 #define FLASH_WRP_PAGE_92_95 ((uint32_t)BIT23) /*!< Write protection of page 92 to 95 */ 76 #define FLASH_WRP_PAGE_96_99 ((uint32_t)BIT24) /*!< Write protection of page 96 to 99 */ 77 #define FLASH_WRP_PAGE_100_103 ((uint32_t)BIT25) /*!< Write protection of page 100 to 103 */ 78 #define FLASH_WRP_PAGE_104_107 ((uint32_t)BIT26) /*!< Write protection of page 104 to 107 */ 79 #define FLASH_WRP_PAGE_108_111 ((uint32_t)BIT27) /*!< Write protection of page 108 to 111 */ 80 #define FLASH_WRP_PAGE_112_115 ((uint32_t)BIT28) /*!< Write protection of page 112 to 115 */ 81 #define FLASH_WRP_PAGE_116_119 ((uint32_t)BIT29) /*!< Write protection of page 116 to 119 */ 82 #define FLASH_WRP_PAGE_120_123 ((uint32_t)BIT30) /*!< Write protection of page 120 to 123 */ 83 #define FLASH_WRP_PAGE_124_127 ((uint32_t)BIT31) /*!< Write protection of page 124 to 127 */ 84 #define FMC_WRP_PAGE_ALL ((uint32_t)0xFFFFFFFF) /*!< Write protection of page all */ 85 86 /**@} end of group FMC_Macros */ 87 88 /** @defgroup FMC_Enumerations Enumerations 89 @{ 90 */ 91 92 /** 93 * @brief Flash Latency 94 */ 95 typedef enum 96 { 97 FMC_LATENCY_0, 98 FMC_LATENCY_1, 99 FMC_LATENCY_2 100 } FMC_LATENCY_T; 101 102 /** 103 * @brief FMC Status 104 */ 105 typedef enum 106 { 107 FMC_STATUS_BUSY = 1, /*!< flash busy */ 108 FMC_STATUS_ERROR_PG, /*!< flash programming error */ 109 FMC_STATUS_ERROR_WRP, /*!< flash write protection error */ 110 FMC_STATUS_COMPLETE, /*!< flash operation complete */ 111 FMC_STATUS_TIMEOUT /*!< flash time out */ 112 } FMC_STATUS_T; 113 114 /** 115 * @brief Option Bytes IWatchdog 116 */ 117 typedef enum 118 { 119 OB_IWDT_HARD = 0x0000, 120 OB_IWDT_SOTF = 0x0001 121 } OB_IWDT_T; 122 123 /** 124 * @brief Option Bytes nRST STOP 125 */ 126 typedef enum 127 { 128 OB_STOP_RST = 0x0000, 129 OB_STOP_NORST = 0x0002 130 } OB_STOP_T; 131 132 /** 133 * @brief Option Bytes nRST STDBY 134 */ 135 typedef enum 136 { 137 OB_STDBY_RST = 0x0000, 138 OB_STDBY_NORST = 0x0004 139 } OB_STDBY_T; 140 141 /** 142 * @brief FMC Interrupts 143 */ 144 typedef enum 145 { 146 FMC_INT_ERR, 147 FMC_INT_OC 148 } FMC_INT_T; 149 150 /** 151 * @brief FMC flag 152 */ 153 typedef enum 154 { 155 FMC_FLAG_BUSY = 0x00000001, /*!< FMC Busy flag */ 156 FMC_FLAG_OC = 0x00000020, /*!< FMC End of Operation flag */ 157 FMC_FLAG_PE = 0x00000004, /*!< FMC Program error flag */ 158 FMC_FLAG_WPE = 0x00000010, /*!< FMC Write protected error flag */ 159 FMC_FLAG_OBE = 0x10000001, /*!< FMC Option Byte error flag */ 160 } FMC_FLAG_T; 161 162 /**@} end of group FMC_Enumerations */ 163 164 /** @defgroup FMC_Structures Structures 165 @{ 166 */ 167 168 /** 169 * @brief User Option byte config struct definition 170 */ 171 typedef struct 172 { 173 OB_IWDT_T iwdtSet; 174 OB_STOP_T stopSet; 175 OB_STDBY_T stdbySet; 176 } FMC_UserConfig_T; 177 178 /**@} end of group FMC_Structures */ 179 180 /** @defgroup FMC_Functions Functions 181 @{ 182 */ 183 184 /* Initialization and Configuration */ 185 void FMC_ConfigLatency(FMC_LATENCY_T latency); 186 void FMC_EnableHalfCycleAccess(void); 187 void FMC_DisableHalfCycleAccess(void); 188 void FMC_EnablePrefetchBuffer(void); 189 void FMC_DisablePrefetchBuffer(void); 190 191 /* Lock management */ 192 void FMC_Unlock(void); 193 void FMC_Lock(void); 194 195 /* Erase management */ 196 FMC_STATUS_T FMC_ErasePage(uint32_t pageAddr); 197 FMC_STATUS_T FMC_EraseAllPage(void); 198 FMC_STATUS_T FMC_EraseOptionBytes(void); 199 200 /* Read Write management */ 201 FMC_STATUS_T FMC_ProgramWord(uint32_t address, uint32_t data); 202 FMC_STATUS_T FMC_ProgramHalfWord(uint32_t address, uint16_t data); 203 FMC_STATUS_T FMC_ProgramOptionByteData(uint32_t address, uint8_t data); 204 FMC_STATUS_T FMC_EnableWriteProtection(uint32_t page); 205 FMC_STATUS_T FMC_EnableReadOutProtection(void); 206 FMC_STATUS_T FMC_DisableReadOutProtection(void); 207 FMC_STATUS_T FMC_ConfigUserOptionByte(FMC_UserConfig_T* userConfig); 208 uint32_t FMC_ReadUserOptionByte(void); 209 uint32_t FMC_ReadOptionByteWriteProtection(void); 210 uint8_t FMC_GetReadProtectionStatus(void); 211 uint8_t FMC_ReadPrefetchBufferStatus(void); 212 213 /* Interrupts and flags */ 214 void FMC_EnableInterrupt(FMC_INT_T interrupt); 215 void FMC_DisableInterrupt(FMC_INT_T interrupt); 216 uint8_t FMC_ReadStatusFlag(FMC_FLAG_T flag); 217 void FMC_ClearStatusFlag(uint32_t flag); 218 219 /* Status management */ 220 FMC_STATUS_T FMC_ReadStatus(void); 221 FMC_STATUS_T FMC_WaitForLastOperation(uint32_t timeOut); 222 223 /**@} end of group FMC_Functions */ 224 /**@} end of group FMC_Driver */ 225 /**@} end of group APM32S10x_StdPeriphDriver */ 226 227 #ifdef __cplusplus 228 } 229 #endif 230 231 #endif /* __APM32S10X_FMC_H */ 232