The SPI-based communication interface to the external quad SPI (QSPI) high-speed memory devices.
The functions and other declarations used in this driver are in cy_smif.h and cy_smif_memslot.h (if used). If you are using the ModusToolbox QSPI Configurator, also include cycfg_qspi_memslot.h.
SMIF: Serial Memory Interface: This IP block implements an SPI-based communication interface for interfacing external memory devices to PSoC. The SMIF supports SPI, dual SPI (DSPI), quad SPI (QSPI), dual QSPI and octal SPI.
Features
The primary usage model for the SMIF is that of an external memory interface. The SMIF is capable of interfacing with different types of memory, up to four types.
SMIF driver is divided into three layers
The SMIF API is divided into the low-level functions and memory-slot functions. Use the low level API for the SMIF block initialization and for implementing a generic SPI communication interface using the SMIF block.
The memory slot API has functions to implement the basic memory operations such as program, read, erase etc. These functions are implemented using the memory parameters in the memory device configuration data structure. The Cy_SMIF_MemInit() API initializes all the memory slots based on the settings in the array.
SMIF Configuration Tool is a stand-alone application, which is a part of PDL (Creator) and could be found in <PDL_DIR>/tools/<OS_DIR>/SMIFConfigurationTool (e.g. for PDL 3.0.0 and Windows OS PDL/3.0.0/tools/win/SMIFConfigurationTool).
In ModusToolbox this tool is called QSPI Configurator. QSPI Configurator is a part of PSoC 6 Software Library and can be found in <ModusToolbox>/tools/qspi-configurator-1.1
Tool generates *.c and *.h file with configuration structures. These configuration structures are input parameters for cy_smif_memslot API level
For the Write operation, check that the SMIF driver has completed transferring by calling Cy_SMIF_BusyCheck(). Also, check that the memory is available with Cy_SMIF_MemIsBusy() before proceeding.
Simple example of external flash memory programming using low level SMIF API. All steps mentioned in example below are incorporated in Cy_SMIF_MemCmdWriteEnable(), Cy_SMIF_MemCmdProgram(), and Cy_SMIF_MemIsBusy() of the memory slot level API.
For the Read operation, before accessing the read buffer, check that it is ready by calling Cy_SMIF_GetTxFifoStatus().
Simple example of external flash memory read using low level SMIF API. All steps mentioned in example below are incorporated in Cy_SMIF_MemCmdRead() of the memory slot level API.
The user should invalidate the cache by calling Cy_SMIF_CacheInvalidate() when switching from the MMIO mode to XIP mode.
PDL API has common parameters: base, context, config described in PDL Design section.
See the documentation for Cy_SMIF_Init() and Cy_SMIF_MemInit() for details on the required configuration structures and other initialization topics.
The normal (MMIO) mode is used for implementing a generic SPI/DSPI/QSPI/dual QSPI/octal SPI communication interface using the SMIF block. This interface can be used to implement special commands like Program/Erase of flash, memory device configuration, sleep mode entry for memory devices or other special commands specific to the memory device. The transfer width (SPI/DSPI/QSPI/octal SPI) of a transmission is a parameter set for each transmit/receive operation. So these can be changed at run time.
In a typical memory interface with flash memory, the SMIF is used in the memory mode when reading from the memory and it switches to the normal mode when writing to flash memory. A typical memory device has multiple types of commands.
The SMIF interface can be used to transmit different types of commands. Each command has different phases: command, dummy cycles, and transmit and receive data which require separate APIs.
Create interrupt function and allocate memory for SMIF context structure
SMIF driver initialization for low level API usage (cysmif.h)
Additional steps to initialize SMIF driver for memory slot level API usage (cy_smif_memslot.h).
The eXecute In Place (XIP) is a mode of operation where read or write commands to the memory device are directed through the SMIF without any use of API function calls. In this mode the SMIF block maps the AHB bus-accesses to external memory device addresses to make it behave similar to internal memory. This allows the CPU to execute code directly from external memory. This mode is not limited to code and is suitable also for data read and write accesses. The memory regions available for XIP addresses allocation are defined in a linker script file (.ld).
More information regarding the Serial Memory Interface can be found in the component datasheet and the Technical Reference Manual (TRM). More information regarding the SMIF Configuration Tool are in SMIF Configuration Tool User Guide located in <PDL_DIR>/tools/<OS_DIR>/SMIFConfigurationTool/ folder
MISRA rule | Rule Class (Required/Advisory) | Rule Description | Description of Deviation(s) |
---|---|---|---|
11.4 | A | The cast is be performed between a pointer to the object type and a different pointer to the object type. | The cast from the pointer to void to the pointer to an unsigned integer does not have any unintended effect, as it is a consequence of the definition of a structure based on hardware registers. |
11.5 | R | Not performed, the cast that removes any const or volatile qualification from the type addressed by a pointer. | The removal of the volatile qualification inside the function has no side effects. |
Version | Changes | Reason for Change |
---|---|---|
1.50.1 | Minor documentation updates. | Documentation improvement. |
1.50 | Added a new function: Cy_SMIF_MemLocateHybridRegion. Added a new structure cy_stc_smif_hybrid_region_info_t. Updated the Cy_SMIF_MemEraseSector and Cy_SMIF_MemCmdSectorErase functions. Updated the Cy_SMIF_MemSfdpDetect function. Updated the cy_stc_smif_mem_device_cfg_t structure. | Support for memories with hybrid regions. |
1.40.1 | The Cy_SMIF_MemInit is changed. | Corrected a false assertion during initialization in SFDP mode. |
Minor documentation updates. | ||
1.40 | The following functions are renamed: Cy_SMIF_GetTxfrStatus into Cy_SMIF_GetTransferStatus; Cy_SMIF_Memslot_Init into Cy_SMIF_MemInit; Cy_SMIF_Memslot_DeInit into Cy_SMIF_MemDeInit; Cy_SMIF_Memslot_CmdWriteEnable into Cy_SMIF_MemCmdWriteEnable; Cy_SMIF_Memslot_CmdWriteDisable into Cy_SMIF_MemCmdWriteDisable; Cy_SMIF_Memslot_IsBusy into Cy_SMIF_MemIsBusy; Cy_SMIF_Memslot_QuadEnable into Cy_SMIF_MemQuadEnable; Cy_SMIF_Memslot_CmdReadSts into Cy_SMIF_MemCmdReadStatus; Cy_SMIF_Memslot_CmdWriteSts into Cy_SMIF_MemCmdWriteStatus; Cy_SMIF_Memslot_CmdChipErase into Cy_SMIF_MemCmdChipErase; Cy_SMIF_Memslot_CmdSectorErase into Cy_SMIF_MemCmdSectorErase; Cy_SMIF_Memslot_SfdpDetect into Cy_SMIF_MemSfdpDetect; Cy_SMIF_Memslot_CmdProgram into Cy_SMIF_MemCmdProgram; Cy_SMIF_Memslot_CmdRead into Cy_SMIF_MemCmdRead. The following ENUMa are renamed: CY_SMIF_SEND_CMPLT into CY_SMIF_SEND_COMPLETE; CY_SMIF_REC_CMPLT into CY_SMIF_RX_COMPLETE; CY_SMIF_REC_BUSY into CY_SMIF_RX_BUSY; CY_SMIF_SEL_INV_INTERNAL_CLK into CY_SMIF_SEL_INVERTED_INTERNAL_CLK; CY_SMIF_SEL_INV_FEEDBACK_CLK into CY_SMIF_SEL_INVERTED_FEEDBACK_CLK; cy_en_smif_cache_en_t into cy_en_smif_cache_t. The following MACROs are renamed: CY_SMIF_FLAG_WR_EN into CY_SMIF_FLAG_WRITE_ENABLE; CY_SMIF_FLAG_CRYPTO_EN into CY_SMIF_FLAG_CRYPTO_ENABLE; CY_SMIF_SFDP_SING_BYTE_00 into CY_SMIF_SFDP_SIGNATURE_BYTE_00; CY_SMIF_SFDP_SING_BYTE_01 into CY_SMIF_SFDP_SIGNATURE_BYTE_01; CY_SMIF_SFDP_SING_BYTE_02 into CY_SMIF_SFDP_SIGNATURE_BYTE_02; CY_SMIF_SFDP_SING_BYTE_03 into CY_SMIF_SFDP_SIGNATURE_BYTE_03; CY_SMIF_WR_STS_REG1_CMD into CY_SMIF_WRITE_STATUS_REG1_CMD; CY_SMIF_WR_DISABLE_CMD into CY_SMIF_WRITE_DISABLE_CMD; CY_SMIF_RD_STS_REG1_CMD into CY_SMIF_READ_STATUS_REG1_CMD; CY_SMIF_WR_ENABLE_CMD into CY_SMIF_WRITE_ENABLE_CMD; CY_SMIF_RD_STS_REG2_T1_CMD into CY_SMIF_READ_STATUS_REG2_T1_CMD; CY_SMIF_WR_STS_REG2_CMD into CY_SMIF_WRITE_STATUS_REG2_CMD; CY_SMIF_RD_STS_REG2_T2_CMD into CY_SMIF_READ_STATUS_REG2_T2_CMD; CY_SMIF_QE_BIT_STS_REG2_T1 into CY_SMIF_QE_BIT_STATUS_REG2_T1; CY_SMIF_STS_REG_BUSY_MASK into CY_SMIF_STATUS_REG_BUSY_MASK. | Documentation improvement. |
Updated the description of the Cy_SMIF_MemInit() function. Updated the Cy_SMIF_Encrypt() function usage example. | ||
The type of arguments that are not modified by the functions are set to const. | Usability improvement. | |
The Cy_SMIF_MemSfdpDetect() function is updated to support new commands for 4 bytes addressing. | Memory devices with new 4 byte addressing commands support. | |
Added the blocking functions which take care of the busy-status check of the memory: | Added new high-level blocking functions. | |
1.30 | The CY_SMIF_CMD_FIFO_WR_RX_COUNT_Msk value is changed to 0x0000FFFFUL. | Driver maintenance. |
Added the check of the size parameter in the Cy_SMIF_TransmitData() function. | ||
Added conditional check for presence of the SMIF hardware IP. | ||
Fixed the wrong erase command in the SFDP protocol for devices with Erase Type 3. | ||
Updated the General Description section with minor changes. Updated the ordering of the parameters descriptions for some functions. Added the text saying that the Cy_SMIF_MemInit() function is applicable to use the external memory as memory-mapped to PSoC (XIP mode). Added the snippet for the Cy_SMIF_Encrypt() function to show how to use this function. Added below the picture in the Low-Level Functions section the sequence of PDL functions required in a Read or Write transaction. Added the text below the picture about the address. Updated DUMMY COUNT in this picture. Added checking of the size parameter in the Cy_SMIF_TransmitData() function. | Documentation improvement. | |
1.20.1 | Added upper limit to size parameter in several functions. | Documentation improvement. |
1.20 | Flattened the organization of the driver source code into the single source directory and the single include directory. | Driver library directory-structure simplification. |
Added a new return status and transfer width option for the case when the memory command is not supported. | Improved the memory command structure usability. | |
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. | Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number. | |
1.11 | Fixed internal function that writes to the SMIF FIFO | The write function stuck in the loop when write speed in external memory is significantly lower than PSoC CPU core speed and write transfer is not finished during the single function call. |
Added optional mode part to the program command flow | Extend usability of program command | |
1.10.1 | Added Low Power Callback section | Documentation update and clarification |
1.10 | Fix write to external memory from CM0+ core. Add checks of API input parameters. Minor documentation updates | |
1.0 | Initial version |
API Reference | |
Macros | |
Functions | |
Data Structures | |
Enumerated Types | |