Skip to content

Commit e4b07c0

Browse files
nilfitglaeqen
andauthored
Update NVM API (#674)
* Nvm: Derive Copy and Clone for `nvm::Bank` * Nvm: refactor focused on extending the userpage API Overview: - Make the NVM bitfield structs' methods public - Add setters for the `Userpage` bitfield struct - CalibrationArea and TemperaturesCalibrationArea do not need setters as they cannot be modified. - Extend the `Userpage` struct to cover the whole page (512 bytes) - Split `Nvm::write` and `Nvm::erase` method into "main address space flash" and "userpage flash" oriented APIs - Add idempotent `Nvm::modify_userpage` (avoids unnecessary flash erase & write) Breaking changes: - Switch to `*mut 32` from `u32` for address arguments - `Nvm::userpage` -> `Nvm::read_userpage` - `Nvm::write` -> `Nvm::write_flash` - `Nvm::write_from_slice` -> `Nvm::write_flash_from_slice` - `Nvm::erase` -> `Nvm::erase_flash` Note: Block erase granularity is assumed for main address space flash erasure; thus `granularity` disappeared from the signature. * Nvm: expose extra commands and raw registers New methods providing access to the following NVM commands - SSB (Enable Security Bit) - CELCK (Enable Chip-Erase Lock) - CEULCK (Disable Chip-Erase Lock) Also, expose unsafely underlying `NVMCTRL` register type as an escape hatch (`Nvm::registers`). * Add NVM API changes to CHANGELOG * Refactor error handling in NVMCTRL * Add `region_lock` API * Fix and invert the condition * Update CHANGELOG.md * Clarify region lock doc comment --------- Co-authored-by: Gabriel Górski <[email protected]>
1 parent ef00865 commit e4b07c0

File tree

4 files changed

+545
-187
lines changed

4 files changed

+545
-187
lines changed

boards/feather_m4/examples/nvm_dsu.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bsp::entry;
1515
use ehal::digital::v2::ToggleableOutputPin;
1616
use hal::clock::GenericClockController;
1717
use hal::dsu::Dsu;
18-
use hal::nvm::{retrieve_bank_size, Bank, EraseGranularity, Nvm, BLOCKSIZE};
18+
use hal::nvm::{retrieve_bank_size, Bank, Nvm, WriteGranularity, BLOCKSIZE};
1919
use hal::pac::{interrupt, CorePeripherals, Peripherals};
2020
use hal::usb::UsbBus;
2121

@@ -105,17 +105,14 @@ fn main() -> ! {
105105
if crc32_checksum_active_bank != crc32_checksum_inactive_bank {
106106
serial_writeln!("Checksums differ: overwrite inactive bank with active one");
107107
serial_writeln!("Erase inactive bank");
108-
nvm.erase(
109-
inactive_bank_address,
110-
bank_size_in_blocks,
111-
EraseGranularity::Block,
112-
)
113-
.unwrap();
108+
nvm.erase_flash(inactive_bank_address as *mut _, bank_size_in_blocks)
109+
.unwrap();
114110
serial_writeln!("Overwrite inactive bank with active bank");
115-
nvm.write(
116-
inactive_bank_address,
117-
active_bank_address,
111+
nvm.write_flash(
112+
inactive_bank_address as *mut _,
113+
active_bank_address as *const _,
118114
bank_size_in_words,
115+
WriteGranularity::Page,
119116
)
120117
.unwrap();
121118
serial_writeln!("Swapping banks & reset!");

hal/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
- Fix failing `bsp_pins!` invocation with no aliases (#605 fixes #599)
1111
- Add Advanced Encryption Standard (AES) peripheral support including RustCrypto compatible backend
1212
- Add embedded-hal `InputPin` trait to EIC pins
13+
- Change NVM API
14+
- Add the ability to modify the user row
15+
- Add security bit and chip-erase lock management
16+
- Add escape hatch to access the underlying NVMCTRL PAC
17+
- Add `Nvm::region_lock` method
18+
- Change flash read/write/erase method signatures
19+
- `Nvm::userpage` -> `Nvm::read_userpage`
20+
- `Nvm::write` -> `Nvm::write_flash`
21+
- `Nvm::write_from_slice` -> `Nvm::write_flash_from_slice`
22+
- `Nvm::erase` -> `Nvm::erase_flash`
23+
- Refactor `Nvm::command_sync` to be less error-prone
1324

1425
# v0.15.1
1526

0 commit comments

Comments
 (0)