Skip to content

Commit 0e7abdc

Browse files
authored
Make BSPs provide boot2 as a default feature (#153)
* Add boot2 feature. Add boot2 linkage into each BSP optional on feature * Enable boot2 feature in BSPs by default. Remove boot2 decl from all BSP examples * Add EXTERN in memory.x for BOOT2_FIRMWARE, rename bootloader static slice to BOOT2_FIRMWARE * Update new examples and itsy_bitsy BSP to use boot2 feature * Remove boot2 as a dev-dependency for the BSPs, no longer needed * Add no_mangle BOOT2_FIRMWARE to adafruit_macropad * Fix itsy-bitsy blinky - it wasn't using the BSP, so it didn't get BOOT2_FIRMWARE linked in
1 parent 88bd408 commit 0e7abdc

36 files changed

+120
-135
lines changed

boards/adafruit_macropad/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
1313
cortex-m = "0.7.2"
14+
rp2040-boot2 = { version = "0.2.0", optional = true }
1415
rp2040-hal = { path = "../../rp2040-hal", version = "0.3.0"}
1516
cortex-m-rt = { version = "0.7", optional = true }
1617

1718
[features]
18-
default = ["rt"]
19+
default = ["rt", "boot2"]
20+
boot2 = ["rp2040-boot2"]
1921
rt = ["cortex-m-rt","rp2040-hal/rt"]
22+

boards/adafruit_macropad/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ extern crate cortex_m_rt;
77
#[cfg(feature = "rt")]
88
pub use cortex_m_rt::entry;
99

10+
// Adafruit macropad uses W25Q64JVxQ flash chip. Should work with BOOT_LOADER_W25Q080 (untested)
11+
12+
//// The linker will place this boot block at the start of our program image. We
13+
//// need this to help the ROM bootloader get our code up and running.
14+
#[cfg(feature = "boot2")]
15+
#[link_section = ".boot2"]
16+
#[no_mangle]
17+
#[used]
18+
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
19+
1020
pub use hal::pac;
1121

1222
hal::bsp_pins!(

boards/feather_rp2040/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
1313
cortex-m = "0.7.2"
14+
rp2040-boot2 = { version = "0.2.0", optional = true }
1415
rp2040-hal = { path = "../../rp2040-hal", version = "0.3.0"}
1516
cortex-m-rt = { version = "0.7", optional = true }
1617
embedded-time = "0.12.0"
1718

1819
[dev-dependencies]
1920
panic-halt= "0.2.0"
2021
embedded-hal ="0.2.5"
21-
rp2040-boot2 = "0.2"
2222
nb = "1.0.0"
2323
smart-leds = "0.3.0"
2424
pio = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
2525
ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "7a11616f994025f5c99f28b283d2b25d60d46a43" }
2626

2727
[features]
28-
default = ["rt"]
28+
default = ["boot2", "rt"]
29+
boot2 = ["rp2040-boot2"]
2930
rt = ["cortex-m-rt","rp2040-hal/rt"]

boards/feather_rp2040/examples/feather_blinky.rs

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ use feather_rp2040::{
1717
Pins, XOSC_CRYSTAL_FREQ,
1818
};
1919
use panic_halt as _;
20-
#[link_section = ".boot2"]
21-
#[used]
22-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GD25Q64CS;
2320

2421
#[entry]
2522
fn main() -> ! {

boards/feather_rp2040/examples/feather_neopixel_rainbow.rs

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ use panic_halt as _;
2424
use rp2040_hal::pio::PIOExt;
2525
use smart_leds::{brightness, SmartLedsWrite, RGB8};
2626
use ws2812_pio::Ws2812;
27-
#[link_section = ".boot2"]
28-
#[used]
29-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GD25Q64CS;
3027

3128
#[entry]
3229
fn main() -> ! {

boards/feather_rp2040/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ extern crate cortex_m_rt;
77
#[cfg(feature = "rt")]
88
pub use cortex_m_rt::entry;
99

10+
//// The linker will place this boot block at the start of our program image. We
11+
//// need this to help the ROM bootloader get our code up and running.
12+
#[cfg(feature = "boot2")]
13+
#[link_section = ".boot2"]
14+
#[no_mangle]
15+
#[used]
16+
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_GD25Q64CS;
17+
1018
pub use hal::pac;
1119

1220
hal::bsp_pins!(

boards/itsy_bitsy_rp2040/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
1313
cortex-m = "0.7.2"
14+
rp2040-boot2 = { version = "0.2.0", optional = true }
1415
rp2040-hal = { path = "../../rp2040-hal", version = "0.3.0"}
1516
cortex-m-rt = { version = "0.7", optional = true }
1617
embedded-time = "0.12.0"
1718

1819
[dev-dependencies]
1920
panic-halt= "0.2.0"
2021
embedded-hal ="0.2.5"
21-
rp2040-boot2 = "0.2"
2222
smart-leds = "0.3"
2323
nb = "1.0.0"
2424
pio = { git = "https://github.com/rp-rs/pio-rs.git", branch = "main" }
2525
ws2812-pio = { git = "https://github.com/ithinuel/ws2812-pio-rs", rev = "7a11616f994025f5c99f28b283d2b25d60d46a43" }
2626

2727
[features]
28-
default = ["rt"]
28+
default = ["rt", "boot2"]
29+
boot2 = ["rp2040-boot2"]
2930
rt = ["cortex-m-rt","rp2040-hal/rt"]

boards/itsy_bitsy_rp2040/examples/itsy_bitsy_blinky.rs

+18-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! # GPIO 'Blinky' Example
22
//!
3-
//! This application demonstrates how to control a GPIO pin on the RP2040.
3+
//! Blinks the LED on a Adafruit itsy-bitsy RP2040 board
44
//!
55
//! It may need to be adapted to your particular board layout and/or pin assignment.
66
//!
@@ -16,27 +16,21 @@ use cortex_m_rt::entry;
1616
// be linked)
1717
use panic_halt as _;
1818

19-
// Alias for our HAL crate
20-
use rp2040_hal as hal;
21-
22-
// A shorter alias for the Peripheral Access Crate, which provides low-level
23-
// register access
24-
use hal::pac;
25-
2619
// Some traits we need
2720
use embedded_hal::digital::v2::OutputPin;
2821
use embedded_time::fixed_point::FixedPoint;
29-
use rp2040_hal::clocks::Clock;
3022

31-
/// The linker will place this boot block at the start of our program image. We
32-
// need this to help the ROM bootloader get our code up and running.
33-
#[link_section = ".boot2"]
34-
#[used]
35-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
23+
use itsy_bitsy_rp2040::{
24+
hal::{
25+
clocks::{init_clocks_and_plls, Clock},
26+
pac,
27+
sio::Sio,
28+
watchdog::Watchdog,
29+
},
30+
Pins, XOSC_CRYSTAL_FREQ,
31+
};
3632

37-
/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust
38-
/// if your board has a different frequency
39-
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
33+
use cortex_m::delay::Delay;
4034

4135
/// Entry point to our bare-metal application.
4236
///
@@ -52,11 +46,11 @@ fn main() -> ! {
5246
let core = pac::CorePeripherals::take().unwrap();
5347

5448
// Set up the watchdog driver - needed by the clock setup code
55-
let mut watchdog = hal::watchdog::Watchdog::new(pac.WATCHDOG);
49+
let mut watchdog = Watchdog::new(pac.WATCHDOG);
5650

5751
// Configure the clocks
58-
let clocks = hal::clocks::init_clocks_and_plls(
59-
XTAL_FREQ_HZ,
52+
let clocks = init_clocks_and_plls(
53+
XOSC_CRYSTAL_FREQ,
6054
pac.XOSC,
6155
pac.CLOCKS,
6256
pac.PLL_SYS,
@@ -67,24 +61,21 @@ fn main() -> ! {
6761
.ok()
6862
.unwrap();
6963

70-
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
64+
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().integer());
7165

7266
// The single-cycle I/O block controls our GPIO pins
73-
let sio = hal::sio::Sio::new(pac.SIO);
67+
let sio = Sio::new(pac.SIO);
7468

75-
// Set the pins to their default state
76-
let pins = hal::gpio::Pins::new(
69+
let pins = Pins::new(
7770
pac.IO_BANK0,
7871
pac.PADS_BANK0,
7972
sio.gpio_bank0,
8073
&mut pac.RESETS,
8174
);
75+
let mut led_pin = pins.d13.into_push_pull_output();
8276

83-
// Configure GPIO25 as an output
84-
let mut led_pin = pins.gpio11.into_push_pull_output();
8577
loop {
8678
led_pin.set_high().unwrap();
87-
// TODO: Replace with proper 1s delays once we have clocks working
8879
delay.delay_ms(500);
8980
led_pin.set_low().unwrap();
9081
delay.delay_ms(500);

boards/itsy_bitsy_rp2040/examples/itsy_bitsy_rainbow.rs

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ use itsy_bitsy_rp2040::{
2222
Pins, XOSC_CRYSTAL_FREQ,
2323
};
2424

25-
#[link_section = ".boot2"]
26-
#[used]
27-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
28-
2925
#[entry]
3026
fn main() -> ! {
3127
let mut pac = pac::Peripherals::take().unwrap();

boards/itsy_bitsy_rp2040/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ extern crate cortex_m_rt;
77
#[cfg(feature = "rt")]
88
pub use cortex_m_rt::entry;
99

10+
//// The linker will place this boot block at the start of our program image. We
11+
//// need this to help the ROM bootloader get our code up and running.
12+
#[cfg(feature = "boot2")]
13+
#[link_section = ".boot2"]
14+
#[no_mangle]
15+
#[used]
16+
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
17+
1018
pub use hal::pac;
1119

1220
hal::bsp_pins!(

boards/pico/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0"
1111

1212
[dependencies]
1313
cortex-m = "0.7.2"
14+
rp2040-boot2 = { version = "0.2.0", optional = true }
1415
rp2040-hal = { path = "../../rp2040-hal", version = "0.3.0"}
1516
cortex-m-rt = { version = "0.7", optional = true }
1617
embedded-time = "0.12.0"
@@ -36,12 +37,12 @@ optional = true
3637
panic-halt= "0.2.0"
3738
embedded-hal ="0.2.5"
3839
cortex-m-rtic = "0.6.0-alpha.5"
39-
rp2040-boot2 = "0.2"
4040
nb = "1.0"
4141
i2c-pio = { git = "https://github.com/ithinuel/i2c-pio-rs", rev = "fb6167d02b7fbc46a83f344f5242823bcd16e271" }
4242

4343
[features]
44-
default = ["rt"]
44+
default = ["boot2", "rt"]
45+
boot2 = ["rp2040-boot2"]
4546
rt = ["cortex-m-rt","rp2040-hal/rt"]
4647
embassy-traits = ["futures", "embassy", "embassy_traits"]
4748

boards/pico/examples/pico_blinky.rs

-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ use pico::hal::pac;
3434
// higher-level drivers.
3535
use pico::hal;
3636

37-
//// The linker will place this boot block at the start of our program image. We
38-
//// need this to help the ROM bootloader get our code up and running.
39-
#[link_section = ".boot2"]
40-
#[used]
41-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
42-
4337
/// Entry point to our bare-metal application.
4438
///
4539
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function

boards/pico/examples/pico_countdown_blinky.rs

-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ use pico::hal::pac;
3333
// higher-level drivers.
3434
use pico::hal;
3535

36-
#[link_section = ".boot2"]
37-
#[used]
38-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
39-
4036
#[entry]
4137
fn main() -> ! {
4238
// Grab our singleton objects

boards/pico/examples/pico_gpio_in_out.rs

-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ use pico::hal::pac;
3030
// higher-level drivers.
3131
use pico::hal;
3232

33-
//// The linker will place this boot block at the start of our program image. We
34-
//// need this to help the ROM bootloader get our code up and running.
35-
#[link_section = ".boot2"]
36-
#[used]
37-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
38-
3933
/// Entry point to our bare-metal application.
4034
///
4135
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function

boards/pico/examples/pico_i2c_controller_peripheral/main.rs

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ use panic_halt as _;
4141
mod controller;
4242
mod peripheral;
4343

44-
#[link_section = ".boot2"]
45-
#[used]
46-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
47-
4844
const ADDRESS: u16 = 0x55;
4945

5046
#[embassy::task]

boards/pico/examples/pico_i2c_pio.rs

-6
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ use pico::hal::pac;
3838
// higher-level drivers.
3939
use pico::hal;
4040

41-
//// The linker will place this boot block at the start of our program image. We
42-
//// need this to help the ROM bootloader get our code up and running.
43-
#[link_section = ".boot2"]
44-
#[used]
45-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
46-
4741
/// Prints the temperature received from the sensor
4842
fn print_temperature(serial: &mut impl FmtWrite, temp: [u8; 2]) {
4943
let temp_i16 = i16::from_be_bytes(temp) >> 5;

boards/pico/examples/pico_pwm_blink.rs

-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ use pico::hal::pac;
3434
// higher-level drivers.
3535
use pico::hal;
3636

37-
//// The linker will place this boot block at the start of our program image. We
38-
//// need this to help the ROM bootloader get our code up and running.
39-
#[link_section = ".boot2"]
40-
#[used]
41-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
42-
4337
// The minimum PWM value (i.e. LED brightness) we want
4438
const LOW: u16 = 0;
4539

boards/pico/examples/pico_rtic.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
use panic_halt as _;
55
use rp2040_hal as hal;
66

7-
#[link_section = ".boot2"]
8-
#[used]
9-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
10-
117
#[rtic::app(device = crate::hal::pac, peripherals = true)]
128
mod app {
139

boards/pico/examples/pico_usb_serial.rs

-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ use usb_device::{class_prelude::*, prelude::*};
3333
// USB Communications Class Device support
3434
use usbd_serial::SerialPort;
3535

36-
//// The linker will place this boot block at the start of our program image. We
37-
//// need this to help the ROM bootloader get our code up and running.
38-
#[link_section = ".boot2"]
39-
#[used]
40-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
41-
4236
/// Entry point to our bare-metal application.
4337
///
4438
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function

boards/pico/examples/pico_usb_serial_interrupt.rs

-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ use usb_device::{class_prelude::*, prelude::*};
4545
// USB Communications Class Device support
4646
use usbd_serial::SerialPort;
4747

48-
//// The linker will place this boot block at the start of our program image. We
49-
//// need this to help the ROM bootloader get our code up and running.
50-
#[link_section = ".boot2"]
51-
#[used]
52-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
53-
5448
/// The USB Device Driver (shared with the interrupt).
5549
static mut USB_DEVICE: Option<UsbDevice<hal::usb::UsbBus>> = None;
5650

boards/pico/examples/pico_usb_twitchy_mouse.rs

-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ use usbd_hid::descriptor::generator_prelude::*;
4444
use usbd_hid::descriptor::MouseReport;
4545
use usbd_hid::hid_class::HIDClass;
4646

47-
//// The linker will place this boot block at the start of our program image. We
48-
//// need this to help the ROM bootloader get our code up and running.
49-
#[link_section = ".boot2"]
50-
#[used]
51-
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
52-
5347
/// The USB Device Driver (shared with the interrupt).
5448
static mut USB_DEVICE: Option<UsbDevice<hal::usb::UsbBus>> = None;
5549

boards/pico/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ extern crate cortex_m_rt;
77
#[cfg(feature = "rt")]
88
pub use cortex_m_rt::entry;
99

10+
//// The linker will place this boot block at the start of our program image. We
11+
//// need this to help the ROM bootloader get our code up and running.
12+
#[cfg(feature = "boot2")]
13+
#[link_section = ".boot2"]
14+
#[no_mangle]
15+
#[used]
16+
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
17+
1018
pub use hal::pac;
1119

1220
hal::bsp_pins!(

0 commit comments

Comments
 (0)