MCUXpresso SDK API Reference Manual  Rev 2.16.000
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SPIFI: SPIFI flash interface driver

Overview

Modules

 SPIFI DMA Driver
 
 SPIFI Driver
 

Data Structures

struct  _spifi_command
 SPIFI command structure. More...
 
struct  _spifi_config
 SPIFI region configuration structure. More...
 
struct  _spifi_transfer
 Transfer structure for SPIFI. More...
 
struct  _spifi_dma_handle
 SPIFI DMA transfer handle, users should not touch the content of the handle. More...
 

Typedefs

typedef enum
_spifi_interrupt_enable 
spifi_interrupt_enable_t
 SPIFI interrupt source.
 
typedef enum _spifi_spi_mode spifi_spi_mode_t
 SPIFI SPI mode select.
 
typedef enum _spifi_dual_mode spifi_dual_mode_t
 SPIFI dual mode select.
 
typedef enum _spifi_data_direction spifi_data_direction_t
 SPIFI data direction.
 
typedef enum _spifi_command_format spifi_command_format_t
 SPIFI command opcode format.
 
typedef enum _spifi_command_type spifi_command_type_t
 SPIFI command type.
 
typedef struct _spifi_command spifi_command_t
 SPIFI command structure.
 
typedef struct _spifi_config spifi_config_t
 SPIFI region configuration structure.
 
typedef struct _spifi_transfer spifi_transfer_t
 Transfer structure for SPIFI.
 
typedef void(* spifi_dma_callback_t )(SPIFI_Type *base, spifi_dma_handle_t *handle, status_t status, void *userData)
 SPIFI DMA transfer callback function for finish and error.
 

Enumerations

enum  {
  kStatus_SPIFI_Idle = MAKE_STATUS(kStatusGroup_SPIFI, 0),
  kStatus_SPIFI_Busy = MAKE_STATUS(kStatusGroup_SPIFI, 1),
  kStatus_SPIFI_Error = MAKE_STATUS(kStatusGroup_SPIFI, 2)
}
 Status structure of SPIFI. More...
 
enum  _spifi_interrupt_enable { kSPIFI_CommandFinishInterruptEnable = SPIFI_CTRL_INTEN_MASK }
 SPIFI interrupt source. More...
 
enum  _spifi_spi_mode {
  kSPIFI_SPISckLow = 0x0U,
  kSPIFI_SPISckHigh = 0x1U
}
 SPIFI SPI mode select. More...
 
enum  _spifi_dual_mode {
  kSPIFI_QuadMode = 0x0U,
  kSPIFI_DualMode = 0x1U
}
 SPIFI dual mode select. More...
 
enum  _spifi_data_direction {
  kSPIFI_DataInput = 0x0U,
  kSPIFI_DataOutput = 0x1U
}
 SPIFI data direction. More...
 
enum  _spifi_command_format {
  kSPIFI_CommandAllSerial = 0x0,
  kSPIFI_CommandDataQuad = 0x1U,
  kSPIFI_CommandOpcodeSerial = 0x2U,
  kSPIFI_CommandAllQuad = 0x3U
}
 SPIFI command opcode format. More...
 
enum  _spifi_command_type {
  kSPIFI_CommandOpcodeOnly = 0x1U,
  kSPIFI_CommandOpcodeAddrOneByte = 0x2U,
  kSPIFI_CommandOpcodeAddrTwoBytes = 0x3U,
  kSPIFI_CommandOpcodeAddrThreeBytes = 0x4U,
  kSPIFI_CommandOpcodeAddrFourBytes = 0x5U,
  kSPIFI_CommandNoOpcodeAddrThreeBytes = 0x6U,
  kSPIFI_CommandNoOpcodeAddrFourBytes = 0x7U
}
 SPIFI command type. More...
 
enum  {
  kSPIFI_MemoryCommandWriteFinished = SPIFI_STAT_MCINIT_MASK,
  kSPIFI_CommandWriteFinished = SPIFI_STAT_CMD_MASK,
  kSPIFI_InterruptRequest = SPIFI_STAT_INTRQ_MASK
}
 SPIFI status flags. More...
 

Functions

static void SPIFI_EnableDMA (SPIFI_Type *base, bool enable)
 Enable or disable DMA request for SPIFI. More...
 
static uint32_t SPIFI_GetDataRegisterAddress (SPIFI_Type *base)
 Gets the SPIFI data register address. More...
 
static void SPIFI_WriteData (SPIFI_Type *base, uint32_t data)
 Write a word data in address of SPIFI. More...
 
static void SPIFI_WriteDataByte (SPIFI_Type *base, uint8_t data)
 Write a byte data in address of SPIFI. More...
 
void SPIFI_WriteDataHalfword (SPIFI_Type *base, uint16_t data)
 Write a halfword data in address of SPIFI. More...
 
static uint32_t SPIFI_ReadData (SPIFI_Type *base)
 Read data from serial flash. More...
 
static uint8_t SPIFI_ReadDataByte (SPIFI_Type *base)
 Read a byte data from serial flash. More...
 
uint16_t SPIFI_ReadDataHalfword (SPIFI_Type *base)
 Read a halfword data from serial flash. More...
 

Driver version

#define FSL_SPIFI_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))
 SPIFI driver version 2.0.3. More...
 

Initialization and deinitialization

uint32_t SPIFI_GetInstance (SPIFI_Type *base)
 Get the SPIFI instance from peripheral base address. More...
 
void SPIFI_Init (SPIFI_Type *base, const spifi_config_t *config)
 Initializes the SPIFI with the user configuration structure. More...
 
void SPIFI_GetDefaultConfig (spifi_config_t *config)
 Get SPIFI default configure settings. More...
 
void SPIFI_Deinit (SPIFI_Type *base)
 Deinitializes the SPIFI regions. More...
 

Basic Control Operations

void SPIFI_SetCommand (SPIFI_Type *base, spifi_command_t *cmd)
 Set SPIFI flash command. More...
 
static void SPIFI_SetCommandAddress (SPIFI_Type *base, uint32_t addr)
 Set SPIFI command address. More...
 
static void SPIFI_SetIntermediateData (SPIFI_Type *base, uint32_t val)
 Set SPIFI intermediate data. More...
 
static void SPIFI_SetCacheLimit (SPIFI_Type *base, uint32_t val)
 Set SPIFI Cache limit value. More...
 
static void SPIFI_ResetCommand (SPIFI_Type *base)
 Reset the command field of SPIFI. More...
 
void SPIFI_SetMemoryCommand (SPIFI_Type *base, spifi_command_t *cmd)
 Set SPIFI flash AHB read command. More...
 
static void SPIFI_EnableInterrupt (SPIFI_Type *base, uint32_t mask)
 Enable SPIFI interrupt. More...
 
static void SPIFI_DisableInterrupt (SPIFI_Type *base, uint32_t mask)
 Disable SPIFI interrupt. More...
 

Status

static uint32_t SPIFI_GetStatusFlag (SPIFI_Type *base)
 Get the status of all interrupt flags for SPIFI. More...
 

Driver version

#define FSL_SPIFI_DMA_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))
 SPIFI DMA driver version 2.0.3. More...
 

DMA Transactional

void SPIFI_TransferTxCreateHandleDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_dma_callback_t callback, void *userData, dma_handle_t *dmaHandle)
 Initializes the SPIFI handle for send which is used in transactional functions and set the callback. More...
 
void SPIFI_TransferRxCreateHandleDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_dma_callback_t callback, void *userData, dma_handle_t *dmaHandle)
 Initializes the SPIFI handle for receive which is used in transactional functions and set the callback. More...
 
status_t SPIFI_TransferSendDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_transfer_t *xfer)
 Transfers SPIFI data using an DMA non-blocking method. More...
 
status_t SPIFI_TransferReceiveDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, spifi_transfer_t *xfer)
 Receives data using an DMA non-blocking method. More...
 
void SPIFI_TransferAbortSendDMA (SPIFI_Type *base, spifi_dma_handle_t *handle)
 Aborts the sent data using DMA. More...
 
void SPIFI_TransferAbortReceiveDMA (SPIFI_Type *base, spifi_dma_handle_t *handle)
 Aborts the receive data using DMA. More...
 
status_t SPIFI_TransferGetSendCountDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, size_t *count)
 Gets the transferred counts of send. More...
 
status_t SPIFI_TransferGetReceiveCountDMA (SPIFI_Type *base, spifi_dma_handle_t *handle, size_t *count)
 Gets the status of the receive transfer. More...
 

Data Structure Documentation

struct _spifi_command

Data Fields

uint16_t dataLen
 How many data bytes are needed in this command. More...
 
bool isPollMode
 For command need to read data from serial flash.
 
spifi_data_direction_t direction
 Data direction of this command. More...
 
uint8_t intermediateBytes
 How many intermediate bytes needed.
 
spifi_command_format_t format
 Command format.
 
spifi_command_type_t type
 Command type.
 
uint8_t opcode
 Command opcode value.
 

Field Documentation

uint16_t _spifi_command::dataLen
spifi_data_direction_t _spifi_command::direction
struct _spifi_config

Data Fields

uint16_t timeout
 SPI transfer timeout, the unit is SCK cycles.
 
uint8_t csHighTime
 CS high time cycles.
 
bool disablePrefetch
 True means SPIFI will not attempt a speculative prefetch. More...
 
bool disableCachePrefech
 Disable prefetch of cache line.
 
bool isFeedbackClock
 Is data sample uses feedback clock. More...
 
spifi_spi_mode_t spiMode
 SPIFI spi mode select.
 
bool isReadFullClockCycle
 If enable read full clock cycle. More...
 
spifi_dual_mode_t dualMode
 SPIFI dual mode, dual or quad. More...
 

Field Documentation

bool _spifi_config::disablePrefetch
bool _spifi_config::isFeedbackClock
bool _spifi_config::isReadFullClockCycle
spifi_dual_mode_t _spifi_config::dualMode
struct _spifi_transfer

Data Fields

uint8_t * data
 Pointer to data to transmit.
 
size_t dataSize
 Bytes to be transmit.
 
struct _spifi_dma_handle

Data Fields

dma_handle_tdmaHandle
 DMA handler for SPIFI send.
 
size_t transferSize
 Bytes need to transfer. More...
 
uint32_t state
 Internal state for SPIFI DMA transfer.
 
spifi_dma_callback_t callback
 Callback for users while transfer finish or error occurred.
 
void * userData
 User callback parameter.
 

Field Documentation

size_t _spifi_dma_handle::transferSize

Macro Definition Documentation

#define FSL_SPIFI_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))
#define FSL_SPIFI_DMA_DRIVER_VERSION   (MAKE_VERSION(2, 0, 3))

Enumeration Type Documentation

anonymous enum
Enumerator
kStatus_SPIFI_Idle 

SPIFI is in idle state.

kStatus_SPIFI_Busy 

SPIFI is busy.

kStatus_SPIFI_Error 

Error occurred during SPIFI transfer.

Enumerator
kSPIFI_CommandFinishInterruptEnable 

Interrupt while command finished.

Enumerator
kSPIFI_SPISckLow 

SCK low after last bit of command, keeps low while CS high.

kSPIFI_SPISckHigh 

SCK high after last bit of command and while CS high.

Enumerator
kSPIFI_QuadMode 

SPIFI uses IO3:0.

kSPIFI_DualMode 

SPIFI uses IO1:0.

Enumerator
kSPIFI_DataInput 

Data input from serial flash.

kSPIFI_DataOutput 

Data output to serial flash.

Enumerator
kSPIFI_CommandAllSerial 

All fields of command are serial.

kSPIFI_CommandDataQuad 

Only data field is dual/quad, others are serial.

kSPIFI_CommandOpcodeSerial 

Only opcode field is serial, others are quad/dual.

kSPIFI_CommandAllQuad 

All fields of command are dual/quad mode.

Enumerator
kSPIFI_CommandOpcodeOnly 

Command only have opcode, no address field.

kSPIFI_CommandOpcodeAddrOneByte 

Command have opcode and also one byte address field.

