Hello, UART
This commit is contained in:
parent
4a7152edff
commit
0afda7192c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -263,6 +263,7 @@ name = "pico-enviro-sensor"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-hal 1.0.0",
|
"embedded-hal 1.0.0",
|
||||||
|
"fugit",
|
||||||
"panic-halt",
|
"panic-halt",
|
||||||
"rp235x-hal",
|
"rp235x-hal",
|
||||||
]
|
]
|
||||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-hal = "1.0.0"
|
embedded-hal = "1.0.0"
|
||||||
|
fugit = "0.3.7"
|
||||||
panic-halt = "1.0.0"
|
panic-halt = "1.0.0"
|
||||||
rp235x-hal = { version = "0.2.0", features = [
|
rp235x-hal = { version = "0.2.0", features = [
|
||||||
"critical-section-impl",
|
"critical-section-impl",
|
||||||
|
2
src/constants.rs
Normal file
2
src/constants.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/// Pico 2 W on-board crystal oscillator frequency (AEL 12.0)
|
||||||
|
pub const XTAL_FREQ_HZ: u32 = 12_000_000u32;
|
36
src/main.rs
36
src/main.rs
@ -1,22 +1,26 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use panic_halt as _;
|
use embedded_hal::delay::DelayNs;
|
||||||
|
use fugit::RateExtU32;
|
||||||
|
use panic_halt as _; // Needed so its built & linked correctly
|
||||||
|
|
||||||
// Alias for our HAL crate
|
// Alias for our HAL crate
|
||||||
use rp235x_hal as hal;
|
use rp235x_hal as hal;
|
||||||
|
|
||||||
// Some things we need
|
// RP235x HAL
|
||||||
use embedded_hal::delay::DelayNs;
|
use hal::uart::DataBits;
|
||||||
use embedded_hal::digital::OutputPin;
|
use hal::uart::StopBits;
|
||||||
|
use hal::uart::UartConfig;
|
||||||
|
use hal::uart::UartPeripheral;
|
||||||
|
use hal::Clock;
|
||||||
|
|
||||||
|
mod constants;
|
||||||
|
|
||||||
#[link_section = ".start_block"]
|
#[link_section = ".start_block"]
|
||||||
#[used]
|
#[used]
|
||||||
pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
|
pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe();
|
||||||
|
|
||||||
/// Pico 2 W on-board crystal oscillator frequency (AEL 12.0)
|
|
||||||
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
|
|
||||||
|
|
||||||
#[hal::entry]
|
#[hal::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut peripherals = hal::pac::Peripherals::take().unwrap();
|
let mut peripherals = hal::pac::Peripherals::take().unwrap();
|
||||||
@ -24,7 +28,7 @@ fn main() -> ! {
|
|||||||
let mut watchdog = hal::Watchdog::new(peripherals.WATCHDOG);
|
let mut watchdog = hal::Watchdog::new(peripherals.WATCHDOG);
|
||||||
|
|
||||||
let clocks = hal::clocks::init_clocks_and_plls(
|
let clocks = hal::clocks::init_clocks_and_plls(
|
||||||
XTAL_FREQ_HZ,
|
constants::XTAL_FREQ_HZ,
|
||||||
peripherals.XOSC,
|
peripherals.XOSC,
|
||||||
peripherals.CLOCKS,
|
peripherals.CLOCKS,
|
||||||
peripherals.PLL_SYS,
|
peripherals.PLL_SYS,
|
||||||
@ -45,12 +49,18 @@ fn main() -> ! {
|
|||||||
&mut peripherals.RESETS,
|
&mut peripherals.RESETS,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut led_pin = pins.gpio19.into_push_pull_output();
|
let uart0_pins = (pins.gpio0.into_function(), pins.gpio1.into_function());
|
||||||
|
|
||||||
|
let uart = UartPeripheral::new(peripherals.UART0, uart0_pins, &mut peripherals.RESETS)
|
||||||
|
.enable(
|
||||||
|
UartConfig::new(9600_u32.Hz(), DataBits::Eight, None, StopBits::One),
|
||||||
|
clocks.peripheral_clock.freq(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
led_pin.set_high().unwrap();
|
uart.write_full_blocking(b"hello, world!\r\n");
|
||||||
timer.delay_ms(1000);
|
timer.delay_ms(500);
|
||||||
led_pin.set_low().unwrap();
|
|
||||||
timer.delay_ms(1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user