Skip to content

Commit f095734

Browse files
committed
Sync pio_side_set examples
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
1 parent 2d815bf commit f095734

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

rp2040-hal-examples/src/bin/pio_side_set.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
#![no_std]
77
#![no_main]
88

9+
use rp2040_hal as hal;
10+
911
use hal::gpio::{FunctionPio0, Pin};
10-
use hal::pac;
1112
use hal::pio::PIOExt;
1213
use hal::Sio;
14+
15+
// Ensure we halt the program on panic (if we don't mention this crate it won't
16+
// be linked)
1317
use panic_halt as _;
14-
use rp2040_hal as hal;
1518

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

2427
/// Entry point to our bare-metal application.
2528
///
26-
/// The `#[rp2040_hal::entry]` macro ensures the Cortex-M start-up code calls this function
29+
/// The `#[hal::entry]` macro ensures the Cortex-M start-up code calls this function
2730
/// as soon as all global variables and the spinlock are initialised.
28-
#[rp2040_hal::entry]
31+
#[hal::entry]
2932
fn main() -> ! {
30-
let mut pac = pac::Peripherals::take().unwrap();
33+
let mut pac = hal::pac::Peripherals::take().unwrap();
3134

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

4548
// Define some simple PIO program.
4649
let program = pio_proc::pio_asm!(
47-
".side_set 1", // each instruction may set 1 bit
50+
".side_set 1", // each instruction must set 1 bit
4851
".wrap_target",
49-
" nop side 1",
50-
" nop side 0",
52+
" nop side 1 [15]",
53+
" nop side 0 [15]",
5154
".wrap",
5255
);
5356

5457
// Initialize and start PIO
5558
let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
5659
let installed = pio.install(&program.program).unwrap();
5760
let (int, frac) = (0, 0); // as slow as possible (0 is interpreted as 65536)
58-
let (mut sm, _, _) = rp2040_hal::pio::PIOBuilder::from_installed_program(installed)
61+
let (mut sm, _, _) = hal::pio::PIOBuilder::from_installed_program(installed)
5962
.side_set_pin_base(led_pin_id)
6063
.clock_divisor_fixed_point(int, frac)
6164
.build(sm0);
@@ -68,3 +71,16 @@ fn main() -> ! {
6871
cortex_m::asm::wfi();
6972
}
7073
}
74+
75+
/// Program metadata for `picotool info`
76+
#[link_section = ".bi_entries"]
77+
#[used]
78+
pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 5] = [
79+
hal::binary_info::rp_cargo_bin_name!(),
80+
hal::binary_info::rp_cargo_version!(),
81+
hal::binary_info::rp_program_description!(c"PIO Side-set Example"),
82+
hal::binary_info::rp_cargo_homepage_url!(),
83+
hal::binary_info::rp_program_build_attribute!(),
84+
];
85+
86+
// End of file

rp235x-hal-examples/src/bin/pio_side_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() -> ! {
4444

4545
// Define some simple PIO program.
4646
let program = pio_proc::pio_asm!(
47-
".side_set 1", // each instruction may set 1 bit
47+
".side_set 1", // each instruction must set 1 bit
4848
".wrap_target",
4949
" nop side 1 [15]",
5050
" nop side 0 [15]",

0 commit comments

Comments
 (0)