Skip to content

Flash Control (FLASH CTL)


1. Overview

In CI13XX series, Flash is used for multiple purposes, including firmware and user data storage. Normally, user data storage should use the NVdata component APIs. During development/debug or when building a bootloader, you may need to access Flash directly. However, because the Flash device may be accessed concurrently by the CPU core and DNN hardware, direct access is not safe. This module provides Flash control read/write APIs that safely acquire bus control to perform Flash operations.


2. Usage

Function Description
post_write_flash Request to write Flash
post_read_flash Request to read Flash
post_erase_flash Request to erase Flash

Warning

In most cases, use post_write_flash, post_read_flash, and post_erase_flash to meet Flash data needs. To store user NV data, use the NVdata component APIs instead of this module.

3. Example (1)

#include "flash_manage_outside_port.h"

#define WAVE_ADDR  0x1000 // Flash offset address
char wav_format_head[44]; // Read buffer

void read_flash_test(void)
{
    /* Read 44 bytes from Flash @0x1000 into wav_format_head */
    post_read_flash(wav_format_head, WAVE_ADDR, sizeof(wav_format_head));
}

4. Example (2)

Details on how to add, pack, and read files stored in Flash.

  • (1) Create a new file under SDK\projects\sample_xxx\firmware\user_file\, e.g., [0]文本文件.txt, with content “123456789”.

!! note “Note” File names are unrestricted, but prefix with [ID]. Avoid conflicts with ID [60000]. The ID is used by the program to locate the file.

Figure 1

  • (2) Double-click make_partition_bin.bat in SDK\projects\sample_xxx\firmware to pack files into user_file.bin.

  • (3) Example code to read the file content:

#include "ci_flash_data_info.h"
#include "flash_manage_outside_port.h"

char value[512] = {0}; // Read buffer

void read_txt_file(void)
{
    uint32_t tabaddr1 = 0; // File offset in Flash
    uint32_t tabsize1 = 0; // File size

    // Use get_userfile_addr to get offset and size of file with ID 0 in Flash
    if(get_userfile_addr(0, &tabaddr1, &tabsize1) != 0)
    {
        ci_loginfo(LOG_USER,"failed!\n");
    }

    ci_loginfo(LOG_USER,"file addr[%x],file size[%x]!\n",tabaddr1,tabsize1);

    // Read content by passing the offset and size of file ID 0
    post_read_flash(value, tabaddr1, tabsize1);
    ci_loginfo(LOG_USER,"file value[%s]",value);
}
  • (4) Output:
file addr[376020],file size[9]!
file value[123456789]

API Reference