硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1174|回复: 3
收起左侧

[其它] STM32G0x0_OPT.s和STM32G0x0_OPT.FLM如何在MDK里使用实现解除读写保护功能

[复制链接]

56

主题

131

回帖

299

积分

高级会员

积分
299
发表于 2022-3-18 13:31:48 | 显示全部楼层 |阅读模式
如题,STM32G0x0_OPT.s和STM32G0x0_OPT.FLM如何在MDK里使用实现解除读写保护功能,这方面的资料都找不到,求指导
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107077
QQ
发表于 2022-3-18 14:41:11 | 显示全部楼层
const  char Write[] __attribute__ ((at(xx)));  xx指定选项字节地址。
然后MDK Option加入选项字节算法即可
回复

使用道具 举报

56

主题

131

回帖

299

积分

高级会员

积分
299
 楼主| 发表于 2022-4-19 14:04:21 | 显示全部楼层
找到了示例工程

FlashOptionBytes.rar

20.09 KB, 下载次数: 31

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107077
QQ
发表于 2022-4-20 09:11:59 | 显示全部楼层

二楼的方法就行,更方便。
你把你发的,也粘贴出来,方便查看

[C] 纯文本查看 复制代码
;/*******************************************************************************/
;/* Copyright (c) 2021 Arm Limited (or its affiliates).                         */
;/* All rights reserved.                                                        */
;/*                                                                             */
;/* SPDX-License-Identifier: BSD-3-Clause                                       */
;/*                                                                             */
;/* Redistribution and use in source and binary forms, with or without          */
;/* modification, are permitted provided that the following conditions are met: */
;/*   1.Redistributions of source code must retain the above copyright          */
;/*     notice, this list of conditions and the following disclaimer.           */
;/*   2.Redistributions in binary form must reproduce the above copyright       */
;/*     notice, this list of conditions and the following disclaimer in the     */
;/*     documentation and/or other materials provided with the distribution.    */
;/*   3.Neither the name of Arm nor the names of its contributors may be used   */
;/*     to endorse or promote products derived from this software without       */
;/*     specific prior written permission.                                      */
;/*                                                                             */
;/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" */
;/* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   */
;/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  */
;/* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE     */
;/* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         */
;/* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        */
;/* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    */
;/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     */
;/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     */
;/* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  */
;/* POSSIBILITY OF SUCH DAMAGE.                                                 */
;/*******************************************************************************/
;/* STM32G4xx_DB_OPT.s: STM32G4xx Dual Bank Flash (Category 3) Option Bytes     */
;/*******************************************************************************/
;/* <<< Use Configuration Wizard in Context Menu >>>                            */
;/*******************************************************************************/


;// <e> Flash Option Bytes
FLASH_OPT       EQU     1

;// <h> Flash Read Protection
;//     <i> Read protection is used to protect the software code stored in Flash memory
;//   <o0.0..7> Read Protection Level
;//     <i> Level 0: No Protection
;//     <i> Level 1: Read Protection of Memories (debug features limited)
;//     <i> Level 2: Chip Protection (debug and boot in RAM features disabled)
;//          <0xAA=> Level 0 (No Protection)
;//          <0x00=> Level 1 (Read Protection of Memories)
;//          <0xCC=> Level 2 (Chip Protection)
;// </h>

