cpu/sam0_common: flashpage: add functions to write to user config area / AUX page#14512
Merged
fjmolinas merged 9 commits intoRIOT-OS:masterfrom Nov 10, 2020
Merged
Conversation
ff529a2 to
ec932fe
Compare
4 tasks
ec932fe to
ffa7136
Compare
ffa7136 to
2dfd157
Compare
4eea598 to
f783a85
Compare
3e17d62 to
a30e55a
Compare
b10e21a to
b5913b7
Compare
Contributor
|
Sweet! Currently, I'm really busy and this state will persist until Oct. the 13th. I won't be able to review your PRs before that date. (I've seen your other request, too.) Please ping me, if I haven't got around after that date! |
Contributor
Author
|
Heh, looks like invalidating the cache after the write does the trick. |
Contributor
|
Quick test on |
7 tasks
Contributor
|
Please squash @benpicco |
716a83d to
8a1d8d0
Compare
We can pad the unaligned bytes with 0xFF to make up a whole word that can be written.
8a1d8d0 to
1b540f8
Compare
Contributor
Author
|
Rebased to add |
1b540f8 to
b66e782
Compare
b66e782 to
b9e61fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
SAM0 MCUs have a page in flash where the boot-up configuration of the MCU is stored.
The MCU configuration does not take up the entire space, but leaves some room that can be used for user configuraiton.
As this flash area will persist across re-flashes and bank switches, it is an ideal candidate to store e.g. MAC addresses or TRIM values.
On samd5x we have 480 bytes available for this, samd21 leaves us with 56 bytes at our disposal.
For writing to this area, I extended the flashpage driver.
To make the API easier to use, I implemented support for unaligned writes.
The MCU only supports writing whole words (4 bytes) to the flash write buffer, any 8 or 16 bit write will lead to a hard fault.
So we have to pad the unaligned start and end of a transfer with
0xFF, as writing that on flash is a no-op (we can only write 1 -> 0 bits, 0 -> 1 writes will be ignored).The original flashpage API did not require this and would instead fail an assertion.
If we want to save code size, I can move the new unaligned
_write_pageto a separate function, so this feature is only available to the config section.Testing procedure
Warning: It is theoretically possible to brick your MCU if you overwrite the factory settings.
Make sure
tests/mtd_flashpagestill works.I did not include a test application yet, but functionality can be tested withI added the commands
test_config_pageanddump_config_pagetotests/periph_flashpage.test_config_pagewill backup the vendor config, clear the config page, write back the vendor config and custom test data at the end of the config page.So if you already have any custom data stored in there, that will be deleted (unlikely since that functionality was just added by this PR 😉)
old version
This will print the contents of the user page and write a small buffer at an offset.
You should see it written when the flash page is dumped again after a reboot.
samr21-xpro
saml10-xpro
same54-xpro
Issues/PRs references
triggers #14929 (fixed by 1840972 ?)