Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
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_init_controller (spiFlash_instance_t *flash)
 Initialize SPI setting.
spiFlash_status_t spiFlash_probe (spiFlash_instance_t *flash, const spiFlash_info_t *user_flash)
 The main wrapper for initialize SPI Flash.

SPI Flash (Public API - Identification)

Used to identify SPI Flash.

u8 spiFlash_read_id (spiFlash_instance_t *flash)
 Select and Read Device ID from spiFlash.
u32 spiFlash_jedec_id (spiFlash_instance_t *flash)
 Select and read JEDEC ID from spiFlash.
spiFlash_status_t spiFlash_verify (spiFlash_instance_t *flash, const spiFlash_info_t *user_flash)
 Verify spiFlash.

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 (spiFlash_instance_t *flash, u32 flashAddress, u8 *src, u32 len)
 Write N byte to Flash using standard write mode.
u8 spiFlash_write_quad (spiFlash_instance_t *flash, u32 flashAddress, u8 *src, u32 len)
 Write N byte to Flash using quad write mode.
void spiFlash_read (spiFlash_instance_t *flash, u32 flashAddress, u8 *buffer, u32 len)
 Read N byte from Flash using standard read mode.
void spiFlash_read_quad (spiFlash_instance_t *flash, u32 flashAddress, u8 *buffer, u32 len)
 Read N byte from Flash using quad read mode.
void spiFlash_f2m (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_dual_f2m (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_quad_f2m (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_globalLock (spiFlash_instance_t *flash)
 Globally locks the SPI flash.
void spiFlash_writeEnable (spiFlash_instance_t *flash)
 Set Write Enable Latch.
void spiFlash_globalUnlock (spiFlash_instance_t *flash)
 Globally unlocks the SPI flash.
void spiFlash_enable_quad_access (spiFlash_instance_t *flash)
 Set Write Enable Latch and set Quad Enable bit to enable Quad SPI.
void spiFlash_sectorErase (spiFlash_instance_t *flash, u32 flashAddress)
 Erases a sector of the SPI flash given an address.

Function Documentation

◆ spiFlash_dual_f2m()

void spiFlash_dual_f2m ( 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.

◆ spiFlash_enable_quad_access()

void spiFlash_enable_quad_access ( spiFlash_instance_t * flash)

#include <spiFlash.h>

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

Parameters
flashPointer to SPI Flash Instance.

Definition at line 375 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 413 of file spiFlash.c.

◆ spiFlash_f2m()

void spiFlash_f2m ( 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 349 of file spiFlash.c.

◆ spiFlash_globalLock()

void spiFlash_globalLock ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Globally locks the SPI flash.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 431 of file spiFlash.c.

◆ spiFlash_globalUnlock()

void spiFlash_globalUnlock ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Globally unlocks the SPI flash.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 440 of file spiFlash.c.

◆ spiFlash_init_controller()

void spiFlash_init_controller ( 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 24 of file spiFlash.c.

◆ spiFlash_jedec_id()

u32 spiFlash_jedec_id ( 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 181 of file spiFlash.c.

◆ spiFlash_probe()

spiFlash_status_t spiFlash_probe ( spiFlash_instance_t * flash,
const spiFlash_info_t * user_flash )

#include <spiFlash.h>

The main wrapper for initialize SPI Flash.

Parameters
flashPointer to SPI Flash Instance.
user_flashPointer to SPI Flash Info Instance.
Note
The following are the work flow of this function:
  • Initialize SPI driver with User Config, fallback with default config if incorrect input.
  • Release flash from deep power down.
  • Identify Flash in terms of Type, brand, JEDEC_ID ,etc ...
  • Load Default Command for exit 4 byte, read status, write status.
  • Checking for quirk for special handling.
  • Return to 3-Byte Addressing Mode.
  • Run user-provided custom setup function (post_init_hook)
Returns
SPI Flash status

Definition at line 44 of file spiFlash.c.

◆ spiFlash_quad_f2m()

void spiFlash_quad_f2m ( 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.

◆ spiFlash_read()

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

#include <spiFlash.h>

Read N byte from Flash using standard read mode.

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 279 of file spiFlash.c.

◆ spiFlash_read_id()

u8 spiFlash_read_id ( 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 172 of file spiFlash.c.

◆ spiFlash_read_quad()

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

#include <spiFlash.h>

Read N byte from Flash using quad read mode.

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 294 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 320 of file spiFlash.c.

◆ spiFlash_sectorErase()

void spiFlash_sectorErase ( 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 468 of file spiFlash.c.

◆ spiFlash_verify()

spiFlash_status_t spiFlash_verify ( spiFlash_instance_t * flash,
const spiFlash_info_t * user_flash )

#include <spiFlash.h>

Verify spiFlash.

Parameters
flashPointer to SPI Flash Instance.
user_flashPointer to Flash Info Instance.
Returns
SPI Flash Status
Note
The following are the sequence:
  1. Call spiFlash_jedec_id to obtain jedec_id.
  2. Hardware Sanity Check.
  3. Call internal func (identifyFlash) to ensure there is known flash.
  4. Return SPI Flash Status.

Definition at line 136 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 449 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 76 of file spiFlash.c.

◆ spiFlash_write()

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

#include <spiFlash.h>

Write N byte to Flash using standard write mode.

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 236 of file spiFlash.c.

◆ spiFlash_write_quad()

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

#include <spiFlash.h>

Write N byte to Flash using quad write mode.

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 258 of file spiFlash.c.

◆ spiFlash_writeEnable()

void spiFlash_writeEnable ( spiFlash_instance_t * flash)

#include <spiFlash.h>

Set Write Enable Latch.

Parameters
flashPointer to SPI Flash Instance.

Definition at line 405 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 339 of file spiFlash.c.