µTasker Spansion S25FL164K Driver with Automatic Erase Suspend and Resume to allow immediate Reading and Programming in other Sectors

During the course of development of a new SPI flash based FAT interface supporting block management and wear-levelling it was identified that the relatively slow SPI Flash erasure times (typically 50ms for a 4k sector) can be a cause of reduced performance when subsequent reading and programming is needed whilst the operation is in progress; in comparision, reading of sectors is limited only by the communication speed and programming sectors is subject to a programming time of about 1.5ms.

FAT Usage

When block management is involved the major FAT activity involves reading and programming. Sector erasure is an operation that is performed by the block manager rather than the FAT itself. As long as there are adequate free FAT sectors available in the SPI Flash erasure is not needed during typical operation and so can be performed as a background process or during times of low system activity. Nevertheless, whenever erasures are performed there can always be a need to initiate new FAT activity which would ideally not need to wait for a Flash sector erasure that has just been started to terminate before it can be executed. This is where the ability of the Spansion S25FL164K to temporarily suspend erasure and allow reading and programming to be performed proves to be very efficient.

Suspending Erasure

The S25FL164K supports a programm/erase suspend command which temporarily stops the programming or erasure that is in progress. The suspend takes up to 20us to take place but then allows reading or programming in a different sector to take place as a sort of interrupt.

It is not possible to read or write the sector that is in the process of being erased but this is something that is generally never required anyway.

Although suspending programming would be possible this is not of great interest to normal FAT activity and so the S25FL164K driver was designed to automatically handle exclusively suspending erasures.

If an operation (read/write/erase) is attempted to the same sector that is being programmed or erased the driver will simply wait until the present activity is complete before continuing with the new operation. This behavior is identical to driver operation without suspend/resume support.

In the case of a read or write operation starting when an SPI Flash sector is in progress, and the accessed sector is not the one being erased, the driver will automatically issue a suspend command and wait until the device signals that it has entered its suspended state (after maximum 20us). This is followed by the new operation being executed. In the case of a read being the new operation the originally suspended erasure will be subsequently resumed by issuing an erase/program resume command.
In the case of a write being the new operation the termination of the programming operation will first be waited for (typically 700us for a page of 256 bytes) and then the erase/program resume command issued.
Since it is not allowed to suspend again within 20us of a resume command a 20us wait is inserted to ensure that this can never occur.

The result is that the read/write operations temporarily "interrupt" an active erase operation in a different sector of SPI Flash with very low delay for the new read/write operations. FAT activity therefore generally suffers no significant reduction in speed, irrespective of erasure operating that happen to be in progress at the time they are executed.

Reset Handling

The S25FL164K doesn't have a reset input and so it is important to consider what would happen if the controlling processor were to be reset when the SPI Flash is in the process of programming/erasing or has been put to the suspend state. Note: In the case of a power cycle the SPI Flash is reset internally.

Due to the fact that SPI Flash operates automomously once a command has been executed, the processor's reset can be considered as a simple period of no activity for the SPI Flash and it is possible that the SPI Flash has completed its operation before the processor starts communicating with it again.
To be sure that any such activity has indeed terminated, the S25FL164K driver will first check the busy state of the device and wait for it to complete if needed, which ensures that active erasures are allowed to terminate.

Suspend states have no timeout and it is important that a processor reset during a suspend period doesn't leave the S25FL164K in this state, which could otherwise cause subsequent errors to occur. This is achieved by checking the suspend state during initialiation (read in its status register 2) and issuing the resume command if it is found. Since it is not possible to know which SPI Flash sector was being erased the SPI Flash is then polled until it no longer returns the busy state (maximum start delay of 50ms), after which operation can continue as normal.

Controlling the Driver's Operation

The S25FL164K driver supports automatic suspend/resume control as discussed above when the project define SUPPORT_ERASE_SUSPEND is enabled. This setting is recommended when it is used together with utFAT and block management/wear-levelling but it can also be enabled generally for low level SPI Flash interfaces. Should the behaviour not be beneficial for a particular usage the define can be removed to force all operations to wait for erasures in progress to first terminate.

Return to the Kinetis landing page



µTasker Spansion S25FL1-K Suspend/Resume. Copyright (c) 2004..2018 M.J.Butcher Consulting