Macro stm32_fmc::reset_reg

source ·
macro_rules! reset_reg {
    ( $periph:path, $instance:expr, $instancemod:path, $reg:ident, $( $field:ident ),+ ) => { ... };
    ( $periph:path, $instance:expr, $instancemod:path, $reg:ident ) => { ... };
}
Expand description

Reset a RWRegister, UnsafeRWRegister, WORegister, or UnsafeWORegister to its reset value.

§Examples

// Safely acquire the peripheral instance (will panic if already acquired)
let gpioa = stm32ral::gpio::GPIOA::take().unwrap();

// Reset PA14 and PA15 to their reset state
reset_reg!(stm32ral::gpio, gpioa, GPIOA, MODER, MODER14, MODER15);

// Reset the entire GPIOA.MODER to its reset state
reset_reg!(stm32ral::gpio, gpioa, GPIOA, MODER);

§Usage

Like write_reg!, this macro can be used in two ways, either resetting the entire register or just resetting specific fields within in. The register or fields are written with their reset values.

In both cases, the first arguments are:

  • the path to the peripheral module: stm32ral::gpio,
  • a reference to the instance of that peripheral: ‘gpioa’ (anything which dereferences to RegisterBlock, such as Instance, &Instance, &RegisterBlock, or *const RegisterBlock),
  • the module for the instance of that peripheral: GPIOA,
  • the register you wish to access: MODER (a field on the RegisterBlock).

In the whole-register usage, that’s it:

// Reset the entire GPIOA.MODER
reset_reg!(stm32ral::gpio, gpioa, GPIOA, MODER);

Otherwise, the remaining arguments are each field names:

// Reset the JTAG pins
reset_reg!(stm32ral::gpio, gpioa, GPIOA, MODER, MODER13, MODER14, MODER15);
reset_reg!(stm32ral::gpio, gpioa, GPIOB, MODER, MODER3, MODER4);

The second form is only available to RWRegister and UnsafeRWRegister, since .read() is not available for WORegister and UnsafeWORegister.

This macro expands to calling (*$instance).$register.write(value), where value is either the register’s reset value, or the current read value of the register masked appropriately and combined with the reset value for each field.

§Safety

This macro will require an unsafe function or block when used with an UnsafeRWRegister or UnsafeRORegister, but not if used with RWRegister or RORegister.

When run in an unsafe context, peripheral instances are directly accessible without requiring having called take() beforehand:

unsafe { reset_reg!(stm32ral::gpio, GPIOA, GPIOA, MODER) };

This works because GPIOA is a *const RegisterBlock in the stm32ral::gpio module; and the macro brings such constants into scope and then dereferences the provided reference.

Note that the second argument is a *const and the third is a path; despite both being written GPIOA they are not the same thing.