HPM SDK
HPMicro Software Development Kit
hpm_serial_nor.c File Reference
#include "hpm_serial_nor.h"
#include "hpm_clock_drv.h"

Macros

#define SERIALNOR_CMD_PAGE_PROGRAM_1_1_4_3B   (0x32U)
 
#define SERIALNOR_CMD_READ_SDR_1_2_2_4B   (0xBCU)
 
#define SERIALNOR_CMD_READ_SDR_1_2_2_3B   (0xBBU)
 
#define SERIALNOR_CMD_READ_SDR_1_1_2_3B   (0x3BU)
 
#define SERIALNOR_CMD_READ_SDR_1_1_2_4B   (0x3CU)
 
#define SERIALNOR_CMD_WRITE_STATUS_REG3   (0x11U)
 
#define SERIALNOR_CMD_READ_STATUS_REG3   (0x15U)
 
#define kSERIALNOR_CMD_WRITE_STATUS_REG2_VIA_0X31   (0x31U)
 
#define kSERIALNOR_CMD_READ_STATUS_REG2_VIA_0X31   (0x35U)
 
#define MAX_24BIT_ADDRESSING_SIZE   ((1UL << 24))
 
#define MAX_24BIT_ADDR_SIZE_IN_KBYTES   ((1UL << 24) / SIZE_1KB)
 
#define SPI_READ_SFDP_FREQUENCY   (10000000U)
 

Enumerations

enum  spi_nor_quad_enable_seq_t {
  spi_nor_quad_en_auto_or_ignore = 0U , spi_nor_quad_en_set_bit6_in_status_reg1 = 1U , spi_nor_quad_en_set_bit1_in_status_reg2 = 2U , spi_nor_quad_en_set_bit7_in_status_reg2 = 3U ,
  spi_nor_quad_en_set_bi1_in_status_reg2_via_0x31_cmd = 4U
}
 QE bit enable sequence option. More...
 

Functions

static hpm_stat_t hpm_serial_nor_read_sfdp_info (hpm_serial_nor_t *flash, jedec_info_table_t *tbl, bool address_shift_enable)
 
static hpm_stat_t hpm_spi_get_read_para (hpm_serial_nor_t *flash, jedec_info_table_t *jedec_info)
 
static hpm_stat_t hpm_spi_get_program_para (hpm_serial_nor_t *flash, jedec_info_table_t *jedec_info)
 
static hpm_stat_t hpm_spi_nor_read_sfdp (hpm_serial_nor_t *flash, uint32_t addr, uint32_t *buffer, uint32_t bytes)
 
static hpm_stat_t hpm_spi_nor_set_command (hpm_serial_nor_t *flash, uint8_t cmd)
 
static hpm_stat_t get_page_sector_block_size_from_sfdp (hpm_serial_nor_info_t *config, jedec_info_table_t *tbl)
 
static hpm_stat_t hpm_spi_nor_read_status_register (hpm_serial_nor_t *flash, uint8_t *reg_data, uint8_t status_reg)
 
static hpm_stat_t hpm_spi_nor_write_status_register (hpm_serial_nor_t *flash, uint8_t reg_data, uint8_t status_reg)
 
static hpm_stat_t prepare_quad_mode_enable_sequence (hpm_serial_nor_t *flash, jedec_info_table_t *jedec_info)
 
hpm_stat_t hpm_serial_nor_is_busy (hpm_serial_nor_t *flash)
 determine whether the serial nor flash is busy More...
 
hpm_stat_t hpm_serial_nor_write_enable (hpm_serial_nor_t *flash)
 set serial nor flash write enable More...
 
hpm_stat_t hpm_serial_nor_erase_chip (hpm_serial_nor_t *flash)
 erase the serial nor flash chip More...
 
hpm_stat_t hpm_serial_nor_erase_block_blocking (hpm_serial_nor_t *flash, uint32_t block_addr)
 erase the serial nor flash block using blocking transfer More...
 
