Skip to content
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

(embassy-rp): Implementation of generic flash mutation access #951

Merged
merged 28 commits into from
Oct 28, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
feb840c
First iteration attempt on implementing generic flash mutation access…
MathiasKoch Sep 16, 2022
7bb9620
make `State::new()` const, consistent with others
FrozenDroid Sep 15, 2022
e5af4c4
Add .into_inner() and .get_mut() to Mutex
hulthe Sep 16, 2022
3f672c8
Make rustfmt happy
hulthe Sep 16, 2022
f46b838
Feature-gate time-driver in embassy-rp
MathiasKoch Sep 9, 2022
5d1576e
Add time-driver feature to docs
MathiasKoch Sep 16, 2022
8129839
rp: remove extraneous newlines in logs
newAM Sep 18, 2022
c145274
rp: fix async SPI read and write
newAM Sep 18, 2022
4322293
rp: let SPI RX overflow during async write
newAM Sep 18, 2022
54ba472
Remove BootFlash borrow
lulf Sep 20, 2022
334dfcd
Take into account size of revert index
lulf Sep 20, 2022
0db1332
Implement RealTimeClock for embassy-rp
MathiasKoch Sep 16, 2022
7412a85
Update Rust nightly.
Dirbaio Sep 22, 2022
2fed9f9
Replace futures::future::poll_fn -> core::future::poll_fn.
Dirbaio Sep 22, 2022
4f33cc5
Replace futures::future::join -> embassy_futures::join::join.
Dirbaio Sep 22, 2022
816778e
Add RP2040 ROM functions and intrinsics aliases
MathiasKoch Sep 23, 2022
9d674f0
First iteration attempt on implementing generic flash mutation access…
MathiasKoch Sep 16, 2022
18dc0de
Drop rp2040-flash as dependency, as they pull in rp2040-hal for rom-d…
MathiasKoch Sep 23, 2022
7ee7109
Rebase on master
MathiasKoch Sep 29, 2022
7152031
Add flash ram helpers
MathiasKoch Sep 29, 2022
8d809c9
Merge branch 'master' of https://github.com/embassy-rs/embassy into e…
MathiasKoch Oct 24, 2022
ad0eb3f
Implement flash padding to 256 under assumption that all QSPI NOR fla…
MathiasKoch Oct 24, 2022
80e5842
Add flash example & flash HIL test
MathiasKoch Oct 26, 2022
1669e39
Buffer data to be written to flash in ram if it does not already resi…
MathiasKoch Oct 26, 2022
3c6c382
Remove random delay from example, and move flash functions to allow u…
MathiasKoch Oct 27, 2022
c871fe0
Rebase on master
MathiasKoch Oct 27, 2022
a7b90c7
Remove unused imports from test
MathiasKoch Oct 27, 2022
bc21b6e
Add delay to flash test to allow time to parse RTT header
MathiasKoch Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove BootFlash borrow
Compiler will infer a different lifetime for BootFlash than for the
borrowed flash, which makes it require more type annotations than if it
was just owning the type. Since it doesn't really matter if it owns or
borrows in practical use, change it to own so that it simplifies usage.
lulf authored and MathiasKoch committed Sep 23, 2022
commit 54ba4725408bca51c5997d16b58cf334b519ac24
24 changes: 12 additions & 12 deletions embassy-boot/boot/src/lib.rs
Original file line number Diff line number Diff line change
@@ -447,66 +447,66 @@ where
}

/// A flash wrapper implementing the Flash and embedded_storage traits.
pub struct BootFlash<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8 = 0xFF>
pub struct BootFlash<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8 = 0xFF>
where
F: NorFlash + ReadNorFlash,
{
flash: &'a mut F,
flash: F,
}

impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE>
impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> BootFlash<F, BLOCK_SIZE, ERASE_VALUE>
where
F: NorFlash + ReadNorFlash,
{
/// Create a new instance of a bootable flash
pub fn new(flash: &'a mut F) -> Self {
pub fn new(flash: F) -> Self {
Self { flash }
}
}

impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> Flash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE>
impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> Flash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE>
where
F: NorFlash + ReadNorFlash,
{
const BLOCK_SIZE: usize = BLOCK_SIZE;
const ERASE_VALUE: u8 = ERASE_VALUE;
}

impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ErrorType for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE>
impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ErrorType for BootFlash<F, BLOCK_SIZE, ERASE_VALUE>
where
F: ReadNorFlash + NorFlash,
{
type Error = F::Error;
}

impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> NorFlash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE>
impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> NorFlash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE>
where
F: ReadNorFlash + NorFlash,
{
const WRITE_SIZE: usize = F::WRITE_SIZE;
const ERASE_SIZE: usize = F::ERASE_SIZE;

fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
F::erase(self.flash, from, to)
F::erase(&mut self.flash, from, to)
}

fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
F::write(self.flash, offset, bytes)
F::write(&mut self.flash, offset, bytes)
}
}

impl<'a, F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ReadNorFlash for BootFlash<'a, F, BLOCK_SIZE, ERASE_VALUE>
impl<F, const BLOCK_SIZE: usize, const ERASE_VALUE: u8> ReadNorFlash for BootFlash<F, BLOCK_SIZE, ERASE_VALUE>
where
F: ReadNorFlash + NorFlash,
{
const READ_SIZE: usize = F::READ_SIZE;

fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
F::read(self.flash, offset, bytes)
F::read(&mut self.flash, offset, bytes)
}

fn capacity(&self) -> usize {
F::capacity(self.flash)
F::capacity(&self.flash)
}
}

2 changes: 1 addition & 1 deletion examples/boot/bootloader/nrf/src/main.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ fn main() -> ! {

let mut bl = BootLoader::default();
let start = bl.prepare(&mut SingleFlashConfig::new(&mut BootFlash::<_, 4096>::new(
&mut WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5),
WatchdogFlash::start(Nvmc::new(p.NVMC), p.WDT, 5),
)));
unsafe { bl.load(start) }
}
7 changes: 3 additions & 4 deletions examples/boot/bootloader/stm32/src/main.rs
Original file line number Diff line number Diff line change
@@ -20,10 +20,9 @@ fn main() -> ! {
*/

let mut bl: BootLoader<ERASE_SIZE, WRITE_SIZE> = BootLoader::default();
let mut flash = Flash::unlock(p.FLASH);
let start = bl.prepare(&mut SingleFlashConfig::new(
&mut BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(&mut flash),
));
let flash = Flash::unlock(p.FLASH);
let mut flash = BootFlash::<_, ERASE_SIZE, ERASE_VALUE>::new(flash);
let start = bl.prepare(&mut SingleFlashConfig::new(&mut flash));
core::mem::drop(flash);
unsafe { bl.load(start) }
}