Programs data into flash memory using SPI programming
Table 151. SPI Program Flash command format
Field | Size | Description |
---|---|---|
SPI_CMD_PROGRAM_FLASH | 1 byte | Command ID |
NumBytes | 2 byte | Total number of bytes to program, MSB first |
mode | 1 byte | XML: mode*. Mode byte* |
delay | 1 byte | XML: delay. Delay, used for different types of programming termination, according to mode byte |
cmd1 | 1 byte | Command 1 (Load Page, Write Program Memory) |
cmd2 | 1 byte | Command 2 (Write Program Memory Page) |
cmd3 | 1 byte | Command 3 (Read Program Memory) |
poll1 | 1 byte | Poll Value #1 |
poll2 | 1 byte | Poll Value #2 (not used for flash programming) |
Data | 1 byte | N data |
*Mode byte: The mode parameter is essential for how this command works. The bits in the mode byte have the following meanings:
Table 152. SPI Flash Programming Mode byte values
Bit | Description | Mode |
---|---|---|
0 | Word/Page Mode (0 = word, 1 = page) | |
1 | Timed delay | Word Mode |
2 | Value polling | Word Mode |
3 | RDY/BSY polling | Word Mode |
4 | Timed delay | Page Mode |
5 | Value polling | Page Mode |
6 | RDY/BSY polling | Page Mode |
7 | Write page | Page Mode |
The Word/Page Modebit selects if the device supports page programming or not. The command bytes are different for word and page mode. In word mode, the SPI commands Write Program Memory and Read Program Memory are used. In page mode, Load Page, Write Program Memory Page and Read Program Memory are used. The read instruction is used if Value Polling is specified in the mode bit. The Low/High byte selection bit (3rd bit in the Load Page, Write Program Memory commands) is handled by EDBG automatically, so leave this bit cleared.
According to the mode, different termination methods are selected – Timed delay, Value polling or RDY/BSY polling.
For paged operation, the Write pagebit decides if a Write Program Memory Page command should be issued after the data has been loaded into the page buffer. For devices with page size bigger than what can be transferred to EDBG in one command, several SPI_CMD_PROGRAM_FLASH commands must be issued. In such a case, only the last command should have the Write Page mode bit set.
NOTE: Only bit 0-6 are set in the XML file, because bit 7 is not constant and must be controlled by the PC software.
When value polling is used to determine when a programming operation is complete, poll1 must be supplied. This value indicates which value will be read from the device until the programmed value is read. This indicates end of programming. poll2 is used only for EEPROM programming.
Response:
Table 153. SPI Program Flash response
Field | Size | Description |
---|---|---|
SPI_CMD_PROGRAM_FLASH | 1 byte | Command ID |
Status | 1 byte | SPI_STATUS_CMD_OK or SPI_STATUS_CMD_TOUT or SPI_STATUS_RDY_BSY_TOUT |