4. Using the driver

When using a new QSPI Memory device, it will first have to be initialized according to its driver before it can be operated. It is possible to:

  • Automatically pick the driver from a collection after identifying the connected device.

  • Explicitly specify which driver will be used on which QSPI controller.

4.1. Device Autodetection

Firmwares that use autodetect first issue a Read JEDEC ID command towards the connected device which returns three bytes as per the device manufacturer’s specifications. Additionally, configuration objects (one for each driver that belongs to the collection) populate a table called flash_config_table[]. The three bytes returned are checked if they match with the .manufacturer_id, .device_type and .device_density of every element of the flash_config_table[]. If the values match then the specific configuration object will be used to initialize the QSPI device.

Enabling Device Autodetection requires the following line to be added to the custom_config files which can be found under {project_root}/config folder.

#define dg_configFLASH_AUTODETECT                        (1)

Adding the new driver to the collection requires modification of file automode.c found under {SDK_root}/sdk/bsp/memory/src. Find the following section and make sure the new driver is included there as well.

#if (FLASH_AUTODETECT == 1)
#               include "qspi_gd25le32.h"
#               include "qspi_mx25u3235.h"
#               include "qspi_w25q32fw.h"
#               include "psram_aps1604jsq.h"
#               include "psram_aps3204jsq.h"
#               include "psram_aps6404jsq.h"

static const qspi_flash_config_t* flash_config_table[] = {
                &flash_gd25le32_config,
                &flash_mx25u3235_config,
                &flash_w25q32fw_config,
                &psram_aps1604jsq_config,
                &psram_aps3204jsq_config,
                &psram_aps6404jsq_config,
};

Additionally, a pointer to the configuration object defined in the driver should be added in flash_config_table[].

The drawback of this approach is that all the configuration objects populating the array require a significant amount of memory. Furthermore, the device takes longer to first issue the Read JEDEC ID, and then compare the results with all the configuration objects one by one compared to simply using a specific device driver only.

Project uartboot along with any project that uses has uartboot as dependency(e.g. cli_programmer) use Device Auto-detection by default.

4.2. Specific Driver

Explicitly specifying the driver used is the preferred method for custom Firmwares as it has a smaller memory footprint and is faster. To specify which driver will be used, first make sure that dg_configFLASH_AUTODETECT has the value zero and then add the following entries to the custom_config file that matches your build target.

For QSPIC Controller…

#define dg_configFLASH_HEADER_FILE              "driver_filename.h"
#define dg_configFLASH_CONFIG                   config_object_name

…replacing driver_filename with the name of the driver to be used and config_object_name with the name of the configuration object as defined in the chosen driver.

Alternatively, for QSPIC2 Controller first the controller should be enabled…

#define dg_configUSE_HW_QSPI2                   (1)

and then the following lines should be added…

#define dg_configQSPIC2_DEV_HEADER_FILE         "driver_filename.h"
#define dg_configQSPIC2_DEV_CONFIG              config_object_name

…replacing driver_filename with the name of the driver to be used and config_object_name with the name of the configuration object as defined in the chosen driver.

Warning

A QSPI Flash connected to QSPIC Controller should be set to draw power from power rail 1V8P. To power up the QSPIC2 along with the device connected, power rail 1V8 needs to be active.

Set the proper MACROS dg_configPOWER_1V8_ACTIVE and dg_configPOWER_1V8_SLEEP in the custom_config_ variant that reflects the compiled version of the project, to ensure that power is supplied to the QSPIC2.