kSPIFI_CommandOpcodeAddrTwoBytes 

Command have opcode and also two bytes address field.

kSPIFI_CommandOpcodeAddrThreeBytes 

Command have opcode and also three bytes address field.

kSPIFI_CommandOpcodeAddrFourBytes 

Command have opcode and also four bytes address field.

kSPIFI_CommandNoOpcodeAddrThreeBytes 

Command have no opcode and three bytes address field.

kSPIFI_CommandNoOpcodeAddrFourBytes 

Command have no opcode and four bytes address field.

anonymous enum
Enumerator
kSPIFI_MemoryCommandWriteFinished 

Memory command write finished.

kSPIFI_CommandWriteFinished 

Command write finished.

kSPIFI_InterruptRequest 

CMD flag from 1 to 0, means command execute finished.

Function Documentation

uint32_t SPIFI_GetInstance ( SPIFI_Type *  base)
Parameters
baseSPIFI peripheral base address.
Returns
SPIFI instance.
void SPIFI_Init ( SPIFI_Type *  base,
const spifi_config_t config 
)

This function configures the SPIFI module with the user-defined configuration.

Parameters
baseSPIFI peripheral base address.
configThe pointer to the configuration structure.
void SPIFI_GetDefaultConfig ( spifi_config_t config)
Parameters
configSPIFI config structure pointer.
void SPIFI_Deinit ( SPIFI_Type *  base)
Parameters
baseSPIFI peripheral base address.
void SPIFI_SetCommand ( SPIFI_Type *  base,
spifi_command_t cmd 
)
Parameters
baseSPIFI peripheral base address.
cmdSPIFI command structure pointer.
static void SPIFI_SetCommandAddress ( SPIFI_Type *  base,
uint32_t  addr 
)
inlinestatic
Parameters
baseSPIFI peripheral base address.
addrAddress value for the command.
static void SPIFI_SetIntermediateData ( SPIFI_Type *  base,
uint32_t  val 
)
inlinestatic

Before writing a command wihch needs specific intermediate value, users shall call this function to write it. The main use of this function for current serial flash is to select no-opcode mode and cancelling this mode. As dummy cycle do not care about the value, no need to call this function.

Parameters
baseSPIFI peripheral base address.
valIntermediate data.
static void SPIFI_SetCacheLimit ( SPIFI_Type *  base,
uint32_t  val 
)
inlinestatic

SPIFI includes caching of prevously-accessed data to improve performance. Software can write an address to this function, to prevent such caching at and above the address.

Parameters
baseSPIFI peripheral base address.
valZero-based upper limit of cacheable memory.
static void SPIFI_ResetCommand ( SPIFI_Type *  base)
inlinestatic

This function is used to abort the current command or memory mode.

Parameters
baseSPIFI peripheral base address.
void SPIFI_SetMemoryCommand ( SPIFI_Type *  base,
spifi_command_t cmd 
)

Call this function means SPIFI enters to memory mode, while users need to use command, a SPIFI_ResetCommand shall be called.

Parameters
baseSPIFI peripheral base address.
cmdSPIFI command structure pointer.
static void SPIFI_EnableInterrupt ( SPIFI_Type *  base,
uint32_t  mask 
)
inlinestatic

The interrupt is triggered only in command mode, and it means the command now is finished.

Parameters
baseSPIFI peripheral base address.
maskSPIFI interrupt enable mask. It is a logic OR of members the enumeration :: spifi_interrupt_enable_t
static void SPIFI_DisableInterrupt ( SPIFI_Type *  base,
uint32_t  mask 
)
inlinestatic

The interrupt is triggered only in command mode, and it means the command now is finished.

Parameters
baseSPIFI peripheral base address.
maskSPIFI interrupt enable mask. It is a logic OR of members the enumeration :: spifi_interrupt_enable_t
static uint32_t SPIFI_GetStatusFlag ( SPIFI_Type *  base)
inlinestatic
Parameters
baseSPIFI peripheral base address.
Returns
SPIFI flag status
static void SPIFI_EnableDMA ( SPIFI_Type *  base,
bool  enable 
)
inlinestatic
Parameters
baseSPIFI peripheral base address.
enableTrue means enable DMA and false means disable DMA.
static uint32_t SPIFI_GetDataRegisterAddress ( SPIFI_Type *  base)
inlinestatic

