static s32_t api_spiffs_erase(u32_t addr, u32_t size) { debugf("api_spiffs_erase"); u32_t sect_first = flashmem_get_sector_of_address(addr); u32_t sect_last = sect_first; while( sect_first <= sect_last ) if( !flashmem_erase_sector( sect_first ++ ) ) return SPIFFS_ERR_INTERNAL; return SPIFFS_OK; }
bool spiffs_format_internal() { spiffs_config cfg = spiffs_get_storage_config(); if (cfg.phys_addr == 0) { SYSTEM_ERROR("Can't format file system, wrong address"); return false; } u32_t sect_first, sect_last; sect_first = flashmem_get_first_free_block_address(); sect_last = flashmem_get_sector_of_address((u32_t)&_SPIFFS_end); debugf("sect_first: %x, sect_last: %x\n", sect_first, sect_last); while( sect_first <= sect_last ) { if(!flashmem_erase_sector( sect_first ++ )) return false; } return true; }
bool spiffs_format_internal(spiffs_config *cfg) { if (cfg->phys_addr == 0) { SYSTEM_ERROR("Can't format file system, wrong address"); return false; } u32_t sect_first, sect_last; sect_first = cfg->phys_addr; sect_first = flashmem_get_sector_of_address(sect_first); sect_last = cfg->phys_addr + cfg->phys_size; sect_last = flashmem_get_sector_of_address(sect_last); debugf("sect_first: %x, sect_last: %x\n", sect_first, sect_last); ETS_INTR_LOCK(); int total = sect_last - sect_first; int cur = 0; int last = -1; while( sect_first <= sect_last ) { if(flashmem_erase_sector( sect_first++ )) { int percent = cur++ * 100 / total; if (percent > last) debugf("%d%%", percent); last = percent; } else { ETS_INTR_UNLOCK(); return false; } } debugf("formated"); ETS_INTR_UNLOCK(); }