void myspiffs_mount() { spiffs_config cfg; #ifdef SPIFFS_FIXED_LOCATION cfg.phys_addr = SPIFFS_FIXED_LOCATION; #else cfg.phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ); #endif cfg.phys_addr += 0x3000; cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS ); cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE; // let us not complicate things cfg.log_page_size = LOG_PAGE_SIZE; // as we said NODE_DBG("fs.start:%x,max:%x\n",cfg.phys_addr,cfg.phys_size); cfg.hal_read_f = my_spiffs_read; cfg.hal_write_f = my_spiffs_write; cfg.hal_erase_f = my_spiffs_erase; int res = SPIFFS_mount(&fs, &cfg, spiffs_work_buf, spiffs_fds, sizeof(spiffs_fds), #if SPIFFS_CACHE spiffs_cache, sizeof(spiffs_cache), #else 0, 0, #endif // myspiffs_check_callback); 0); NODE_DBG("mount res: %i\n", res); }
// FS formatting function // Returns 1 if OK, 0 for error int myspiffs_format( void ) { SPIFFS_unmount(&fs); u32_t sect_first, sect_last; sect_first = ( u32_t )platform_flash_get_first_free_block_address( NULL ); sect_first += 0x3000; sect_first &= 0xFFFFC000; // align to 4 sector. sect_first = platform_flash_get_sector_of_address(sect_first); sect_last = INTERNAL_FLASH_SIZE + INTERNAL_FLASH_START_ADDRESS - 4; sect_last = platform_flash_get_sector_of_address(sect_last); NODE_DBG("sect_first: %x, sect_last: %x", sect_first, sect_last); while( sect_first <= sect_last ) if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) return 0; spiffs_mount(); return 1; }
static bool myspiffs_set_location(spiffs_config *cfg, int align, int offset, int block_size) { #ifdef SPIFFS_FIXED_LOCATION cfg->phys_addr = (SPIFFS_FIXED_LOCATION + block_size - 1) & ~(block_size-1); #else cfg->phys_addr = ( u32_t )platform_flash_get_first_free_block_address( NULL ) + offset; cfg->phys_addr = (cfg->phys_addr + align - 1) & ~(align - 1); #endif #ifdef SPIFFS_SIZE_1M_BOUNDARY cfg->phys_size = ((0x100000 - (SYS_PARAM_SEC_NUM * INTERNAL_FLASH_SECTOR_SIZE) - ( ( u32_t )cfg->phys_addr )) & ~(block_size - 1)) & 0xfffff; #else cfg->phys_size = (INTERNAL_FLASH_SIZE - ( ( u32_t )cfg->phys_addr )) & ~(block_size - 1); #endif if ((int) cfg->phys_size < 0) { return FALSE; } cfg->log_block_size = block_size; return (cfg->phys_size / block_size) >= MIN_BLOCKS_FS; }