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