-
Notifications
You must be signed in to change notification settings - Fork 2k
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/sam0_common: flashpage: add functions to write to user config area / AUX page #14512
cpu/sam0_common: flashpage: add functions to write to user config area / AUX page #14512
Conversation
ff529a2
to
ec932fe
Compare
ec932fe
to
ffa7136
Compare
ffa7136
to
2dfd157
Compare
4eea598
to
f783a85
Compare
3e17d62
to
a30e55a
Compare
b10e21a
to
b5913b7
Compare
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! |
Heh, looks like invalidating the cache after the write does the trick. |
Quick test on
|
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
Rebased to add |
1b540f8
to
b66e782
Compare
b66e782
to
b9e61fd
Compare
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
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_page
to 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_flashpage
still works.I did not include a test application yet, but functionality can be tested withI added the commands
test_config_page
anddump_config_page
totests/periph_flashpage
.test_config_page
will 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 ?)