This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zephyr SPI Nor flash driver incorrectly sends DPD command twice at end of Init.

We have a Macronix MX25R6435F flash chip on our custom LTE-M product, which uses the NRF9160. It's intended to eventually be used for full modem FOTA image storage. For now though, I needed to get it up and running so that it could be put in DPD mode, and not consume so much power.

To that end, I followed some information from other questions, notably this one:
https://devzone.nordicsemi.com/f/nordic-q-a/64355/is-there-any-spi-example-of-ncs-v1-3-to-refer-to

and this sample:
https://github.com/nrfconnect/sdk-zephyr/blob/master/samples/drivers/spi_flash/src/main.c

So, was able to see that the SPI flash is found, and it can be read and written to. What I noted though is that during spi_nor_configure() the wake command (0x9f) is sent twice, and the deep power down (0xB9) is sent twice as well. I should mention that I set

CONFIG_SPI_NOR_IDLE_IN_DPD=y

Sending the wake command twice isn't really a problem, but sending the sleep twice likely is, as the second send of the command wakes the device on the falling chip select, and the command is sent too soon to be picked up by the device, so it's likely that the device will be left in standby rather than deep power down.

If you subsequently send a command to the flash ( a read for example) this transaction works correctly, with just a single DPD sent and the appropriate restrictions on timing respected. So, I have a viable workaround, but it seems the behavior in spi_nor_configure() isn't correct.

Logic trace showing wake 1, Wake 2(w2) and query sequence (Query)

Closeup of query sequence:

RDSR: Read status register

JEDEC: Read JEDIC Id

S1 and S2, two 0xB9 Sleep commands.

Related