static s32_t my_spiffs_erase(u32_t addr, u32_t size) { u32_t sect_first = platform_flash_get_sector_of_address(addr); u32_t sect_last = sect_first; while( sect_first <= sect_last ) if( platform_flash_erase_sector( sect_first ++ ) == PLATFORM_ERR ) return SPIFFS_ERR_INTERNAL; return SPIFFS_OK; }
void config_save(config_data * data){ NODE_DBG("Config save"); platform_flash_erase_sector(CONFIG_SECTOR); if(data!=NULL){ platform_flash_write((const void *)data,CONFIG_ADDRESS,sizeof(config_data)); os_memcpy(temp_data,data,sizeof(config_data)); local_up_to_date=1; } else{ platform_flash_write((const void *)&temp_data,CONFIG_ADDRESS,sizeof(config_data)); } }
// 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; }