Add BSP for Seeeduino XIAO RP2040 (#369)

* Add BSP for Seeeduino XIAO RP2040

* Add missing link target

* Add top-level README mention of XIAO RP2040
This commit is contained in:
Philip L. McMahon 2022-07-06 03:41:47 -07:00 committed by GitHub
parent 711694881d
commit 803f582e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 361 additions and 0 deletions

View file

@ -15,6 +15,7 @@ members = [
"boards/pimoroni-plasma-2040",
"boards/pimoroni-tiny2040",
"boards/rp-pico",
"boards/seeeduino-xiao-rp2040",
"boards/solderparty-rp2040-stamp",
"boards/sparkfun-pro-micro-rp2040",
"boards/sparkfun-thing-plus-rp2040",

View file

@ -261,6 +261,18 @@ RP2040 chip according to how it is connected up on the nano connect.
[Arduino Nano RP2040 Connect]: https://store-usa.arduino.cc/collections/boards/products/arduino-nano-rp2040-connect
[arduino_nano_connect]: https://github.com/rp-rs/rp-hal/tree/main/boards/arduino_nano_connect
### [seeeduino-xiao-rp2040] - Board Support for the [Seeeduino XIAO RP2040]
You should include this crate if you are writing code that you want to run on
a [Seeeduino XIAO RP2040] - a tiny board for wearable devices and small
projects.
This crate includes the [rp2040-hal], but also configures each pin of the
RP2040 chip according to how it is connected up on the XIAO RP2040.
[Seeeduino XIAO RP2040]: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
[seeeduino-xiao-rp2040]: https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp2040
<!-- PROGRAMMING -->
## Programming

View file

@ -0,0 +1,21 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- None
### Changed
- None
## 0.1.0 - 2022-06-26
- Initial release

View file

@ -0,0 +1,28 @@
[package]
name = "seeeduino-xiao-rp2040"
version = "0.1.0"
authors = ["Philip L. McMahon <plm@users.noreply.github.com>", "The rp-rs Developers"]
edition = "2018"
homepage = "https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp02040"
description = "Board Support Package for the Seeediuno XIAO RP2040"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rp-rs/rp-hal.git"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cortex-m = "0.7.2"
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true }
rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies]
embedded-time = "0.12.0"
panic-halt= "0.2.0"
embedded-hal ="0.2.5"
nb = "1.0"
[features]
default = ["boot2", "rt"]
boot2 = ["rp2040-boot2"]
rt = ["cortex-m-rt","rp2040-hal/rt"]

View file