hpm_stat_t hpm_serial_nor_erase_sector_blocking (hpm_serial_nor_t *flash, uint32_t sector_addr)
 erase the serial nor flash sector using blocking transfer More...
 
hpm_stat_t hpm_serial_nor_erase_block_nonblocking (hpm_serial_nor_t *flash, uint32_t block_addr)
 erase the serial nor flash block using nonblocking transfer More...
 
hpm_stat_t hpm_serial_nor_erase_sector_nonblocking (hpm_serial_nor_t *flash, uint32_t sector_addr)
 erase the serial nor flash sector using nonblocking transfer More...
 
hpm_stat_t hpm_serial_nor_erase_blocking (hpm_serial_nor_t *flash, uint32_t start, uint32_t length)
 erase the serial nor flash specified start address and length using blocking transfer More...
 
hpm_stat_t hpm_serial_nor_program_blocking (hpm_serial_nor_t *flash, uint8_t *buf, uint32_t data_len, uint32_t address)
 program data to the specified serial nor flash address using blocking transfer More...
 
hpm_stat_t hpm_serial_nor_page_program_nonblocking (hpm_serial_nor_t *flash, uint8_t *buf, uint32_t data_len, uint32_t address)
 program data to the page nor flash address using nonblocking transfer More...
 
hpm_stat_t hpm_serial_nor_read (hpm_serial_nor_t *flash, uint8_t *buf, uint16_t data_len, uint32_t address)
 read the data of specified serial nor flash address More...
 
hpm_stat_t hpm_serial_nor_init (hpm_serial_nor_t *flash, hpm_serial_nor_info_t *info)
 the serial nor flash initialization More...
 
hpm_stat_t hpm_serial_nor_get_info (hpm_serial_nor_t *flash, hpm_serial_nor_info_t *info)
 get the serial nor flash information More...
 

Macro Definition Documentation

◆ kSERIALNOR_CMD_READ_STATUS_REG2_VIA_0X31

#define kSERIALNOR_CMD_READ_STATUS_REG2_VIA_0X31   (0x35U)

◆ kSERIALNOR_CMD_WRITE_STATUS_REG2_VIA_0X31

#define kSERIALNOR_CMD_WRITE_STATUS_REG2_VIA_0X31   (0x31U)

◆ MAX_24BIT_ADDR_SIZE_IN_KBYTES

#define MAX_24BIT_ADDR_SIZE_IN_KBYTES   ((1UL << 24) / SIZE_1KB)

◆ MAX_24BIT_ADDRESSING_SIZE

#define MAX_24BIT_ADDRESSING_SIZE   ((1UL << 24))

◆ SERIALNOR_CMD_PAGE_PROGRAM_1_1_4_3B

#define SERIALNOR_CMD_PAGE_PROGRAM_1_1_4_3B   (0x32U)

◆ SERIALNOR_CMD_READ_SDR_1_1_2_3B

#define SERIALNOR_CMD_READ_SDR_1_1_2_3B   (0x3BU)

◆ SERIALNOR_CMD_READ_SDR_1_1_2_4B

#define SERIALNOR_CMD_READ_SDR_1_1_2_4B   (0x3CU)

◆ SERIALNOR_CMD_READ_SDR_1_2_2_3B

#define SERIALNOR_CMD_READ_SDR_1_2_2_3B   (0xBBU)

◆ SERIALNOR_CMD_READ_SDR_1_2_2_4B

#define SERIALNOR_CMD_READ_SDR_1_2_2_4B   (0xBCU)

◆ SERIALNOR_CMD_READ_STATUS_REG3

#define SERIALNOR_CMD_READ_STATUS_REG3   (0x15U)

◆ SERIALNOR_CMD_WRITE_STATUS_REG3

#define SERIALNOR_CMD_WRITE_STATUS_REG3   (0x11U)

◆ SPI_READ_SFDP_FREQUENCY

#define SPI_READ_SFDP_FREQUENCY   (10000000U)

Enumeration Type Documentation

