请问一下
就是如果我的板子是2MB的 SPI flash,如果我在编译和烧写固件的时候都选择的是1MB的配置,我还能在自己的程序里面时候后面的1MB来做自己的一些存储吗?
关于FLASH的使用问题
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());
}
#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
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.