Skip to content

Commit 1d78ae6

Browse files
committed
ARMmbed#92 Erase flash storage with erase.act file and allow filesize of up to 127KB
1 parent 9ff7357 commit 1d78ae6

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

source/board/microbitv2/microbitv2.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
#define FLASH_CONFIG_ADDRESS (0x00020000)
6363
#define FLASH_CONFIG_SIZE (0x00000400)
64-
#define FLASH_DAL_CFG_SIZE (0x00000400)
6564
#define FLASH_INTERFACE_SIZE (128*1024)
6665
#define FLASH_STORAGE_ADDRESS (0x00020400)
6766
#define FLASH_CFG_FILENAME "DATA BIN"
@@ -533,6 +532,16 @@ void board_vfs_stream_closed_hook()
533532
PORT_SetPinMux(COMBINED_SENSOR_INT_PORT, COMBINED_SENSOR_INT_PIN, kPORT_PinDisabledOrAnalog);
534533
}
535534

535+
bool vfs_user_magic_file_hook(const vfs_filename_t filename, bool *do_remount)
536+
{
537+
if (!memcmp(filename, "ERASE ACT", sizeof(vfs_filename_t))) {
538+
// Erase last 128KB flash block
539+
FLASH_Erase(&g_flash, FLASH_CONFIG_ADDRESS, g_flash.PFlashTotalSize / g_flash.PFlashBlockCount, kFLASH_apiEraseKey);
540+
}
541+
542+
return false;
543+
}
544+
536545
void vfs_user_build_filesystem_hook() {
537546
uint32_t file_size;
538547
error_t status;
@@ -935,7 +944,7 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size) {
935944
pI2cCommand->cmdData.data[3] << 0;
936945

937946
/* Validate file size */
938-
if (tempFileSize <= (FLASH_INTERFACE_SIZE - FLASH_CONFIG_SIZE - FLASH_DAL_CFG_SIZE)) {
947+
if (tempFileSize <= (FLASH_INTERFACE_SIZE - FLASH_CONFIG_SIZE)) {
939948
gflashConfig.fileSize = tempFileSize;
940949
tempFileSize = __REV(gflashConfig.fileSize);
941950
i2c_fillBuffer((uint8_t*) pI2cCommand, 0, 1);
@@ -996,7 +1005,7 @@ static void i2c_write_flash_callback(uint8_t* pData, uint8_t size) {
9961005
i2c_fillBuffer((uint8_t*) pI2cCommand, 0, 1);
9971006
break;
9981007
case gFlashStorageSize_c:
999-
pI2cCommand->cmdData.data[0] = (FLASH_INTERFACE_SIZE - FLASH_CONFIG_SIZE - FLASH_DAL_CFG_SIZE)/1024;
1008+
pI2cCommand->cmdData.data[0] = (FLASH_INTERFACE_SIZE - FLASH_CONFIG_SIZE)/1024;
10001009
i2c_fillBuffer((uint8_t*) pI2cCommand, 0, 2);
10011010
break;
10021011
case gFlashSectorSize_c:

0 commit comments

Comments
 (0)