![GigaDevice Semiconductor GD32E23 Series User Manual Download Page 48](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32e23-series/gd32e23-series_user-manual_2225794048.webp)
GD32E23x User Manual
48
Unlock the FMC_CTL register if necessary.
Check the BUSY bit in FMC_STAT register to confirm that no flash memory operation is
in progress (BUSY equal to 0). Otherwise, wait until the operation has been finished.
Set the PGW bit if needed.
Write the word program command into the PG bit in FMC_CTL register.
Write the data to be programed by DBUS with desired absolute address (0x08XX
XXXX).
If DBUS program is 32-bit word and the PGW bit is set to 0(32-bit program to flash
memory), the DBUS write once and the data program to flash memory. The data to be
programed must word alignment.
If DBUS program is 32-bit and the PGW bit is set to 1(64-bit program to flash memory),
the DBUS write twice to form a 64-bit data and then the 64-bit data program to flash
memory. The data to be programed must double-word alignment.
If DBUS program is 16-bit and the PGW bit is set to 0(32-bit program to flash memory),
the DBUS write twice to form a 32-bit data and then the 32-bit data program to flash
memory. The data to be programed must word alignment.
If DBUS program is 16-bit and the PGW bit is set to 1(64-bit program to flash memory),
the DBUS write four times to form a 64-bit data and then the 64-bit data program to flash
memory. The data to be programed must double-word alignment.
For less program time, suggest the DBUS program use 32-bit, set the PGW to 1 if the
data to be programed is double-word alignment, or set PGW to 0 if the data to be
programed is word alignment
Wait until all the operations have been completed by checking the value of the BUSY bit
in FMC_STAT register.
Read and verify the flash memory if required using a DBUS access.
When the operation is executed successfully, an interrupt will be triggered by FMC if the
ENDIE bit in the FMC_CTL register is set, and the ENDF in FMC_STAT register is set. Note
that before the word/half word programming operation you should check the address that it
has been erased. If the address has not been erased, PGERR bit will set when programming
the address even if programming 0x0. Each word can be programmed only one time after
erase and before next erase. Additionally, the program operation will be ignored on protected
pages. A flash operation error interrupt will be triggered by the FMC if the ERRIE bit in the
FMC_CTL register is set. The software can check the PGERR bit in the FMC_STAT register
to detect this condition in the interrupt handler. The end of this operation is indicated by the
ENDF bit in the FMC_STAT register.
In the following cases, the PGAERR bit in the FMC_STAT register will be set.
-
The DBUS program use byte write (not 32-bit or 16-bit write)
-
The DBUS program size is not equal previous size. It not allow mix 32-bit with 16-bit
write.