RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches

Overview

Function definitions for SPI Flash driver.

SPI Flash (Public API -Initialization)

Used to initialize SPI Flash.

void spiFlash_wake (spiFlash_instance_t *flash)
 Select spi and wake up SPI Flash.
void spiFlash_applyConfig (spiFlash_instance_t *flash)
 Apply stored SPI Flash configuration to hardware.
void spiFlash_registerFlash (const spiFlash_info_t *table, size_t count)
 Register Custom Flash to the driver.
void spiFlash_initController (spiFlash_instance_t *flash)
 Initialize SPI setting.
spiFlash_status_t spiFlash_probe (spiFlash_instance_t *flash)
 Main wrapper function to initialize the SPI Flash.
#define spiFlash_register(table)
 High level Wrapper to register Custom Flash to the driver.

SPI Flash (Public API - Identification)

Used to identify SPI Flash.

u8 spiFlash_readId (spiFlash_instance_t *flash)
 Select and Read Device ID from spiFlash.
u32 spiFlash_readJedecId (spiFlash_instance_t *flash)
 Select and read JEDEC ID from spiFlash.
const spiFlash_info_tspiFlash_lookup (u32 detected_id)
 Identify SPI Flash by looking up User Flash Table and known flash table.
spiFlash_status_t spiFlash_verify (spiFlash_instance_t *flash)
 Verify spiFlash.
void spiFlash_applyQuirks (spiFlash_instance_t *flash)
 Handle those spiFlash that have unique register/way.

SPI Flash (Public API - Read/Write Operation)

Used for read/write SPI Flash.

u8 spiFlash_readStatusReg (spiFlash_instance_t *flash)
 Read Status Register.
void spiFlash_writeStatusReg (spiFlash_instance_t *flash, u8 data)
 Write Status Register.
u8 spiFlash_write_single (spiFlash_instance_t *flash, u32 flashAddress, u8 *src, u32 len)
 Write N byte to Flash using standard write mode via single Data Line.
void spiFlash_read_single (spiFlash_instance_t *flash, u32 flashAddress, u8 *buffer, u32 len)
 Read N byte from Flash using standard read mode via single Data Line.
void spiFlash_f2m_single (spiFlash_instance_t *flash, u32 flashAddress, uintptr_t memoryAddress, u32 size)
 This function read data from FlashAddress and copy to memoryAddress of specific size with single data line.
void spiFlash_f2m_dual (spiFlash_instance_t *flash, u32 flashAddress, uintptr_t memoryAddress, u32 size)
 This function read data from FlashAddress and copy to memoryAddress of specific size with dual data line.
void spiFlash_f2m_quad (spiFlash_instance_t *flash, u32 flashAddress, uintptr_t memoryAddress, u32 size)
 This function read data from FlashAddress and copy to memoryAddress of specific size with quad data line.

SPI Flash (Public API - Configuration)

Used to configure SPI Flash setting.

spiFlash_status_t spiFlash_waitBusy (spiFlash_instance_t *flash)
 Wait for spiFlash to be free.
u8 spiFlash_exit4ByteAddr (spiFlash_instance_t *flash)
 Exit 4-byte addressing.
void spiFlash_lockGlobal (spiFlash_instance_t *flash)
 Globally locks the SPI flash.
void spiFlash_enableWrite (spiFlash_instance_t *flash)
 Set Write Enable Latch (WEL) to 1.
void spiFlash_unlockGlobal (spiFlash_instance_t *flash)
 Globally unlocks the SPI flash.
void spiFlash_enableQuadMode (spiFlash_instance_t *flash)
 Set Write Enable Latch and set Quad Enable bit to enable Quad Mode.
void spiFlash_enableQPI (spiFlash_instance_t *flash)
 Set Write Enable Latch and send CMD 0x38 to enable QPI Mode.
void spiFlash_eraseSector (spiFlash_instance_t *flash, u32 flashAddress)
 Erases a sector of the SPI flash given an address.

Macro Definition Documentation

◆ spiFlash_register

#define spiFlash_register ( table)

#include <spiFlash.h>

Value:
spiFlash_registerFlash((table), sizeof(table) / sizeof((table)[0]))
void spiFlash_registerFlash(const spiFlash_info_t *table, size_t count)
Register Custom Flash to the driver.
Definition spiFlash.c:27

High level Wrapper to register Custom Flash to the driver.

Parameters
tablePointer to SPI Flash Info Instance.
countThe number of entry in the table.
Warning
User should use this macro to register flash, and it will call spiFlash_registerFlash to store the pointer and count of user flash table.

