HS6621CG 的片上 Flash 读写
HS6621CG 的片上 Flash 读写
主要是接口调用的第三个参数需要注意,第三个参数为地址的偏移量,而不是直接填入地址
内存分布
片上Flash 的地址范围为 0x00400000 - 0x00800000,芯片上带有一个 4M 大小的片上 Flash。
HS6621C memory consists of ROM, RAM, external SPI Flash. Cache have dedicated RAM. The memery map is shown as follow:
函数原型
/**
* @brief sf erase
*
* @param[in] sf sf object
* @param[in] cs cs (0 ~ SFB_CS_NUM-1)
* @param[in] addr sflash address
* @param[in] length length
**/
void sf_erase(HS_SF_Type *sf, uint32_t cs, uint32_t addr, uint32_t length);
/**
* @brief sf write
*
* @param[in] sf sf object
* @param[in] cs cs (0 ~ SFB_CS_NUM-1)
* @param[in] addr sflash address
* @param[in] data write data
* @param[in] length length
**/
void sf_write(HS_SF_Type *sf, uint32_t cs, uint32_t addr, const void *data, uint32_t length);
/**
* @brief sf read
*
* @param[in] sf sf object
* @param[in] cs cs (0 ~ SFB_CS_NUM-1)
* @param[in] addr sflash address
* @param[out] data read data buffer
* @param[in] length length
**/
void sf_read(HS_SF_Type *sf, uint32_t cs, uint32_t addr, void *data, uint32_t length);
例程
/*********************************************************************
* INCLUDES
*/
#include "peripheral.h"
/*********************************************************************
* PUBLIC FUNCTIONS
*/
void example_sf(void)
{
CO_ALIGN(8) uint8_t write_buffer[100];
CO_ALIGN(8) uint8_t read_buffer[100];
int i;
for(i=0; i<100; ++i){
write_buffer[i] = i;
}
/*
* Inside flash: sf=HS_SF, cs=0
*/
// Enable flash
sf_enable(HS_SF, 0);
// Erase sector in 128K
sf_erase(HS_SF, 0, 128*1024, 4*1024);
// Read 100 bytes in 128K, it should be all 0xFF
sf_read(HS_SF, 0, 128*1024, read_buffer, 100);
// Write 100 bytes to 128K
sf_write(HS_SF, 0, 128*1024, write_buffer, 100);
// Read 100 bytes in 128K, it should be same as write_buffer
sf_read(HS_SF, 0, 128*1024, read_buffer, 100);
}
- 下面的128 * 1024 是偏移量,起始地址为 0x00400000,也就是从 4M 空间的 128K 开始读写
/*
* 使能片上 Flash
* 0 为片上Flash
*/
sf_enable(HS_SF, 0);
/*
* 这是我当时最头疼的一段,没弄懂128*1024是什么
*/
// Erase sector in 128K
sf_erase(HS_SF, 0, 128*1024, 4*1024);
// Read 100 bytes in 128K, it should be all 0xFF
sf_read(HS_SF, 0, 128*1024, read_buffer, 100);
// Write 100 bytes to 128K
sf_write(HS_SF, 0, 128*1024, write_buffer, 100);
- 初入职场的新人,网上这颗芯片的资料较少,这只是我在工程中自己的一些体会,如有不足之处还望多多包涵,也欢迎交流