diff --git a/port/fal/samples/porting/fal_flash_stm32f2_port.c b/port/fal/samples/porting/fal_flash_stm32f2_port.c index 81c8ca3..35bb8f2 100644 --- a/port/fal/samples/porting/fal_flash_stm32f2_port.c +++ b/port/fal/samples/porting/fal_flash_stm32f2_port.c @@ -146,6 +146,7 @@ static int write(long offset, const uint8_t *buf, size_t size) /* check data */ if (read_data != *buf) { + FLASH_Lock(); return -1; } } @@ -173,6 +174,7 @@ static int erase(long offset, size_t size) flash_status = FLASH_EraseSector(cur_erase_sector, VoltageRange_3); if (flash_status != FLASH_COMPLETE) { + FLASH_Lock(); return -1; } erased_size += stm32_get_sector_size(cur_erase_sector); diff --git a/port/fal/samples/porting/fal_flash_stm32f4.c b/port/fal/samples/porting/fal_flash_stm32f4.c index 1cb124b..8505fb3 100644 --- a/port/fal/samples/porting/fal_flash_stm32f4.c +++ b/port/fal/samples/porting/fal_flash_stm32f4.c @@ -182,11 +182,13 @@ static int write(long offset, const uint8_t *buf, size_t size) { if (*(uint8_t *) addr != *buf) { + HAL_FLASH_Lock(); return -1; } } else { + HAL_FLASH_Lock(); return -1; } } @@ -221,6 +223,7 @@ static int erase(long offset, size_t size) if (HAL_FLASHEx_Erase(&EraseInitStruct, (uint32_t *) &SECTORError) != HAL_OK) { + HAL_FLASH_Lock(); return -1; }