esp-hal/examples/src/bin/lp_core_uart.rs
Björn Quentin 2faa2654cb
GPIO Refactoring (#1542)
* GPIO Refactoring

* CHANGELOG.md

* Addressed review comments

* Use `Level` instead of plain bool in public API

* Let drivers enable analog functions
2024-05-15 08:49:33 +00:00

74 lines
1.9 KiB
Rust

//! This shows a very basic example of running code on the LP core.
//!
//! Code on LP core uses LP_UART initialized on HP core. For more information
//! check `lp_core_uart` example in the `esp-lp-hal.
//!
//! Make sure to first compile the `esp-lp-hal/examples/uart.rs` example
//% CHIPS: esp32c6
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
clock::ClockControl,
gpio::{
lp_io::{LowPowerInput, LowPowerOutput},
Io,
},
lp_core::{LpCore, LpCoreWakeupSource},
peripherals::Peripherals,
prelude::*,
system::SystemControl,
uart::{config::Config, lp_uart::LpUart, TxRxPins, Uart},
};
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Set up (HP) UART1:
let pins = TxRxPins::new_tx_rx(io.pins.gpio6, io.pins.gpio7);
let mut uart1 = Uart::new_with_config(
peripherals.UART1,
Config::default(),
Some(pins),
&clocks,
None,
);
// Set up (LP) UART:
let lp_tx = LowPowerOutput::new(io.pins.gpio5);
let lp_rx = LowPowerInput::new(io.pins.gpio4);
let lp_uart = LpUart::new(peripherals.LP_UART, lp_tx, lp_rx);
let mut lp_core = LpCore::new(peripherals.LP_CORE);
lp_core.stop();
println!("lp core stopped");
// Load code to LP core:
let lp_core_code =
load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/uart");
// Start LP core:
lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_uart);
println!("lpcore run");
loop {
let read = nb::block!(uart1.read_byte());
match read {
Ok(read) => println!("Read 0x{:02x}", read),
Err(err) => println!("Error {:?}", err),
}
}
}