Newer
Older
Tardis / src / FlashErase.cpp
@Jookia Jookia on 19 Mar 2023 824 bytes Initial commit
#include "mbed.h"
#include <errno.h>
#include <functional>
#include "FlashErase.h"

// function to erase the flash
void doErase(mbed::BlockDevice& bd, LittleFileSystem2& fs) {
	// Try to unmount the filesystem
	unmountFilesystem(bd, fs);
	printf("Initializing the block device... ");
	fflush(stdout);
	int err = bd.init();
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
		error("error: %s (%d)\n", strerror(-err), err);
	}

	printf("Erasing the block device... ");
	fflush(stdout);
	err = bd.erase(0, bd.size());
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
		error("error: %s (%d)\n", strerror(-err), err);
	}

	printf("Deinitializing the block device... ");
	fflush(stdout);
	err = bd.deinit();
	printf("%s\n", (err ? "Fail :(" : "OK"));
	if (err) {
	error("error: %s (%d)\n", strerror(-err), err);
	}
}