For FL-S Flash, how do I return to the standby state when the P_ERR bit or E_ERR bit is Set?
The Clear Status Register (CLSR=30h) command followed by the Write Disable (WRDI = 04h) command can be used to return the SPI flash to the standby state if the Write in Progress bit is set (WIP = 1) and when either the Program Error bit (P_ERR = 1) or the Erase Error bit is set (E_ERR = 1). Software Reset (RESET = F0h) and RESET# can also return the flash to the standby state.
For example, here is the Status Register 1 (SR1) for the FL-S family of SPI flash with the relevant bits highlighted (reference 001-98283 Rev J):
Here are the detailed descriptions of the bits in question:
Here is where the datasheet shows how to manage these bits:
Once you start a program or erase operation, the WIP bit changes from 0 to 1 to show that the flash is busy with no errors. Normally, the flash operation completes whereupon the WIP bits change from 1 to 0 to show the flash is no longer busy; i.e., it is in the standby mode.
However, in the rare event that an error happens while the flash is busy programming or erasing, then the appropriate error bit (P_ERR or E_ERR) changes from 0 to 1. If this happens, the flash is in a volatile error state that must be cleared before the flash can return to standby mode.