◆ spi_nor_quad_enable_seq_t

QE bit enable sequence option.

Enumerator
spi_nor_quad_en_auto_or_ignore 

Auto enable or ignore

spi_nor_quad_en_set_bit6_in_status_reg1 

QE bit is at bit6 in Status register 1

spi_nor_quad_en_set_bit1_in_status_reg2 

QE bit is at bit1 in Status register 2 register 2

spi_nor_quad_en_set_bit7_in_status_reg2 

QE bit is at bit7 in Status register 2

spi_nor_quad_en_set_bi1_in_status_reg2_via_0x31_cmd 

QE bit is in status register 2 and configured by CMD 0x31

Function Documentation

◆ get_page_sector_block_size_from_sfdp()

static hpm_stat_t get_page_sector_block_size_from_sfdp ( hpm_serial_nor_info_t config,
jedec_info_table_t tbl 
)
static

◆ hpm_serial_nor_erase_block_blocking()

hpm_stat_t hpm_serial_nor_erase_block_blocking ( hpm_serial_nor_t flash,
uint32_t  block_addr 
)

erase the serial nor flash block using blocking transfer

Note
the erase block address must be block alignment
Parameters
[in]hostthe serial nor context
[in]block_addrthe serial nor flash block address
Returns
hpm_stat_t: status_success if erase block success

◆ hpm_serial_nor_erase_block_nonblocking()

hpm_stat_t hpm_serial_nor_erase_block_nonblocking ( hpm_serial_nor_t flash,
uint32_t  block_addr 
)

erase the serial nor flash block using nonblocking transfer

Note
the erase block address must be block alignment, it'not wait flash busy status.
Parameters
[in]hostthe serial nor context
[in]block_addrthe serial nor flash block address
Returns
hpm_stat_t: status_success if erase block success

◆ hpm_serial_nor_erase_blocking()

hpm_stat_t hpm_serial_nor_erase_blocking ( hpm_serial_nor_t flash,
uint32_t  start,
uint32_t  length 
)

erase the serial nor flash specified start address and length using blocking transfer

Note
the erase sector address must be sector alignment
Parameters
[in]hostthe serial nor context
[in]sector_addrthe serial nor flash sector address
Returns
hpm_stat_t: status_success if erase success

◆ hpm_serial_nor_erase_chip()

hpm_stat_t hpm_serial_nor_erase_chip ( hpm_serial_nor_t flash)

erase the serial nor flash chip

Parameters
[in]hostthe serial nor context
Returns
hpm_stat_t: status_success if erase chip success

◆ hpm_serial_nor_erase_sector_blocking()

hpm_stat_t hpm_serial_nor_erase_sector_blocking ( hpm_serial_nor_t flash,
uint32_t  sector_addr 
)

erase the serial nor flash sector using blocking transfer

Note
the erase sector address must be sector alignment
Parameters
[in]hostthe serial nor context
[in]sector_addrthe serial nor flash sector address
Returns
hpm_stat_t: status_success if erase sector success

◆ hpm_serial_nor_erase_sector_nonblocking()

hpm_stat_t hpm_serial_nor_erase_sector_nonblocking ( hpm_serial_nor_t flash,
uint32_t  sector_addr 
)

erase the serial nor flash sector using nonblocking transfer

Note
the erase sector address must be sector alignment, it'not wait flash busy status.
Parameters
[in]hostthe serial nor context
[in]sector_addrthe serial nor flash sector address
Returns
hpm_stat_t: status_success if erase sector success

◆ hpm_serial_nor_get_info()

hpm_stat_t hpm_serial_nor_get_info ( hpm_serial_nor_t flash,
hpm_serial_nor_info_t info 
)

get the serial nor flash information

Parameters
[in]hostthe serial nor context
[out]infoserial_nor_flash_info_t
Returns
hpm_stat_t: status_success if get information success

◆ hpm_serial_nor_init()

hpm_stat_t hpm_serial_nor_init ( hpm_serial_nor_t flash,
hpm_serial_nor_info_t info 
)

