The last issue of the STM32 tutorial from Jiangxie teaches us to use flash storage (actually, there is CAN communication after this, but it is presented separately).
(1) What is flash#
Flash memory (FLASH EEPROM), also known as flash, is a type of EEPROM. It combines the strengths of ROM and RAM. It not only has the electronic erasable and editable (EEPROM) performance but also does not lose data when power is off and can read data quickly. The biggest difference from EEPROM is that FLASH operates by sectors (blocks), while EEPROM operates by bytes. The circuit structure of FLASH is simpler, and it occupies less chip area for the same capacity, making it naturally cheaper than EEPROM, thus suitable for use as program memory.
The FLASH of the STM32F1 series includes three parts: program memory, system memory, and option bytes. The flash memory interface (peripheral) can be used to erase and program the program memory and option bytes.
Uses of reading and writing FLASH:
Utilize the remaining space of program memory to save user data that does not get lost during power off.
Achieve self-updating of the program through in-program programming (IAP).
In-Circuit Programming (ICP) is used to update the entire content of program memory. It downloads programs via JTAG, SWD protocol, or system bootloader.
In-Application Programming (IAP) can download programs using any communication interface supported by the microcontroller.
(2) Flash module organization#
The flash module of STM32 is divided into: main storage (code storage part), information block (stores the boot program and option bytes), and interface registers (links to peripherals).
(3) Flash structure#
The structure diagram of flash is as follows:
(4) Code part#
Yes, we directly fast-forward to the code part. Why? Although using flash requires changing many registers, the standard library has already wrapped it for us, and we can simply call it.
It is worth noting that you must erase before writing; otherwise, you cannot modify it.
Also, our data storage address needs to be placed at the end; otherwise, it will conflict with the program code.
So, that's all for the flash study notes. I'll take a shortcut here and then go learn PCB wiring to play with a project.