GD32F10x User Manual
46
2.3.3.
Unlock the FMC_CTLx registers
After reset, the FMC_CTLx registers are not accessible in write mode, and the LK bit in
FMC_CTLx register is 1. An unlocking sequence consists of two write operations to the
FMC_KEY0 register to open the access to the FMC_CTL0 register. The two write operations
are writing 0x45670123 and 0xCDEF89AB to the FMC_KEY0 register. After the two write
operations, the LK bit in FMC_CTL0 register is reset to 0 by hardware. The software can lock
the FMC_CTL0 again by setting the LK bit in FMC_CTL0 register to 1. Any wrong operations
to the FMC_KEY0 will set the LK bit to 1, and lock FMC_CTL0 register, and lead to a bus
error.
The OBPG bit and OBER bit in FMC_CTL0 are still protected even the FMC_CTL0 is
unlocked. The unlocking sequence is two write operations, which are writing 0x45670123 and
0xCDEF89AB to FMC_OBKEY register. And then the hardware sets the OBWEN bit in
FMC_CTL0 register to 1. The software can reset OBWEN bit to 0 to protect the OBPG bit and
OBER bit in FMC_CTL0 register again.
For the GD32F10x_CL and GD32F10x_XD, the FMC_CTL0 register is used to configure the
operations to bank0 and the option bytes block, while FMC_CTL1 register is used to configure
the program and erase operations to bank1. The lock/unlock mechanism of FMC_CTL1
register is similar to FMC_CTL0 register. The unlock sequence should be written to
FMC_KEY1 when unlocking FMC_CTL1.
2.3.4.
Page erase
The FMC provides a page erase function which is used to initialize the contents of a main
flash memory page to a high state. Each page can be erased independently without affecting
the contents of other pages. The following steps show the access sequence of the registers
for a page erase operation.
Unlock the FMC_CTLx registers if necessary.
Check the BUSY bit in FMC_STATx registers to confirm that no flash memory operation
is in progress (BUSY equals to 0). Otherwise, wait until the operation has finished.
Set the PER bit in FMC_CTLx registers.
Write the page absolute address (0x08XX XXXX) into the FMC_ADDRx registers.
Send the page erase command to the FMC by setting the START bit in FMC_CTLx
registers.
Wait until all the operations have finished by checking the value of the BUSY bit in
FMC_STATx registers.
Read and verify the page if required using a DBUS access.
When the operation is executed successfully, the ENDF in FMC_STATx registers is set, and
an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTLx registers is set. It is
notable that a correct target page address must be confirmed, or else the software may run
out of control if the target erase page is being used to fetch codes or to access data, the FMC
Summary of Contents for GD32F10 Series
Page 63: ...GD32F10x User Manual 63 programmed during the chip production ...
Page 117: ...GD32F10x User Manual 117 010 1 0 011 0 9 ...
Page 416: ...GD32F10x User Manual 416 shadow register updates every update event ...
Page 427: ...GD32F10x User Manual 427 value ...
Page 518: ...GD32F10x User Manual 518 These bits are not used in SPI mode ...