How to configure spiffs in singleton mode

btomic
Posts: 2
Joined: Thu May 04, 2017 7:01 pm

How to configure spiffs in singleton mode

Postby btomic » Thu May 04, 2017 7:38 pm

Hi, I'm trying to figure out how to use SPIFFS in the 'singletone' mode, as explained in spiffs_config.h:

// Enable if only one spiffs instance with constant configuration will exist
// on the target. This will reduce calculations, flash and memory accesses.
// Parts of configuration must be defined below instead of at time of mount.
#ifndef SPIFFS_SINGLETON
#define SPIFFS_SINGLETON 0
#endif

The problem is that the spiffs_config structure (defined in spiffs.h) is this:

// spiffs spi configuration struct
typedef struct {
// physical read function
spiffs_read hal_read_f;
// physical write function
spiffs_write hal_write_f;
// physical erase function
spiffs_erase hal_erase_f;
#if SPIFFS_SINGLETON == 0
// physical size of the spi flash
u32_t phys_size;
// physical offset in spi flash used for spiffs,
// must be on block boundary
u32_t phys_addr;
// physical size when erasing a block
u32_t phys_erase_block;

// logical size of a block, must be on physical
// block size boundary and must never be less than
// a physical block
u32_t log_block_size;
// logical size of a page, must be at least
// log_block_size / 8
u32_t log_page_size;
#endif
} spiffs_config;

When SPIFFS_SINGLETON == 1 the config structure does not have the members 'phys_size', 'phys_addr', 'phys_erase_block', 'log_block_size' and 'log_page_size'. However, those members need to be initialized when mounting the file system, as specified in the function defined in test_spiffs.c:

s32_t fs_mount_specific(u32_t phys_addr, u32_t phys_size,
u32_t phys_sector_size,
u32_t log_block_size, u32_t log_page_size) {
spiffs_config c;
c.hal_erase_f = _erase;
c.hal_read_f = _read;
c.hal_write_f = _write;
c.log_block_size = log_block_size;
c.log_page_size = log_page_size;
c.phys_addr = phys_addr;
c.phys_erase_block = phys_sector_size;
c.phys_size = phys_size;

return SPIFFS_mount(&__fs, &c, _work, _fds, sizeof(_fds), _cache, sizeof(_cache), spiffs_check_cb_f);
}

All other spiffs API functions (SPIFFS_open, SPIFFS_read...) also require passing the spiffs_config structure.

I understand that the spiffs can be initialized as specified in the test_main.c function

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);
}

but how do I initialize the spiffs_config structure without the members which specify the spiffs size, address etc? Could anyone explain please.

User avatar
pratik
Posts: 402
Joined: Wed Jun 29, 2016 7:17 pm
Location: India
Contact:

Re: How to configure spiffs in singleton mode

Postby pratik » Sun May 14, 2017 8:06 pm

The singleton mode seems to go with certain default settings. If you use that, your init routine does not need to initialize the undefined parameters.
The whole point of having singleton mode is that you cannot DYNAMICALLY change the spiffs parameters at runtime.
i.e. you can only use a 32MBit flash or 16MBit. YOu cannot reconfigure the flash size during runtime if needed.
So these structure members are not required in singleton mode. Because they are probably defined elsewhere in a spiffs header file. Therefore, when singleton mode is used, the default parameters will be considered.
Regards,
Pratik Panda
Website: http://www.PratikPanda.com

Custom firmware, Knowledge base and freelancing (ESP8266/ESP32):
http://www.iot-bits.com

btomic
Posts: 2
Joined: Thu May 04, 2017 7:01 pm

Re: How to configure spiffs in singleton mode

Postby btomic » Mon May 15, 2017 4:29 am

Thanks for the reply. The documentation on the SPIFFS filesystem I was talking about is on https://github.com/pellepl/spiffs. The provided test code works with 2 file systems simultaneously existing on the flash (FS1 and FS2), each of them having its own address and size. The test code was built based on SINGLETON=0.

However, it seems that in order to use the spiffs with SINGLETON=1 one has to recompile the spiffs source code and cannot use the spiffs library provided by Espressif (libspiffs.a) because it has also been built with SINGLETON=0. There are no API calls which can set singleton spiffs mode at run time (which you also pointed out) and the provided library supports only SINGLETON=0 mode. I think that's the explanation, please correct me if I'm wrong.

User avatar
pratik
Posts: 402
Joined: Wed Jun 29, 2016 7:17 pm
Location: India
Contact:

Re: How to configure spiffs in singleton mode

Postby pratik » Fri May 19, 2017 5:46 pm

Correct. The singleton mode optimizes the library during COMPILE phase, and not during run time.
And you are right, if you make any modifications to config options of a header file related to a .a type library file, you need to reconfigure the sources in most cases.
Regards,
Pratik Panda
Website: http://www.PratikPanda.com

Custom firmware, Knowledge base and freelancing (ESP8266/ESP32):
http://www.iot-bits.com

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 7 guests