diff options
| author | James Munns <[email protected]> | 2025-11-18 14:19:09 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-18 14:19:09 +0100 |
| commit | 5b1149a52dbec9e3bdd10dc341dc0751ab4798a6 (patch) | |
| tree | 3ff7098471cf660a54a707464a0e2feb2080b09e /examples/src/bin/hello.rs | |
| parent | 62e297c130ac26afe4d7d5752bb79709bd370e39 (diff) | |
| parent | c8942aec2478ff077b55da0e86801f8a6a88a7de (diff) | |
Merge pull request #11 from jamesmunns/james/impl-clocks
Implement initial `clock` driver.
This PR introduces an initial two-phase clock driver system:
1. The first stage is responsible for initializing the core/system clocks at the time of `embassy_mcxa::init()`
2. The second stage is done on creation of peripherals
This work is limited to currently used clocks and peripherals, but has room for expansion for later peripherals. This model is based on the preliminary refactoring performed for the `embassy-imxrt` crate.
Diffstat (limited to 'examples/src/bin/hello.rs')
| -rw-r--r-- | examples/src/bin/hello.rs | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/examples/src/bin/hello.rs b/examples/src/bin/hello.rs index 5c4336d50..207c157c3 100644 --- a/examples/src/bin/hello.rs +++ b/examples/src/bin/hello.rs | |||
| @@ -2,12 +2,11 @@ | |||
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 5 | use embassy_mcxa_examples::init_uart2; | 5 | use hal::lpuart::{Blocking, Config, Lpuart}; |
| 6 | use hal::uart; | ||
| 7 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 6 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 8 | 7 | ||
| 9 | /// Simple helper to write a byte as hex to UART | 8 | /// Simple helper to write a byte as hex to UART |
| 10 | fn write_hex_byte(uart: &hal::uart::Uart<hal::uart::Lpuart2>, byte: u8) { | 9 | fn write_hex_byte(uart: &mut Lpuart<'_, Blocking>, byte: u8) { |
| 11 | const HEX_DIGITS: &[u8] = b"0123456789ABCDEF"; | 10 | const HEX_DIGITS: &[u8] = b"0123456789ABCDEF"; |
| 12 | uart.write_byte(HEX_DIGITS[(byte >> 4) as usize]); | 11 | uart.write_byte(HEX_DIGITS[(byte >> 4) as usize]); |
| 13 | uart.write_byte(HEX_DIGITS[(byte & 0xF) as usize]); | 12 | uart.write_byte(HEX_DIGITS[(byte & 0xF) as usize]); |
| @@ -19,15 +18,25 @@ async fn main(_spawner: Spawner) { | |||
| 19 | 18 | ||
| 20 | defmt::info!("boot"); | 19 | defmt::info!("boot"); |
| 21 | 20 | ||
| 22 | // Board-level init for UART2 clocks and pins. | 21 | // Create UART configuration |
| 22 | let config = Config { | ||
| 23 | baudrate_bps: 115_200, | ||
| 24 | enable_tx: true, | ||
| 25 | enable_rx: true, | ||
| 26 | ..Default::default() | ||
| 27 | }; | ||
| 28 | |||
| 29 | // Create UART instance using LPUART2 with PIO2_2 as TX and PIO2_3 as RX | ||
| 23 | unsafe { | 30 | unsafe { |
| 24 | init_uart2(hal::pac()); | 31 | embassy_mcxa_examples::init_uart2_pins(hal::pac()); |
| 25 | } | 32 | } |
| 26 | 33 | let mut uart = Lpuart::new_blocking( | |
| 27 | // Get UART source frequency from clock configuration | 34 | p.LPUART2, // Peripheral |
| 28 | // Using hardcoded frequency for now - dynamic detection may have issues | 35 | p.PIO2_2, // TX pin |
| 29 | let src = 12_000_000; // FRO_LF_DIV at 12MHz with DIV=0 | 36 | p.PIO2_3, // RX pin |
| 30 | let uart = uart::Uart::<uart::Lpuart2>::new(p.LPUART2, uart::Config::new(src)); | 37 | config, |
| 38 | ) | ||
| 39 | .unwrap(); | ||
| 31 | 40 | ||
| 32 | // Print welcome message before any async delays to guarantee early console output | 41 | // Print welcome message before any async delays to guarantee early console output |
| 33 | uart.write_str_blocking("\r\n=== MCXA276 UART Echo Demo ===\r\n"); | 42 | uart.write_str_blocking("\r\n=== MCXA276 UART Echo Demo ===\r\n"); |
| @@ -66,7 +75,7 @@ async fn main(_spawner: Spawner) { | |||
| 66 | let num_str = &command[4..]; | 75 | let num_str = &command[4..]; |
| 67 | if let Ok(num) = parse_u8(num_str) { | 76 | if let Ok(num) = parse_u8(num_str) { |
| 68 | uart.write_str_blocking("Hex: 0x"); | 77 | uart.write_str_blocking("Hex: 0x"); |
| 69 | write_hex_byte(&uart, num); | 78 | write_hex_byte(&mut uart, num); |
| 70 | uart.write_str_blocking("\r\n"); | 79 | uart.write_str_blocking("\r\n"); |
| 71 | } else { | 80 | } else { |
| 72 | uart.write_str_blocking("Invalid number for hex command\r\n"); | 81 | uart.write_str_blocking("Invalid number for hex command\r\n"); |
