From a39f4e2ed6c0d68fbd35f449f01725b9795809bd Mon Sep 17 00:00:00 2001 From: Denis Shreiber Date: Sun, 2 Oct 2022 21:08:57 +0700 Subject: [PATCH] [fal] Execute HAL_FLASH_Lock() in case of error wile writing and erasing (#183) * Execute HAL_FLASH_Lock() in case of error wile writing and erasing * Also fix fal_flash_stm32f2_port.c * Replace tabs to spaces --- port/fal/samples/porting/fal_flash_stm32f2_port.c | 2 ++ port/fal/samples/porting/fal_flash_stm32f4.c | 3 +++ 2 files changed, 5 insertions(+) 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; }