the serial nor flash initialization

Parameters
[in]hostthe serial nor context
[out]infoserial_nor_flash_info_t
Returns
hpm_stat_t: status_success if initialization success

◆ hpm_serial_nor_is_busy()

hpm_stat_t hpm_serial_nor_is_busy ( hpm_serial_nor_t flash)

determine whether the serial nor flash is busy

Parameters
[in]hostthe serial nor context
Returns
hpm_stat_t: status_spi_nor_flash_is_busy if the serial nor flash is busy

◆ hpm_serial_nor_page_program_nonblocking()

hpm_stat_t hpm_serial_nor_page_program_nonblocking ( hpm_serial_nor_t flash,
uint8_t *  buf,
uint32_t  data_len,
uint32_t  address 
)

program data to the page nor flash address using nonblocking transfer

Parameters
[in]hostthe serial nor context
[in]bufthe data source pointer
[in]data_lenthe data length
[in]addressthe serial nor flash programming address
Returns
hpm_stat_t: status_success if program success

◆ hpm_serial_nor_program_blocking()

hpm_stat_t hpm_serial_nor_program_blocking ( hpm_serial_nor_t flash,
uint8_t *  buf,
uint32_t  data_len,
uint32_t  address 
)

program data to the specified serial nor flash address using blocking transfer

Parameters
[in]hostthe serial nor context
[in]bufthe data source pointer
[in]data_lenthe data length
[in]addressthe serial nor flash programming address
Returns
hpm_stat_t: status_success if program success

◆ hpm_serial_nor_read()

hpm_stat_t hpm_serial_nor_read ( hpm_serial_nor_t flash,
uint8_t *  buf,
uint16_t  data_len,
uint32_t  address 
)

read the data of specified serial nor flash address

Parameters
[in]hostthe serial nor context
[in]bufthe data source pointer
[in]data_lenthe data length
[in]addressthe serial nor flash reading address
Returns
hpm_stat_t: status_success if read success

◆ hpm_serial_nor_read_sfdp_info()

static hpm_stat_t hpm_serial_nor_read_sfdp_info ( hpm_serial_nor_t flash,
jedec_info_table_t tbl,
bool  address_shift_enable 
)
static

◆ hpm_serial_nor_write_enable()

hpm_stat_t hpm_serial_nor_write_enable ( hpm_serial_nor_t flash)

set serial nor flash write enable

Parameters
[in]channelserial nor flash channel
Returns
hpm_stat_t: status_success if write enable success

◆ hpm_spi_get_program_para()

static hpm_stat_t hpm_spi_get_program_para ( hpm_serial_nor_t flash,
jedec_info_table_t jedec_info 
)
static

◆ hpm_spi_get_read_para()

static hpm_stat_t hpm_spi_get_read_para ( hpm_serial_nor_t flash,
jedec_info_table_t jedec_info 
)
static

◆ hpm_spi_nor_read_sfdp()

static hpm_stat_t hpm_spi_nor_read_sfdp ( hpm_serial_nor_t flash,
uint32_t  addr,
uint32_t *  buffer,
uint32_t  bytes 
)
static

◆ hpm_spi_nor_read_status_register()

static hpm_stat_t hpm_spi_nor_read_status_register ( hpm_serial_nor_t flash,
uint8_t *  reg_data,
uint8_t  status_reg 
)
static

◆ hpm_spi_nor_set_command()

static hpm_stat_t hpm_spi_nor_set_command ( hpm_serial_nor_t flash,
uint8_t  cmd 
)
static

◆ hpm_spi_nor_write_status_register()

static hpm_stat_t hpm_spi_nor_write_status_register ( hpm_serial_nor_t flash,
uint8_t  reg_data,
uint8_t  status_reg 
)
static

◆ prepare_quad_mode_enable_sequence()

static hpm_stat_t prepare_quad_mode_enable_sequence ( hpm_serial_nor_t flash,
jedec_info_table_t jedec_info 
)
static