Interpretation of STM32 MCU: Code to implement PCROP clearing

Publisher:SereneSoul55Latest update time:2017-09-02 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Preface
STM32  PCROP proprietary code readout protection sets a certain area to only allow execution, which can prevent the code from being illegally read out and modified. The ST website provides free PCROP reference code, but the routine only provides code to set PCROP. To facilitate the development and deployment of intellectual property protection using PCROP, this article provides a method to use code to clear PCROP when the RDP level is set to 1 or 0.

PCROP reference code on the ST website
To learn how to use PCROP, you can download documents and reference code from the ST website. The document has detailed step-by-step instructions. The reference code implements how to set up the compilation development environment to remove the literal pool to avoid the need for read access to the protected area; the reference code also implements how to use code to enable PCROP protection and how to export interface symbols for secondary development.
You can compile and run the PCROP reference code. Once downloaded to the development board and run, sector 2 will automatically be set to PCROP protection. You will not be able to download code to this sector again, nor can you read the contents of this sector. If you want to remove PCROP protection through the STLink tool , the entire Flash will be erased.

Using code to clear PCROP
Based on the familiarity of the PCROP reference code on the ST website, we will discuss how to use code to clear PCROP.

  1. Principle
According to the STM32 user manual , to clear PCROP protection, the read protection RDP level must be set from 1 to 0. That is to say, even if the current RDP level is 0, we have to use code to set it to 1. Then, turn off PCROP and set RDP to 0 at the same time. This also shows that even if it is to clear PCROP protection, our code must add the RDP setting function, and cannot simply modify the status field of PCROP_Enable in the reference code to make it PCROP_Disable.

Interpretation of STM32 MCU: Code Implementation of PCROP Clear


  2. Material preparation
Development board:  STM32F429I_Discovery
Development tools: STM32Cube_FW_F4 _V1.15.0
                STM32CubeExpansion_AN4701_F4_V1.0.0 (reference code downloaded from ST website)
                STM32  STLink
                IAR/Keil
Note: You can also select other STM32 series that support PCROP, and select the corresponding STM32 development board and STM32 firmware library .

3. Code
 ● Set RDP to level 1
This function must be used when the RDP level is 0 if you need to clear PCROP.

Interpretation of STM32 MCU: Code Implementation of PCROP Clear


 ●Set RDP to level 0
This function is not called directly in the code that clears PCROP protection. The reference manual mentions that clearing PCROP must happen at the same time as RDP goes from 1 to 0, and the following RDP_Disable function is completely independent and cannot be operated at the same time as the Option bytes of PCROP. However, the middle part of this code, which is the actual functional part, will be reused when clearing PCROP.
Interpretation of STM32 MCU: Code Implementation of PCROP Clear
Interpretation of STM32 MCU: Code Implementation of PCROP Clear


 ●Clear PCROP
The following code clears PCROP. It is rewritten based on the PCROP_Enable function in the reference code. First, it sets RDP to 1 through RDP_Enable. Note that you should not set RDP to 2 in the experiment, otherwise all Option bytes will no longer be allowed to be modified. Then, after setting both RDP and PCROP, call HAL_FLASH_OB_Launch once to set RDP to 1 and clear PCROP protection at the same time.

Interpretation of STM32 MCU: Code Implementation of PCROP Clear

Interpretation of STM32 MCU: Code Implementation of PCROP Clear



4. Run
in the main function and call PCROP_Disable to remove the PCROP protection. After RDP_Enable, you need to turn off the power, restart, and then run the system normally to remove the PCROP protection. After removing the protection, you can confirm that the PCROP Option bytes have been restored through STLink, and you can also see that the entire Flash content has been erased.

Conclusion
This article discusses the setting and clearing of PCROP completely controlled by code. It can be used in the development and deployment stage of PCROP code protection.


Reference address:Interpretation of STM32 MCU: Code to implement PCROP clearing

Previous article:How to deal with the MCU system failure
Next article:MSP430 AD Module Notes

Recommended ReadingLatest update time:2024-11-16 14:39

No default placement for segment .FLASH_CODE encountered when STVP was compiled
Recently, I needed to use the flash library function when compiling STM8S003. It looked simple, but it took me more than a day to figure it out. Today I summarize the method as follows: 1. Modify stm8s.h line 156 #define RAM_EXECUTION and remove the comment. If you are using COSMIC, you can leave this uncommented. 2.
[Microcontroller]
STM32 is in the spotlight, but Microchip has released more than 60 8-bit MCUs
To meet the demand for 8-bit microcontrollers (MCUs), Microchip has launched five new series and more than 60 devices at once, covering PICs and AVRs. Embedded design is becoming an increasingly popular and important element of electronic products. As it stands today, you can find MCUs in the vast majority of electr
[Microcontroller]
STM32 is in the spotlight, but Microchip has released more than 60 8-bit MCUs
About stm32 microcontroller, using id encryption, plain code security analysis
  The id provided by stm32 allows us to perform software encryption.     This feature is pretty good.     But I studied the weaknesses of plaintext encryption.     Post it here for everyone to study.     Wrote a simple code as follows to verify the ID         The program outputs ok1 to rep
[Microcontroller]
About stm32 microcontroller, using id encryption, plain code security analysis
STM32 MCU (7) Serial communication printf redirection
1. Add header file #include stdio.h 2. Project "Target" -- check "Use MicroLIB" 3. Redefine the fputc function int fputc(int ch, FILE *f)   {   Uart1_PutChar((u8)ch); //This is a custom function, see serial port interrupt communication, please do not copy blindly   return (ch);   }   After the above configu
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号