FLASH

[English]

FLASH API Status

API

BK7256

BK7256_cp1

bk_flash_driver_init()

Y

Y

bk_flash_driver_deinit()

Y

Y

bk_flash_set_line_mode()

Y

Y

bk_flash_get_line_mode()

Y

Y

bk_flash_get_id()

Y

Y

bk_flash_set_clk_dpll()

Y

Y

bk_flash_set_clk_dco()

Y

Y

bk_flash_write_enable()

Y

Y

bk_flash_write_disable()

Y

Y

bk_flash_set_protect_type()

Y

Y

bk_flash_get_protect_type()

Y

Y

bk_flash_read_status_reg()

Y

Y

bk_flash_write_status_reg()

Y

Y

bk_flash_erase_sector()

Y

Y

bk_flash_write_bytes()

Y

Y

bk_flash_read_bytes()

Y

Y

FLASH API Reference

Header File

Functions

bk_err_t bk_flash_driver_init(void)

Init the flash driver.

This API init the resoure common:

  • Init flash driver control memory

Attention

1. This API should be called before any other flash APIs.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_driver_deinit(void)

Deinit the flash driver.

This API free all resource related to flash and disable flash.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_set_line_mode(flash_line_mode_t line_mode)

Set flash line mode.

Parameters

line_mode – flash line mode

Returns

  • BK_OK: succeed

  • others: other errors.

flash_line_mode_t bk_flash_get_line_mode(void)

Get flash line mode.

Returns

flash line mode

uint32_t bk_flash_get_id(void)

Get flash id.

Returns

flash line mode

bk_err_t bk_flash_set_clk_dpll(void)

Set flash clock dpll.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_set_clk_dco(void)

Set flash clock dco.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_write_enable(void)

Enable flash write.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_write_disable(void)

Disable flash write.

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_set_protect_type(flash_protect_type_t type)

Set flash protect type.

Parameters

type – flash protect type

Returns

  • BK_OK: succeed

  • others: other errors.

flash_protect_type_t bk_flash_get_protect_type(void)

Get flash protect type.

Returns

the flash protect type

uint16_t bk_flash_read_status_reg(void)

Get flash status register value.

Returns

the flash status register value

bk_err_t bk_flash_write_status_reg(uint16_t status_reg_data)

Set flash status register value.

Parameters

status_reg_data – the flash status register data

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_erase_sector(uint32_t address)

Erase a sector of flash, use flash command 0x20.

Parameters

address – flash address

Returns

  • BK_OK: succeed

  • BK_ERR_FLASH_ADDR_OUT_OF_RANGE: flash address is out of range

  • others: other errors.

bk_err_t bk_flash_write_bytes(uint32_t address, const uint8_t *user_buf, uint32_t size)

Write data to flash.

Parameters
  • address – address to write

  • user_buf – the pointer to data which is to write

  • size – size to write

Returns

  • BK_OK: succeed

  • BK_ERR_FLASH_ADDR_OUT_OF_RANGE: flash address is out of range

  • others: other errors.

bk_err_t bk_flash_read_bytes(uint32_t address, uint8_t *user_buf, uint32_t size)

Read data from flash.

Parameters
  • address – address to read

  • user_buf – the buffer to read the data

  • size – size to read

Returns

  • BK_OK: succeed

  • BK_ERR_FLASH_ADDR_OUT_OF_RANGE: flash address is out of range

  • others: other errors.

bk_err_t bk_flash_read_word(uint32_t address, uint32_t *user_buf, uint32_t size)

Read data from flas.

Parameters
  • address – address to read

  • user_buf – the buffer to read the data, intend to psram addr must aline by 4 Bytes

  • size – size to read, length uint by byte

Returns

  • BK_OK: succeed

  • BK_ERR_FLASH_ADDR_OUT_OF_RANGE: flash address is out of range

  • others: other errors.

bool bk_flash_is_driver_inited(void)

Get flash init flag.

Returns

the flash init flag

uint32_t bk_flash_get_current_total_size(void)

Get flash total size.

Returns

the flash total size

bk_err_t bk_flash_register_ps_suspend_callback(flash_ps_callback_t ps_suspend_cb)

Register flash power save suspend callback.

Parameters

ps_suspend_cb – power save suspend callback

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_register_ps_resume_callback(flash_ps_callback_t ps_resume_cb)

Register flash power save resume callback.

Parameters

ps_resume_cb – power save resume callback

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_clk_switch(uint32_t flash_speed_type, uint32_t modules)

