| BlueNRG-1 Peripherals drivers APIs

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

BlueNRG1_flash.c
Go to the documentation of this file.
1
22 /* Includes ------------------------------------------------------------------*/
23 #include "BlueNRG1_flash.h"
24
85 void FLASH_ErasePage(uint16_t PageNumber)
86 {
87 uint16_t pageAddress;
88
89 assert_param(IS_PAGE_NUMBER(PageNumber));
90
91 pageAddress = (PageNumber * N_BYTES_PAGE)>>2;
92
93 /* Clear IRQ */
94 FLASH->IRQSTAT = 0x3F;
95
96 /* Write the page address */
97 FLASH->ADDRESS = pageAddress;
98
99 /* Write the ERASE command */
100 FLASH->COMMAND = FLASH_ERASE;
101
102 FLASH_WaitCmdDone();
103
104 /* Verify */
105 // return;
106 }
107
113 void FLASH_EraseAllFlash(void)
114 {
115 /* Clear IRQ */
116 FLASH->IRQSTAT = 0x3F;
117
118 /* Write the MASSERASE command */
119 FLASH->COMMAND = FLASH_MASSERASE;
120
121 FLASH_WaitCmdDone();
122
123 }
124
130 uint32_t FLASH_ReadWord(uint32_t Address)
131 {
132 assert_param(IS_FLASH_ADDRESS(Address));
133
134 return (*((volatile uint32_t*)(Address)));
135 }
136
143 void FLASH_ProgramWord(uint32_t Address, uint32_t Data)
144 {
145 assert_param(IS_FLASH_ADDRESS(Address));
146
147 /* Clear IRQ */
148 FLASH->IRQSTAT = 0x3F;
149
150 /* Write the page address */
151 FLASH->ADDRESS = Address>>2;
152
153 /* Write the data to program */
154 FLASH->DATA0 = Data;
155
156 /* Write the WRITE command */
157 FLASH->COMMAND = FLASH_WRITE;
158
159 FLASH_WaitCmdDone();
160
161 /* Verify */
162 // return ;
163 }
164
172 void FLASH_ProgramWordBurst(uint32_t Address, uint32_t* Data)
173 {
174 assert_param(IS_FLASH_ADDRESS(Address));
175
176 /* Clear IRQ */
177 FLASH->IRQSTAT = 0x3F;
178
179 /* Write the page address */
180 FLASH->ADDRESS = Address>>2;
181
182 /* Write the data to program */
183 FLASH->DATA0 = Data[0];
184 FLASH->DATA1 = Data[1];
185 FLASH->DATA2 = Data[2];
186 FLASH->DATA3 = Data[3];
187
188 /* Write the BURSTWRITE command */
189 FLASH->COMMAND = FLASH_BURSTWRITE;
190
191 FLASH_WaitCmdDone();
192
193 /* Verify */
194 // return ;
195 }
196
197
203 void FLASH_WaitCmdDone(void)
204 {
205 /* Waits for Command Done */
206 while(FLASH->IRQRAW_b.CMDDONE != SET);
207 }
208
209
215 void FLASH_ClearCmdDone(void)
216 {
217 /* Clear the CMDDONE flag */
218 SET_BIT(FLASH->IRQSTAT, Flash_CMDDONE);
219 }
220
221
227 uint16_t FLASH_NextFreeFlashAddress(void)
228 {
229 return FLASH->SIZE;
230 }
231
232
246 void FLASH_ITConfig(uint8_t FlashFlag, FunctionalState NewState)
247 {
248 /* Check the parameters */
249 assert_param(IS_FLASH_FLAG(FlashFlag));
250 assert_param(IS_FUNCTIONAL_STATE(NewState));
251
252 if (NewState == ENABLE) {
253 SET_BIT(FLASH->IRQMASK, FlashFlag);
254 }
255 else if (NewState == DISABLE) {
256 CLEAR_BIT(FLASH->IRQMASK, FlashFlag);
257 }
258 }
259
260
272 void FLASH_ClearITPendingBit(uint8_t FlashFlag)
273 {
274 assert_param(IS_FLASH_FLAG(FlashFlag)) ;
275
276 /* Clear the flags */
277 FLASH->IRQSTAT = FlashFlag;
278 }
279
280
293 FlagStatus FLASH_GetFlagStatus(uint8_t FlashFlag)
294 {
295 /* Check the parameters */
296 assert_param(IS_FLASH_FLAG(FlashFlag));
297
298 if((FLASH->IRQRAW & FlashFlag) != (uint16_t)RESET) {
299 return SET;
300 }
301 else {
302 return RESET;
303 }
304 }
305
317 void FLASH_ClearFlag(uint8_t FlashFlag)
318 {
319 assert_param(IS_FLASH_FLAG(FlashFlag)) ;
320
321 /* Clear the flags */
322 FLASH->IRQSTAT = FlashFlag;
323 }
324
337 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/
FLASH_WRITE
#define FLASH_WRITE
Definition: BlueNRG1_flash.h:107
FLASH_ReadWord
uint32_t FLASH_ReadWord(uint32_t Address)
Flash read 32 bits.
Definition: BlueNRG1_flash.c:130
IS_FLASH_FLAG
#define IS_FLASH_FLAG(FLAG)
Definition: BlueNRG1_flash.h:57
N_BYTES_PAGE
#define N_BYTES_PAGE
Definition: BlueNRG1_flash.h:86
FLASH_ErasePage
void FLASH_ErasePage(uint16_t PageNumber)
Erases a specified flash page.
Definition: BlueNRG1_flash.c:85
FLASH_ProgramWord
void FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Flash write 32 bits.
Definition: BlueNRG1_flash.c:143
FLASH_ProgramWordBurst
void FLASH_ProgramWordBurst(uint32_t Address, uint32_t *Data)
Flash write 32 bits.
Definition: BlueNRG1_flash.c:172
FLASH_NextFreeFlashAddress
uint16_t FLASH_NextFreeFlashAddress(void)
Wait loop for CMDDONE status.
Definition: BlueNRG1_flash.c:227
FLASH_ClearCmdDone
void FLASH_ClearCmdDone(void)
Clear CMDDONE flag.
Definition: BlueNRG1_flash.c:215
BlueNRG1_flash.h
This file contains all the functions prototypes for the FLASH firmware library.
FLASH_EraseAllFlash
void FLASH_EraseAllFlash(void)
Erases all main Flash.
Definition: BlueNRG1_flash.c:113
FLASH_BURSTWRITE
#define FLASH_BURSTWRITE
Definition: BlueNRG1_flash.h:112
FLASH_ERASE
#define FLASH_ERASE
Definition: BlueNRG1_flash.h:105
Flash_CMDDONE
#define Flash_CMDDONE
Flash status enumeration.
Definition: BlueNRG1_flash.h:50
IS_FLASH_ADDRESS
#define IS_FLASH_ADDRESS(ADDR)
Definition: BlueNRG1_flash.h:78
FLASH_GetFlagStatus
FlagStatus FLASH_GetFlagStatus(uint8_t FlashFlag)
Checks whether the specified FLASH raw flag is set or not.
Definition: BlueNRG1_flash.c:293
IS_PAGE_NUMBER
#define IS_PAGE_NUMBER(PAGE)
Definition: BlueNRG1_flash.h:88
FLASH_ITConfig
void FLASH_ITConfig(uint8_t FlashFlag, FunctionalState NewState)
Enables or disables the specified flash interrupts.
Definition: BlueNRG1_flash.c:246
FLASH_ClearFlag
void FLASH_ClearFlag(uint8_t FlashFlag)
Clears the specific flash pending flags.
Definition: BlueNRG1_flash.c:317
FLASH_WaitCmdDone
void FLASH_WaitCmdDone(void)
Wait loop for CMDDONE status.
Definition: BlueNRG1_flash.c:203
FLASH_MASSERASE
#define FLASH_MASSERASE
Definition: BlueNRG1_flash.h:106
FLASH_ClearITPendingBit
void FLASH_ClearITPendingBit(uint8_t FlashFlag)
Clears the specific flash pending IT bit.
Definition: BlueNRG1_flash.c:272