Skip to content

Commit

Permalink
Sync pio_side_set examples
Browse files Browse the repository at this point in the history
The rp2040 and rp235x example of pio_side_set have diverged a bit.
Port the changes made to the rp235x back to rp2040, where applicable.

Also update a comment, as suggested in rp-rs/pio-rs#62
  • Loading branch information
jannic committed Aug 27, 2024
1 parent 2d815bf commit f095734
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
34 changes: 25 additions & 9 deletions rp2040-hal-examples/src/bin/pio_side_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#![no_std]
#![no_main]

use rp2040_hal as hal;

use hal::gpio::{FunctionPio0, Pin};
use hal::pac;
use hal::pio::PIOExt;
use hal::Sio;

// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;
use rp2040_hal as hal;

/// The linker will place this boot block at the start of our program image. We
/// need this to help the ROM bootloader get our code up and running.
Expand All @@ -23,11 +26,11 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;

/// Entry point to our bare-metal application.
///
/// The `#[rp2040_hal::entry]` macro ensures the Cortex-M start-up code calls this function
/// The `#[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]
#[hal::entry]
fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap();
let mut pac = hal::pac::Peripherals::take().unwrap();

let sio = Sio::new(pac.SIO);
let pins = hal::gpio::Pins::new(
Expand All @@ -44,18 +47,18 @@ fn main() -> ! {

// Define some simple PIO program.
let program = pio_proc::pio_asm!(
".side_set 1", // each instruction may set 1 bit
".side_set 1", // each instruction must set 1 bit
".wrap_target",
" nop side 1",
" nop side 0",
" nop side 1 [15]",
" nop side 0 [15]",
".wrap",
);

// Initialize and start PIO
let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
let installed = pio.install(&program.program).unwrap();
let (int, frac) = (0, 0); // as slow as possible (0 is interpreted as 65536)
let (mut sm, _, _) = rp2040_hal::pio::PIOBuilder::from_installed_program(installed)
let (mut sm, _, _) = hal::pio::PIOBuilder::from_installed_program(installed)
.side_set_pin_base(led_pin_id)
.clock_divisor_fixed_point(int, frac)
.build(sm0);
Expand All @@ -68,3 +71,16 @@ fn main() -> ! {
cortex_m::asm::wfi();
}
}

/// Program metadata for `picotool info`
#[link_section = ".bi_entries"]
#[used]
pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 5] = [
hal::binary_info::rp_cargo_bin_name!(),
hal::binary_info::rp_cargo_version!(),
hal::binary_info::rp_program_description!(c"PIO Side-set Example"),
hal::binary_info::rp_cargo_homepage_url!(),
hal::binary_info::rp_program_build_attribute!(),
];

// End of file
2 changes: 1 addition & 1 deletion rp235x-hal-examples/src/bin/pio_side_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> ! {

// Define some simple PIO program.
let program = pio_proc::pio_asm!(
".side_set 1", // each instruction may set 1 bit
".side_set 1", // each instruction must set 1 bit
".wrap_target",
" nop side 1 [15]",
" nop side 0 [15]",
Expand Down

0 comments on commit f095734

Please sign in to comment.