embassy-mcxa

Crates

git

Versions

mcx-a256

Flavors

Module clocks

Module clocks 

Source
Expand description

§Clock Module

For the MCX-A, we separate clock and peripheral control into two main stages:

  1. At startup, e.g. when embassy_mcxa::init() is called, we configure the core system clocks, including external and internal oscillators. This configuration is then largely static for the duration of the program.
  2. When HAL drivers are created, e.g. Lpuart::new() is called, the driver is responsible for two main things:
    • Ensuring that any required “upstream” core system clocks necessary for clocking the peripheral is active and configured to a reasonable value
    • Enabling the clock gates for that peripheral, and resetting the peripheral

From a user perspective, only step 1 is visible. Step 2 is automatically handled by HAL drivers, using interfaces defined in this module.

It is also possible to view the state of the clock configuration after init() has been called, using the with_clocks() function, which provides a view of the Clocks structure.

§For HAL driver implementors

The majority of peripherals in the MCXA chip are fed from either a “hard-coded” or configurable clock source, e.g. selecting the FROM12M or clk_1m as a source. This selection, as well as often any pre-scaler division from that source clock, is made through MRCC registers.

Any peripheral that is controlled through the MRCC register can automatically implement the necessary APIs using the impl_cc_gate! macro in this module. You will also need to define the configuration surface and steps necessary to fully configure that peripheral from a clocks perspective by:

  1. Defining a configuration type in the periph_helpers module that contains any selects or divisions available to the HAL driver
  2. Implementing the periph_helpers::SPConfHelper trait, which should check that the necessary input clocks are reasonable

Modules§

config
Clock Configuration
periph_helpers
Peripheral Helpers

Structs§

Clock
Information regarding a system clock
Clocks
The Clocks structure contains the initialized state of the core system clocks

Enums§

ClockError
ClockError is the main error returned when configuring or checking clock state
PoweredClock
The power state of a given clock.

Traits§

Gate
Trait describing an AHB clock gate that can be toggled through MRCC.

Functions§

assert_reset
Assert a reset line for the given peripheral set.
disable
Disable the clock gate for the given peripheral.
enable
Enable the clock gate for the given peripheral.
enable_and_reset
This is the primary helper method HAL drivers are expected to call when creating an instance of the peripheral.
init
Initialize the core system clocks with the given ClocksConfig.
is_clock_enabled
Check whether a gate is currently enabled.
is_reset_released
Check whether the peripheral is held in reset.
pulse_reset
Pulse a reset line (assert then release) with a short delay.
release_reset
Release a reset line for the given peripheral set.
with_clocks
Obtain the full clocks structure, calling the given closure in a critical section.