2021-09-29 05:48:05 +10:00
|
|
|
//! This example toggles the GPIO25 pin, using a PIO program compiled via pio_proc::pio!().
|
|
|
|
//!
|
|
|
|
//! If a LED is connected to that pin, like on a Pico board, the LED should blink.
|
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use hal::gpio::{FunctionPio0, Pin};
|
|
|
|
use hal::pac;
|
|
|
|
use hal::pio::PIOExt;
|
2021-12-04 15:52:46 +11:00
|
|
|
use hal::Sio;
|
2021-09-29 05:48:05 +10:00
|
|
|
use panic_halt as _;
|
|
|
|
use rp2040_hal as hal;
|
|
|
|
|
|
|
|
#[link_section = ".boot2"]
|
|
|
|
#[used]
|
2022-08-11 21:56:36 +10:00
|
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;
|
2021-09-29 05:48:05 +10:00
|
|
|
|
2022-08-22 04:01:45 +10:00
|
|
|
/// Entry point to our bare-metal application.
|
|
|
|
///
|
|
|
|
/// The `#[rp2040_hal::entry]` macro ensures the Cortex-M start-up code calls this function
|
|
|
|
/// as soon as all global variables and the spinlock are initialised.
|
|
|
|
#[rp2040_hal::entry]
|
2021-09-29 05:48:05 +10:00
|
|
|
fn main() -> ! {
|
|
|
|
let mut pac = pac::Peripherals::take().unwrap();
|
|
|
|
|
|
|
|
let sio = Sio::new(pac.SIO);
|
|
|
|
let pins = hal::gpio::Pins::new(
|
|
|
|
pac.IO_BANK0,
|
|
|
|
pac.PADS_BANK0,
|
|
|
|
sio.gpio_bank0,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
);
|
|
|
|
|
|
|
|
// configure LED pin for Pio0.
|
|
|
|
let _led: Pin<_, FunctionPio0> = pins.gpio25.into_mode();
|
|
|
|
// PIN id for use inside of PIO
|
|
|
|
let led_pin_id = 25;
|
|
|
|
|
|
|
|
// Define some simple PIO program.
|
2022-03-11 22:37:34 +11:00
|
|
|
let program = pio_proc::pio_asm!(
|
|
|
|
".wrap_target",
|
|
|
|
"set pins, 1 [31]",
|
|
|
|
"set pins, 0 [31]",
|
|
|
|
".wrap"
|
2021-09-29 05:48:05 +10:00
|
|
|
);
|
|
|
|
|
|
|
|
// Initialize and start PIO
|
|
|
|
let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
|
|
|
|
let installed = pio.install(&program.program).unwrap();
|
|
|
|
let div = 0f32; // as slow as possible (0 is interpreted as 65536)
|
2021-09-30 17:07:15 +10:00
|
|
|
let (mut sm, _, _) = rp2040_hal::pio::PIOBuilder::from_program(installed)
|
2021-09-29 05:48:05 +10:00
|
|
|
.set_pins(led_pin_id, 1)
|
|
|
|
.clock_divisor(div)
|
|
|
|
.build(sm0);
|
|
|
|
// The GPIO pin needs to be configured as an output.
|
2021-10-22 21:13:22 +11:00
|
|
|
sm.set_pindirs([(led_pin_id, hal::pio::PinDir::Output)]);
|
2021-09-29 05:48:05 +10:00
|
|
|
sm.start();
|
|
|
|
|
|
|
|
// PIO runs in background, independently from CPU
|
2022-08-02 00:50:48 +10:00
|
|
|
loop {
|
|
|
|
cortex_m::asm::wfi();
|
|
|
|
}
|
2021-09-29 05:48:05 +10:00
|
|
|
}
|