;// <h> User Configuration
;//   <o0.30> IRH_IN
;//     <i> Internal reset holder for PG10
;//          <0=> IRH disabled
;//          <1=> IRH enabled
;//   <o0.28..29> NRST_MODE
;//     <i> PG10 pad mode
;//          <0=> Reset Input/Output
;//          <1=> Reset Input only
;//          <2=> GPIO
;//          <3=> Reset Input/Output
;//   <o0.27> nBOOT0
;//     <i> nBOOT0 option bit
;//   <o0.26> nSWBOOT0
;//     <i> Software BOOT0
;//          <0=> Option bit nBOOT0
;//          <1=> PB8/BOOT0 pin
;//   <o0.25> CCMSRAM_RST
;//     <i> CCM SRAM Erase when system reset
;//          <0=> CCM SRAM erased when a system reset occurs
;//          <1=> CCM SRAM is not erased when a system reset occurs
;//   <o0.24> SRAM2_PE
;//     <i> SRAM1 and CCM SRAM parity check enable
;//          <0=> SRAM1 and CCM SRAM parity check enable
;//          <1=> SRAM1 and CCM SRAM parity check disable
;//   <o0.23> nBOOT1
;//     <i> Boot configuration
;//     <i> Together with the BOOT0 pin, this bit selects boot mode from
;//     <i> the Flash main memory, SRAM1 or the System memory
;//          <0=> System memory
;//          <1=> Embedded SRAM1
;//   <o0.22> DBANK mode
;//     <i> Dual-bank
;//          <0=> Single bank mode with 128 bits data read width
;//          <1=> Dual bank mode with 64 bits data
;//   <o0.20> BFB2
;//     <i> Dual-bank boot
;//          <0=> Dual-bank boot disable
;//          <1=> Dual-bank boot enable
;//   <o0.19> WWDG_SW
;//     <i> Window watchdog selection
;//          <0=> Hardware window watchdog
;//          <1=> Software window watchdog
;//   <o0.18> IWDG_STDBY
;//     <i> Independent watchdog counter freeze in Standby mode
;//          <0=> Freeze IWDG counter in Standby mode
;//          <1=> IWDG counter active in Standby mode
;//   <o0.17> IWDG_STOP
;//     <i> Independent watchdog counter freeze in Stop mode
;//          <0=> Freeze IWDG counter in STOP mode
;//          <1=> IWDG counter active in STOP mode
;//   <o0.16> IWDG_SW
;//     <i> Independent watchdog selection
;//          <0=> Hardware independant watchdog
;//          <1=> Software independant watchdog
;//   <o0.14> nRST_SHDW
;//     <i> Generate Reset when entering Shutdown Mode
;//          <0=> Reset generated
;//          <1=> Reset not generated
;//   <o0.13> nRST_STDBY
;//     <i> Generate Reset when entering Standby Mode
;//          <0=> Reset generated
;//          <1=> Reset not generated
;//   <o0.12> nRST_STOP
;//     <i> Generate Reset when entering STOP Mode
;//          <0=> Reset generated
;//          <1=> Reset not generated
;//   <o0.8..10> BOR_LEV
;//     <i>These bits contain the VDD supply level threshold that activates/releases the reset.
;//          <0=> BOR Level 0 (Reset level threshold is around 1.7 V)
;//          <1=> BOR Level 1 (Reset level threshold is around 2.0 V)
;//          <2=> BOR Level 2 (Reset level threshold is around 2.2 V)
;//          <3=> BOR Level 3 (Reset level threshold is around 2.5 V)
;//          <4=> BOR Level 4 (Reset level threshold is around 2.8 V)
;// </h>
FLASH_OPTR     EQU     0xFFEFF8AA       ; reset value 0xFFEFF8AA

