Skip to content

STM32F4 FLASH API update #13802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions targets/TARGET_STM/TARGET_STM32F4/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
#include "flash_data.h"
#include "platform/mbed_critical.h"

// This file is automatically generated


static uint32_t GetSector(uint32_t Address);
static uint32_t GetSectorSize(uint32_t Sector);

Expand All @@ -37,30 +34,8 @@ 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*/
static FLASH_EraseInitTypeDef EraseInitStruct;
uint32_t FirstSector;
uint32_t SectorError = 0;
Expand All @@ -70,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();

/* Get the 1st sector to erase */
FirstSector = GetSector(address);

Expand All @@ -86,7 +63,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
status = -1;
}

flash_lock();
core_util_critical_section_exit();

HAL_FLASH_Lock();

return status;
}
Expand All @@ -99,10 +78,11 @@ 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
Expand All @@ -126,7 +106,9 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
}
}

flash_lock();
core_util_critical_section_exit();

HAL_FLASH_Lock();

return status;
}
Expand Down