/* * Returns TRUE if FS was found * align must be a power of two */ static bool myspiffs_set_cfg(spiffs_config *cfg, int align, int offset, bool force_create) { cfg->phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet cfg->log_page_size = LOG_PAGE_SIZE; // as we said cfg->hal_read_f = my_spiffs_read; cfg->hal_write_f = my_spiffs_write; cfg->hal_erase_f = my_spiffs_erase; if (!myspiffs_set_location(cfg, align, offset, LOG_BLOCK_SIZE)) { if (!myspiffs_set_location(cfg, align, offset, LOG_BLOCK_SIZE_SMALL_FS)) { return FALSE; } } NODE_DBG("fs.start:%x,max:%x\n",cfg->phys_addr,cfg->phys_size); #ifdef SPIFFS_USE_MAGIC_LENGTH if (force_create) { return TRUE; } int size = SPIFFS_probe_fs(cfg); if (size > 0 && size < cfg->phys_size) { NODE_DBG("Overriding size:%x\n",size); cfg->phys_size = size; } if (size > 0) { return TRUE; } return FALSE; #else return TRUE; #endif }
s32_t spiffs_mount_manual(u32_t phys_addr, u32_t phys_size) { spiffs_config cfg = {0}; // Set Spiffs HAL functions cfg.hal_read_f = api_spiffs_read; cfg.hal_write_f = api_spiffs_write; cfg.hal_erase_f = api_spiffs_erase; // Set Spiffs physical layout cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 2; // Important to make large cfg.log_page_size = LOG_PAGE_SIZE; // as we said // Set spiffs location cfg.phys_addr = phys_addr; cfg.phys_size = phys_size; if (cfg.phys_size == 0) { s32_t probeSize = SPIFFS_probe_fs(&cfg); if (probeSize < 0) { return probeSize; // Requested automatic sizing but not possible to detect } else { cfg.phys_size = probeSize; } } int spiffsResult = SPIFFS_mount(&_filesystemStorageHandle, &cfg, spiffs_work_buf, spiffs_fds, sizeof(spiffs_fds), spiffs_cache, sizeof(spiffs_cache), NULL); debugf("mount res: %d\n", spiffsResult); debugf("fs.start: address %X, size: %d Kb, result : %d \n", cfg.phys_addr, cfg.phys_size / 1024, spiffsResult ); return spiffsResult; }