To program the flash memory:
- Select the command in the CMDTYPE register:
- Set the COMMAND field in the CMDTYPE register to PROGRAM.
- Set the SIZE field in the CMDTYPE register to the desired size (1, 2, 4, or 8 flash words). If a device does not support multi-word programming, select ONEWORD. If a device supports
multi-word programming, and multi-word programming is desired, select the desired size which is less than or equal to the max size supported by the target device. The hardware will not check for invalid configuration of the SIZE
field; software must ensure that the selection option is supported by the device. Note that SECTOR and BANK sizes are not valid sizes for PROGRAM operations. These sizes only apply to erase operations.
- Configure the program command in the CMDCTL register:
- On devices with ECC, the flash controller by default will generate the needed ECC bits from the data during the PROGRAM operation. Optionally, software can override the hardware ECC
code generation and manually provide the ECC code to be programmed by setting the ECCGENOVR bit in CMDCTL register.
- Select the target programming address in the CMDADDR and CMDBYTEN register:
- Load the target system address into the CMDADDR register to indicate the base address from which programming will start. The target address must be a flash word address (64-bit
aligned). The flash controller will translate the system address into the applicable flash region, bank ID, and bank address. If desired, after the operation completes the flash region, bank ID, and bank address can be read from
the STATADDR register. In a multi-word program, STATADDR will indicate the bank ID and the final address which was programmed.
- If sub-word programming (programming of less than the full 64 or 72 bit flash word) is desired, configure the CMDBYTEN register to set the bytes within the addressed flash word
which are to be programmed. Each bit in CMDBYTEN corresponds to a byte in the addressed flash word to be programmed, including the ECC byte. For example, programming of the ECC code can be masked by clearing bit 8 in CMDBYTEN
while programming the data bytes of the flash word. Note that there is a maximum number of program operations allowed per word line before a sector erase must be applied (see the device specific data sheet for the maximum).
- Load the data to program into the CMDDATAx registers:
- For a single flash word programming operation (64 or 72 bits depending on the presence of ECC), load the data into the CMDDATAx registers consistent with the alignment requirements
(for devices which only support single-word programming, CMDDATA0 and CMDDATA1 are always used regardless of the target address).
- For multi-word programming (if available and selected), load data into the CMDDATAx registers consistent with the alignment rules and the size of the multi-word program operation
specified in step 1.
- If ECCGENOVR in the CMDCTL register was set above (disabling hardware ECC code generation), then write the ECC data in the CMDDATAECC0 register (for single word programming) and
optionally additional CMDDATAECCx registers as applicable for multi-word programming.
- Note that the CMDDATA registers are used as bit masking registers by the flash controller during the program operation; after the operation completes, the values written to these
registers will have been overwritten by the flash controller.
- Ensure the write protection scheme is configured to allow writes to the target addresses (see the write
protection section of this guide for additional information on configuring write protection).
- Execute the program operation by writing 0x1 to the CMDEXEC register.
- Monitor for completion of the program operation:
- The STATCMD register can be polled to determine the status of the program operation. The CMDINPROGRESS bit will be set by hardware as soon as the command is initiated. The CMDDONE
bit will be set when the operation terminates.
- When CMDDONE is set, the CMDPASS bit will be reset or set at the same time to indicate whether the operation completed successfully or failed. If a program was attempted on a
protected region, the FAILWEPROT bit is asserted. If the program operation cannot be completed successfully within the maximum program pulse count limit FAILVERIFY will be asserted. See the device-specific data sheet for maximum
program times.
- After completion of a program operation, the flash controller will configure several settings:
- All dynamic write protection registers are set to a protected state (to protect against inadvertent programming)
- All data registers are set to 1.
- All program byte enables are cleared to 0.
- Following programming of the flash memory, it is possible that there may be stale data in the processor's cache and prefetch logic. Before reading locations which were programmed, it is
recommended to first flush the cache in the CPU subsystem.