;// <h> PCROP / WRP Configuration (Bank1)
;//   <o1.31> PCROP_RDP
;//     <i>   Bit is set only! Bit is reset when changing RDP level from 1 to 0
;//     <i>   checked: PCROP area erased when RDP level is decreased from 1 to 0 (full mass erase)
;//     <i>   unchecked: PCROP area is not erased when RDP level is decreased from 1 to 0
;//   <o0.0..14> PCROP_STRT
;//     <i> PCROP Start address (included): Base address + (PCROP_STRT x 0x8)
;//   <o1.0..14> PCROP_END
;//     <i> PCROP End address (excluded): Base address + ((PCROP_END+1) x 0x8)
;//   <o2.0..6> WRP_A_STRT
;//     <i> WRP A area: Base address + (WRP_A_STRT x 0x800) (included) to Base address + ((WRP_A_END+1) x 0x800) (excluded)
;//   <o2.16..22> WRP_A_END
;//     <i> WRP A area: Base address + (WRP_A_STRT x 0x800) (included) to Base address + ((WRP_A_END+1) x 0x800) (excluded)
;//   <o3.0..6> WRP_B_STRT
;//     <i> WRP B area: Base address + (WRP_B_STRT x 0x800) (included) to Base address + ((WRP_B_END+1) x 0x800) (excluded)
;//   <o3.16..22> WRP_B_END
;//     <i> WRP B area: Base address + (WRP_B_STRT x 0x800) (included) to Base address + ((WRP_B_END+1) x 0x800) (excluded)
;//   <o4.0..7> SEC_SIZE1
;//     <i> Securable memory area size
;//     <i> Contains the number of Securable Flash memory pages
;//   <o4.16> BOOT_LOCK
;//     <i> used to force boot from user area
;//          <0=> Boot based on the pad/option bit configuration
;//          <1=> Boot forced from Main Flash memory
;// </h>
FLASH_PCROP1SR EQU     0xFFFFFFFF       ; reset value cat3: 0xFFFFFFFF
FLASH_PCROP1ER EQU     0x0FFF8000       ; reset value cat3: 0x0FFF8000
FLASH_WRP1AR   EQU     0xFF80FFFF       ; reset value cat3: 0xFF80FFFF
FLASH_WRP1BR   EQU     0xFF80FFFF       ; reset value cat3: 0xFF80FFFF
FLASH_SEC1R    EQU     0xFFFEFF00       ; reset value cat3: 0xFFFEFF00
;// <h> PCROP / WRP Configuration (Bank2)
;//   <o0.0..14> PCROP_STRT
;//     <i> PCROP Start address (included): Base address + (PCROP_STRT x 0x8)
;//   <o1.0..14> PCROP_END
;//     <i> PCROP End address (excluded): Base address + ((PCROP_END+1) x 0x8)
;//   <o2.0..6> WRP_A_STRT
;//     <i> WRP A area: Base address + (WRP_A_STRT x 0x800) (included) to Base address + ((WRP_A_END+1) x 0x800) (excluded)
;//   <o2.16..22> WRP_A_END
;//     <i> WRP A area: Base address + (WRP_A_STRT x 0x800) (included) to Base address + ((WRP_A_END+1) x 0x800) (excluded)
;//   <o3.0..6> WRP_B_STRT
;//     <i> WRP B area: Base address + (WRP_B_STRT x 0x800) (included) to Base address + ((WRP_B_END+1) x 0x800) (excluded)
;//   <o3.16..22> WRP_B_END
;//     <i> WRP B area: Base address + (WRP_B_STRT x 0x800) (included) to Base address + ((WRP_B_END+1) x 0x800) (excluded)
;//   <o4.0..7> SEC_SIZE2
;//     <i> Securable memory area size
;//     <i> Contains the number of Securable Flash memory pages
;// </h>
FLASH_PCROP2SR EQU     0xFFFFFFFF       ; reset value cat3: 0xFFFFFFFF
FLASH_PCROP2ER EQU     0x0FFF8000       ; reset value cat3: 0x0FFF8000
FLASH_WRP2AR   EQU     0xFF80FFFF       ; reset value cat3: 0xFF80FFFF
FLASH_WRP2BR   EQU     0xFF80FFFF       ; reset value cat3: 0xFF80FFFF
FLASH_SEC2R    EQU     0xFFFEFF00       ; reset value cat3: 0xFFFEFF00
;// </e>


                IF      FLASH_OPT <> 0
                AREA    |.ARM.__AT_0x1FFF7800|, CODE, READONLY
                DCD     FLASH_OPTR
                DCD     FLASH_PCROP1SR
                DCD     FLASH_PCROP1ER
                DCD     FLASH_WRP1AR
                DCD     FLASH_WRP1BR
                DCD     FLASH_SEC1R
                DCD     FLASH_PCROP2SR
                DCD     FLASH_PCROP2ER
                DCD     FLASH_WRP2AR
                DCD     FLASH_WRP2BR
                DCD     FLASH_SEC2R
                ENDIF

                END

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-17 06:16 , Processed in 0.173984 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表