The Quad Serial Peripheral Interface (QSPI) driver includes two layers: the hardware access layer (HAL) and the driver layer (DRV).
The hardware access layer provides basic APIs for accessing the registers of the QSPI peripheral. For details, see the API documentation for QSPI HAL.
The driver layer provides APIs on a higher level than the HAL. For details, see the API documentation for QSPI driver.
Key features include:
The Experimental: QSPI Example provides sample code that you can use to quickly get started. Note that before the transmission starts, both the peripheral and memory must be configured, unlike for other drivers, where only the peripheral must be configured.
The configurable parameters include:
Writing an application that uses QSPI involves two steps:
Define a helper Boolean and the data handling function for QSPI. Example:
Call nrf_drv_qspi_init to initialize and configure the driver. For possible configuration options, refer to the nrf_drv_qspi_config_t structure documentation. Values in fields configured by NRF_DRV_QSPI_DEFAULT_CONFIG can be found in the sdk_config.h file (see the QSPI_ prefix). Remember that the default configuration of pins is fetched from the pca10056.h file which can be found in the components/boards directory.
Example:
Configure the memory using proper custom instructions. This task depends on the chosen memory. Refer to the memory documentation before writing code. The example code below works with MX25L6435F memory which can be find on the PCA10056 Development Kit.
Remember that nrf_drv_qspi_cinstr_xfer is a synchronous function and it does not require checking the status flags in peripheral registers.
You can now use nrf_drv_qspi_write and nrf_drv_qspi_read to transfer data. Memory status is checked automatically before the start of read, write, and erase operations. The event comes after the last operation is finished.
Remember to align the adress to four bytes. You do not need to check how much data will be transfered into memory during one transfer. The peripheral splits data into 256-byte transfers.
Another option is to prepare a function that waits for Erase Finished state. Additionally, a timeout feature can be implemented in such case:
When the QSPI driver is no longer needed or its configuration must be changed, call nrf_drv_qspi_uninit.