MG32F157 Standard Peripherals Firmware Library
mg32f157_flash.h
Go to the documentation of this file.
1 
10 /* Define to prevent recursive inclusion -------------------------------------*/
11 #ifndef __MG32F157_FLASH_H
12 #define __MG32F157_FLASH_H
13 
14 #ifdef __cplusplus
15  extern "C" {
16 #endif
17 
18 /* Includes ------------------------------------------------------------------*/
19 #include "mg32f157.h"
20 
29 /* Exported types ------------------------------------------------------------*/
30 
34 typedef enum
35 {
36  FLASH_BUSY = 1,
37  FLASH_ERROR_PG,
38  FLASH_ERROR_WRP,
39  FLASH_COMPLETE,
40  FLASH_TIMEOUT
41 } FLASH_Status;
42 
43 /* Exported constants --------------------------------------------------------*/
44 
52 #define FLASH_Latency_0 ((uint32_t)0x00000000)
53 #define FLASH_Latency_1 ((uint32_t)0x00000001)
54 #define FLASH_Latency_2 ((uint32_t)0x00000002)
55 #define IS_FLASH_LATENCY(LATENCY) (((LATENCY) == FLASH_Latency_0) || \
56  ((LATENCY) == FLASH_Latency_1) || \
57  ((LATENCY) == FLASH_Latency_2))
58 
66 #define FLASH_HalfCycleAccess_Enable ((uint32_t)0x00000008)
67 #define FLASH_HalfCycleAccess_Disable ((uint32_t)0x00000000)
68 #define IS_FLASH_HALFCYCLEACCESS_STATE(STATE) (((STATE) == FLASH_HalfCycleAccess_Enable) || \
69  ((STATE) == FLASH_HalfCycleAccess_Disable))
70 
78 #define FLASH_PrefetchBuffer_Enable ((uint32_t)0x00000010)
79 #define FLASH_PrefetchBuffer_Disable ((uint32_t)0x00000000)
80 #define IS_FLASH_PREFETCHBUFFER_STATE(STATE) (((STATE) == FLASH_PrefetchBuffer_Enable) || \
81  ((STATE) == FLASH_PrefetchBuffer_Disable))
82 
90 #define FLASH_WRProt_Pages0to1 ((uint32_t)0x00000001)
91 #define FLASH_WRProt_Pages2to3 ((uint32_t)0x00000002)
92 #define FLASH_WRProt_Pages4to5 ((uint32_t)0x00000004)
93 #define FLASH_WRProt_Pages6to7 ((uint32_t)0x00000008)
94 #define FLASH_WRProt_Pages8to9 ((uint32_t)0x00000010)
95 #define FLASH_WRProt_Pages10to11 ((uint32_t)0x00000020)
96 #define FLASH_WRProt_Pages12to13 ((uint32_t)0x00000040)
97 #define FLASH_WRProt_Pages14to15 ((uint32_t)0x00000080)
98 #define FLASH_WRProt_Pages16to17 ((uint32_t)0x00000100)
99 #define FLASH_WRProt_Pages18to19 ((uint32_t)0x00000200)
100 #define FLASH_WRProt_Pages20to21 ((uint32_t)0x00000400)
101 #define FLASH_WRProt_Pages22to23 ((uint32_t)0x00000800)
102 #define FLASH_WRProt_Pages24to25 ((uint32_t)0x00001000)
103 #define FLASH_WRProt_Pages26to27 ((uint32_t)0x00002000)
104 #define FLASH_WRProt_Pages28to29 ((uint32_t)0x00004000)
105 #define FLASH_WRProt_Pages30to31 ((uint32_t)0x00008000)
106 #define FLASH_WRProt_Pages32to33 ((uint32_t)0x00010000)
107 #define FLASH_WRProt_Pages34to35 ((uint32_t)0x00020000)
108 #define FLASH_WRProt_Pages36to37 ((uint32_t)0x00040000)
109 #define FLASH_WRProt_Pages38to39 ((uint32_t)0x00080000)
110 #define FLASH_WRProt_Pages40to41 ((uint32_t)0x00100000)
111 #define FLASH_WRProt_Pages42to43 ((uint32_t)0x00200000)
112 #define FLASH_WRProt_Pages44to45 ((uint32_t)0x00400000)
113 #define FLASH_WRProt_Pages46to47 ((uint32_t)0x00800000)
114 #define FLASH_WRProt_Pages48to49 ((uint32_t)0x01000000)
115 #define FLASH_WRProt_Pages50to51 ((uint32_t)0x02000000)
116 #define FLASH_WRProt_Pages52to53 ((uint32_t)0x04000000)
117 #define FLASH_WRProt_Pages54to55 ((uint32_t)0x08000000)
118 #define FLASH_WRProt_Pages56to57 ((uint32_t)0x10000000)
119 #define FLASH_WRProt_Pages58to59 ((uint32_t)0x20000000)
120 #define FLASH_WRProt_Pages60to61 ((uint32_t)0x40000000)
121 #define FLASH_WRProt_Pages62to255 ((uint32_t)0x80000000)
123 #define FLASH_WRProt_AllPages ((uint32_t)0xFFFFFFFF)
125 #define IS_FLASH_WRPROT_PAGE(PAGE) (((PAGE) != 0x00000000))
126 
127 #define IS_FLASH_ADDRESS(ADDRESS) (((ADDRESS) >= 0x08000000) && ((ADDRESS) < 0x080FFFFF))
128 
129 #define IS_OB_DATA_ADDRESS(ADDRESS) (((ADDRESS) == 0x1FFFF804) || ((ADDRESS) == 0x1FFFF806))
130 
138 #define OB_IWDG_SW ((uint16_t)0x0001)
139 #define OB_IWDG_HW ((uint16_t)0x0000)
140 #define IS_OB_IWDG_SOURCE(SOURCE) (((SOURCE) == OB_IWDG_SW) || ((SOURCE) == OB_IWDG_HW))
141 
149 #define OB_STOP_NoRST ((uint16_t)0x0002)
150 #define OB_STOP_RST ((uint16_t)0x0000)
151 #define IS_OB_STOP_SOURCE(SOURCE) (((SOURCE) == OB_STOP_NoRST) || ((SOURCE) == OB_STOP_RST))
152 
160 #define OB_STDBY_NoRST ((uint16_t)0x0004)
161 #define OB_STDBY_RST ((uint16_t)0x0000)
162 #define IS_OB_STDBY_SOURCE(SOURCE) (((SOURCE) == OB_STDBY_NoRST) || ((SOURCE) == OB_STDBY_RST))
163 
171 #define FLASH_IT_ERROR ((uint32_t)0x00000400)
172 #define FLASH_IT_EOP ((uint32_t)0x00001000)
173 #define FLASH_IT_BANK1_ERROR FLASH_IT_ERROR
174 #define FLASH_IT_BANK1_EOP FLASH_IT_EOP
176 #define IS_FLASH_IT(IT) ((((IT) & (uint32_t)0xFFFFEBFF) == 0x00000000) && (((IT) != 0x00000000)))
177 
185 #define FLASH_FLAG_BSY ((uint32_t)0x00000001)
186 #define FLASH_FLAG_EOP ((uint32_t)0x00000020)
187 #define FLASH_FLAG_PGERR ((uint32_t)0x00000004)
188 #define FLASH_FLAG_WRPRTERR ((uint32_t)0x00000010)
189 #define FLASH_FLAG_OPTERR ((uint32_t)0x00000001)
191 #define FLASH_FLAG_BANK1_BSY FLASH_FLAG_BSY
192 #define FLASH_FLAG_BANK1_EOP FLASH_FLAG_EOP
193 #define FLASH_FLAG_BANK1_PGERR FLASH_FLAG_PGERR
194 #define FLASH_FLAG_BANK1_WRPRTERR FLASH_FLAG_WRPRTERR
196 #define IS_FLASH_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFFCA) == 0x00000000) && ((FLAG) != 0x00000000))
197 #define IS_FLASH_GET_FLAG(FLAG) (((FLAG) == FLASH_FLAG_BSY) || ((FLAG) == FLASH_FLAG_EOP) || \
198  ((FLAG) == FLASH_FLAG_PGERR) || ((FLAG) == FLASH_FLAG_WRPRTERR) || \
199  ((FLAG) == FLASH_FLAG_BANK1_BSY) || ((FLAG) == FLASH_FLAG_BANK1_EOP) || \
200  ((FLAG) == FLASH_FLAG_BANK1_PGERR) || ((FLAG) == FLASH_FLAG_BANK1_WRPRTERR) || \
201  ((FLAG) == FLASH_FLAG_OPTERR))
202 
210 /* Exported macro ------------------------------------------------------------*/
211 /* Exported functions --------------------------------------------------------*/
212 
213 /*------------ Functions used for all MG32F157 devices -----*/
214 void FLASH_SetLatency(uint32_t FLASH_Latency);
215 void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess);
216 void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer);
217 void FLASH_Unlock(void);
218 void FLASH_Lock(void);
219 FLASH_Status FLASH_ErasePage(uint32_t Page_Address);
222 FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data);
223 FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data);
224 FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data);
225 FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages);
226 FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState);
227 FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY);
228 uint32_t FLASH_GetUserOptionByte(void);
230 FlagStatus FLASH_GetReadOutProtectionStatus(void);
231 FlagStatus FLASH_GetPrefetchBufferStatus(void);
232 void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState);
233 FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG);
234 void FLASH_ClearFlag(uint32_t FLASH_FLAG);
236 FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout);
237 
238 /*------------ New function used for all MG32F157 devices -----*/
239 void FLASH_UnlockBank1(void);
240 void FLASH_LockBank1(void);
244 
253 #ifdef __cplusplus
254 }
255 #endif
256 
257 #endif /* __MG32F157_FLASH_H */
void FLASH_PrefetchBufferCmd(uint32_t FLASH_PrefetchBuffer)
Enables or disables the Prefetch Buffer.
Definition: mg32f157_flash.c:133
FLASH_Status FLASH_ProgramHalfWord(uint32_t Address, uint16_t Data)
Programs a half word at a specified address.
Definition: mg32f157_flash.c:383
FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
Enables or disables the read out protection.
Definition: mg32f157_flash.c:527
FLASH_Status FLASH_WaitForLastOperation(uint32_t Timeout)
Waits for a Flash operation to complete or a TIMEOUT to occur.
Definition: mg32f157_flash.c:863
void FLASH_ITConfig(uint32_t FLASH_IT, FunctionalState NewState)
Enables or disables the specified FLASH interrupts.
Definition: mg32f157_flash.c:703
FLASH_Status FLASH_UserOptionByteConfig(uint16_t OB_IWDG, uint16_t OB_STOP, uint16_t OB_STDBY)
Programs the FLASH User Option Byte: IWDG_SW / RST_STOP / RST_STDBY.
Definition: mg32f157_flash.c:595
FLASH_Status FLASH_ProgramOptionByteData(uint32_t Address, uint8_t Data)
Programs a half word at a specified Option Byte Data address.
Definition: mg32f157_flash.c:417
FLASH_Status FLASH_GetBank1Status(void)
Returns the FLASH Bank1 Status.
Definition: mg32f157_flash.c:827
void FLASH_ClearFlag(uint32_t FLASH_FLAG)
Clears the FLASH's pending flags.
Definition: mg32f157_flash.c:774
FLASH_Status FLASH_EnableWriteProtection(uint32_t FLASH_Pages)
Write protects the desired pages.
Definition: mg32f157_flash.c:454
void FLASH_HalfCycleAccessCmd(uint32_t FLASH_HalfCycleAccess)
Enables or disables the Half cycle flash access.
Definition: mg32f157_flash.c:115
uint32_t FLASH_GetWriteProtectionOptionByte(void)
Returns the FLASH Write Protection Option Bytes Register value.
Definition: mg32f157_flash.c:647
void FLASH_Unlock(void)
Unlocks the FLASH Program Erase Controller.
Definition: mg32f157_flash.c:148
FLASH_Status FLASH_EraseAllPages(void)
Erases all FLASH pages.
Definition: mg32f157_flash.c:228
FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
Erases a specified FLASH page.
Definition: mg32f157_flash.c:195
FlagStatus FLASH_GetFlagStatus(uint32_t FLASH_FLAG)
Checks whether the specified FLASH flag is set or not.
Definition: mg32f157_flash.c:732
FlagStatus FLASH_GetReadOutProtectionStatus(void)
Checks whether the FLASH Read Out Protection Status is set or not.
Definition: mg32f157_flash.c:658
FLASH_Status FLASH_WaitForLastBank1Operation(uint32_t Timeout)
Waits for a Flash operation on Bank1 to complete or a TIMEOUT to occur.
Definition: mg32f157_flash.c:890
FLASH_Status FLASH_EraseOptionBytes(void)
Erases the FLASH option bytes.
Definition: mg32f157_flash.c:286
FlagStatus FLASH_GetPrefetchBufferStatus(void)
Checks whether the FLASH Prefetch Buffer status is set or not.
Definition: mg32f157_flash.c:677
void FLASH_SetLatency(uint32_t FLASH_Latency)
Sets the code latency value.
Definition: mg32f157_flash.c:89
uint32_t FLASH_GetUserOptionByte(void)
Returns the FLASH User Option Bytes values.
Definition: mg32f157_flash.c:636
void FLASH_UnlockBank1(void)
Unlocks the FLASH Bank1 Program Erase Controller.
Definition: mg32f157_flash.c:160
FLASH_Status FLASH_GetStatus(void)
Returns the FLASH Status.
Definition: mg32f157_flash.c:790
void FLASH_Lock(void)
Locks the FLASH Program Erase Controller.
Definition: mg32f157_flash.c:172
FLASH_Status
FLASH Status.
Definition: mg32f157_flash.h:34
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Programs a word at a specified address.
Definition: mg32f157_flash.c:350
void FLASH_LockBank1(void)
Locks the FLASH Bank1 Program Erase Controller.
Definition: mg32f157_flash.c:183
FLASH_Status FLASH_EraseAllBank1Pages(void)
Erases all Bank1 FLASH pages.
Definition: mg32f157_flash.c:257