QSPIEMLIB

Detailed Description

QSPI Octal-SPI Controller API.

These QSPI functions provide basic support for using the QSPI peripheral in the following configurations:

  • Direct Read/Write, used for memory mapped access to external memory.
  • STIG Command, used for configuring and executing commands on the external memory device.

Indirect read/write, PHY configuration, and Execute-In-Place (XIP) configurations are not supported.

The example below shows how to set up the QSPI for direct read and write operation:

QSPI_Init(QSPI0, &initQspi);
// Configure QSPI pins.
GPIO_PinModeSet(EXTFLASH_PORT_CS, EXTFLASH_PIN_CS, gpioModePushPull, 0);
GPIO_PinModeSet(EXTFLASH_PORT_SCLK, EXTFLASH_PIN_SCLK, gpioModePushPull, 0);
GPIO_PinModeSet(EXTFLASH_PORT_DQ0, EXTFLASH_PIN_DQ0, gpioModePushPull, 0);
GPIO_PinModeSet(EXTFLASH_PORT_DQ1, EXTFLASH_PIN_DQ1, gpioModePushPull, 0);
GPIO_PinModeSet(EXTFLASH_PORT_DQ2, EXTFLASH_PIN_DQ2, gpioModePushPull, 0);
GPIO_PinModeSet(EXTFLASH_PORT_DQ3, EXTFLASH_PIN_DQ3, gpioModePushPull, 0);
// Configure QSPI routing to GPIO.
QSPI0->ROUTELOC0 = EXTFLASH_QSPI_LOC;
| EXTFLASH_QSPI_CSPEN
// Configure the direct read.
readConfig.dummyCycles = 8;
readConfig.opCode = 0x6B;
QSPI_ReadConfig(QSPI0, &readConfig);
// Configure the direct write.
writeConfig.dummyCycles = 0;
writeConfig.opCode = 0x38;
writeConfig.autoWEL = true;
QSPI_WriteConfig(QSPI0, &writeConfig);

To configure an external flash, commands can be set up and executed using the Software Triggered Instruction Generator (STIG) function of the QSPI, as shown in the example below:

uint8_t status;
QSPI_StigCmd_TypeDef stigCmd = {0};
stigCmd.cmdOpcode = EXTFLASH_OPCODE_READ_STATUS;
stigCmd.readDataSize = 1;
stigCmd.readBuffer = &status;

Data Structures

struct  QSPI_DelayConfig_TypeDef
 
struct  QSPI_Init_TypeDef
 
struct  QSPI_ReadConfig_TypeDef
 
struct  QSPI_StigCmd_TypeDef
 
struct  QSPI_WriteConfig_TypeDef
 

Macros

#define QSPI_INIT_DEFAULT
 
#define QSPI_READCONFIG_DEFAULT
 
#define QSPI_WRITECONFIG_DEFAULT
 

Enumerations

enum  QSPI_TransferType_TypeDef {
  qspiTransferSingle = 0,
  qspiTransferDual = 1,
  qspiTransferQuad = 2,
  qspiTransferOctal = 3
}
 

Functions

__STATIC_INLINE void QSPI_Enable (QSPI_TypeDef *qspi, bool enable)
 Enable/disable Quad SPI.
 
void QSPI_ExecStigCmd (QSPI_TypeDef *qspi, const QSPI_StigCmd_TypeDef *stigCmd)
 Execute a STIG command.
 
__STATIC_INLINE uint16_t QSPI_GetReadLevel (QSPI_TypeDef *qspi)
 Get the fill level of the read partition of the QSPI internal SRAM.
 
__STATIC_INLINE uint16_t QSPI_GetWriteLevel (QSPI_TypeDef *qspi)
 Get the fill level of the write partition of the QSPI internal SRAM.
 
void QSPI_Init (QSPI_TypeDef *qspi, const QSPI_Init_TypeDef *init)
 Initialize QSPI.
 
__STATIC_INLINE void QSPI_IntClear (QSPI_TypeDef *qspi, uint32_t flags)
 Clear interrupt flags.
 
__STATIC_INLINE void QSPI_IntDisable (QSPI_TypeDef *qspi, uint32_t flags)
 Disable interrupts.
 
__STATIC_INLINE void QSPI_IntEnable (QSPI_TypeDef *qspi, uint32_t flags)
 Enable interrupts.
 
__STATIC_INLINE uint32_t QSPI_IntGet (QSPI_TypeDef *qspi)
 Get the current interrupt flags.
 
void QSPI_ReadConfig (QSPI_TypeDef *qspi, const QSPI_ReadConfig_TypeDef *config)
 Configure Read Operations.
 
__STATIC_INLINE void QSPI_WaitForIdle (QSPI_TypeDef *qspi)
 Wait for the QSPI to go into idle state.
 
void QSPI_WriteConfig (QSPI_TypeDef *qspi, const QSPI_WriteConfig_TypeDef *config)
 Configure Write Operations.
 

Macro Definition Documentation

#define QSPI_INIT_DEFAULT
Value:
{ \
true, /* Enable Quad SPI. */ \
32, /* Divide QSPI clock by 32. */ \
}

Default configuration for QSPI_Init_TypeDef structure.

Definition at line 200 of file em_qspi.h.

#define QSPI_READCONFIG_DEFAULT
Value:
{ \
0x03, /* 0x03 is the standard read opcode. */ \
0, /* 0 dummy cycles. */ \
qspiTransferSingle, /* Single I/O mode. */ \
qspiTransferSingle, /* Single I/O mode. */ \
qspiTransferSingle, /* Single I/O mode. */ \
}

