[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
This commit is contained in:
Denis Shreiber 2022-10-02 21:08:57 +07:00 committed by GitHub
parent d914eb068c
commit a39f4e2ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -146,6 +146,7 @@ static int write(long offset, const uint8_t *buf, size_t size)
/* check data */ /* check data */
if (read_data != *buf) if (read_data != *buf)
{ {
FLASH_Lock();
return -1; return -1;
} }
} }
@ -173,6 +174,7 @@ static int erase(long offset, size_t size)
flash_status = FLASH_EraseSector(cur_erase_sector, VoltageRange_3); flash_status = FLASH_EraseSector(cur_erase_sector, VoltageRange_3);
if (flash_status != FLASH_COMPLETE) if (flash_status != FLASH_COMPLETE)
{ {
FLASH_Lock();
return -1; return -1;
} }
erased_size += stm32_get_sector_size(cur_erase_sector); erased_size += stm32_get_sector_size(cur_erase_sector);

View File

@ -182,11 +182,13 @@ static int write(long offset, const uint8_t *buf, size_t size)
{ {
if (*(uint8_t *) addr != *buf) if (*(uint8_t *) addr != *buf)
{ {
HAL_FLASH_Lock();
return -1; return -1;
} }
} }
else else
{ {
HAL_FLASH_Lock();
return -1; return -1;
} }
} }
@ -221,6 +223,7 @@ static int erase(long offset, size_t size)
if (HAL_FLASHEx_Erase(&EraseInitStruct, (uint32_t *) &SECTORError) != HAL_OK) if (HAL_FLASHEx_Erase(&EraseInitStruct, (uint32_t *) &SECTORError) != HAL_OK)
{ {
HAL_FLASH_Lock();
return -1; return -1;
} }