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; }
spiffs_config spiffs_get_storage_config() { spiffs_config cfg = {0}; cfg.phys_addr = ( u32_t )flashmem_get_first_free_block_address(); if (cfg.phys_addr == 0) return cfg; 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_addr = INTERNAL_FLASH_SIZE - SPIFFS_WORK_SIZE + INTERNAL_FLASH_START_ADDRESS; cfg.phys_addr += 0x3000; cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. cfg.phys_size = SPIFFS_WORK_SIZE;*/ 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 return cfg; }
u32_t spiffs_get_startaddress() { s32_t phys_addr = flashmem_get_first_free_block_address(); phys_addr &= 0xFFFFF000; return phys_addr; }