📄 stm32f10x_flash.lst
字号:
435 /* if the program operation is completed, disable the OPTPG Bit */
436 FLASH->CR &= CR_OPTPG_Reset;
437 }
438 }
439 /* Return the Option Byte Data Program Status */
440 return status;
441 }
442
443 /*******************************************************************************
444 * Function Name : FLASH_EnableWriteProtection
445 * Description : Write protects the desired pages
446 * Input : - FLASH_Pages: specifies the address of the pages to be
447 * write protected. This parameter can be:
448 * - A value between FLASH_WRProt_Pages0to3 and
449 * FLASH_WRProt_Pages124to127
450 * - FLASH_WRProt_AllPages
451 * Output : None
452 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
453 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
454 * FLASH_TIMEOUT.
455 *******************************************************************************/
456 FLASH_Status FLASH_EnableWriteProtection(u32 FLASH_Pages)
457 {
458 u16 WRP0_Data = 0xFFFF, WRP1_Data = 0xFFFF, WRP2_Data = 0xFFFF, WRP3_Data = 0xFFFF;
459
460 FLASH_Status status = FLASH_COMPLETE;
461
462 /* Check the parameters */
463 assert(IS_FLASH_WRPROT_PAGE(FLASH_Pages));
464
465 FLASH_Pages = (u32)(~FLASH_Pages);
466 WRP0_Data = (vu16)(FLASH_Pages & WRP0_Mask);
467 WRP1_Data = (vu16)((FLASH_Pages & WRP1_Mask) >> 8);
468 WRP2_Data = (vu16)((FLASH_Pages & WRP2_Mask) >> 16);
469 WRP3_Data = (vu16)((FLASH_Pages & WRP3_Mask) >> 24);
470
471 /* Wait for last operation to be completed */
472 status = FLASH_WaitForLastOperation(ProgramTimeout);
473
474 if(status == FLASH_COMPLETE)
475 {
476 /* Authorizes the small information block programming */
477 FLASH->OPTKEYR = FLASH_KEY1;
478 FLASH->OPTKEYR = FLASH_KEY2;
479 FLASH->CR |= CR_OPTPG_Set;
480
481 if(WRP0_Data != 0xFF)
482 {
483 OB->WRP0 = WRP0_Data;
484
485 /* Wait for last operation to be completed */
486 status = FLASH_WaitForLastOperation(ProgramTimeout);
487 }
488 if((status == FLASH_COMPLETE) && (WRP1_Data != 0xFF))
489 {
490 OB->WRP1 = WRP1_Data;
491
492 /* Wait for last operation to be completed */
493 status = FLASH_WaitForLastOperation(ProgramTimeout);
494 }
495
496 if((status == FLASH_COMPLETE) && (WRP2_Data != 0xFF))
497 {
498 OB->WRP2 = WRP2_Data;
499
500 /* Wait for last operation to be completed */
501 status = FLASH_WaitForLastOperation(ProgramTimeout);
502 }
503
504 if((status == FLASH_COMPLETE)&& (WRP3_Data != 0xFF))
505 {
506 OB->WRP3 = WRP3_Data;
507
508 /* Wait for last operation to be completed */
509 status = FLASH_WaitForLastOperation(ProgramTimeout);
510 }
511
512 if(status != FLASH_BUSY)
513 {
514 /* if the program operation is completed, disable the OPTPG Bit */
515 FLASH->CR &= CR_OPTPG_Reset;
516 }
517 }
518 /* Return the write protection operation Status */
519 return status;
520 }
521
522 /*******************************************************************************
523 * Function Name : FLASH_ReadOutProtection
524 * Description : Enables or disables the read out protection
525 * Input : - Newstate: new state of the ReadOut Protection.
526 * This parameter can be: ENABLE or DISABLE.
527 * Output : None
528 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
529 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
530 * FLASH_TIMEOUT.
531 *******************************************************************************/
532 FLASH_Status FLASH_ReadOutProtection(FunctionalState NewState)
533 {
534 FLASH_Status status = FLASH_COMPLETE;
535
536 /* Check the parameters */
537 assert(IS_FUNCTIONAL_STATE(NewState));
538
539 status = FLASH_WaitForLastOperation(EraseTimeout);
540
541 if(status == FLASH_COMPLETE)
542 {
543 /* Authorizes the small information block programming */
544 FLASH->OPTKEYR = FLASH_KEY1;
545 FLASH->OPTKEYR = FLASH_KEY2;
546
547 FLASH->CR |= CR_OPTER_Set;
548 FLASH->CR |= CR_STRT_Set;
549
550 /* Wait for last operation to be completed */
551 status = FLASH_WaitForLastOperation(EraseTimeout);
552
553 if(status == FLASH_COMPLETE)
554 {
555 /* if the erase operation is completed, disable the OPTER Bit */
556 FLASH->CR &= CR_OPTER_Reset;
557
558 /* Enable the Option Bytes Programming operation */
559 FLASH->CR |= CR_OPTPG_Set;
560
561 if(NewState != DISABLE)
562 {
563 OB->RDP = 0x00;
564 }
565 else
566 {
567 OB->RDP = RDP_Key;
568 }
569
570 /* Wait for last operation to be completed */
571 status = FLASH_WaitForLastOperation(EraseTimeout);
572
573 if(status != FLASH_BUSY)
574 {
575 /* if the program operation is completed, disable the OPTPG Bit */
576 FLASH->CR &= CR_OPTPG_Reset;
577 }
578 }
579 else
580 {
581 if(status != FLASH_BUSY)
582 {
583 /* Disable the OPTER Bit */
584 FLASH->CR &= CR_OPTER_Reset;
585 }
586 }
587 }
588 /* Return the protection operation Status */
589 return status;
590 }
591
592 /*******************************************************************************
593 * Function Name : FLASH_UserOptionByteConfig
594 * Description : Programs the FLASH User Option Byte: IWDG_SW / RST_STOP /
595 * RST_STDBY.
596 * Input : - OB_IWDG: Selects the IWDG mode
597 * This parameter can be one of the following values:
598 * - OB_IWDG_SW: Software IWDG selected
599 * - OB_IWDG_HW: Hardware IWDG selected
600 * - OB_STOP: Reset event when entering STOP mode.
601 * This parameter can be one of the following values:
602 * - OB_STOP_NoRST: No reset generated when entering in STOP
603 * - OB_STOP_RST: Reset generated when entering in STOP
604 * - OB_STDBY: Reset event when entering Standby mode.
605 * This parameter can be one of the following values:
606 * - OB_STDBY_NoRST: No reset generated when entering in STANDBY
607 * - OB_STDBY_RST: Reset generated when entering in STANDBY
608 * Output : None
609 * Return : FLASH Status: The returned value can be: FLASH_BUSY,
610 * FLASH_ERROR_PG or FLASH_ERROR_WRP or FLASH_COMPLETE or
611 * FLASH_TIMEOUT.
612 *******************************************************************************/
613 FLASH_Status FLASH_UserOptionByteConfig(u16 OB_IWDG, u16 OB_STOP, u16 OB_STDBY)
614 {
615 FLASH_Status status = FLASH_COMPLETE;
616
617 /* Check the parameters */
618 assert(IS_OB_IWDG_SOURCE(OB_IWDG));
619 assert(IS_OB_STOP_SOURCE(OB_STOP));
620 assert(IS_OB_STDBY_SOURCE(OB_STDBY));
621
622 /* Authorize the small information block programming */
623 FLASH->OPTKEYR = FLASH_KEY1;
624 FLASH->OPTKEYR = FLASH_KEY2;
625
626 /* Wait for last operation to be completed */
627 status = FLASH_WaitForLastOperation(ProgramTimeout);
628
629 if(status == FLASH_COMPLETE)
630 {
631 /* Enable the Option Bytes Programming operation */
632 FLASH->CR |= CR_OPTPG_Set;
633
634 OB->USER = ( OB_IWDG | OB_STOP |OB_STDBY) | (u16)0xF8;
635
636 /* Wait for last operation to be completed */
637 status = FLASH_WaitForLastOperation(ProgramTimeout);
638
639 if(status != FLASH_BUSY)
640 {
641 /* if the program operation is completed, disable the OPTPG Bit */
642 FLASH->CR &= CR_OPTPG_Reset;
643 }
644 }
645 /* Return the Option Byte program Status */
646 return status;
647 }
648
649 /*******************************************************************************
650 * Function Name : FLASH_GetUserOptionByte
651 * Description : Returns the FLASH User Option Bytes values.
652 * Input : None
653 * Output : None
654 * Return : The FLASH User Option Bytes values:IWDG_SW(Bit0), RST_STOP(Bit1)
655 * and RST_STDBY(Bit2).
656 *******************************************************************************/
657 u32 FLASH_GetUserOptionByte(void)
658 {
659 /* Return the User Option Byte */
660 return (u32)(FLASH->OBR >> 2);
661 }
662
663 /*******************************************************************************
664 * Function Name : FLASH_GetWriteProtectionOptionByte
665 * Description : Returns the FLASH Write Protection Option Bytes Register value.
666 * Input : None
667 * Output : None
668 * Return : The FLASH Write Protection Option Bytes Register value
669 *******************************************************************************/
670 u32 FLASH_GetWriteProtectionOptionByte(void)
671 {
672 /* Return the Falsh write protection Register value */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -