RM0366
The main flash memory programming sequence in standard mode is as follows:
1.
Check that no main flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
2.
Set the PG bit in the FLASH_CR register.
3.
Perform the data write (half-word) at the desired address.
4.
Wait until the BSY bit is reset in the FLASH_SR register.
5.
Check the EOP flag in the FLASH_SR register (it is set when the programming
operation has succeeded), and then clear it by software.
Note:
The registers are not accessible in write mode when the BSY bit of the FLASH_SR register
is set.
Flash memory erase
The flash memory can be erased page by page or completely (mass erase).
Page erase
To erase a page, the procedure below must be followed:
1.
Check that no flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
2.
Set the PER bit in the FLASH_CR register.
3.
Program the FLASH_AR register to select a page to erase.
4.
Set the STRT bit in the FLASH_CR register (see below note).
5.
Wait for the BSY bit to be reset.
6.
Check the EOP flag in the FLASH_SR register (it is set when the erase operation has
succeeded), and then clear it by software.
7.
Clear the EOP flag.
Note:
The software should start checking if the BSY bit equals '0' at least one CPU cycle after
setting the STRT bit.
RM0366 Rev 5
Embedded flash memory
51/874
67
Need help?
Do you have a question about the STM32F301 6 Series and is the answer not in the manual?