📄 stm32f10x_flash.lst
字号:
197 /* if the erase operation is completed, disable the PER Bit */
198 FLASH->CR &= CR_PER_Reset;
199 }
200 }
201 /* Return the Erase Status */
202 return status;
203 }
204
205 /*******************************************************************************
206 * Function Name : FLASH_EraseAllPages
207 * Description : Erases all FLASH pages.
208 * Input : None
209 * Output : None
210 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
211 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
212 * FLASH_TIMEOUT.
213 *******************************************************************************/
214 FLASH_Status FLASH_EraseAllPages(void)
215 {
216 FLASH_Status status = FLASH_COMPLETE;
217
218 /* Wait for last operation to be completed */
219 status = FLASH_WaitForLastOperation(EraseTimeout);
220
221 if(status == FLASH_COMPLETE)
222 {
223 /* if the previous operation is completed, proceed to erase all pages */
224 FLASH->CR |= CR_MER_Set;
225 FLASH->CR |= CR_STRT_Set;
226
227 /* Wait for last operation to be completed */
228 status = FLASH_WaitForLastOperation(EraseTimeout);
229
230 if(status != FLASH_BUSY)
231 {
232 /* if the erase operation is completed, disable the MER Bit */
233 FLASH->CR &= CR_MER_Reset;
234 }
235 }
236 /* Return the Erase Status */
237 return status;
238 }
239
240 /*******************************************************************************
241 * Function Name : FLASH_EraseOptionBytes
242 * Description : Erases the FLASH option bytes.
243 * Input : None
244 * Output : None
245 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
246 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
247 * FLASH_TIMEOUT.
248 *******************************************************************************/
249 FLASH_Status FLASH_EraseOptionBytes(void)
250 {
251 FLASH_Status status = FLASH_COMPLETE;
252
253 /* Wait for last operation to be completed */
254 status = FLASH_WaitForLastOperation(EraseTimeout);
255
256 if(status == FLASH_COMPLETE)
257 {
258 /* Authorize the small information block programming */
259 FLASH->OPTKEYR = FLASH_KEY1;
260 FLASH->OPTKEYR = FLASH_KEY2;
261
262 /* if the previous operation is completed, proceed to erase the option bytes */
263 FLASH->CR |= CR_OPTER_Set;
264 FLASH->CR |= CR_STRT_Set;
265
266 /* Wait for last operation to be completed */
267 status = FLASH_WaitForLastOperation(EraseTimeout);
268
269 if(status == FLASH_COMPLETE)
270 {
271 /* if the erase operation is completed, disable the OPTER Bit */
272 FLASH->CR &= CR_OPTER_Reset;
273
274 /* Enable the Option Bytes Programming operation */
275 FLASH->CR |= CR_OPTPG_Set;
276
277 /* Enable the readout access */
278 OB->RDP= RDP_Key;
279
280 /* Wait for last operation to be completed */
281 status = FLASH_WaitForLastOperation(ProgramTimeout);
282
283 if(status != FLASH_BUSY)
284 {
285 /* if the program operation is completed, disable the OPTPG Bit */
286 FLASH->CR &= CR_OPTPG_Reset;
287 }
288 }
289 else
290 {
291 if (status != FLASH_BUSY)
292 {
293 /* Disable the OPTPG Bit */
294 FLASH->CR &= CR_OPTPG_Reset;
295 }
296 }
297 }
298 /* Return the erase status */
299 return status;
300 }
301
302 /*******************************************************************************
303 * Function Name : FLASH_ProgramWord
304 * Description : Programs a word at a specified address.
305 * Input : - Address: specifies the address to be programmed.
306 * - Data: specifies the data to be programmed.
307 * Output : None
308 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
309 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
310 * FLASH_TIMEOUT.
311 *******************************************************************************/
312 FLASH_Status FLASH_ProgramWord(u32 Address, u32 Data)
313 {
314 FLASH_Status status = FLASH_COMPLETE;
315
316 /* Check the parameters */
317 assert(IS_FLASH_ADDRESS(Address));
318
319 /* Wait for last operation to be completed */
320 status = FLASH_WaitForLastOperation(ProgramTimeout);
321
322 if(status == FLASH_COMPLETE)
323 {
324 /* if the previous operation is completed, proceed to program the new first
325 half word */
326 FLASH->CR |= CR_PG_Set;
327
328 *(vu16*)Address = (u16)Data;
329
330 /* Wait for last operation to be completed */
331 status = FLASH_WaitForLastOperation(ProgramTimeout);
332
333 if(status == FLASH_COMPLETE)
334 {
335 /* if the previous operation is completed, proceed to program the new second
336 half word */
337 *(vu16*)(Address + 2) = Data >> 16;
338
339 /* Wait for last operation to be completed */
340 status = FLASH_WaitForLastOperation(ProgramTimeout);
341
342 if(status != FLASH_BUSY)
343 {
344 /* Disable the PG Bit */
345 FLASH->CR &= CR_PG_Reset;
346 }
347 }
348 else
349 {
350 if (status != FLASH_BUSY)
351 {
352 /* Disable the PG Bit */
353 FLASH->CR &= CR_PG_Reset;
354 }
355 }
356 }
357 /* Return the Program Status */
358 return status;
359 }
360
361 /*******************************************************************************
362 * Function Name : FLASH_ProgramHalfWord
363 * Description : Programs a half word at a specified address.
364 * Input : - Address: specifies the address to be programmed.
365 * - Data: specifies the data to be programmed.
366 * Output : None
367 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
368 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
369 * FLASH_TIMEOUT.
370 *******************************************************************************/
371 FLASH_Status FLASH_ProgramHalfWord(u32 Address, u16 Data)
372 {
373 FLASH_Status status = FLASH_COMPLETE;
374
375 /* Check the parameters */
376 assert(IS_FLASH_ADDRESS(Address));
377
378 /* Wait for last operation to be completed */
379 status = FLASH_WaitForLastOperation(ProgramTimeout);
380
381 if(status == FLASH_COMPLETE)
382 {
383 /* if the previous operation is completed, proceed to program the new data */
384 FLASH->CR |= CR_PG_Set;
385
386 *(vu16*)Address = Data;
387 /* Wait for last operation to be completed */
388 status = FLASH_WaitForLastOperation(ProgramTimeout);
389
390 if(status != FLASH_BUSY)
391 {
392 /* if the program operation is completed, disable the PG Bit */
393 FLASH->CR &= CR_PG_Reset;
394 }
395 }
396 /* Return the Program Status */
397 return status;
398 }
399
400 /*******************************************************************************
401 * Function Name : FLASH_ProgramOptionByteData
402 * Description : Programs a half word at a specified Option Byte Data address.
403 * Input : - Address: specifies the address to be programmed.
404 * This parameter can be 0x1FFFF804 or 0x1FFFF806.
405 * - Data: specifies the data to be programmed.
406 * Output : None
407 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
408 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
409 * FLASH_TIMEOUT.
410 *******************************************************************************/
411 FLASH_Status FLASH_ProgramOptionByteData(u32 Address, u8 Data)
412 {
413 FLASH_Status status = FLASH_COMPLETE;
414
415 /* Check the parameters */
416 assert(IS_OB_DATA_ADDRESS(Address));
417
418 status = FLASH_WaitForLastOperation(ProgramTimeout);
419
420 if(status == FLASH_COMPLETE)
421 {
422 /* Authorize the small information block programming */
423 FLASH->OPTKEYR = FLASH_KEY1;
424 FLASH->OPTKEYR = FLASH_KEY2;
425
426 /* Enables the Option Bytes Programming operation */
427 FLASH->CR |= CR_OPTPG_Set;
428 *(vu16*)Address = Data;
429
430 /* Wait for last operation to be completed */
431 status = FLASH_WaitForLastOperation(ProgramTimeout);
432
433 if(status != FLASH_BUSY)
434 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -