GD32W51x User Manual
74
2.4.6.
Main flash programming
The FMC provides a 32-bit word programming function by DBUS which is used to modify the
main Flash memory contents. Operate secure Flash or non-secure Flash using secure or
non-secure registers.
The following steps show the register access sequence of the programming operation.
Unlock the FMC_CTL/FMC_SECCTL register if necessary.
Check the BUSY/SECBUSY bit in the FMC_STAT/FMC_SECSTAT register to confirm
that no Flash memory operation is in progress (BUSY/SECBUSY equals to 0). Otherwise,
wait until the operation has finished.
Set the PG/SECPG bit in the FMC_CTL/FMC_SECCTL register.
Write the data to be programed with desired absolute address (0x08XX XXXX/0x0CXX
XXXX).
Wait until all the operations have been finished by checking the value of the
BUSY/SECBUSY bit in the FMC_STAT/FMC_SECSTAT register.
Read and verify the Flash memory using a DBUS access if required.
When the operation is executed successfully, the ENDF/SECENDF bit in the
FMC_STAT/FMC_SECSTAT register is set, and an interrupt will be triggered by FMC if the
ENDIE bit in the FMC_CTL/FMC_SECCTL register is set. Note that there are some program
errors need caution:
Each word can be programmed only one time after erase and before next erase. Note that
the PG/SECPG bit must be set before the word programming operation.
Additionally, the program operation will be ignored on erase/program protected pages and
the WPERR/SECWPERR bit in the FMC_STAT/FMC_SECSTAT will be set.
In these conditions, a Flash operation error interrupt will be triggered by the FMC if the
ERRIE/SECERRIE bit in the FMC_CTL/FMC_SECCTL register is set. The software can
check WPERR/SECWPERR bit in the FMC_STAT/FMC_SECSTAT register to detect which
condition occurred in the interrupt handler. The following figure
shows the word programming operation flow.