Closed Abestanis closed 6 months ago
This looks useful, and I don't think it breaks any existing assumptions. After all it doesn't modify registers.
It would be interesting to know if similar crates (stm32-rs/stm32f4xx-hal or stm32-rs/stm32f7xx-hal perhaps) already have methods like this
stm32-rs/stm32f4xx-hal
's flash extension doesn't really distinguish between the two banks, they have a FlashExt::dual_bank(&self) -> bool
, but their way of accessing the flash just takes a mutable self and returns an accessor that operates on sectors/offset from the flash base regardless of the bank: FlashExt::unlocked(&mut self) -> UnlockedFlash
. So they don't have a split
method and the unlocked
method is like the access_banks
method proposed here but it gives access to the entire flash range in one struct rather than two.stm32-rs/stm32f7xx-hal
does not have a concept of banks, they just provide a thin wrapper over the FLASH
peripheral with the fn lock(&mut self)
, fn program<'a, 'b>(&'a mut self, start_offset: usize, data: &'b [u8]) -> Result<ProgrammingSequence<'a, 'b>, Error>
and fn unlock(&mut self)
methods.Nice, I appreciate for the summary. Given this crate's abstraction over the banks these methods definitely make sense. Thanks again for the contribution!
This adds a
access_banks
helper to theFlashExt
, which is a middle ground betweenaccess_bank1
andsplit
.Problem
Right now the only way to access bank 2 is using the
split
method, which consumes theFLASH
instance. In my usecase I want to access both flash banks but I also need to flip the banks at some point, so I need to have access to the option control register viaFLASH::optcr(&self)
, which needs theFLASH
instance.Solution
Using the new
access_banks
helper I can keep theFLASH
instance around and get access to both banks as well as the option control register when I need it.