FLASH API

[中文]

FLASH memory API interface.

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.

void bk_flash_lock(void)

Lock current operation.

Uses mutex lock to protect concurrent operations of flash read/write/… The default flash driver layer API doesn’t add lock/unlock to improve performance. it should be called in APP-layer.

Param

void bk_flash_unlock(void)

unlock current operation.

Param

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

uint32_t bk_flash_get_capacity_bytes(void)

Get flash capacity.

Returns

flash size with bytes

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_erase_block(uint32_t address)

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

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_enter_deep_sleep(void)

Entry flash deep power-down flash, use flash command 0xB9.

Returns

  • BK_OK: succeed

  • BK_FAIL: failed

bk_err_t bk_flash_exit_deep_sleep(void)

Exit flash deep power-down flash, use flash command 0xAB.

Returns

  • BK_OK: succeed

  • BK_FAIL: failed

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.

BK_OK: succeed

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

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_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.

bk_err_t bk_flash_set_operate_status(flash_op_status_t status)

Set flash operate status.

Parameters

flash – operate status

Returns

  • BK_OK: succeed

  • others: other errors.

flash_op_status_t bk_flash_get_operate_status(void)

Get flash operate status.

Returns

flash operate status