Program Address Alignment on Cypress SPI Flash – KBA219890

Version: **



Using Cypress SPI Flash, can I program to an address that is not page-aligned? 



There are two parts to this question: 

Part 1: Yes, the starting byte for programming does not need to be aligned to the beginning of the page. 

Part 2: No, it is not possible to program any bytes outside of the selected page-aligned region; to do this, a subsequent programming command is required to select another page. 

Briefly, the data to be programmed can only be loaded within a page-aligned buffer. You can start programming at any address within that buffer, but since the programming scope is limited to the buffer size, when the address automatically increments during loading, it will wrap to the beginning of the buffer once the last address in the buffer is loaded. 

Depending on the device family, the specific part number (ordering options) and the configuration register setting, the page size can either be 256 bytes or 512 bytes. This table shows how the address argument for the page programming command selects the page and starting offset within the page: 


Program Page Size (B)Page AddressStarting Offset
256A31 or A23 → A8A7 → A0
512A31 or A23 → A9A8 → A0


A programming command is initiated by sending the programming command followed by the three- or four-byte address, as is appropriate for that command and device. Once the flash receives the address it:

  • selects the target page in the flash using the page address, 
  • initializes the page buffer to all 0xFF, and 
  • sets the buffer address pointer to the starting offset.

Next, the system transmits the first byte of data, which the flash loads to the starting offset of the page buffer, whereupon the page buffer address pointer is incremented by one. Any number of subsequent bytes of data may be transmitted. 

  • If the number of transmitted bytes is at least one but less than or equal to the program page size (256 or 512 bytes), then the non-0xFF data is programmed from the buffer to the chosen flash page address starting at the rising edge of CS#. 
  • If the number of transmitted bytes is greater than the program page size, then the most recent 256 or 512 bytes written to the buffer are programmed to the chosen flash page address starting at the rising edge of CS#. 

This mechanism shows that once the starting address argument is transmitted, thereafter the page address never changes; only the offset increments by +1 and only within the eight-bit or nine-bit address space that spans the program page size. 

In summary, the programming page is always aligned on the page size address boundary, however: 

  • If programming does not start at the beginning of a page and the end address would cross the end of the page boundary, then the address wraps to the beginning of the page boundary. 
  • If less than a page of data is sent to the device, these data bytes are programmed to the flash; the 0xFF data in the buffer has no effect on any erased or already programmed bytes within the flash page.
  • If the number of bytes transmitted to the flash exceeds the page size, then every transmitted byte that wraps around to the starting offset begins to overwrite previously written buffer contents.