Merge pull request #13914 from JeanMarcR/FLASH_API

STM32 FLASH API : add critical sections
pull/13957/head
Martin Kojtal 2020-11-24 14:08:52 +00:00 committed by GitHub
commit 59c03e1e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 197 additions and 280 deletions

View File

@ -30,27 +30,6 @@
// Minimum number of bytes to be programmed at a time
#define MIN_PROG_SIZE (4U)
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Flash */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_init(flash_t *obj)
{
return 0;
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
// Clear Flash status register's flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
@ -93,7 +74,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -145,7 +132,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -30,27 +30,6 @@
// Minimum number of bytes to be programmed at a time
#define MIN_PROG_SIZE (4U)
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Flash */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_init(flash_t *obj)
{
return 0;
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
// Clear Flash status register's flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_OPTVERR);
@ -93,7 +74,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -145,7 +132,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -25,27 +25,6 @@
static uint32_t GetSector(uint32_t Address);
static uint32_t GetSectorSize(uint32_t Sector);
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_init(flash_t *obj)
{
return 0;
@ -67,10 +46,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Get the 1st sector to erase */
FirstSector = GetSector(address);
@ -84,7 +65,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -97,10 +82,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
you have to make sure that these data are rewritten before they are accessed during code
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
@ -124,7 +111,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -30,27 +30,6 @@
// Minimum number of bytes to be programmed at a time
#define MIN_PROG_SIZE (4U)
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Flash */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_init(flash_t *obj)
{
return 0;
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
// Clear Flash status register's flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
@ -93,7 +74,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -145,7 +132,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -65,7 +65,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
core_util_critical_section_exit();
HAL_FLASH_Lock();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -83,6 +85,7 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
core_util_critical_section_enter();
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
you have to make sure that these data are rewritten before they are accessed during code
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
@ -108,7 +111,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
core_util_critical_section_exit();
HAL_FLASH_Lock();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -61,27 +61,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
{
/* Variable used for Erase procedure */
@ -94,10 +73,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
you have to make sure that these data are rewritten before they are accessed during code
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
@ -122,7 +103,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
SCB_InvalidateICache();
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -138,10 +123,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
you have to make sure that these data are rewritten before they are accessed during code
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
@ -164,7 +151,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)StartAddress, FullSize);
SCB_InvalidateICache();
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -34,27 +34,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
{
uint32_t PAGEError = 0;
@ -66,10 +45,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
@ -88,7 +69,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
@ -109,10 +94,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -143,7 +130,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -91,27 +91,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
/** Erase one sector starting at defined address
*
* The address should be at sector boundary. This function does not do any check for address alignments
@ -131,10 +110,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -158,7 +139,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -189,10 +174,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -229,7 +216,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -62,6 +62,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
while (LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID)) {
}
#endif /* DUAL_CORE */
if (HAL_FLASH_Unlock() != HAL_OK) {
#if defined(DUAL_CORE)
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
@ -69,6 +70,8 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
core_util_critical_section_enter();
/* Fill EraseInit structure */
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
#if defined (FLASH_CR_PSIZE)
@ -97,9 +100,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
SCB_InvalidateICache();
#endif /* DUAL_CORE */
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
HAL_FLASH_Lock();
#if defined(DUAL_CORE)
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
#endif /* DUAL_CORE */
@ -128,6 +134,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
return -1;
}
core_util_critical_section_enter();
StartAddress = address;
while ((address < (StartAddress + size)) && (status == 0)) {
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, (uint32_t)data) == HAL_OK) {
@ -148,7 +156,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
SCB_InvalidateICache();
#endif /* DUAL_CORE */
HAL_FLASH_Lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
#if defined(DUAL_CORE)
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
#endif /* DUAL_CORE */

View File

@ -36,27 +36,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
{
uint32_t PAGEError = 0;
@ -68,10 +47,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear OPTVERR bit set on virgin samples */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
@ -90,7 +71,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -145,7 +132,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -36,27 +36,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
{
uint32_t PAGEError = 0;
@ -68,10 +47,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR);
/* MBED HAL erases 1 sector at a time */
/* Fill EraseInit structure*/
@ -88,7 +69,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
@ -109,10 +94,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Program the user Flash area word by word */
StartAddress = address;
@ -143,7 +130,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -94,27 +94,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
/** Erase one sector starting at defined address
*
* The address should be at sector boundary. This function does not do any check for address alignments
@ -134,10 +113,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -161,7 +142,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}
@ -192,10 +177,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -232,7 +219,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
flash_lock();
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
return status;
}

View File

@ -72,7 +72,7 @@ static uint32_t GetBank(uint32_t Addr)
int32_t flash_init(flash_t *obj)
{
#ifdef TARGET_TFM
/* TFM implementation needs dual bank configuration */
/* TFM implementation needs dual bank configuration */
if (READ_BIT(FLASH->OPTR, FLASH_OPTR_DBANK) != 0U) {
return 0;
} else {
@ -93,27 +93,6 @@ int32_t flash_free(flash_t *obj)
return 0;
}
static int32_t flash_unlock(void)
{
/* Allow Access to Flash control registers and user Falsh */
if (HAL_FLASH_Unlock()) {
return -1;
} else {
return 0;
}
}
static int32_t flash_lock(void)
{
/* Disable the Flash option control register access (recommended to protect
the option Bytes against possible unwanted operations) */
if (HAL_FLASH_Lock()) {
return -1;
} else {
return 0;
}
}
/** Erase one sector starting at defined address
*
* The address should be at sector boundary. This function does not do any check for address alignments
@ -131,10 +110,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -154,7 +135,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}
if (flash_lock() != HAL_OK) {
core_util_critical_section_exit();
if (HAL_FLASH_Lock() != HAL_OK) {
return -1;
}
@ -186,10 +169,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
return -1;
}
if (flash_unlock() != HAL_OK) {
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
@ -226,7 +211,11 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
}
}
status = flash_unlock();
if (HAL_FLASH_Unlock() != HAL_OK) {
return -1;
}
core_util_critical_section_enter();
return status;
}