Definition at line 285 of file spiFlash.h.

Function Documentation

◆ spiFlash_applyConfig()

void spiFlash_applyConfig ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Apply stored SPI Flash configuration to hardware.

Parameters
instPointer to SPI Flash instance.
Note
Refer to spi_applyConfig for more details.

Definition at line 94 of file spiFlash.c.

◆ spiFlash_applyQuirks()

void spiFlash_applyQuirks ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Handle those spiFlash that have unique register/way.

Parameters
flashPointer to SPI Flash Instance.
Note
This function apply for write protection, 4-byte exit cmd, quad enable

Definition at line 189 of file spiFlash.c.

◆ spiFlash_enableQPI()

void spiFlash_enableQPI ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Set Write Enable Latch and send CMD 0x38 to enable QPI Mode.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 373 of file spiFlash.c.

◆ spiFlash_enableQuadMode()

void spiFlash_enableQuadMode ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Set Write Enable Latch and set Quad Enable bit to enable Quad Mode.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 349 of file spiFlash.c.

◆ spiFlash_enableWrite()

void spiFlash_enableWrite ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Set Write Enable Latch (WEL) to 1.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 392 of file spiFlash.c.

◆ spiFlash_eraseSector()

void spiFlash_eraseSector ( spiFlash_instance_t * flash,
u32 flashAddress )

#include <spiFlash.h>

Erases a sector of the SPI flash given an address.

Parameters
flashPointer to SPI Flash Instance.
flashAddressThe flash address to read the data

Definition at line 455 of file spiFlash.c.

◆ spiFlash_exit4ByteAddr()

u8 spiFlash_exit4ByteAddr ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Exit 4-byte addressing.

Parameters
flashPointer to SPI Flash Instance.
Returns
SPI Flash status, 3-> skip

Definition at line 400 of file spiFlash.c.

◆ spiFlash_f2m_dual()

void spiFlash_f2m_dual ( spiFlash_instance_t * flash,
u32 flashAddress,
uintptr_t memoryAddress,
u32 size )

#include <spiFlash.h>

This function read data from FlashAddress and copy to memoryAddress of specific size with dual data line.

Parameters
spiSPI port base address
flashAddressThe flash address to read the data
memoryAddressThe RAM address to write the data
sizeThe size of data to copy
Note
Make sure hardware need to connect both Data0 and Data1 port. Else, it would not work.

Definition at line 329 of file spiFlash.c.

◆ spiFlash_f2m_quad()

void spiFlash_f2m_quad ( spiFlash_instance_t * flash,
u32 flashAddress,
uintptr_t memoryAddress,
u32 size )

#include <spiFlash.h>

This function read data from FlashAddress and copy to memoryAddress of specific size with quad data line.

Parameters
spiSPI port base address
flashAddressThe flash address to read the data
memoryAddressThe RAM address to write the data
sizeThe size of data to copy
Note
Make sure hardware need to connect all data ports. Else, it would not work.

Definition at line 336 of file spiFlash.c.

◆ spiFlash_f2m_single()

void spiFlash_f2m_single ( spiFlash_instance_t * flash,
u32 flashAddress,
uintptr_t memoryAddress,
u32 size )

#include <spiFlash.h>

This function read data from FlashAddress and copy to memoryAddress of specific size with single data line.

Parameters
spiSPI port base address
flashAddressThe flash address to read the data
memoryAddressThe RAM address to write the data
sizeThe size of data to copy

Definition at line 322 of file spiFlash.c.

◆ spiFlash_initController()

void spiFlash_initController ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Initialize SPI setting.

Parameters
flashPointer to SPI Flash Instance.
Note
It will check if user provide a correct value to SPI setting. Else, default value is used.

Definition at line 33 of file spiFlash.c.

◆ spiFlash_lockGlobal()

void spiFlash_lockGlobal ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Globally locks the SPI flash.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 418 of file spiFlash.c.

◆ spiFlash_lookup()

const spiFlash_info_t * spiFlash_lookup ( u32 detected_id)

#include <spiFlash.h>

Identify SPI Flash by looking up User Flash Table and known flash table.

Parameters
detected_idDetected JEDEC ID.
tablePointer to SPI Flash Info Instance.
Returns
SPI Flash Info
Note
The sequence of the function:
  • Check User Flash Table, if exist, return SPI Flash Info.
  • Fall Back to Known Flash Table if user Flash doesn't exist/match.
  • If match, then return the table info.
  • Else, return NULL.

Definition at line 143 of file spiFlash.c.

◆ spiFlash_probe()

spiFlash_status_t spiFlash_probe ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Main wrapper function to initialize the SPI Flash.

