Skip to content

Commit 93264a0

Browse files
plmExplodingWaffle
authored andcommitted
Add BSP for Seeeduino XIAO RP2040 (rp-rs#369)
* Add BSP for Seeeduino XIAO RP2040 * Add missing link target * Add top-level README mention of XIAO RP2040
1 parent c1c0507 commit 93264a0

File tree

7 files changed

+361
-0
lines changed

7 files changed

+361
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"boards/pimoroni-plasma-2040",
1616
"boards/pimoroni-tiny2040",
1717
"boards/rp-pico",
18+
"boards/seeeduino-xiao-rp2040",
1819
"boards/solderparty-rp2040-stamp",
1920
"boards/sparkfun-pro-micro-rp2040",
2021
"boards/sparkfun-thing-plus-rp2040",

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ RP2040 chip according to how it is connected up on the nano connect.
261261
[Arduino Nano RP2040 Connect]: https://store-usa.arduino.cc/collections/boards/products/arduino-nano-rp2040-connect
262262
[arduino_nano_connect]: https://github.com/rp-rs/rp-hal/tree/main/boards/arduino_nano_connect
263263

264+
### [seeeduino-xiao-rp2040] - Board Support for the [Seeeduino XIAO RP2040]
265+
266+
You should include this crate if you are writing code that you want to run on
267+
a [Seeeduino XIAO RP2040] - a tiny board for wearable devices and small
268+
projects.
269+
270+
This crate includes the [rp2040-hal], but also configures each pin of the
271+
RP2040 chip according to how it is connected up on the XIAO RP2040.
272+
273+
[Seeeduino XIAO RP2040]: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
274+
[seeeduino-xiao-rp2040]: https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp2040
275+
264276
<!-- PROGRAMMING -->
265277
## Programming
266278

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## Unreleased
9+
10+
### Added
11+
12+
- None
13+
14+
### Changed
15+
16+
- None
17+
18+
## 0.1.0 - 2022-06-26
19+
20+
- Initial release
21+
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "seeeduino-xiao-rp2040"
3+
version = "0.1.0"
4+
authors = ["Philip L. McMahon <[email protected]>", "The rp-rs Developers"]
5+
edition = "2018"
6+
homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp02040"
7+
description = "Board Support Package for the Seeediuno XIAO RP2040"
8+
license = "MIT OR Apache-2.0"
9+
repository = "https://github.com/rp-rs/rp-hal.git"
10+
11+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
12+
13+
[dependencies]
14+
cortex-m = "0.7.2"
15+
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
16+
cortex-m-rt = { version = "0.7", optional = true }
17+
rp2040-boot2 = { version = "0.2.0", optional = true }
18+
19+
[dev-dependencies]
20+
embedded-time = "0.12.0"
21+
panic-halt= "0.2.0"
22+
embedded-hal ="0.2.5"
23+
nb = "1.0"
24+
25+
[features]
26+
default = ["boot2", "rt"]
27+
boot2 = ["rp2040-boot2"]
28+
rt = ["cortex-m-rt","rp2040-hal/rt"]
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# [seeeduino-xiao-rp2040] - Board Support for the [Seeeduino XIAO RP2040]
2+
3+
You should include this crate if you are writing code that you want to run on
4+
a [Seeeduino XIAO RP2040] - a tiny board for wearable devices and small
5+
projects.
6+
7+
This crate includes the [rp2040-hal], but also configures each pin of the
8+
RP2040 chip according to how it is connected up on the XIAO RP2040.
9+
10+
[Seeeduino XIAO RP2040]: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
11+
[seeeduino-xiao-rp2040]: https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp2040
12+
[rp2040-hal]: https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal
13+
14+
## Using
15+
16+
To use this crate, your `Cargo.toml` file should contain:
17+
18+
```toml
19+
seeeduino-xiao-rp2040 = "0.1.0"
20+
```
21+
22+
In your program, you will need to call `seeeduino-xiao-rp2040::Pins::new` to create
23+
a new `Pins` structure. This will set up all the GPIOs for any on-board
24+
devices. See the [examples](./examples) folder for more details.
25+
26+
## Examples
27+
28+
### General Instructions
29+
30+
To compile an example, clone the _rp-hal_ repository and run:
31+
32+
```console
33+
rp-hal/boards/seeeduino-xiao-rp2040 $ cargo build --release --example <name>
34+
```
35+
36+
You will get an ELF file called
37+
`./target/thumbv6m-none-eabi/release/examples/<name>`, where the `target`
38+
folder is located at the top of the _rp-hal_ repository checkout. Normally
39+
you would also need to specify `--target=thumbv6m-none-eabi` but when
40+
building examples from this git repository, that is set as the default.
41+
42+
If you want to convert the ELF file to a UF2 and automatically copy it to the
43+
USB drive exported by the RP2040 bootloader, simply boot your board into
44+
bootloader mode and run:
45+
46+
```console
47+
rp-hal/boards/seeeduino-xiao-rp2040 $ cargo run --release --example <name>
48+
```
49+
50+
If you get an error about not being able to find `elf2uf2-rs`, try:
51+
52+
```console
53+
$ cargo install elf2uf2-rs
54+
```
55+
56+
After installing `elf2uf2-rs`, retry the `cargo run` command above.
57+
58+
### [seeeduino_xiao_rp2040_blinky](./examples/seeeduino_xiao_rp2040_blinky.rs)
59+
60+
Flashes the XIAO RP2040's on-board LED on and off.
61+
62+
## Contributing
63+
64+
Contributions are what make the open source community such an amazing place to
65+
be learn, inspire, and create. Any contributions you make are **greatly
66+
appreciated**.
67+
68+
The steps are:
69+
70+
1. Fork the Project by clicking the 'Fork' button at the top of the page.
71+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
72+
3. Make some changes to the code or documentation.
73+
4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
74+
5. Push to the Feature Branch (`git push origin feature/AmazingFeature`)
75+
6. Create a [New Pull Request](https://github.com/rp-rs/rp-hal/pulls)
76+
7. An admin will review the Pull Request and discuss any changes that may be required.
77+
8. Once everyone is happy, the Pull Request can be merged by an admin, and your work is part of our project!
78+
79+
## Code of Conduct
80+
81+
Contribution to this crate is organized under the terms of the [Rust Code of
82+
Conduct][CoC], and the maintainer of this crate, the [rp-rs team], promises
83+
to intervene to uphold that code of conduct.
84+
85+
[CoC]: CODE_OF_CONDUCT.md
86+
[rp-rs team]: https://github.com/orgs/rp-rs/teams/rp-rs
87+
88+
## License
89+
90+
The contents of this repository are dual-licensed under the _MIT OR Apache
91+
2.0_ License. That means you can choose either the MIT license or the
92+
Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more
93+
information on each specific license.
94+
95+
Any submissions to this project (e.g. as Pull Requests) must be made available
96+
under these terms.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//! # Seeeduino XIAO RP2040 Blinky Example
2+
//!
3+
//! Blinks the LED on a Seeeduino XIAO RP2040 16MB board.
4+
//!
5+
//! This will blink an LED attached to GPIO25, which is the pin the XIAO RP2040
6+
//! uses for the on-board LED.
7+
//!
8+
//! See the `Cargo.toml` file for Copyright and license details.
9+
10+
#![no_std]
11+
#![no_main]
12+
13+
// The macro for our start-up function
14+
use seeeduino_xiao_rp2040::entry;
15+
16+
// GPIO traits
17+
use embedded_hal::digital::v2::OutputPin;
18+
use embedded_hal::PwmPin;
19+
20+
// Time handling traits
21+
use embedded_time::rate::*;
22+
23+
// Ensure we halt the program on panic (if we don't mention this crate it won't
24+
// be linked)
25+
use panic_halt as _;
26+
27+
// Pull in any important traits
28+
use seeeduino_xiao_rp2040::hal::prelude::*;
29+
30+
// A shorter alias for the Peripheral Access Crate, which provides low-level
31+
// register access
32+
use seeeduino_xiao_rp2040::hal::pac;
33+
34+
// A shorter alias for the Hardware Abstraction Layer, which provides
35+
// higher-level drivers.
36+
use seeeduino_xiao_rp2040::hal;
37+
38+
// The minimum PWM value (i.e. LED brightness) we want
39+
const LOW: u16 = 0;
40+
41+
// The maximum PWM value (i.e. LED brightness) we want
42+
const HIGH: u16 = 60000;
43+
44+
/// Entry point to our bare-metal application.
45+
///
46+
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function
47+
/// as soon as all global variables are initialised.
48+
///
49+
/// The function configures the RP2040 peripherals, then blinks the LED in an
50+
/// infinite loop.
51+
#[entry]
52+
fn main() -> ! {
53+
// Grab our singleton objects
54+
let mut pac = pac::Peripherals::take().unwrap();
55+
let core = pac::CorePeripherals::take().unwrap();
56+
57+
// Set up the watchdog driver - needed by the clock setup code
58+
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
59+
60+
// Configure the clocks
61+
//
62+
// The default is to generate a 125 MHz system clock
63+
let clocks = hal::clocks::init_clocks_and_plls(
64+
seeeduino_xiao_rp2040::XOSC_CRYSTAL_FREQ,
65+
pac.XOSC,
66+
pac.CLOCKS,
67+
pac.PLL_SYS,
68+
pac.PLL_USB,
69+
&mut pac.RESETS,
70+
&mut watchdog,
71+
)
72+
.ok()
73+
.unwrap();
74+
75+
// The single-cycle I/O block controls our GPIO pins
76+
let sio = hal::Sio::new(pac.SIO);
77+
78+
// Set the pins up according to their function on this particular board
79+
let pins = seeeduino_xiao_rp2040::Pins::new(
80+
pac.IO_BANK0,
81+
pac.PADS_BANK0,
82+
sio.gpio_bank0,
83+
&mut pac.RESETS,
84+
);
85+
86+
// The delay object lets us wait for specified amounts of time (in
87+
// milliseconds)
88+
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
89+
90+
// Init PWMs
91+
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
92+
93+
// Configure PWM4
94+
let pwm = &mut pwm_slices.pwm0;
95+
pwm.set_ph_correct();
96+
pwm.enable();
97+
98+
// Output channel B on PWM0 to the red LED pin, initially off
99+
let channel = &mut pwm.channel_b;
100+
channel.output_to(pins.led_red);
101+
channel.set_duty(u16::MAX);
102+
103+
// Set the blue LED to be an output, initially off
104+
let mut led_blue_pin = pins.led_blue.into_push_pull_output();
105+
led_blue_pin.set_high().unwrap();
106+
107+
// Turn off the green LED
108+
let mut led_green_pin = pins.led_green.into_push_pull_output();
109+
led_green_pin.set_high().unwrap();
110+
111+
loop {
112+
// Blink blue LED at 1 Hz
113+
for _ in 0..5 {
114+
led_blue_pin.set_low().unwrap();
115+
delay.delay_ms(500);
116+
led_blue_pin.set_high().unwrap();
117+
delay.delay_ms(500);
118+
}
119+
120+
// Ramp red LED brightness up
121+
for i in (LOW..=HIGH).skip(30) {
122+
delay.delay_us(100);
123+
channel.set_duty(u16::MAX - i);
124+
}
125+
126+
// Ramp red LED brightness down
127+
for i in (LOW..=HIGH).rev().skip(30) {
128+
delay.delay_us(100);
129+
channel.set_duty(u16::MAX - i);
130+
}
131+
}
132+
}
133+
134+
// End of file
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#![no_std]
2+
3+
pub use rp2040_hal as hal;
4+
5+
#[cfg(feature = "rt")]
6+
extern crate cortex_m_rt;
7+
#[cfg(feature = "rt")]
8+
pub use hal::entry;
9+
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+
18+
pub use hal::pac;
19+
20+
hal::bsp_pins!(
21+
Gpio0 {
22+
name: tx,
23+
aliases: { FunctionUart: UartTx }
24+
},
25+
Gpio1 {
26+
name: rx
27+
aliases: { FunctionUart: UartRx, FunctionSpi: Csn }
28+
},
29+
Gpio2 {
30+
name: d8,
31+
aliases: { FunctionSpi: Sck }
32+
},
33+
Gpio3 {
34+
name: mosi,
35+
aliases: { FunctionSpi: Mosi }
36+
},
37+
Gpio4 {
38+
name: miso,
39+
aliases: { FunctionSpi: Miso }
40+
},
41+
Gpio6 {
42+
name: sda,
43+
aliases: { FunctionI2C: Sda }
44+
},
45+
Gpio7 {
46+
name: scl,
47+
aliases: { FunctionI2C: Scl }
48+
},
49+
Gpio11 { name: neopixel_power },
50+
Gpio12 { name: neopixel_data },
51+
Gpio16 {
52+
name: led_green,
53+
aliases: { FunctionPwm: LedGreenPwm }
54+
},
55+
Gpio17 {
56+
name: led_red,
57+
aliases: { FunctionPwm: LedRedPwm }
58+
},
59+
Gpio25 {
60+
name: led_blue,
61+
aliases: { FunctionPwm: LedBluePwm }
62+
},
63+
Gpio26 { name: a0 },
64+
Gpio27 { name: a1 },
65+
Gpio28 { name: a2 },
66+
Gpio29 { name: a3 },
67+
);
68+
69+
pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000;

0 commit comments

Comments
 (0)