mirror of https://github.com/ARMmbed/mbed-os.git
STM32 FLASH API : add critical sections
See PR #13802 (for F4 board) Concerned boards are STM32F0 STM32F1 STM32F2 STM32F3 STM32F4 STM32F7 STM32G0 STM32G4 STM32H7 STM32L0 STM32L1 STM32L4 STM32L5 Adding test of return code of HAL_FLASH_Lock() function Adding board STM32F4 Running AStylepull/13914/head
parent
f2278567d0
commit
16e63dc108
|
@ -30,27 +30,6 @@
|
||||||
// Minimum number of bytes to be programmed at a time
|
// Minimum number of bytes to be programmed at a time
|
||||||
#define MIN_PROG_SIZE (4U)
|
#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)
|
int32_t flash_init(flash_t *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
// Clear Flash status register's flags
|
// Clear Flash status register's flags
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
|
__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;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,27 +30,6 @@
|
||||||
// Minimum number of bytes to be programmed at a time
|
// Minimum number of bytes to be programmed at a time
|
||||||
#define MIN_PROG_SIZE (4U)
|
#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)
|
int32_t flash_init(flash_t *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
// Clear Flash status register's flags
|
// Clear Flash status register's flags
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_OPTVERR);
|
__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;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,27 +25,6 @@
|
||||||
static uint32_t GetSector(uint32_t Address);
|
static uint32_t GetSector(uint32_t Address);
|
||||||
static uint32_t GetSectorSize(uint32_t Sector);
|
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)
|
int32_t flash_init(flash_t *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -67,10 +46,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Get the 1st sector to erase */
|
/* Get the 1st sector to erase */
|
||||||
FirstSector = GetSector(address);
|
FirstSector = GetSector(address);
|
||||||
|
|
||||||
|
@ -84,7 +65,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -97,10 +82,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
|
/* 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
|
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
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,27 +30,6 @@
|
||||||
// Minimum number of bytes to be programmed at a time
|
// Minimum number of bytes to be programmed at a time
|
||||||
#define MIN_PROG_SIZE (4U)
|
#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)
|
int32_t flash_init(flash_t *obj)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -71,10 +50,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
// Clear Flash status register's flags
|
// Clear Flash status register's flags
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
|
__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;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
|
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
HAL_FLASH_Lock();
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
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();
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
|
/* 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
|
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
|
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();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
HAL_FLASH_Lock();
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,27 +61,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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)
|
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
{
|
{
|
||||||
/* Variable used for Erase procedure */
|
/* Variable used for Erase procedure */
|
||||||
|
@ -94,10 +73,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
|
/* 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
|
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
|
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_CleanInvalidateDCache_by_Addr((uint32_t *)GetSectorBase(SectorId), GetSectorSize(SectorId));
|
||||||
SCB_InvalidateICache();
|
SCB_InvalidateICache();
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -138,10 +123,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Note: If an erase operation in Flash memory also concerns data in the data or instruction cache,
|
/* 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
|
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
|
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_CleanInvalidateDCache_by_Addr((uint32_t *)StartAddress, FullSize);
|
||||||
SCB_InvalidateICache();
|
SCB_InvalidateICache();
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,27 +34,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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)
|
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
{
|
{
|
||||||
uint32_t PAGEError = 0;
|
uint32_t PAGEError = 0;
|
||||||
|
@ -66,10 +45,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear OPTVERR bit set on virgin samples */
|
/* Clear OPTVERR bit set on virgin samples */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
||||||
|
|
||||||
|
@ -88,7 +69,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
@ -109,10 +94,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,27 +91,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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
|
/** Erase one sector starting at defined address
|
||||||
*
|
*
|
||||||
* The address should be at sector boundary. This function does not do any check for address alignments
|
* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -189,10 +174,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
while (LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID)) {
|
while (LL_HSEM_1StepLock(HSEM, CFG_HW_FLASH_SEMID)) {
|
||||||
}
|
}
|
||||||
#endif /* DUAL_CORE */
|
#endif /* DUAL_CORE */
|
||||||
|
|
||||||
if (HAL_FLASH_Unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
#if defined(DUAL_CORE)
|
#if defined(DUAL_CORE)
|
||||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Fill EraseInit structure */
|
/* Fill EraseInit structure */
|
||||||
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
EraseInitStruct.TypeErase = FLASH_TYPEERASE_SECTORS;
|
||||||
#if defined (FLASH_CR_PSIZE)
|
#if defined (FLASH_CR_PSIZE)
|
||||||
|
@ -97,9 +100,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
SCB_InvalidateICache();
|
SCB_InvalidateICache();
|
||||||
#endif /* DUAL_CORE */
|
#endif /* DUAL_CORE */
|
||||||
|
|
||||||
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
HAL_FLASH_Lock();
|
|
||||||
#if defined(DUAL_CORE)
|
#if defined(DUAL_CORE)
|
||||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
|
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
|
||||||
#endif /* DUAL_CORE */
|
#endif /* DUAL_CORE */
|
||||||
|
@ -128,6 +134,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
StartAddress = address;
|
StartAddress = address;
|
||||||
while ((address < (StartAddress + size)) && (status == 0)) {
|
while ((address < (StartAddress + size)) && (status == 0)) {
|
||||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_FLASHWORD, address, (uint32_t)data) == HAL_OK) {
|
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();
|
SCB_InvalidateICache();
|
||||||
#endif /* DUAL_CORE */
|
#endif /* DUAL_CORE */
|
||||||
|
|
||||||
HAL_FLASH_Lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(DUAL_CORE)
|
#if defined(DUAL_CORE)
|
||||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
|
LL_HSEM_ReleaseLock(HSEM, CFG_HW_FLASH_SEMID, HSEM_CR_COREID_CURRENT);
|
||||||
#endif /* DUAL_CORE */
|
#endif /* DUAL_CORE */
|
||||||
|
|
|
@ -36,27 +36,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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)
|
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
{
|
{
|
||||||
uint32_t PAGEError = 0;
|
uint32_t PAGEError = 0;
|
||||||
|
@ -68,10 +47,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear OPTVERR bit set on virgin samples */
|
/* Clear OPTVERR bit set on virgin samples */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
||||||
|
|
||||||
|
@ -90,7 +71,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
@ -111,10 +96,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,27 +36,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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)
|
int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
{
|
{
|
||||||
uint32_t PAGEError = 0;
|
uint32_t PAGEError = 0;
|
||||||
|
@ -68,10 +47,12 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR);
|
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR | FLASH_FLAG_EOP | FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR);
|
||||||
/* MBED HAL erases 1 sector at a time */
|
/* MBED HAL erases 1 sector at a time */
|
||||||
/* Fill EraseInit structure*/
|
/* Fill EraseInit structure*/
|
||||||
|
@ -88,7 +69,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
|
||||||
status = -1;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
@ -109,10 +94,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Program the user Flash area word by word */
|
/* Program the user Flash area word by word */
|
||||||
StartAddress = address;
|
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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,27 +94,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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
|
/** Erase one sector starting at defined address
|
||||||
*
|
*
|
||||||
* The address should be at sector boundary. This function does not do any check for address alignments
|
* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
status = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash_lock();
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -192,10 +177,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,27 +93,6 @@ int32_t flash_free(flash_t *obj)
|
||||||
return 0;
|
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
|
/** Erase one sector starting at defined address
|
||||||
*
|
*
|
||||||
* The address should be at sector boundary. This function does not do any check for address alignments
|
* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_lock() != HAL_OK) {
|
core_util_critical_section_exit();
|
||||||
|
|
||||||
|
if (HAL_FLASH_Lock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +169,12 @@ int32_t flash_program_page(flash_t *obj, uint32_t address,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flash_unlock() != HAL_OK) {
|
if (HAL_FLASH_Unlock() != HAL_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core_util_critical_section_enter();
|
||||||
|
|
||||||
/* Clear error programming flags */
|
/* Clear error programming flags */
|
||||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
|
__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;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue