Skip to content

STM32L4: clear error programming flags before erase & program operations #8263

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 2 commits into from
Oct 9, 2018
Merged

STM32L4: clear error programming flags before erase & program operations #8263

merged 2 commits into from
Oct 9, 2018

Conversation

juhoeskeli
Copy link
Contributor

Description

On STM32L486 when using dual bank operation where the program code was in bank 0 and BlockDevice in bank1 the erase and program operations would fail with Flash_error: 32.

From the reference manual: Bit 7 PGSERR: Programming sequence error Set by hardware when a write access to the Flash memory is performed by the code while PG or FSTPG have not been set previously. Set also by hardware when PROGERR, SIZERR, PGAERR, MISSERR or FASTERR is set due to a previous programming error. Cleared by writing 1.

The suggested write sequence can be found from reference: en.DM00083560.pdf 3.3.7 Flash main memory programming sequences - 2. Check and clear all error programming flags due to a previous programming.

The code change performs just that, clears the flags as per instructions. With the change it is possible to use bank 0 for running the program code while writing data to bank 1. I have tested this change on STM32L486 where OTA FW image was loaded to bank 1 and successfully updated from therein to bank 0.

Further reference: MBEDOSTEST-206

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Breaking change

@cmonr cmonr requested a review from a team September 27, 2018 03:16
@jeromecoutant
Copy link
Collaborator

Flash test results with this patch for STM32L4 NUCLEO boards:

target platform_name test suite result elapsed_time (sec) copy_method
NUCLEO_L432KC-ARM NUCLEO_L432KC tests-mbed_drivers-flashiap OK 21.36 default
NUCLEO_L432KC-ARM NUCLEO_L432KC tests-mbed_hal-flash OK 18.25 default
NUCLEO_L433RC_P-ARM NUCLEO_L433RC_P tests-mbed_drivers-flashiap OK 18.13 default
NUCLEO_L433RC_P-ARM NUCLEO_L433RC_P tests-mbed_hal-flash OK 17.99 default
NUCLEO_L476RG-ARM NUCLEO_L476RG tests-mbed_drivers-flashiap OK 18.09 default
NUCLEO_L476RG-ARM NUCLEO_L476RG tests-mbed_hal-flash OK 17.96 default
NUCLEO_L486RG-ARM NUCLEO_L486RG tests-mbed_drivers-flashiap OK 18.37 default
NUCLEO_L486RG-ARM NUCLEO_L486RG tests-mbed_hal-flash OK 18.1 default
NUCLEO_L496ZG-ARM NUCLEO_L496ZG tests-mbed_drivers-flashiap OK 18.08 default
NUCLEO_L496ZG-ARM NUCLEO_L496ZG tests-mbed_hal-flash OK 18.11 default

@@ -137,6 +137,9 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
return -1;
}

/* Clear error programming flags */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you clear all flash error, maybe you can remove next __HAL_FLASH_CLEAR_FLAG ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be OK now. FLASH_FLAG_ALL_ERRORS includes also FLASH_FLAG_OPTVERR

@jeromecoutant
Copy link
Collaborator

Need to check other STM32 families

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 4, 2018

Need to check other STM32 families

Any update?

@jeromecoutant
Copy link
Collaborator

Any update?

Sorry, this is "only" a reminder for my todo list
You can start CI for this PR

@jeromecoutant
Copy link
Collaborator

Need to check other STM32 families

For information, it seems that L4 FLASH driver is different from other STM32 families.
So this fix has not to be applied everywhere.
Regards,

@juhoeskeli
Copy link
Contributor Author

To next patch release, please.

@NirSonnenschein
Copy link
Contributor

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 9, 2018

Build : SUCCESS

Build number : 3293
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/8263/

Triggering tests

/morph test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Oct 9, 2018

@NirSonnenschein
Copy link
Contributor

exporter / mbed2 build seems to have failed because of IAR license shortage - re-=running:
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Oct 9, 2018

@mbed-ci
Copy link

mbed-ci commented Oct 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants