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
cpu/stm32f3: add support for flashpage and flashpage_raw #11749
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on stm32f302r8, the tests pass and everything seems to work but according to the datasheet HSI also needs to be enabled for erase operations, which is not being done here for F3.
cpu/stm32_common/periph/flashpage.c
Outdated
@@ -174,7 +175,7 @@ void flashpage_write_raw(void *target_addr, const void *data, size_t len) | |||
|
|||
DEBUG("[flashpage_raw] write: now writing the data\n"); | |||
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) || \ | |||
defined(CPU_FAM_STM32L4) | |||
defined(CPU_FAM_STM32L4) || defined(CPU_FAM_STM32F3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minot nit-picking, this could be in alphabetical order.
*/ | ||
#define FLASHPAGE_RAW_BLOCKSIZE (2U) | ||
/* Writing should be always 4 bytes aligned */ | ||
#define FLASHPAGE_RAW_ALIGNMENT (4U) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 4 bytes? The blocksize is 2 bytes, skimming through the datasheet I couldn't find a reference to this being a requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the answer to this in a comment in tests/periph_flashpage
:
The flash page in RAM must be correctly aligned, even in RAM, when
* using flashpage_raw. This is because some architecture uses
* 32 bit alignment implicitly and there are cases (stm32l4) that
* requires 64 bit alignment.
So its an architecture requirement, and does need to be 32b aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fjmolinas :)
CNTRL_REG &= ~(FLASH_CR_PG); | ||
#endif | ||
DEBUG("[flashpage_raw] write: done writing data\n"); | ||
|
||
/* lock the flash module again */ | ||
_lock(); | ||
|
||
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) | ||
#if defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F1) || \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also need to be done for erase operations according to the reference manual p68.
For program and erase operations on the Flash memory (write/erase), the internal RC
oscillator (HSI) must be ON.
@aabadie I see you have addressed my comments and I re-tested that tests are still passing. Can you rebase? |
c4e6f2d
to
3b58b4b
Compare
Thanks @fjmolinas, squashed and rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK!
Contribution description
This PR is adding support for
periph_flashpage
andperiph_flashpage_raw
on stm32f3 MCU.I tested it with success on all stm32f3 boards supported in RIOT: nucleo-f303re, nucleo-f303ze, nucleo-f303k8, nucleo-f302r8, nucleo-f334r8
Testing procedure
The following command should work:
The boards to test: nucleo-f303{re,ze,k8}, nucleo-f302r8 and nucleo-f334r8
Issues/PRs references
None