Struct stm32wlxx_hal::flash::Page

source ·
pub struct Page { /* private fields */ }
Expand description

Page address.

Implementations§

source§

impl Page

source

pub const SIZE: usize = 2_048usize

Page size in bytes.

source

pub const unsafe fn from_index_unchecked(idx: u8) -> Self

Create a page address from an index without checking bounds.

Safety
  1. The idx argument must be a valid page number, less than the value returned by num_pages.
Example
use stm32wlxx_hal::flash::Page;

let page0 = unsafe { Page::from_index_unchecked(0) };
source

pub fn from_index(idx: u8) -> Option<Self>

Create a page address from an index.

Returns None if the value index is greater than the index of the last page, for example 0x7F (page 127) on the STM32WLE5.

Example
use stm32wlxx_hal::flash::Page;

assert!(Page::from_index(8).is_some());
assert!(Page::from_index(128).is_none());
source

pub fn from_byte_offset(offset: usize) -> Option<Self>

Create a page address from an offset from the base of the flash memory.

Returns None if the address is out of bounds, or not page aligned.

Example
use stm32wlxx_hal::flash::Page;

assert_eq!(Page::from_byte_offset(0), Page::from_index(0));
assert_eq!(Page::from_byte_offset(2048), Page::from_index(1));
assert!(Page::from_byte_offset(2047).is_none());
assert!(Page::from_byte_offset(usize::MAX).is_none());
source

pub fn from_addr(addr: usize) -> Option<Self>

Create a page address from an absolute address.

Returns None if the address is out of bounds, or not page aligned.

Example
use stm32wlxx_hal::flash::Page;

assert_eq!(Page::from_addr(0x0800_0000), Page::from_index(0));
assert_eq!(Page::from_addr(0x0800_0800), Page::from_index(1));
assert!(Page::from_addr(0).is_none());
assert!(Page::from_addr(usize::MAX).is_none());
assert!(Page::from_addr(0x0800_0001).is_none());
source

pub const fn to_index(self) -> u8

Get the page index.

Example
use stm32wlxx_hal::flash::Page;

let page7 = unsafe { Page::from_index_unchecked(7) };
assert_eq!(page7.to_index(), 7);
source

pub const fn addr(&self) -> usize

Get the page address.

Example
use stm32wlxx_hal::flash::Page;

let page127 = unsafe { Page::from_index_unchecked(127) };
let page0 = unsafe { Page::from_index_unchecked(0) };

assert_eq!(page0.addr(), 0x0800_0000);
assert_eq!(page127.addr(), 0x0803_F800);
source

pub const fn addr_range(&self) -> Range<usize>

Get the address range of the page.

Example
use core::ops::Range;
use stm32wlxx_hal::flash::Page;

let page0 = unsafe { Page::from_index_unchecked(0) };
assert_eq!(
    page0.addr_range(),
    Range {
        start: 0x0800_0000,
        end: 0x0800_0800
    }
);

Trait Implementations§

source§

impl Clone for Page

source§

fn clone(&self) -> Page

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Page

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Page> for AlignedAddr

source§

fn from(page: Page) -> Self

Converts to this type from the input type.
source§

impl Hash for Page

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Page

source§

fn cmp(&self, other: &Page) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Page

source§

fn eq(&self, other: &Page) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Page

source§

fn partial_cmp(&self, other: &Page) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Page

source§

impl Eq for Page

source§

impl StructuralEq for Page

source§

impl StructuralPartialEq for Page

Auto Trait Implementations§

§

impl RefUnwindSafe for Page

§

impl Send for Page

§

impl Sync for Page

§

impl Unpin for Page

§

impl UnwindSafe for Page

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.