@ -0,0 +1,96 @@
# [seeeduino-xiao-rp2040] - Board Support for the [Seeeduino XIAO RP2040]
You should include this crate if you are writing code that you want to run on
a [Seeeduino XIAO RP2040] - a tiny board for wearable devices and small
projects.
This crate includes the [rp2040-hal], but also configures each pin of the
RP2040 chip according to how it is connected up on the XIAO RP2040.
[Seeeduino XIAO RP2040]: https://www.seeedstudio.com/XIAO-RP2040-v1-0-p-5026.html
[seeeduino-xiao-rp2040]: https://github.com/rp-rs/rp-hal/tree/main/boards/seeeduino-xiao-rp2040
[rp2040-hal]: https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal
## Using
To use this crate, your `Cargo.toml` file should contain:
```toml
seeeduino-xiao-rp2040 = "0.1.0"
```
In your program, you will need to call `seeeduino-xiao-rp2040::Pins::new` to create
a new `Pins` structure. This will set up all the GPIOs for any on-board
devices. See the [examples](./examples) folder for more details.
## Examples
### General Instructions
To compile an example, clone the _rp-hal_ repository and run:
```console
rp-hal/boards/seeeduino-xiao-rp2040 $ cargo build --release --example <name>
```
You will get an ELF file called
`./target/thumbv6m-none-eabi/release/examples/<name>`, where the `target`
folder is located at the top of the _rp-hal_ repository checkout. Normally
you would also need to specify `--target=thumbv6m-none-eabi` but when
building examples from this git repository, that is set as the default.
If you want to convert the ELF file to a UF2 and automatically copy it to the
USB drive exported by the RP2040 bootloader, simply boot your board into
bootloader mode and run:
```console
rp-hal/boards/seeeduino-xiao-rp2040 $ cargo run --release --example <name>
```
If you get an error about not being able to find `elf2uf2-rs`, try:
```console
$ cargo install elf2uf2-rs
```
After installing `elf2uf2-rs`, retry the `cargo run` command above.
### [seeeduino_xiao_rp2040_blinky](./examples/seeeduino_xiao_rp2040_blinky.rs)
Flashes the XIAO RP2040's on-board LED on and off.
## Contributing
Contributions are what make the open source community such an amazing place to
be learn, inspire, and create. Any contributions you make are **greatly
appreciated**.
The steps are:
1. Fork the Project by clicking the 'Fork' button at the top of the page.
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Make some changes to the code or documentation.
4. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
5. Push to the Feature Branch (`git push origin feature/AmazingFeature`)
6. Create a [New Pull Request](https://github.com/rp-rs/rp-hal/pulls)
7. An admin will review the Pull Request and discuss any changes that may be required.
8. Once everyone is happy, the Pull Request can be merged by an admin, and your work is part of our project!
## Code of Conduct
Contribution to this crate is organized under the terms of the [Rust Code of
Conduct][CoC], and the maintainer of this crate, the [rp-rs team], promises
to intervene to uphold that code of conduct.
[CoC]: CODE_OF_CONDUCT.md
[rp-rs team]: https://github.com/orgs/rp-rs/teams/rp-rs
## License
The contents of this repository are dual-licensed under the _MIT OR Apache
2.0_ License. That means you can choose either the MIT license or the
Apache-2.0 license when you re-use this code. See `MIT` or `APACHE2.0` for more
information on each specific license.
Any submissions to this project (e.g. as Pull Requests) must be made available
under these terms.

View file

@ -0,0 +1,134 @@
//! # Seeeduino XIAO RP2040 Blinky Example
//!
//! Blinks the LED on a Seeeduino XIAO RP2040 16MB board.
//!
//! This will blink an LED attached to GPIO25, which is the pin the XIAO RP2040
//! uses for the on-board LED.
//!
//! See the `Cargo.toml` file for Copyright and license details.
#![no_std]
#![no_main]
// The macro for our start-up function
use seeeduino_xiao_rp2040::entry;
// GPIO traits
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::PwmPin;
// Time handling traits
use embedded_time::rate::*;
// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;
// Pull in any important traits
use seeeduino_xiao_rp2040::hal::prelude::*;
// A shorter alias for the Peripheral Access Crate, which provides low-level
// register access
use seeeduino_xiao_rp2040::hal::pac;
// A shorter alias for the Hardware Abstraction Layer, which provides
// higher-level drivers.
use seeeduino_xiao_rp2040::hal;
// The minimum PWM value (i.e. LED brightness) we want
const LOW: u16 = 0;
// The maximum PWM value (i.e. LED brightness) we want
const HIGH: u16 = 60000;
/// Entry point to our bare-metal application.
///
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function
/// as soon as all global variables are initialised.
///
/// The function configures the RP2040 peripherals, then blinks the LED in an
/// infinite loop.
#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
// Configure the clocks
//
// The default is to generate a 125 MHz system clock
let clocks = hal::clocks::init_clocks_and_plls(
seeeduino_xiao_rp2040::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
// Set the pins up according to their function on this particular board
let pins = seeeduino_xiao_rp2040::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
// The delay object lets us wait for specified amounts of time (in
// milliseconds)
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
// Init PWMs
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
// Configure PWM4
let pwm = &mut pwm_slices.pwm0;
pwm.set_ph_correct();
pwm.enable();
// Output channel B on PWM0 to the red LED pin, initially off
let channel = &mut pwm.channel_b;
channel.output_to(pins.led_red);
channel.set_duty(u16::MAX);
// Set the blue LED to be an output, initially off
let mut led_blue_pin = pins.led_blue.into_push_pull_output();
led_blue_pin.set_high().unwrap();
// Turn off the green LED
let mut led_green_pin = pins.led_green.into_push_pull_output();
led_green_pin.set_high().unwrap();
loop {
// Blink blue LED at 1 Hz
for _ in 0..5 {
led_blue_pin.set_low().unwrap();
delay.delay_ms(500);
led_blue_pin.set_high().unwrap();
delay.delay_ms(500);
}
// Ramp red LED brightness up
for i in (LOW..=HIGH).skip(30) {
delay.delay_us(100);
channel.set_duty(u16::MAX - i);
}
// Ramp red LED brightness down
for i in (LOW..=HIGH).rev().skip(30) {
delay.delay_us(100);
channel.set_duty(u16::MAX - i);
}
}
}
// End of file

View file

@ -0,0 +1,69 @@
#![no_std]
pub use rp2040_hal as hal;
#[cfg(feature = "rt")]
extern crate cortex_m_rt;
#[cfg(feature = "rt")]
pub use hal::entry;
/// 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.
#[cfg(feature = "boot2")]
#[link_section = ".boot2"]
#[no_mangle]
#[used]
pub static BOOT2_FIRMWARE: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
pub use hal::pac;
hal::bsp_pins!(
Gpio0 {
name: tx,
aliases: { FunctionUart: UartTx }
},
Gpio1 {
name: rx
aliases: { FunctionUart: UartRx, FunctionSpi: Csn }
},
Gpio2 {
name: d8,
aliases: { FunctionSpi: Sck }
},
Gpio3 {
name: mosi,
aliases: { FunctionSpi: Mosi }
},
Gpio4 {
name: miso,
aliases: { FunctionSpi: Miso }
},
Gpio6 {
name: sda,
aliases: { FunctionI2C: Sda }
},
Gpio7 {
name: scl,
aliases: { FunctionI2C: Scl }
},
Gpio11 { name: neopixel_power },
Gpio12 { name: neopixel_data },
Gpio16 {
name: led_green,
aliases: { FunctionPwm: LedGreenPwm }
},
Gpio17 {
name: led_red,
aliases: { FunctionPwm: LedRedPwm }
},
Gpio25 {
name: led_blue,
aliases: { FunctionPwm: LedBluePwm }
},
Gpio26 { name: a0 },
Gpio27 { name: a1 },
Gpio28 { name: a2 },
Gpio29 { name: a3 },
);
pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000;