Two kinds of data power-off protection methods in STM32 system!

Two kinds of data power-off protection methods in STM32 system !

In the development of embedded devices, it is often necessary to save some data that is not volatile after power failure. If the system configuration, user customized information, etc., if additional ROM ICs are added , such as ( 24C02 based on I2C , etc.) often cause additional PCB space increases, hardware costs increase, and the cost-effectiveness of products is reduced. In terms of practicality alone, in the stm32 system, and the like, I recommend the following two methods to try and learn from.

 

 

Based on backup register

 

Principle: For large-capacity MCU series, it has a 42 Ge 16bit backup register, while the small capacity of the microprocessor is only 10 Ge 16bit backup registers. In STM32F103C8T6 example, 42 is the Shift Register Offset Address is : 0x04 ~ ~ 0xBC 0x28,0x40 , can store a total of 84 th byte data. The backup register is dependent on the backup power supply. When the external VDD is powered off, as long as the system's VBAT can exist normally, then the contents of Bakeup Domaain Registers can be saved normally.

 

The main points of software programming, take the case commonly used in a project as an example:

 

Function initialization:

 

Backup register read out: void BKP_WriteBackupRegister (uint16_t BKP_DR, uint16_t Data)

 

Backup register readout: uint16_t BKP_ReadBackupRegister (uint16_t BKP_DR)

 

This method is simple and clear to use, but because the total available space is small, this method is only suitable for saving small batches of data, such as common configuration data of users in wearable devices.

 

Based on internal flash memory

 

Principle: FLASH memory is also called flash memory, it is also a re-writable memory. It is divided into NOR FLASH and NAND FLASH . NOR FLASH is generally used in code storage occasions, such as the program storage space inside the embedded controller; and NAND FLASH is generally used in large data storage occasions, such as U disk and solid state hard disk, etc. , Generally NAND FLASH type.

 

In the stm32 chip, the reading and writing units of Flash are all in "pages". Taking STM32F103C8T6 as an example, the size of each page is 2K bytes;

 

Essentials of software programming

 

Read and write protection is lifted: the premise of using this method is that the current read and write Flash is allowed, assuming that the current flash is already allowed to write. So for the time being, some API operations such as OptionBytes and Flash read-write protection operations will not be discussed for the time being.

 

FlashWrite : The simple process of writing a single uint32_t data is shown in the figure:

 

FlashRead : The reading of a single int data is relatively simple, and is completed by the following statement: rdData = (* (__ IOuint32_t *) dataAddr);

 

Because there are many APIs involved in SW , and there is a lot of additional background knowledge that code farmers need to understand, using this method is relatively complicated. However, because the data is saved in pages, the size of the page can be up to 2048bytes , so this method can be used to save large data that is not easy to lose when power is lost. Considering the logical mechanism of flash read-write protection, this method is best used without considering the security of data.

Guess you like

Origin www.cnblogs.com/646087666-lxd/p/12720125.html