关于FLASH的使用问题

maike
Posts: 9
Joined: Wed Jun 29, 2016 6:29 pm

关于FLASH的使用问题

Postby maike » Wed Jun 29, 2016 6:52 pm

请问一下
就是如果我的板子是2MB的 SPI flash,如果我在编译和烧写固件的时候都选择的是1MB的配置,我还能在自己的程序里面时候后面的1MB来做自己的一些存储吗?

ESP_Rubin
Posts: 222
Joined: Wed Jun 29, 2016 11:59 am

【Feedback】关于FLASH的使用问题

Postby ESP_Rubin » Thu Jun 30, 2016 10:54 am

可以的,需要注意flash map的地址,你的数据不能覆盖到我们系统预留的空间内

maike
Posts: 9
Joined: Wed Jun 29, 2016 6:29 pm

Re: 关于FLASH的使用问题

Postby maike » Fri Jul 01, 2016 10:12 am

我试过了,如果我编译都是1MB(512KB+512KB)的方式,烧写也是1MB的烧写方式,flash本身是2MB。后面我在SPI flash操作的时候不能正常读写呢(系统采用的RTOS),这个我应该做什么修改才能操作后面的1MBflash空间呢?

ESP_Rubin
Posts: 222
Joined: Wed Jun 29, 2016 11:59 am

Re: 关于FLASH的使用问题

Postby ESP_Rubin » Fri Jul 01, 2016 3:49 pm

你可以参考下面这段代码或者我们SDK中spiffs_test,注意地址设置:
#include "esp_common.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "spiffs.h"
#include "spiffs_nucleus.h"


#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FS1_FLASH_SIZE (128*1024)
#define FS1_FLASH_ADDR (4096*1024)
#define SECTOR_SIZE (4*1024)
#define LOG_BLOCK SECTOR_SIZE
#define LOG_PAGE (128)
#define FD_BUF_SIZE (32*4)
#define CACHE_BUF_SIZE (LOG_PAGE+32)*8


void spiffs_fs1_init(void)
{
struct esp_spiffs_config config;
config.phys_size = FS1_FLASH_SIZE;
config.phys_addr = FS1_FLASH_ADDR;
config.phys_erase_block = SECTOR_SIZE;
config.log_block_size = LOG_BLOCK;
config.log_page_size = LOG_PAGE;
config.fd_buf_size = FD_BUF_SIZE * 2;
config.cache_buf_size = CACHE_BUF_SIZE;
esp_spiffs_init(&config);
}

void spiffs_fs1_write_read(void)
{
char *buf="hello world";
char out[20] = {0};
int pfd = open("myfile", O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
if(pfd <= 3) {
printf("open file error \n");
}
int write_byte = write(pfd, buf, strlen(buf));
if (write_byte <= 0)
{
printf("write file error \n");
}

close(pfd);

open("myfile",O_RDWR);
if (read(pfd, out, 20) < 0)
printf("read errno \n");
close(pfd);
printf("--> %s <--\n", out);
}


/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
void user_init(void)
{
spiffs_fs1_init();
spiffs_fs1_write_read();
printf("----------------------SDK version:%s\n", system_get_sdk_version());
}

Who is online

Users browsing this forum: No registered users and 288 guests