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