Modify flash speed type.

Parameters
  • flash_speed_type – the high/low type of flash clock

  • modules – the app module to control the flash spped

Returns

  • BK_OK: succeed

  • others: other errors.

bk_err_t bk_flash_register_wait_cb(flash_wait_callback_t wait_cb)

register a callback to be called when flash is busy waiting. WARNING/NOTES:

    1. the wait_cb code is better in ITCM to avoid running in flash.
                  or the wait_cb will be blocked until flash is idle.
    2.The wait_cb will be called forever until flash is idle, so the implemetion of
      wait_cb should garante the programm is safe.

Parameters

wait_cb:If – flash is writing/erasing, it will block all of other applications. But maybe the application can’t be blocked when flash is writing/erasing. So the application should register this wait_cb to flash. When flash is writing/erasing, it will call this wait_cb

Returns

  • BK_OK: succeed

  • others: registered too many(>4) wait_cb to flash.

bk_err_t bk_flash_unregister_wait_cb(flash_wait_callback_t wait_cb)

unregister the wait_cb from flash waiting.

Parameters

wait_cb:If – flash is writing/erasing, it will block all of other applications. But maybe the application can’t be blocked when flash is writing/erasing. So the application should register this wait_cb to flash. When flash is writing/erasing, it will call this wait_cb

Returns

  • BK_OK: succeed

  • others: The wait_cb isn’t registered to flash.

FLASH API Typedefs

Header File

Macros

BK_ERR_FLASH_NOT_INIT

FLASH driver not init

BK_ERR_FLASH_ADDR_OUT_OF_RANGE

FLASH address is out of range

BK_ERR_FLASH_PARTITION_NOT_FOUND

FLASH partition not found

BK_ERR_FLASH_WAIT_CB_FULL

FLASH wait cb is registered too much

BK_ERR_FLASH_WAIT_CB_NOT_REGISTER

FLASH wait cb is not registered but tried to unregister

FLASH_ATE_BIT
FLASH_MAC_BIT

Type Definitions

typedef void (*flash_ps_callback_t)(void)
typedef void (*flash_wait_callback_t)(void)

Enumerations

enum flash_line_mode_t

Values:

enumerator FLASH_LINE_MODE_TWO

flash line mode 2

enumerator FLASH_LINE_MODE_FOUR

flash line mode 4

enum flash_protect_type_t

Values:

enumerator FLASH_PROTECT_NONE

flash protect type none

enumerator FLASH_PROTECT_ALL

flash protect type all

enumerator FLASH_PROTECT_HALF

flash protect type half

enumerator FLASH_UNPROTECT_LAST_BLOCK

flash protect type unprotect last block

enum flash_speed_type_t

Values:

enumerator FLASH_SPEED_HIGH
enumerator FLASH_SPEED_LOW
enum flash_ctrl_module_t

Values:

enumerator FLASH_ATE
enumerator FLASH_MAC

Header File

Type Definitions

typedef uint8_t flash_unit_t

flash uint id

Enumerations

enum flash_op_cmd_t

Values:

enumerator FLASH_OP_CMD_WREN

flash command write enable

enumerator FLASH_OP_CMD_WRDI

flash command write disable

enumerator FLASH_OP_CMD_RDSR

flash command read status register

enumerator FLASH_OP_CMD_WRSR

flash command write status register

enumerator FLASH_OP_CMD_READ

flash command read data

enumerator FLASH_OP_CMD_RDSR2

flash command read status register-2

enumerator FLASH_OP_CMD_WRSR2

flash command write status register-2

enumerator FLASH_OP_CMD_PP

flash command page program

enumerator FLASH_OP_CMD_SE

flash command sector erase

enumerator FLASH_OP_CMD_BE1

flash command block erase-1

enumerator FLASH_OP_CMD_BE2

flash command block erase-2

enumerator FLASH_OP_CMD_CE

flash command chip erase

enumerator FLASH_OP_CMD_DP
enumerator FLASH_OP_CMD_RFDP
enumerator FLASH_OP_CMD_RDID

flash command read device id

enumerator FLASH_OP_CMD_HPM

flash command high performance mode

enumerator FLASH_OP_CMD_CRMR
enumerator FLASH_OP_CMD_CRMR2
enum flash_mode_t

Values:

enumerator FLASH_MODE_STANDARD

flash standard mode

enumerator FLASH_MODE_DUAL

flash dual mode

enumerator FLASH_MODE_QUAD

flash quad mode