stm32-rs / stm32h7xx-hal

Peripheral access API for STM32H7 series microcontrollers
BSD Zero Clause License
215 stars 101 forks source link

Add access_banks flash accessor #489

Closed Abestanis closed 6 months ago

Abestanis commented 6 months ago

This adds a access_banks helper to the FlashExt, which is a middle ground between access_bank1 and split.

Problem

Right now the only way to access bank 2 is using the split method, which consumes the FLASH 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 via FLASH::optcr(&self), which needs the FLASH instance.

Solution

Using the new access_banks helper I can keep the FLASH instance around and get access to both banks as well as the option control register when I need it.

richardeoin commented 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

Abestanis commented 6 months ago
richardeoin commented 6 months ago

Nice, I appreciate for the summary. Given this crate's abstraction over the banks these methods definitely make sense. Thanks again for the contribution!