pub struct FlashCtrl<'a> { /* private fields */ }
Implementations§
Source§impl FlashCtrl<'_>
impl FlashCtrl<'_>
pub fn new(base: StaticRef<FlashCtrlRegisters>, region_num: FlashRegion) -> Self
Sourcepub fn reset_fifos(&self)
pub fn reset_fifos(&self)
Reset the internal FIFOs, used for when recovering from errors.
pub fn handle_interrupt(&self)
Sourcepub fn mp_set_region_perms(
&self,
start_addr: usize,
end_addr: usize,
region_num: usize,
mp_perms: &FlashMPConfig,
) -> Result<(), ErrorCode>
pub fn mp_set_region_perms( &self, start_addr: usize, end_addr: usize, region_num: usize, mp_perms: &FlashMPConfig, ) -> Result<(), ErrorCode>
Setup the specified flash memory protection configuration
Returns Ok(())
on successfully applying the requested configuration
Returns [
NOSUPPORT](ErrorCode::NOSUPPORT)
if address space is not supported,
or the region_num
does not exist
§Arguments
start_addr
- Starting address that bounds the start of this region. Note: This is the absolute address, i.eFLASH_ADDR_OFFSET
and onwardsend_addr
- End address that bounds the end of this region Note: This is the absolute address, i.eFLASH_ADDR_OFFSET
and onwardsregion_num
- The configuration region number associated with this region. This associates the specified permissions to a configuration region, the number of simultaneous configs supported should be requested bymp_get_num_regions()
mp_perms
- Specifies the permissions to set
§Examples
Usage:
peripherals
.flash_ctrl
.mp_set_region_perms(0x0, text_end_addr as usize, 5, &mp_cfg)
The snippet reads as:
Allow access controls as specified by mp_cfg, for the address space bounded by
start_addr=0x0
to end_addr=text_end_addr
and associate this cfg to region_num=5
.
If a user would want to modify this region (assuming it wasn’t locked), you can index into it with the
associated region_num
, in this case 5
.
Sourcepub fn mp_read_region_perms(
&self,
region_num: usize,
) -> Result<FlashMPConfig, ErrorCode>
pub fn mp_read_region_perms( &self, region_num: usize, ) -> Result<FlashMPConfig, ErrorCode>
Read the flash memory protection configuration bounded by the specified region
Returns [
FlashMPConfig](lowrisc::flash_ctrl::FlashMPConfig)
on success, with the permissions
specified by this region
Returns [
NOSUPPORT](ErrorCode::NOSUPPORT)
if the region_num
does not exist
§Arguments
region_num
- The configuration region number associated with this region. This associates the specified permissions to a configuration region.
Sourcepub fn mp_get_num_regions(&self) -> Result<u32, ErrorCode>
pub fn mp_get_num_regions(&self) -> Result<u32, ErrorCode>
Get the number of configuration regions supported by this hardware
Returns Ok(FLASH_MP_MAX_CFGS)
where FLASH_MP_MAX_CFGS is the number of
cfg regions supported
Note: Indexing starts with 0, this returns the total number of configuration registers.
Sourcepub fn mp_is_region_locked(&self, region_num: usize) -> Result<bool, ErrorCode>
pub fn mp_is_region_locked(&self, region_num: usize) -> Result<bool, ErrorCode>
Check if the specified region_num
is locked by hardware
Returns Ok(bool)
on success, if true the region is locked till next reset,
if false, it is unlocked.
Returns [
NOSUPPORT](ErrorCode::NOSUPPORT)
if the region_num
does not exist
§Arguments
region_num
- The configuration region number associated with this region. This associates the specified permissions to a configuration region.
Sourcepub fn mp_lock_region_cfg(&self, region_num: usize) -> Result<(), ErrorCode>
pub fn mp_lock_region_cfg(&self, region_num: usize) -> Result<(), ErrorCode>
Lock the configuration
Locks the config bounded by region_num
such that no further modifications can be made until the next system reset.
Returns [
NOSUPPORT](ErrorCode::NOSUPPORT)
if the region_num
does not exist
Returns [
ALREADY](ErrorCode::ALREADY)
if the region_num
region is already locked
Returns Ok(())
on successfully locking the region
§Arguments
region_num
- The configuration region number associated with this region. This associates the specified permissions to a configuration region.
Trait Implementations§
Source§impl Flash for FlashCtrl<'_>
impl Flash for FlashCtrl<'_>
Source§fn read_page(
&self,
page_number: usize,
buf: &'static mut Self::Page,
) -> Result<(), (ErrorCode, &'static mut Self::Page)>
fn read_page( &self, page_number: usize, buf: &'static mut Self::Page, ) -> Result<(), (ErrorCode, &'static mut Self::Page)>
The flash controller will truncate to the closest, lower word aligned address. For example, if 0x13 is supplied, the controller will perform a read at address 0x10.
Source§fn write_page(
&self,
page_number: usize,
buf: &'static mut Self::Page,
) -> Result<(), (ErrorCode, &'static mut Self::Page)>
fn write_page( &self, page_number: usize, buf: &'static mut Self::Page, ) -> Result<(), (ErrorCode, &'static mut Self::Page)>
The flash controller will truncate to the closest, lower word aligned address. For example, if 0x13 is supplied, the controller will perform a write at address 0x10. the controller does not have read modified write support.
Source§fn erase_page(&self, page_number: usize) -> Result<(), ErrorCode>
fn erase_page(&self, page_number: usize) -> Result<(), ErrorCode>
The controller will truncate to the closest lower page aligned address. Similarly for bank erases, the controller will truncate to the closest lower bank aligned address.