Parameters
flashPointer to the SPI Flash instance.
Warning
Efinix recommends that users use spiFlash_probe for initialization instead of calling spiFlash_applyConfig directly.
Note
The initialization sequence is as follows:
  • Initialize the SPI driver with the user configuration (falls back to default settings if input is invalid).
  • Release the flash from Deep Power-Down mode.
  • Read the JEDEC ID.
  • Identify the SPI Flash by cross-referencing the detected ID with the User Flash Table and Known Flash Table.
  • Load default commands for 4-byte exit, status read, and status write.
  • Check for and apply hardware quirks for special handling.
  • Ensure the device returns to 3-Byte Addressing Mode.
  • Execute the user-provided custom setup function (post_init_hook).
Returns
spiFlash_status_t Status of the initialization process.

Definition at line 62 of file spiFlash.c.

◆ spiFlash_read_single()

void spiFlash_read_single ( spiFlash_instance_t * flash,
u32 flashAddress,
u8 * buffer,
u32 len )

#include <spiFlash.h>

Read N byte from Flash using standard read mode via single Data Line.

Parameters
flashPointer to SPI Flash Instance.
flashAddressThe Flash address to read the data
bufferThe variable that stored the data.
lenThe length of data to be read.

Definition at line 270 of file spiFlash.c.

◆ spiFlash_readId()

u8 spiFlash_readId ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Select and Read Device ID from spiFlash.

Parameters
flashPointer to SPI Flash Instance.
Returns
SPI Flash status

Definition at line 125 of file spiFlash.c.

◆ spiFlash_readJedecId()

u32 spiFlash_readJedecId ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Select and read JEDEC ID from spiFlash.

Parameters
flashPointer to SPI Flash Instance.
Returns
SPI Flash status

Definition at line 134 of file spiFlash.c.

◆ spiFlash_readStatusReg()

u8 spiFlash_readStatusReg ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Read Status Register.

Parameters
flashPointer to SPI Flash Instance.
Returns
Value of status

Definition at line 294 of file spiFlash.c.

◆ spiFlash_registerFlash()

void spiFlash_registerFlash ( const spiFlash_info_t * table,
size_t count )

#include <spiFlash.h>

Register Custom Flash to the driver.

Parameters
tablePointer to SPI Flash Info Instance.
countThe number of entry in the table.
Warning
User should use spiFlash_register to register flash, and it will call spiFlash_registerFlash to store the pointer and count of user flash table.

Definition at line 27 of file spiFlash.c.

◆ spiFlash_unlockGlobal()

void spiFlash_unlockGlobal ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Globally unlocks the SPI flash.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 427 of file spiFlash.c.

◆ spiFlash_verify()

spiFlash_status_t spiFlash_verify ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Verify spiFlash.

Parameters
flashPointer to SPI Flash Instance.
Returns
SPI Flash Status
Note
The following are the sequence:
  1. Call spiFlash_readJedecId to obtain jedec_id.
  2. Hardware Sanity Check.
  3. Call spiFlash_lookup to ensure there is known flash.
  4. Return SPI Flash Status.

Definition at line 164 of file spiFlash.c.

◆ spiFlash_waitBusy()

spiFlash_status_t spiFlash_waitBusy ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Wait for spiFlash to be free.

Parameters
flashPointer to SPI Flash Instance.
Returns
SPI Flash status, 1 -> timeout, 0-> Ok

Definition at line 436 of file spiFlash.c.

◆ spiFlash_wake()

void spiFlash_wake ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Select spi and wake up SPI Flash.

Parameters
flashPointer to SPI Flash Instance.
Note
Make sure to used it to ensure the device is in operation state before start communicate with the device.

Definition at line 100 of file spiFlash.c.

◆ spiFlash_write_single()

u8 spiFlash_write_single ( spiFlash_instance_t * flash,
u32 flashAddress,
u8 * src,
u32 len )

#include <spiFlash.h>

Write N byte to Flash using standard write mode via single Data Line.

Parameters
flashPointer to SPI Flash Instance.
flashAddressThe Flash address to read the data
srcThe source of data to be written.
lenThe length of data to be written.
Returns
SPI Flash Status.
Note
Used to write 256 byte Only!

Definition at line 249 of file spiFlash.c.

◆ spiFlash_writeStatusReg()

void spiFlash_writeStatusReg ( spiFlash_instance_t * flash,
u8 data )

#include <spiFlash.h>

Write Status Register.

Parameters
flashPointer to SPI Flash Instance.
data8-bit data.

Definition at line 313 of file spiFlash.c.