4.6. Writing Blocks

The flashWriteBlocks() method is implemented to write blocks. It iterates over the blocks, first unlocking them, then writing the buffer contents to the flash device, and then locking them. The unlocking is necessary because the default state of many flash devices is to have the blocks locked. The locking after the erase is optional, but is included to prevent accidental modification of the flash contents.

The writing code supports both word programming and buffer programming modes. Word programming mode is the simplest to implement and is supported by most CFI compatible flash devices. Buffer programming mode writes to a group of flash locations in parallel and results in faster programmer; however, it is more complex to implement and is not supported by all flash devices. The choice of programming method is determined in the flashSelect() method by querying the size of the write buffer in the CFI information block.

After writing each block the flash device status register is checked for any errors. If an error is detected then the method returns immediately without attempting further write operations.

The flash blocks are always left in read mode after writing is complete. Care is taken to ensure that read mode is selected even in the case of an error being detected.

Copyright © 2007. All rights reserved.DAI0190A