I am using Nordic SDK 15.3 and nRF52840 to interface to a NAND flash TC58CVG2S0HRAIG.
I'm new with the SDK and I have little experience with the SPI / SPIM functions.
I started with the SDK SPI example. I possibly also could have started with the SPIM example, since both use the SPIM with DMA, as far as I understand.
And I'm using the SPI_SS_PIN to select the Nand Flash device.
For my SPI communication I'm using functions like
nrf_drv_spi_init(&spiInst, &spi_config, NULL, NULL);
and
nrf_drv_spi_transfer(&spiInst, &tx_buf, 2, rx_buf, 4);
This basically works fine and I also verify what's happening on the bus with my Logic Analyzer.
But for certain operations with the flash it seems not to be appropriate / efficient to use the nrf_drv_spi_transfer function.
It does its job, but the timing will be far away from optimal.
Example:
For many commands which are sent to the NAND Flash (e.g. erase a block of memory), the device takes some unknown / varying time to finish it. For this reason the device provides a status command, which returns one byte with the current busy status. This "can" be done by sending the complete 3 byte GETSTATUS command and receive just one single status byte with each call to nrf_drv_spi_transfer.
But the better / faster way to do this is by sending the same 3 byte GETSTATUS command sequence only once, but keeping the SS PIN active, and then continue transferring dummy bytes (in order to read the status from the device) until a specific BUSY bit is cleared. Only then the SS PIN is returned to inactive.
No need (and no easy way) to actually save all the received and unknown number of bytes in a buffer. Only the last read byte is of interest.
I'm aware that I might implement this GETSTATUS function somehow with a lower API level or directly programming the SPIM registers.
But basically my question is, which API level should I use to interface with the Nand Flash then ?
a) Is it possible to mix such a status query with other regular calls to nrf_drv_spi_transfer ? Does the API allow that ?
b) Or does it mean, I have to drop the functions around nrf_drv_spi_transfer and do all SPI communication with a lower level ?
Thanks for any pointer.