Default Read Configuration Structure.

Definition at line 102 of file em_qspi.h.

#define QSPI_WRITECONFIG_DEFAULT
Value:
{ \
0x02, /* 0x02 is the standard write opcode. */ \
0, /* 0 dummy cycles. */ \
qspiTransferSingle, /* Single I/O mode. */ \
qspiTransferSingle, /* Single I/O mode. */ \
true, /* Send WEL command automatically. */ \
}

Default Write Configuration Structure.

Definition at line 140 of file em_qspi.h.

Enumeration Type Documentation

Transfer type.

Enumerator
qspiTransferSingle 

Single IO mode. DQ0 used for output and DQ1 as input.

qspiTransferDual 

Dual I/O transfer. DQ0 and DQ1 are used as both inputs and outputs.

qspiTransferQuad 

Quad I/O transfer. DQ0, DQ1, DQ2 and DQ3 are used as both inputs and outputs.

qspiTransferOctal 

Octal I/O transfer. DQ[7:0] are used as both inputs and outputs.

Definition at line 65 of file em_qspi.h.

Function Documentation

__STATIC_INLINE void QSPI_Enable ( QSPI_TypeDef qspi,
bool  enable 
)

Enable/disable Quad SPI.

Parameters
[in]qspiPointer to QSPI peripheral register block.
[in]enabletrue to enable quad spi, false to disable quad spi.

Definition at line 272 of file em_qspi.h.

References _QSPI_CONFIG_ENBSPI_SHIFT, BUS_RegBitWrite(), and QSPI_TypeDef::CONFIG.

Referenced by QSPI_Init().

__STATIC_INLINE uint16_t QSPI_GetReadLevel ( QSPI_TypeDef qspi)

Get the fill level of the read partition of the QSPI internal SRAM.

Parameters
[in]qspiPointer to QSPI peripheral register block.
Returns
SRAM fill level of the read partition. The value is the number of 4 byte words in the read partition.

Definition at line 256 of file em_qspi.h.

References _QSPI_SRAMFILL_SRAMFILLINDACREAD_MASK, _QSPI_SRAMFILL_SRAMFILLINDACREAD_SHIFT, and QSPI_TypeDef::SRAMFILL.

__STATIC_INLINE uint16_t QSPI_GetWriteLevel ( QSPI_TypeDef qspi)

Get the fill level of the write partition of the QSPI internal SRAM.

Parameters
[in]qspiPointer to QSPI peripheral register block.
Returns
SRAM fill level of the write partition. The value is the number of 4 byte words in the write partition.

Definition at line 239 of file em_qspi.h.

References _QSPI_SRAMFILL_SRAMFILLINDACWRITE_MASK, _QSPI_SRAMFILL_SRAMFILLINDACWRITE_SHIFT, and QSPI_TypeDef::SRAMFILL.

void QSPI_Init ( QSPI_TypeDef qspi,
const QSPI_Init_TypeDef init 
)

Initialize QSPI.

Parameters
[in]qspiA pointer to the QSPI peripheral register block.
[in]initA pointer to the initialization structure used to configure QSPI.

Definition at line 135 of file em_qspi.c.

References _QSPI_CONFIG_MSTRBAUDDIV_MASK, _QSPI_CONFIG_MSTRBAUDDIV_SHIFT, QSPI_TypeDef::CONFIG, QSPI_Init_TypeDef::divisor, QSPI_Init_TypeDef::enable, and QSPI_Enable().

__STATIC_INLINE void QSPI_IntClear ( QSPI_TypeDef qspi,
uint32_t  flags 
)

Clear interrupt flags.

Parameters
[in]qspiPointer to QSPI peripheral register block.
[in]flagsThe interrupt flags to clear.

Definition at line 302 of file em_qspi.h.

References QSPI_TypeDef::IRQSTATUS.

__STATIC_INLINE void QSPI_IntDisable ( QSPI_TypeDef qspi,
uint32_t  flags 
)

Disable interrupts.

Parameters
[in]qspiPointer to QSPI peripheral register block.
[in]flagsThe interrupt flags to disable.

Definition at line 332 of file em_qspi.h.

References _QSPI_IRQMASK_MASK, and QSPI_TypeDef::IRQMASK.

__STATIC_INLINE void QSPI_IntEnable ( QSPI_TypeDef qspi,
uint32_t  flags 
)

Enable interrupts.

Parameters
[in]qspiPointer to QSPI peripheral register block.
[in]flagsThe interrupt flags to enable.

Definition at line 317 of file em_qspi.h.

References _QSPI_IRQMASK_MASK, and QSPI_TypeDef::IRQMASK.

__STATIC_INLINE uint32_t QSPI_IntGet ( QSPI_TypeDef qspi)

Get the current interrupt flags.

Parameters
[in]qspiPointer to QSPI peripheral register block.
Returns
This functions returns the current interrupt flags that are set.

Definition at line 287 of file em_qspi.h.

References QSPI_TypeDef::IRQSTATUS.

__STATIC_INLINE void QSPI_WaitForIdle ( QSPI_TypeDef qspi)

Wait for the QSPI to go into idle state.

Parameters
[in]qspiPointer to QSPI peripheral register block.

Definition at line 222 of file em_qspi.h.

References _QSPI_CONFIG_IDLE_MASK, and QSPI_TypeDef::CONFIG.

Referenced by QSPI_ExecStigCmd(), QSPI_ReadConfig(), and QSPI_WriteConfig().