This API is used to provide a transfer address for the SPIFI DMA transfer configuration.

Parameters
baseSPIFI base pointer
Returns
data register address
static void SPIFI_WriteData ( SPIFI_Type *  base,
uint32_t  data 
)
inlinestatic

Users can write a page or at least a word data into SPIFI address.

Parameters
baseSPIFI peripheral base address.
dataData need be write.
static void SPIFI_WriteDataByte ( SPIFI_Type *  base,
uint8_t  data 
)
inlinestatic

Users can write a byte data into SPIFI address.

Parameters
baseSPIFI peripheral base address.
dataData need be write.
void SPIFI_WriteDataHalfword ( SPIFI_Type *  base,
uint16_t  data 
)

Users can write a halfword data into SPIFI address.

Parameters
baseSPIFI peripheral base address.
dataData need be write.
static uint32_t SPIFI_ReadData ( SPIFI_Type *  base)
inlinestatic

Users should notice before call this function, the data length field in command register shall larger than 4, otherwise a hardfault will happen.

Parameters
baseSPIFI peripheral base address.
Returns
Data input from flash.
static uint8_t SPIFI_ReadDataByte ( SPIFI_Type *  base)
inlinestatic
Parameters
baseSPIFI peripheral base address.
Returns
Data input from flash.
uint16_t SPIFI_ReadDataHalfword ( SPIFI_Type *  base)
Parameters
baseSPIFI peripheral base address.
Returns
Data input from flash.
void SPIFI_TransferTxCreateHandleDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
spifi_dma_callback_t  callback,
void *  userData,
dma_handle_t dmaHandle 
)
Parameters
baseSPIFI peripheral base address
handlePointer to spifi_dma_handle_t structure
callbackSPIFI callback, NULL means no callback.
userDataUser callback function data.
dmaHandleUser requested DMA handle for DMA transfer
void SPIFI_TransferRxCreateHandleDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
spifi_dma_callback_t  callback,
void *  userData,
dma_handle_t dmaHandle 
)
Parameters
baseSPIFI peripheral base address
handlePointer to spifi_dma_handle_t structure
callbackSPIFI callback, NULL means no callback.
userDataUser callback function data.
dmaHandleUser requested DMA handle for DMA transfer
status_t SPIFI_TransferSendDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
spifi_transfer_t xfer 
)

This function writes data to the SPIFI transmit FIFO. This function is non-blocking.

Parameters
basePointer to QuadSPI Type.
handlePointer to spifi_dma_handle_t structure
xferSPIFI transfer structure.
status_t SPIFI_TransferReceiveDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
spifi_transfer_t xfer 
)

This function receive data from the SPIFI receive buffer/FIFO. This function is non-blocking.

Parameters
basePointer to QuadSPI Type.
handlePointer to spifi_dma_handle_t structure
xferSPIFI transfer structure.
void SPIFI_TransferAbortSendDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle 
)

This function aborts the sent data using DMA.

Parameters
baseSPIFI peripheral base address.
handlePointer to spifi_dma_handle_t structure
void SPIFI_TransferAbortReceiveDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle 
)

This function abort receive data which using DMA.

Parameters
baseSPIFI peripheral base address.
handlePointer to spifi_dma_handle_t structure
status_t SPIFI_TransferGetSendCountDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
size_t *  count 
)
Parameters
basePointer to QuadSPI Type.
handlePointer to spifi_dma_handle_t structure.
countBytes sent.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.
status_t SPIFI_TransferGetReceiveCountDMA ( SPIFI_Type *  base,
spifi_dma_handle_t handle,
size_t *  count 
)
Parameters
basePointer to QuadSPI Type.
handlePointer to spifi_dma_handle_t structure
countBytes received.
Return values
kStatus_SuccessSucceed get the transfer count.
kStatus_NoTransferInProgressThere is not a non-blocking transaction currently in progress.