From fb12e5b4da1db0a54964256e665cc46446a102b2 Mon Sep 17 00:00:00 2001 From: Thad House Date: Thu, 12 Oct 2023 17:58:45 -0700 Subject: [PATCH] Add support for Sparkfun XRP --- Cargo.toml | 1 + README.md | 15 +++++- boards/sparkfun-xrp/CHANGELOG.md | 10 ++++ boards/sparkfun-xrp/Cargo.toml | 51 ++++++++++++++++++ boards/sparkfun-xrp/README.md | 90 ++++++++++++++++++++++++++++++++ boards/sparkfun-xrp/src/lib.rs | 52 ++++++++++++++++++ 6 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 boards/sparkfun-xrp/CHANGELOG.md create mode 100644 boards/sparkfun-xrp/Cargo.toml create mode 100644 boards/sparkfun-xrp/README.md create mode 100644 boards/sparkfun-xrp/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 960a2e83..29a54233 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ members = [ "boards/sparkfun-micromod-rp2040", "boards/sparkfun-pro-micro-rp2040", "boards/sparkfun-thing-plus-rp2040", + "boards/sparkfun-xrp", "boards/vcc-gnd-yd-rp2040", "boards/waveshare-rp2040-zero", "boards/waveshare-rp2040-lcd-0-96", diff --git a/README.md b/README.md index f0fddc1f..a075eb0a 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Each BSP includes some examples to show off the features of that particular boar ### [rp-pico] - Board Support for the [Raspberry Pi Pico] You should include this crate if you are writing code that you want to run on -a [Raspberry Pi Pico] - the original launch PCB for the RP2040 chip. +a [Raspberry Pi Pico] - the original launch PCB for the RP2040 chip. This crate includes the [rp2040-hal], but also configures each pin of the RP2040 chip according to how it is connected up on the Pico. @@ -287,6 +287,17 @@ RP2040 chip according to how it is connected up on the Thing Plus RP2040. [Sparkfun Thing Plus RP2040]: https://www.sparkfun.com/products/17745 [sparkfun-thing-plus-rp2040]: https://github.com/rp-rs/rp-hal-boards/tree/main/boards/sparkfun-thing-plus-rp2040 +### [sparkfun-xrp] - Board Support for the [Sparkfun XRP Robot] + +You should include this crate if you are writing code that you want to run on +a [Sparkfun XRP Robot] - a robot kit with an RP2040 control board. + +This crate includes the [rp2040-hal], but also configures each pin of the +RP2040 chip according to how it is connected up on the XRP. + +[Sparkfun XRP Robot]: https://www.sparkfun.com/products/22230 +[sparkfun-xrp]: https://github.com/rp-rs/rp-hal-boards/tree/main/boards/sparkfun-xrp + ### [arduino_nano_connect] - Board Support for the [Arduino Nano RP2040 Connect] You should include this crate if you are writing code that you want to run on @@ -335,7 +346,7 @@ RP2040 chip according to how it is connected up on the Feather. ### [waveshare-rp2040-lcd-0_96] - Board Support for the [Waveshare RP2040 LCD 0.96"] You should include this crate if you are writing code that you want to run on -an [Waveshare RP2040 LCD 0.96"] - a very small RP2040 breakout board with USB-C, +an [Waveshare RP2040 LCD 0.96"] - a very small RP2040 breakout board with USB-C, a 65K IPS LCD 160x80, 16MBit Flash and 1A battery charger from Waveshare. This crate includes the [rp2040-hal], but also configures each pin of the diff --git a/boards/sparkfun-xrp/CHANGELOG.md b/boards/sparkfun-xrp/CHANGELOG.md new file mode 100644 index 00000000..b943d5d9 --- /dev/null +++ b/boards/sparkfun-xrp/CHANGELOG.md @@ -0,0 +1,10 @@ +# 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 + +- Initial release diff --git a/boards/sparkfun-xrp/Cargo.toml b/boards/sparkfun-xrp/Cargo.toml new file mode 100644 index 00000000..107a2d44 --- /dev/null +++ b/boards/sparkfun-xrp/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "sparkfun-xrp" +version = "0.1.0" +authors = ["Thad House ", "The rp-rs Developers"] +edition = "2018" +homepage = "https://github.com/rp-rs/rp-hal-boards/tree/main/boards/sparkfun-xrp" +description = "Board Support Package for the Sparkfun XRP Robot" +license = "MIT OR Apache-2.0" +repository = "https://github.com/rp-rs/rp-hal-boards.git" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cortex-m-rt = { version = "0.7.3", optional = true } +embedded-hal = { version = "0.2.7", features = ["unproven"] } +rp2040-boot2 = { version = "0.3.0", optional = true } +rp2040-hal = { version = "0.9.0" } + +[dev-dependencies] +fugit = "0.3.7" +nb = "1.1.0" +panic-halt = "0.2.0" +pio = "0.2.1" +smart-leds = "0.3.0" +ws2812-pio = "0.7.0" + +[features] +# This is the set of features we enable by default +default = ["boot2", "rt", "critical-section-impl", "rom-func-cache"] + +# critical section that is safe for multicore use +critical-section-impl = ["rp2040-hal/critical-section-impl"] + +# 2nd stage bootloaders for rp2040 +boot2 = ["rp2040-boot2"] + +# Minimal startup / runtime for Cortex-M microcontrollers +rt = ["cortex-m-rt","rp2040-hal/rt"] + +# This enables a fix for USB errata 5: USB device fails to exit RESET state on busy USB bus. +# Only required for RP2040 B0 and RP2040 B1, but it also works for RP2040 B2 and above +rp2040-e5 = ["rp2040-hal/rp2040-e5"] + +# Memoize(cache) ROM function pointers on first use to improve performance +rom-func-cache = ["rp2040-hal/rom-func-cache"] + +# Disable automatic mapping of language features (like floating point math) to ROM functions +disable-intrinsics = ["rp2040-hal/disable-intrinsics"] + +# This enables ROM functions for f64 math that were not present in the earliest RP2040s +rom-v2-intrinsics = ["rp2040-hal/rom-v2-intrinsics"] diff --git a/boards/sparkfun-xrp/README.md b/boards/sparkfun-xrp/README.md new file mode 100644 index 00000000..d814ac8e --- /dev/null +++ b/boards/sparkfun-xrp/README.md @@ -0,0 +1,90 @@ +# [sparkfun-xrp] - Board Support for the [Sparkfun XRP Robot] + +You should include this crate if you are writing code that you want to run on +a [Sparkfun XRP Robot] - a robot kit with an RP2040 control board. + +This crate includes the [rp2040-hal], but also configures each pin of the +RP2040 chip according to how it is connected up on the XRP. + +[Sparkfun XRP Robot]: https://www.sparkfun.com/products/22230 +[sparkfun-xrp]: https://github.com/rp-rs/rp-hal-boards/tree/main/boards/sparkfun-xrp +[rp2040-hal]: https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal +[Raspberry Silicon RP2040]: https://www.raspberrypi.org/products/rp2040/ + +## Using + +To use this crate, your `Cargo.toml` file should contain: + +```toml +sparkfun-xrp = "0.1.0" +``` + +In your program, you will need to call `sparkfun_xrp::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-boards_ repository and run: + +```console +rp-hal-boards/boards/sparkfun-xrp $ cargo build --release --example +``` + +You will get an ELF file called +`./target/thumbv6m-none-eabi/release/examples/`, where the `target` +folder is located at the top of the _rp-hal-boards_ 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/boards/sparkfun-xrp $ cargo run --release --example +``` + +If you get an error about not being able to find `elf2uf2-rs`, try: + +```console +$ cargo install elf2uf2-rs, then repeating the `cargo run` command above. +``` + +## 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-boards/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. diff --git a/boards/sparkfun-xrp/src/lib.rs b/boards/sparkfun-xrp/src/lib.rs new file mode 100644 index 00000000..6cf9ce01 --- /dev/null +++ b/boards/sparkfun-xrp/src/lib.rs @@ -0,0 +1,52 @@ +#![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: motor_3_enc_a }, + Gpio1 { name: motor_3_enc_b }, + Gpio2 { name: motor_3_phase }, + Gpio3 { name: motor_3_enable }, + Gpio4 { name: left_motor_enc_a }, + Gpio5 { name: left_motor_enc_b }, + Gpio6 { name: left_motor_phase }, + Gpio7 { name: left_motor_enable }, + Gpio8 { name: motor_4_enc_a }, + Gpio9 { name: motor_4_enc_b }, + Gpio10 { name: motor_4_phase }, + Gpio11 { name: motor_4_enable }, + Gpio12 { name: right_motor_enc_a }, + Gpio13 { name: right_motor_enc_b }, + Gpio14 { name: right_motor_phase }, + Gpio15 { name: right_motor_enable }, + Gpio16 { name: servo_1 }, + Gpio17 { name: servo_2 }, + Gpio18 { name: qwiic_sda }, + Gpio19 { name: qwiic_scl }, + Gpio20 { name: range_trigger }, + Gpio21 { name: range_echo }, + Gpio22 { name: user_button }, + Gpio23 { name: wireless_power }, + Gpio24 { name: wireless_data }, + Gpio25 { name: wireless_cs } + Gpio26 { name: line_follower_left }, + Gpio27 { name: line_follower_right }, + Gpio28 { name: vin_measure }, + Gpio29 { name: wireless_clk } +); + +pub const XOSC_CRYSTAL_FREQ: u32 = 12_000_000;