Visible to Intel only — Ixiasoft
Visible to Intel only — Ixiasoft
14.5. NAND Flash Controller Programming Model
Basic Flash Programming
NAND Flash Controller Optimization Sequence
- Set the rb_pin_enabled register to the desired mode of operation for each flash device.
- For polling mode, set the load_wait_cnt register to the appropriate value depending on the speed of operation of the NAND flash controller, and the desired wait value.
- For polling mode, set the program_wait_cnt register to the appropriate value by software depending on the speed of operation of the NAND flash controller, and the desired wait value.
- For polling mode, set the erase_wait_cnt register to the appropriate value by software depending on the speed of operation of the NAND flash controller, and the desired wait value.
- For polling mode, set the int_mon_cyccnt register to the appropriate value by software depending on the speed of operation of the NAND flash controller, and the desired wait value.
At any time, the software can change any flash device from interrupt mode to polling mode or vice‑versa, using the bank0 bit of the rb_pin_enabled register.
The software must ensure that the particular flash device does not have any outstanding transactions before changing the mode of operation for that particular flash device.
Device Initialization Sequence
- Set the devices_connected register to 1.
- Set the device_width register to 8.
- Set the device_main_area_size register to the appropriate value.
- Set the device_spare_area_size register to the appropriate value.
- Set the pages_per_block register according to the parameters of the flash device.
- Set the number_of_planes register according to the parameters of the flash device.
- If the device allows two ROW address cycles, the flag bit of the two_row_addr_cycles register must be set to 1. The host program can ensure this condition either of the following ways:
- Set the flag bit of the bootstrap_two_row_addr_cycles register to 1 prior to the NAND flash controller’s reset initialization sequence, causing the flash controller to initialize the bit automatically.
- Set the flag bit of the two_row_addr_cycles register directly to 1.
- Clear the chip_enable_dont_care register in the config group to 0.
The NAND flash controller can identify the flash device features, allowing you to initialize the flash controller registers to interface correctly with the device, as described in Discovery and Initialization.
However, a few NAND devices do not follow any universally accepted identification protocol. If connected to such a device, the NAND flash controller cannot identify it correctly. If you are using such a device, your software must use other means to ensure that the initialization registers are set up correctly.
Device Operation Control
Program the following registers in the config group to achieve the best performance from a given device:
- Set flag bit in the multiplane_operation register in the config group to 1 if the device supports multi‑plane operations to access the data on the flash device connected to the NAND flash controller. If the flash controller is set up for multi‑plane operations, the number of pages to be accessed is always a multiple of the number of planes in the device.
- If the NAND flash controller is configured for multi‑plane operation, and if the device has support for multi‑plane read command sequence, set the multiplane_read_enable register in the config group.
- If the device implements multiplane address restrictions, set the flag bit in the multiplane_addr_restrict register to 1.
- Initialize the die_mask and first_block_of_next_plane registers as per device requirements.
- If the device supports cache command sequences, enable the cache_write_enable and cache_read_enable registers in the config group.
- Clear the flag bit of the copyback_disable register in the config group to 0 if the device does not support the copyback command sequences. The register defaults to enabled state.
- The read_mode, write_mode and copyback_mode registers, in the config group, currently need not be written by software, because the NAND flash controller is capable of using the correct sequences based on a combination of some multi‑plane or cache‑related settings of the NAND flash controller and the manufacturer ID. If at some future time these settings change, program the registers to accommodate the change.
ECC Enabling
To prevent spurious ECC errors, software must use the memory initialization block in the ECC controller to clear the entire memory data and initialize the ECC bits. The initialization block clears the memory data. Initializing the memory with the initialization block is independent of enabling the ECC.
If the ECC needs enabling, set up the appropriate correction level depending on the page size and the spare area available on the device.
Set the flag bit in the ecc_enable register in the config group to 1 to enable ECC. If enabled, the following registers in the config group must be programmed accordingly, else they can be ignored:
- Initialize the ecc_correction register to the appropriate correction level.
- Program the spare_area_skip_bytes and spare_area_marker registers in the config group if the software needs to preserve the bad block marker.
NAND Flash Controller Performance Registers
Initialize the flash_burst_length register in the dma group to a value which maximizes the performance of the device interface by minimizing the number of bursts required to transfer a page.
Interrupt and DMA Enabling
- Set the flag bit in the global_int_enable register in the config group to 1, to enable global interrupt.
- Set the relevant bits of the intr_en0 register in the status group to 1 before initiating any operations if the flash controller is in interrupt mode. Intel recommends that the software reads back this register to ensure clearing an interrupt status. This recommendation applies also to an interrupt service routine.
- Enable DMA if your application needs DMA mode. Enable DMA by setting the flag bit of the dma_enable register in the dma group. Intel recommends that the software reads back this register to ensure that the mode change is accepted before sending a DMA command to the flash controller.
- If the DMA is enabled, then set up the appropriate bits of the dma_intr_en register in the dma group.
Order of Interrupt Status Bits Assertion
- time_out—All other interrupt bits are set to 0 when the watchdog time_out bit is asserted.
- dma_cmd_comp—This bit signifies the completion of data transfer sequence.32
- pipe_cpybck_cmd_comp—This bit is asserted when a copyback command or the last page of a pipeline command completes.
- locked_blk—This bit is asserted when a program (or erase) is performed on a locked block.
- INT_act—No relationship with other interrupt status bits. Indicates a transition from 0 to 1 on the ready_busy pin value for that flash device.
- rst_comp—No relationship with other interrupt status bits. Occurs after a reset command has completed.
- For an erase command:
- erase_fail (if failure)
- erase_comp
- For a program command:
- locked_blk (if performed on a locked block)
- pipe_cmd_err (if the pipeline sequence is broken by a MAP01 command)
- page_xfer_inc (at the end of each page data transfer)
- program_fail (if failure)
- pipe_cpybck_cmd_comp
- program_comp
- dma_cmd_comp (If DMA enabled)
- For a read command:
- pipe_cmd_err (if the pipeline sequence is broken by a MAP01 command)
- page_xfer_inc (at the end of each page data transfer)
- pipe_cpybck_cmd_comp
- load_comp
- ecc_uncor_error (if failure)
- dma_cmd_comp (If DMA enabled)
Timing Registers
Set the following registers in the config group to optimize the NAND flash controller for the speed grade of the connected device and frequency of operation of the flash controller:
- twhr2_and_we_2_re
- tcwaw_and_addr_2_data
- re_2_we
- acc_clks
- rdwr_en_lo_cnt
- rdwr_en_hi_cnt
- max_rd_delay
- cs_setup_cnt
- re_2_re
In the case of the reading process mechanism, the NAND controller operates in two work modes: Boot mode and Performance mode.
After reset, the controller starts in Boot mode. In this mode, the data sampling doesn't depend on the default value of acc_clks or max_rd_delay registers but the correct sampling is warranted (with low performance) using the default values of the other registers listed above. The NAND controller remains in Boot mode as long as the value of acc_clks register remains in 0 (default value).
Once the acc_clks register takes a different value, the controller switches to Performance mode. In Performance mode, the data sampling on read operations now follows the functionality described in the acc_clks and max_rd_delay registers. The NAND controller remains in Performance mode until a reset occurs; for example, returning a value of 0 in acc_clks register doesn't make the controller to transit back to Boot mode again.
Registers to Ignore
- The transfer_spare_reg register—Data transfer mode can be initialized using MAP10 commands.
- The write_protect register—Does not need initializing unless you are testing the write protection feature.
Flash-Related Special Function Operations
The functions are defined by MAP10 commands as described in Command Mapping.
Erase Operations
The controller decodes the block address from the indirect addressing shown in "MAP10 Command Format".
Single Block Erase
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the desired erase block.
- Write 0x01 to the Data register.
For a single block erase, the register multiplane_operation in the config group must be reset.
After the device completes the erase operation, the controller generates an erase_comp interrupt. If the erase operation fails, the erase_fail interrupt is issued. The failing block's address is updated in the err_block_addr0 register in the status group.
Multi-Plane Erase
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the desired erase block.
- Write 0x01 to the Data register.
For multi‑plane erase, the register multiplane_operation in the config group must be set.
After the device completes erase operation on all planes, the NAND flash controller generates an erase_comp interrupt. If the erase operation fails on any of the blocks in a multi‑plane erase command, an erase_fail interrupt is issued. The failing block's address is updated in the err_block_addr0 register in the status group.
Lock Operations
- Flash locking—The NAND flash controller supports all flash locking operations.
The flash device itself might have limited support for these functions. If the device does not support locking functions, the flash controller ignores these commands.
- Lock‑tight—With the lock‑tight feature, the NAND flash controller can prevent lock status from being changed. After the memory is locked tight, the flash controller must be reset before any flash area can be locked or unlocked.
Unlocking a Span of Memory Blocks
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the area to unlock.
- Write 0x10 to the Data register.
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the ending address of the area to unlock.
- Write 0x11 to the Data register.
When unlocking a range of blocks, the start block address must be less than the end block address. Otherwise, the NAND flash controller exhibits undetermined behavior.
Locking All Memory Blocks
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to any memory address.
- Write 0x21 to the Data register.
Setting Lock-Tight on All Memory Blocks
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to any memory address.
- Write 0x31 to the Data register.
To disable the lock‑tight, reset the memory controller.
Transfer Mode Operations
- Default area transfer mode
- Spare area transfer mode
- Main+spare area transfer mode
The NAND flash controller determines the default transfer mode from the setting of transfer_spare_reg register in the config group. Use MAP10 commands to dynamically change the transfer mode from the existing mode to the new mode. All subsequent commands are in the new mode of transfer. You must consider that transfer modes can be changed at logical data transfer boundaries. For example:
- At the beginning or end of a page in case of single page read or write.
- At the beginning or end of a complete multi‑page pipeline read or write command.
transfer_spare_reg and MAP10 Transfer Mode Commands
Configure for Default Area Access
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to any block.
- Write 0x42 to the Data register.
The NAND flash controller determines the default area transfer mode from the setting of the transfer_spare_reg register in the config group. If it is set to 1, then the transfer mode becomes main+spare area, otherwise it is main area.
Configure for Spare Area Access
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the target block.
- Write 0x41 to the Data register.
Configure for Main+Spare Area Access
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ ADDR field to the target block.
- Write 0x43 to the Data register.
Read-Modify-Write Operations
The read‑modify‑write command operates on an entire page. This command is also useful for a copy type operation, where most of a page is saved to a new location. In this type of operation, the NAND flash controller reads the data, modifies a specified number of words in the page, and then writes the modified page to a new location.
Read-Modify-Write Operation Flow
- Start the flow by reading a page from the memory:
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the desired block.
- Write 0x60 to the Data register.
This step makes the page available to you in the page buffer in the flash device. - Provide the destination page address:
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the destination address of the desired block.
- Write 0x61 to the Data register.
This step initiates the page program and provides the destination address to the device. - Use the MAP00 page buffer read and write commands to modify the data in the page buffer.
- Write the page buffer data back to memory:
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the same destination address.
- Write 0x62 to the Data register.
This step performs the write.
After the device completes the load operation, the NAND flash controller issues a load_comp interrupt. A program_comp interrupt is issued when the host issues the write command and the device completes the program operation.
If the page program operation (as a part of an RMW operation) results in a program failure in the device, program_fail interrupt is issued. The failing page's block and page address is updated in the err_block_addr0 and err_page_addr0 registers in the status group.
Copy-Back Operations
The NAND flash controller cannot do ECC validation in case of copy‑back commands. The flash controller copies the ECC data, but does not check it during the copy operation.
The 8‑bit value <PP> specifies the number of pages for copy‑back. With this feature, the NAND flash controller can copy multiple consecutive pages with a single command. When you issue a copy‑back command, the flash controller performs the operation in the background. The flash controller puts other commands on hold until the current copy‑back completes.
For a multi‑plane device, if the flag bit in the multiplane_operation register in the config group is set to 1, multi‑plane copy‑back is available as an option. In this case, the block address specified must be plane‑aligned and the value <PP> must specify the total number of pages to copy as a multiple of the number of planes. The block address continues incrementing, keeping the page address fixed, for the total number of planes in the device before incrementing the page address.
A pipe_cpyback_cmd_comp interrupt is generated when the flash controller has completed copy‑back operation of all <PP> pages. If any page program operation (as a part of copy back operation) results in a program failure in the device, the program_fail interrupt is issued. The failing page's block and page address is updated in the err_block_addr0 and err_page_addr0 registers in the status group.
Copying a Memory Area (Single Plane)
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the area to be copied.
- Write 0x1000 to the Data register.
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the new area to be written.
- Write 0x11<PP> to the Data register, where <PP> is the number of pages to copy.
Copying a Memory Area (Multi-Plane)
- Set the flag bit of the multiplane_operation register in the config group to 1.
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the area to be copied. The address must be plane‑aligned.
- Write 0x1000 to the Data register.
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the new area to be written. This address must also be plane‑aligned.
- Write 0x11<PP> to the Data register, where <PP> is the number of pages to copy.
The parameter <PP> must be a multiple of the number of planes in the device.
Pipeline Read-Ahead and Write-Ahead Operations
The NAND flash controller can handle at the most four outstanding pipeline commands, queued up in the order in which the flash controller received the commands. The flash controller operates on the pipeline command at the head of the queue until all the pages corresponding to the pipeline command are executed. The flash controller then pops the pipeline command at the head of the queue and proceeds to work on the next pipeline command in the queue.
Pipeline Read-Ahead Function
The pipeline read‑ahead function allows for a continuous reading of the flash memory. On receiving a pipeline read command, the flash controller immediately issues a load command to the device. While data is read out with MAP01 commands in a consecutive or multi‑plane address pattern, the flash controller maintains additional cache or multi‑plane read command sequencing for continuous streaming of data from the flash device.
Pipeline read‑ahead commands can read data from the queue in this interleaved fashion. The parameter <PP> denotes the total number of pages in multiples of the number of planes available, and the block address must be plane‑aligned, which keeps the page address constant while incrementing the block address for each page‑size chunk of data. After reading from every plane, the NAND flash controller increments the page address and resets the block address to the initial address. You can also use pipeline write‑ahead commands in multi‑plane mode. The write operation works similarly to the read operation, holding the page address constant while incrementing the block address until all planes are written.
Because the value of the flag bit of the multiplane_operation register in the config group determines pipeline read‑ahead or write‑ahead behavior, it can only be changed when the pipeline registers are empty.
When the host issues a pipeline read‑ahead command, and the flash controller is idle, the load operation occurs immediately.
Set Up a Single Area for Pipeline Read-Ahead
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the block to pre‑read.
- Write 0x20<PP> to the Data register, where the 0 sets this command as a read‑ahead and <PP> is the number of pages to pre‑read. The pages must not cross a block boundary. If a block boundary is crossed, the NAND flash controller generates an unsupported command (unsup_cmd) interrupt and drops the command.
The read‑ahead command is a hint to the flash device to start loading the next page in the page buffer as soon as the previous page buffer operation has completed. After you set up the read‑ahead, use a MAP01 command to actually read the data. In the MAP01 command, specify the same starting address as in the read‑ahead.
If the read command received following a pipeline read‑ahead request is not to a pre‑read page, then an interrupt bit is set to 1 and the pipeline read‑ahead or write‑ahead registers are cleared. You must issue a new pipeline read‑ahead request to re‑load the same data. You must use MAP01 commands to read all of the data that is pre‑read before the NAND flash controller returns to the idle state.
Pipeline Write-Ahead Function
The pipeline write‑ahead function allows for a continuous writing of the flash memory. While data is written with MAP01 commands in a consecutive or multi‑plane address pattern, the NAND flash controller maintains cache or multi‑plane command sequences for continuous streaming of data into the flash device.
For pipeline write commands, if any page program results in a failure in the device, a program_fail interrupt is issued. The failing page's block and page addresses are updated in the err_block_addr0 and err_page_addr0 registers in the status group.
Set Up a Single Area for Pipeline Write-Ahead
- Write to the command register, setting the CMD_MAP field to 2 and the BLK_ADDR field to the starting address of the block to pre‑write.
- Write 0x21<PP> to the Data register, where the value 1 sets this command as a write‑ahead and <PP> is the number of pages to pre‑write. The pages must not cross a block boundary. If a block boundary is crossed, the NAND flash controller generates an unsupported command (unsup_cmd) interrupt and drops the command.
After you set up the write‑ahead, use a MAP01 command to write the data. In the MAP01 command, specify the same starting address as in the write‑ahead.
If the write command received following a pipeline write‑ahead request is not to a pre‑written page, then an interrupt bit is set to 1 and the pipeline read‑ahead or write‑ahead registers are cleared. You must issue a new pipeline write‑ahead request to configure the write logic.
You must use MAP01 commands to write all of the data that is pre‑written before the NAND flash controller returns to the idle state.
Other Supported Commands
MAP01 commands must read or write pages in the same sequence that the pipelined commands were issued to the NAND flash controller. If the host issues multiple pipeline commands, pages must be read or written in the order the pipeline commands were issued. It is not possible to read or write pages for a second pipeline command before completing the first pipeline command. If the pipeline sequence is broken by a MAP01 command, the pipe_cmd_err interrupt is issued, and the flash controller clears the pipeline command queue. The flash controller services the violating incoming MAP01 read or write request with a normal page read or write sequence.
For a multi‑plane device that supports multi‑plane programming, you must set the flag bit of the multiplane_operation register in the config group to 1. In this case, the data is interleaved into page‑size chunks to consecutive blocks.
A pipe_cpyback_cmd_comp interrupt is generated when the NAND flash controller has finished processing a pipeline command and has discarded that command from its queue. At this point of time, the host can send another pipeline command. A pipeline command is popped from the queue, and an interrupt is issued when the flash controller has started processing the last page of pipeline command. Hence, the pipe_cpyback_cmd_comp interrupt is issued prior to the last page load in the case of a pipeline read command and start of data transfer of the last page to be programmed, in the case of a pipeline write command.
An additional program_comp interrupt is generated when the last page program operation completes in the case of a pipeline write command.
If the device command set requires the NAND flash controller to issue a load command for the last page in the pipeline read command, a load_comp interrupt is generated after the last page load operation completes.
The pipeline commands sequence advanced commands in the device, such as cache and multi‑plane. When the NAND flash controller receives a multi‑page read or write pipeline command, it sequences commands sent to the device depending on settings in the following registers in the config group:
- cache_read_enable
- cache_write_enable
- multiplane_operation
For a device that supports cache read sequences, the flag bit of the cache_read_enable register must be set to 1. The NAND flash controller sequences each multi‑page pipeline read command as a cache read sequence. For a device that supports cache program command sequences, cache_write_enable must be set. The flash controller sequences each multi‑page write pipeline command as a cache write sequence.
For a device that has multi‑planes and supports multi‑plane program commands, the NAND flash controller register multiplane_operation, in the config group, must be set. On receiving the multi‑page pipeline write command, the flash controller sequences the device with multi‑plane program commands and expects that the host transfers data to the flash controller in an even‑odd block increment addressing mode.