Chat freely about anything...

User avatar
By vkthakar
#64819 Hi,

I have tested file service in esp8266 and it works fine.
but issue cause when i have included lwip's headers then fail to open file.

code snippet:

#include "esp_common.h"
#include "uart.h"
#include <fcntl.h>

// if include this files then file system not works.
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"

#define Delay(ms) vTaskDelay(ms / portTICK_RATE_MS);

uint32 user_rf_cal_sector_set(void)
{
flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;

switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
break;

case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
break;

case FLASH_SIZE_16M_MAP_512_512:
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
break;

case FLASH_SIZE_32M_MAP_512_512:
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
break;

default:
rf_cal_sec = 0;
break;
}

return rf_cal_sec;
}



#define FS1_FLASH_SIZE (128*1024)
#define FS1_FLASH_ADDR (3000*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;

printf("esp_spiffs_init return status = %d\r\n",esp_spiffs_init(&config));
}

void spiffs_fs1_write_read(void *parameter)
{
while(1)
{
char *buf="esp8266 file services test in 1.5.0";
char out[50] = {0};
int pfd = open("myfile",O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
// int pfd = open("myfile", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
// int pfd = open("myfile",O_RDWR);;
if(pfd <= 3)
{
printf("open file error error code = %d\r\n",pfd);
}
int write_byte = write(pfd, buf, strlen(buf));
if (write_byte <= 0)
{
printf("write file error code =%d\r\n",write_byte);
}

close(pfd);

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

Delay(3000);
}
}


/******************************************************************************
* FunctionName : user_init
* Description : entry of user application, init user function here
* Parameters : none
* Returns : none
*******************************************************************************/
xTaskHandle supervisor_task_handle;
void ICACHE_RODATA_ATTR SupervisorTask(void *arg);
void user_init(void)
{


uart_init_new();

spiffs_fs1_init();
Delay(1000);
xTaskCreate(spiffs_fs1_write_read, (const signed char *)"file_test", 512, NULL, 2, NULL);

}

output:

open file error error code = -1
write file error code =-1
read errno
--> <--
open file error error code = -1
write file error code =-1
read errno
--> <--
open file error error code = -1
write file error code =-1
read errno

Can any one have a idea what this happens.