From b31683c62907a20763f7314c67f19b1c1d470eae Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Fri, 16 Aug 2024 17:37:03 +0100 Subject: [PATCH 1/3] Deletes the top-level workspace and moves the examples. RP2350 stuff is coming, and you can't build rp2040-hal for Armv8-M and you can't build rp235x-hal for Armv6-M, and so they cannot be in the same workspace. Ergo, if the rp2350-hal is coming to this repo (and it is), we cannot have a workspace any more. I also moved the examples into their own package, because that's much neater than having to deal with memory.x being in magically the right place, or a bunch of dev-dependencies that are not relevant to most crate users. --- .github/workflows/build_and_test.yml | 63 ++++-- .github/workflows/clippy.yml | 14 +- .github/workflows/rustfmt.yml | 11 +- Cargo.toml | 23 -- format.bat | 6 + format.sh | 8 + .../.cargo}/config.toml | 0 on-target-tests/Cargo.toml | 12 + on-target-tests/README.md | 2 + .../run_tests.bat | 2 +- run_tests.sh => on-target-tests/run_tests.sh | 2 +- rp2040-hal-examples/.cargo/config.toml | 37 ++++ rp2040-hal-examples/Cargo.toml | 36 +++ rp2040-hal-examples/LICENSE-APACHE | 202 +++++++++++++++++ rp2040-hal-examples/LICENSE-MIT | 19 ++ rp2040-hal-examples/NOTICE | 3 + rp2040-hal-examples/README.md | 149 +++++++++++++ rp2040-hal-examples/build.rs | 14 ++ memory.x => rp2040-hal-examples/memory.x | 7 +- .../src/bin}/adc.rs | 0 .../src/bin}/adc_fifo_dma.rs | 0 .../src/bin}/adc_fifo_irq.rs | 0 .../src/bin}/adc_fifo_poll.rs | 0 .../src/bin}/alloc.rs | 0 .../src/bin}/binary_info_demo.rs | 0 .../src/bin}/blinky.rs | 0 .../src/bin}/dht11.rs | 0 .../src/bin}/dormant_sleep.rs | 0 .../src/bin}/gpio_dyn_pin_array.rs | 0 .../src/bin}/gpio_in_out.rs | 0 .../src/bin}/gpio_irq_example.rs | 0 .../src/bin}/i2c.rs | 0 .../src/bin}/i2c_async.rs | 0 .../src/bin}/i2c_async_cancelled.rs | 0 .../src/bin}/lcd_display.rs | 0 .../src/bin}/mem_to_mem_dma.rs | 0 .../src/bin}/multicore_fifo_blink.rs | 0 .../src/bin}/multicore_polyblink.rs | 0 .../src/bin}/pio_blink.rs | 0 .../src/bin}/pio_dma.rs | 0 .../src/bin}/pio_proc_blink.rs | 0 .../src/bin}/pio_side_set.rs | 0 .../src/bin}/pio_synchronized.rs | 0 .../src/bin}/pwm_blink.rs | 0 .../src/bin}/pwm_blink_embedded_hal_1.rs | 0 .../src/bin}/pwm_irq_input.rs | 0 .../src/bin}/rom_funcs.rs | 0 .../src/bin}/rosc_as_system_clock.rs | 0 .../src/bin}/rtc_irq_example.rs | 0 .../src/bin}/rtc_sleep_example.rs | 0 .../src/bin}/spi.rs | 0 .../src/bin}/spi_dma.rs | 0 .../src/bin}/uart.rs | 0 .../src/bin}/uart_dma.rs | 0 .../src/bin}/vector_table.rs | 0 .../src/bin}/watchdog.rs | 0 rp2040-hal/Cargo.toml | 207 ++---------------- rp2040-hal/README.md | 19 +- 58 files changed, 581 insertions(+), 255 deletions(-) delete mode 100644 Cargo.toml create mode 100644 format.bat create mode 100755 format.sh rename {.cargo => on-target-tests/.cargo}/config.toml (100%) rename run_tests.bat => on-target-tests/run_tests.bat (78%) rename run_tests.sh => on-target-tests/run_tests.sh (83%) create mode 100644 rp2040-hal-examples/.cargo/config.toml create mode 100644 rp2040-hal-examples/Cargo.toml create mode 100644 rp2040-hal-examples/LICENSE-APACHE create mode 100644 rp2040-hal-examples/LICENSE-MIT create mode 100644 rp2040-hal-examples/NOTICE create mode 100644 rp2040-hal-examples/README.md create mode 100644 rp2040-hal-examples/build.rs rename memory.x => rp2040-hal-examples/memory.x (91%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/adc.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/adc_fifo_dma.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/adc_fifo_irq.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/adc_fifo_poll.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/alloc.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/binary_info_demo.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/blinky.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/dht11.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/dormant_sleep.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/gpio_dyn_pin_array.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/gpio_in_out.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/gpio_irq_example.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/i2c.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/i2c_async.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/i2c_async_cancelled.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/lcd_display.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/mem_to_mem_dma.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/multicore_fifo_blink.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/multicore_polyblink.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pio_blink.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pio_dma.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pio_proc_blink.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pio_side_set.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pio_synchronized.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pwm_blink.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pwm_blink_embedded_hal_1.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/pwm_irq_input.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/rom_funcs.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/rosc_as_system_clock.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/rtc_irq_example.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/rtc_sleep_example.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/spi.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/spi_dma.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/uart.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/uart_dma.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/vector_table.rs (100%) rename {rp2040-hal/examples => rp2040-hal-examples/src/bin}/watchdog.rs (100%) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 703a34d29..e90213ed3 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -12,11 +12,16 @@ jobs: - name: Install cargo-hack run: | curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin - - name: Build rp2040-hal's workspace (without the examples) - run: cargo hack build --optional-deps --each-feature - - run: cargo clean - - name: Build rp2040-hal's workspace (with the examples) - run: cargo hack build --examples --optional-deps --each-feature + - name: Build rp2040-hal + run: cd rp2040-hal && cargo hack build --optional-deps --each-feature --target=thumbv6m-none-eabi + - name: Build rp2040-hal-macros + run: cd rp2040-hal-macros && cargo hack build --optional-deps --each-feature + - name: Build on-target-tests + run: cd on-target-tests && cargo hack build --optional-deps --each-feature + - name: Build rp2040-hal-examples + run: cd rp2040-hal-examples && cargo hack build --optional-deps --each-feature + - name: Build rp-binary-info + run: cd rp-binary-info && cargo hack build --optional-deps --each-feature tests: name: Execute host-runable tests runs-on: ubuntu-20.04 @@ -28,16 +33,18 @@ jobs: - name: Install cargo-hack run: | curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin - - name: Test - run: cargo hack test -p rp2040-hal --target x86_64-unknown-linux-gnu --optional-deps --each-feature --tests --features critical-section-impl - - name: Test docs - run: cargo hack test -p rp2040-hal --target x86_64-unknown-linux-gnu --optional-deps --each-feature --doc --features critical-section-impl - - name: Test macros - run: cargo hack test -p rp2040-hal-macros --target x86_64-unknown-linux-gnu --optional-deps --tests --each-feature - - name: Test macro docs - run: cargo hack test -p rp2040-hal-macros --target x86_64-unknown-linux-gnu --optional-deps --doc --each-feature - - name: Clean - run: cargo clean + - name: Test rp2040-hal + run: cd rp2040-hal && cargo hack test --optional-deps --each-feature --tests --features critical-section-impl + - name: Test rp2040-hal docs + run: cd rp2040-hal && cargo hack test --optional-deps --each-feature --doc --features critical-section-impl + - name: Test rp2040-hal-macros + run: cd rp2040-hal-macros && cargo hack test --optional-deps --tests --each-feature + - name: Test rp2040-hal-macros docs + run: cd rp2040-hal-macros && cargo hack test --optional-deps --doc --each-feature + - name: Test rp-binary-info + run: cd rp-binary-info && cargo hack test --optional-deps --each-feature --tests + - name: Test rp-binary-info docs + run: cd rp-binary-info && cargo hack test --optional-deps --each-feature --doc udeps: name: Check rp2040-hal for unused dependencies runs-on: ubuntu-20.04 @@ -53,8 +60,16 @@ jobs: - name: Install cargo-udeps run: | curl -sSL https://github.com/est31/cargo-udeps/releases/download/v0.1.45/cargo-udeps-v0.1.45-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - --strip-components=2 -C ~/.cargo/bin ./cargo-udeps-v0.1.45-x86_64-unknown-linux-gnu/cargo-udeps - - name: Check unused deps - run: cargo hack udeps --optional-deps --each-feature + - name: Check unused deps in rp2040-hal + run: cd rp2040-hal && cargo hack udeps --optional-deps --each-feature --target=thumbv6m-none-eabi + - name: Check unused deps in rp2040-hal-macros + run: cd rp2040-hal-macros && cargo hack udeps --optional-deps --each-feature + - name: Check unused deps in rp2040-hal-examples + run: cd rp2040-hal-examples && cargo hack udeps --optional-deps --each-feature + - name: Check unused deps in on-target-tests + run: cd on-target-tests && cargo hack udeps --optional-deps --each-feature + - name: Check unused deps in rp-binary-info + run: cd rp-binary-info && cargo hack udeps --optional-deps --each-feature msrv: name: Verify build on MSRV runs-on: ubuntu-20.04 @@ -68,6 +83,14 @@ jobs: run: | curl -sSL https://github.com/taiki-e/cargo-hack/releases/download/v0.6.17/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xvzf - -C ~/.cargo/bin - name: Use older version of regex - run: cargo update -p regex --precise 1.9.3 - - name: Verify MSRV - run: cargo hack build --examples --optional-deps --each-feature + run: cd rp2040-hal-examples && cargo update -p regex --precise 1.9.3 + - name: Build rp2040-hal (on MSRV) + run: cd rp2040-hal && cargo hack build --optional-deps --each-feature --target=thumbv6m-none-eabi + - name: Build rp2040-hal-macros (on MSRV) + run: cd rp2040-hal-macros && cargo hack build --optional-deps --each-feature + - name: Build on-target-tests (on MSRV) + run: cd on-target-tests && cargo hack build --optional-deps --each-feature + - name: Build rp2040-hal-examples (on MSRV) + run: cd rp2040-hal-examples && cargo hack build --optional-deps --each-feature + - name: Build rp-binary-info (on MSRV) + run: cd rp-binary-info && cargo hack build --optional-deps --each-feature diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 3483dd414..0bb56bc80 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -12,5 +12,15 @@ jobs: with: target: thumbv6m-none-eabi components: clippy - - run: cargo clippy --workspace --examples - - run: cargo clippy --workspace --examples --all-features + - name: Build rp2040-hal + run: cd rp2040-hal && cargo clippy --target=thumbv6m-none-eabi + - name: Build rp2040-hal (with all features) + run: cd rp2040-hal && cargo clippy --target=thumbv6m-none-eabi --all-features + - name: Build rp2040-hal-macros + run: cd rp2040-hal-macros && cargo clippy + - name: Build on-target-tests + run: cd on-target-tests && cargo clippy + - name: Build rp2040-hal-examples + run: cd rp2040-hal-examples && cargo clippy + - name: Build rp-binary-info + run: cd rp-binary-info && cargo clippy diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index 9d7b8065b..70b74389a 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -12,4 +12,13 @@ jobs: with: target: thumbv6m-none-eabi components: rustfmt - - run: cargo fmt -- --check + - name: Check format of rp2040-hal + run: cd rp2040-hal && cargo fmt -- --check + - name: Check format of rp2040-hal-macros + run: cd rp2040-hal-macros && cargo fmt -- --check + - name: Check format of on-target-tests + run: cd on-target-tests && cargo fmt -- --check + - name: Check format of rp2040-hal-examples + run: cd rp2040-hal-examples && cargo fmt -- --check + - name: Check format of rp-binary-info + run: cd rp-binary-info && cargo fmt -- --check diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index 2eb595db0..000000000 --- a/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[workspace] -resolver = "2" -members = ["rp2040-hal", "rp2040-hal-macros", "on-target-tests", "rp-binary-info"] -exclude = [] - -[patch.'https://github.com/rp-rs/rp-hal.git'] -rp2040-hal = { path = "./rp2040-hal" } - -[patch.crates-io] -rp2040-hal = { path = "./rp2040-hal" } - -# Those profiles are only used for `on-target-tests` compilation -[profile.dev] -codegen-units = 1 -incremental = false -lto = 'fat' -opt-level = 's' - -[profile.test] -codegen-units = 1 -incremental = false -lto = 'fat' -opt-level = 's' diff --git a/format.bat b/format.bat new file mode 100644 index 000000000..c22532265 --- /dev/null +++ b/format.bat @@ -0,0 +1,6 @@ +rem Formats all the files in the repo + +cargo fmt --manifest-path rp2040-hal\Cargo.toml -- --check +cargo fmt --manifest-path rp2040-hal-macros\Cargo.toml -- --check +cargo fmt --manifest-path rp2040-hal-examples\Cargo.toml -- --check +cargo fmt --manifest-path on-target-tests\Cargo.toml -- --check diff --git a/format.sh b/format.sh new file mode 100755 index 000000000..3f141459a --- /dev/null +++ b/format.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Formats all the files in the repo + +cargo fmt --manifest-path rp2040-hal/Cargo.toml -- --check +cargo fmt --manifest-path rp2040-hal-macros/Cargo.toml -- --check +cargo fmt --manifest-path rp2040-hal-examples/Cargo.toml -- --check +cargo fmt --manifest-path on-target-tests/Cargo.toml -- --check diff --git a/.cargo/config.toml b/on-target-tests/.cargo/config.toml similarity index 100% rename from .cargo/config.toml rename to on-target-tests/.cargo/config.toml diff --git a/on-target-tests/Cargo.toml b/on-target-tests/Cargo.toml index 90b9274b1..2352d9872 100644 --- a/on-target-tests/Cargo.toml +++ b/on-target-tests/Cargo.toml @@ -77,3 +77,15 @@ futures = { version = "0.3.30", default-features = false, features = [ ] } i2c-write-iter = { version = "1.0.0", features = ["async"] } itertools = { version = "0.12.0", default-features = false } + +[profile.dev] +codegen-units = 1 +incremental = false +lto = 'fat' +opt-level = 's' + +[profile.test] +codegen-units = 1 +incremental = false +lto = 'fat' +opt-level = 's' diff --git a/on-target-tests/README.md b/on-target-tests/README.md index 51877f54d..6fe00d310 100644 --- a/on-target-tests/README.md +++ b/on-target-tests/README.md @@ -9,10 +9,12 @@ Adding a test: Running all tests: Linux (and any other Unix-likes where probe-rs are supported): ```system +cd on-target-tests ./run_tests.sh ``` Windows ```system +cd on-target-tests run_tests.bat ``` diff --git a/run_tests.bat b/on-target-tests/run_tests.bat similarity index 78% rename from run_tests.bat rename to on-target-tests/run_tests.bat index afe938520..f8fcfa61d 100755 --- a/run_tests.bat +++ b/on-target-tests/run_tests.bat @@ -3,4 +3,4 @@ @SET "CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER=probe-rs run" -cargo test -p on-target-tests --no-fail-fast -- --chip rp2040 +cargo test --no-fail-fast -- --chip rp2040 diff --git a/run_tests.sh b/on-target-tests/run_tests.sh similarity index 83% rename from run_tests.sh rename to on-target-tests/run_tests.sh index 92b3402af..326e7992b 100755 --- a/run_tests.sh +++ b/on-target-tests/run_tests.sh @@ -3,4 +3,4 @@ # Keep running tests even if one of them fails # We need to specify probe-rs as our runner via environment variables here # to control build since we aren't able to override them in config.toml -CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER="probe-rs run" cargo test -p on-target-tests --no-fail-fast -- --chip rp2040 +CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER="probe-rs run" cargo test --no-fail-fast -- --chip rp2040 diff --git a/rp2040-hal-examples/.cargo/config.toml b/rp2040-hal-examples/.cargo/config.toml new file mode 100644 index 000000000..e548cb625 --- /dev/null +++ b/rp2040-hal-examples/.cargo/config.toml @@ -0,0 +1,37 @@ +# +# Cargo Configuration for the https://github.com/rp-rs/rp-hal.git repository. +# +# You might want to make a similar file in your own repository if you are +# writing programs for Raspberry Silicon microcontrollers. +# + +[build] +# Set the default target to match the Cortex-M0+ in the RP2040 +target = "thumbv6m-none-eabi" + +# Target specific options +[target.thumbv6m-none-eabi] +# Pass some extra options to rustc, some of which get passed on to the linker. +# +# * linker argument --nmagic turns off page alignment of sections (which saves +# flash space) +# * linker argument -Tlink.x tells the linker to use link.x as the linker +# script. This is usually provided by the cortex-m-rt crate, and by default +# the version in that crate will include a file called `memory.x` which +# describes the particular memory layout for your specific chip. +# * no-vectorize-loops turns off the loop vectorizer (seeing as the M0+ doesn't +# have SIMD) +rustflags = [ + "-C", "link-arg=--nmagic", + "-C", "link-arg=-Tlink.x", + "-C", "link-arg=-Tdefmt.x", + "-C", "no-vectorize-loops", +] + +# This runner will make a UF2 file and then copy it to a mounted RP2040 in USB +# Bootloader mode: +runner = "elf2uf2-rs -d" + +# This runner will find a supported SWD debug probe and flash your RP2040 over +# SWD: +# runner = "probe-rs run --chip RP2040" diff --git a/rp2040-hal-examples/Cargo.toml b/rp2040-hal-examples/Cargo.toml new file mode 100644 index 000000000..495dd16e6 --- /dev/null +++ b/rp2040-hal-examples/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "rp2040-hal-examples" +version = "0.1.0" +edition = "2021" +authors = ["The rp-rs Developers"] +homepage = "https://github.com/rp-rs/rp-hal" +description = "Examples for the rp2040-hal crate" +license = "MIT OR Apache-2.0" +rust-version = "1.77" +repository = "https://github.com/rp-rs/rp-hal" +categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"] +keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"] + +[dependencies] +cortex-m = "0.7.2" +cortex-m-rt = "0.7" +cortex-m-rtic = "1.1.4" +critical-section = { version = "1.0.0" } +defmt = "0.3" +defmt-rtt = "0.4.0" +dht-sensor = "0.2.1" +embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } +embedded-alloc = "0.5.1" +embedded-hal = "1.0.0" +embedded-hal-async = "1.0.0" +fugit = "0.3.6" +futures = { version = "0.3.30", default-features = false, features = ["async-await"] } +hd44780-driver = "0.4.0" +nb = "1.0" +nostd_async = { version = "0.6.1", features = ["cortex_m"] } +panic-halt = "0.2.0" +panic-probe = { version = "0.3.1", features = ["print-defmt"] } +pio = "0.2.0" +pio-proc = "0.2.0" +rp2040-boot2 = "0.3.0" +rp2040-hal = { path = "../rp2040-hal", version = "0.10.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"] } diff --git a/rp2040-hal-examples/LICENSE-APACHE b/rp2040-hal-examples/LICENSE-APACHE new file mode 100644 index 000000000..d64569567 --- /dev/null +++ b/rp2040-hal-examples/LICENSE-APACHE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/rp2040-hal-examples/LICENSE-MIT b/rp2040-hal-examples/LICENSE-MIT new file mode 100644 index 000000000..6e052e35b --- /dev/null +++ b/rp2040-hal-examples/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) 2021-2024 The rp-rs Developers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/rp2040-hal-examples/NOTICE b/rp2040-hal-examples/NOTICE new file mode 100644 index 000000000..790ecb167 --- /dev/null +++ b/rp2040-hal-examples/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) 2021-2024 The rp-rs Developers + +Originally published at https://github.com/rp-rs/rp-hal diff --git a/rp2040-hal-examples/README.md b/rp2040-hal-examples/README.md new file mode 100644 index 000000000..f10ad6a6c --- /dev/null +++ b/rp2040-hal-examples/README.md @@ -0,0 +1,149 @@ + +
+

+ + Logo + + +

rp-hal

+ +

+ Rust Examples for the Raspberry Silicon RP2040 Microcontroller +
+ Explore the API docs » +
+
+ View more Demos + · + Report a Bug + · + Chat on Matrix +

+

+ + + + +
+

Table of Contents

+
    +
  1. Introduction
  2. +
  3. Getting Started
  4. +
  5. Roadmap
  6. +
  7. Contributing
  8. +
  9. License
  10. +
  11. Contact
  12. +
  13. Acknowledgements
  14. +
+
+ + +## Introduction + +The `rp2040-hal` package is a library crate of high-level Rust drivers for the +Raspberry Silicon RP2040 microcontroller. This folder contains a collection of +non-board specific example programs for you to study. + +We also provide a series of [*Board Support Package* (BSP) crates][BSPs], which +take the HAL crate and pre-configure the pins according to a specific PCB +design. If you are using one of the supported boards, you should use one of +those crates in preference, and return here to see documentation about specific +peripherals on the RP2040 and how to use them. See the `boards` folder in +https://github.com/rp-rs/rp-hal-boards/ for more details. + +[BSPs]: https://github.com/rp-rs/rp-hal-boards/ + + +## Getting Started + +To build all the examples, first grab a copy of the source code: + +```console +$ git clone https://github.com/rp-rs/rp-hal.git +``` + +Then use `rustup` to grab the Rust Standard Library for the appropriate target and our preferred flashing tool: + +```console +$ rustup target add thumbv6m-none-eabi +``` + +Then you can build the examples: + +```console +$ cd rp2040-hal-examples +$ cargo build + Compiling rp2040-hal-examples v0.1.0 (/home/user/rp-hal/rp2040-hal-examples) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.53s +$ cargo build --bin dormant_sleep + Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s +$ file ./target/thumbv6m-none-eabi/debug/dormant_sleep +./target/thumbv6m-none-eabi/debug/dormant_sleep: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped +``` + +You can also 'run' an example, which will invoke [`elf2uf2-rs`] to copy it to an +RP2040's virtual USB Mass Storage Device (which it puts over the USB port when +in its ROM bootloader). You should install that if you don't have it already: + +```console +$ cargo install elf2uf2-rs --locked +$ cd rp2040-hal-examples +$ cargo run --bin dormant_sleep + Compiling rp2040-hal v0.10.0 (/home/user/rp-hal/rp2040-hal) + Compiling rp2040-hal-examples v0.1.0 (/home/user/rp-hal/rp2040-hal-examples) + Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.62s + Running `elf2uf2-rs -d target/thumbv6m-none-eabi/debug/dormant_sleep` +Found pico uf2 disk /media/user/RP2040 +Transfering program to pico +88.50 KB / 88.50 KB [=====================================] 100.00 % 430.77 KB/s +$ +``` + +[`elf2uf2-rs`]: https://github.com/JoNil/elf2uf2-rs + + +## Roadmap + +NOTE The HAL is under active development, and so are these examples. As such, it +is likely to remain volatile until a 1.0.0 release. + +See the [open issues](https://github.com/rp-rs/rp-hal/issues) for a list of +proposed features (and known issues). + + +## 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**. + +1. Fork the Project +2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) +3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) +4. Push to the Branch (`git push origin feature/AmazingFeature`) +5. Open a Pull Request + + + +## 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 [`LICENSE-MIT`](./LICENSE-MIT) or +[`LICENSE-APACHE`](./LICENSE-APACHE) for more information on each specific +license. Our Apache 2.0 notices can be found in [`NOTICE`](./NOTICE). + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. + + +## Contact + +* Project Link: [https://github.com/rp-rs/rp-hal/issues](https://github.com/rp-rs/rp-hal/issues) +* Matrix: [#rp-rs:matrix.org](https://matrix.to/#/#rp-rs:matrix.org) + + +## Acknowledgements + +* [Othneil Drew's README template](https://github.com/othneildrew) diff --git a/rp2040-hal-examples/build.rs b/rp2040-hal-examples/build.rs new file mode 100644 index 000000000..b2dd9ec07 --- /dev/null +++ b/rp2040-hal-examples/build.rs @@ -0,0 +1,14 @@ +use std::fs::File; +use std::io::Write; +use std::path::PathBuf; + +fn main() { + // Put the linker script somewhere the linker can find it + let out = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); + let memory_x = include_bytes!("memory.x"); + let mut f = File::create(out.join("memory.x")).unwrap(); + f.write_all(memory_x).unwrap(); + println!("cargo:rustc-link-search={}", out.display()); + println!("cargo:rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=memory.x"); +} diff --git a/memory.x b/rp2040-hal-examples/memory.x similarity index 91% rename from memory.x rename to rp2040-hal-examples/memory.x index 67df0fc02..10c6cfa62 100644 --- a/memory.x +++ b/rp2040-hal-examples/memory.x @@ -1,5 +1,10 @@ MEMORY { BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 + /* + * Here we assume you have 2048 KiB of Flash. This is what the Pi Pico + * has, but your board may have more or less Flash and you should adjust + * this value to suit. + */ FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 /* * RAM consists of 4 banks, SRAM0-SRAM3, with a striped mapping. @@ -75,4 +80,4 @@ SECTIONS { /* We put this in the header */ __bi_entries_end = .; } > FLASH -} INSERT AFTER .text; \ No newline at end of file +} INSERT AFTER .text; diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal-examples/src/bin/adc.rs similarity index 100% rename from rp2040-hal/examples/adc.rs rename to rp2040-hal-examples/src/bin/adc.rs diff --git a/rp2040-hal/examples/adc_fifo_dma.rs b/rp2040-hal-examples/src/bin/adc_fifo_dma.rs similarity index 100% rename from rp2040-hal/examples/adc_fifo_dma.rs rename to rp2040-hal-examples/src/bin/adc_fifo_dma.rs diff --git a/rp2040-hal/examples/adc_fifo_irq.rs b/rp2040-hal-examples/src/bin/adc_fifo_irq.rs similarity index 100% rename from rp2040-hal/examples/adc_fifo_irq.rs rename to rp2040-hal-examples/src/bin/adc_fifo_irq.rs diff --git a/rp2040-hal/examples/adc_fifo_poll.rs b/rp2040-hal-examples/src/bin/adc_fifo_poll.rs similarity index 100% rename from rp2040-hal/examples/adc_fifo_poll.rs rename to rp2040-hal-examples/src/bin/adc_fifo_poll.rs diff --git a/rp2040-hal/examples/alloc.rs b/rp2040-hal-examples/src/bin/alloc.rs similarity index 100% rename from rp2040-hal/examples/alloc.rs rename to rp2040-hal-examples/src/bin/alloc.rs diff --git a/rp2040-hal/examples/binary_info_demo.rs b/rp2040-hal-examples/src/bin/binary_info_demo.rs similarity index 100% rename from rp2040-hal/examples/binary_info_demo.rs rename to rp2040-hal-examples/src/bin/binary_info_demo.rs diff --git a/rp2040-hal/examples/blinky.rs b/rp2040-hal-examples/src/bin/blinky.rs similarity index 100% rename from rp2040-hal/examples/blinky.rs rename to rp2040-hal-examples/src/bin/blinky.rs diff --git a/rp2040-hal/examples/dht11.rs b/rp2040-hal-examples/src/bin/dht11.rs similarity index 100% rename from rp2040-hal/examples/dht11.rs rename to rp2040-hal-examples/src/bin/dht11.rs diff --git a/rp2040-hal/examples/dormant_sleep.rs b/rp2040-hal-examples/src/bin/dormant_sleep.rs similarity index 100% rename from rp2040-hal/examples/dormant_sleep.rs rename to rp2040-hal-examples/src/bin/dormant_sleep.rs diff --git a/rp2040-hal/examples/gpio_dyn_pin_array.rs b/rp2040-hal-examples/src/bin/gpio_dyn_pin_array.rs similarity index 100% rename from rp2040-hal/examples/gpio_dyn_pin_array.rs rename to rp2040-hal-examples/src/bin/gpio_dyn_pin_array.rs diff --git a/rp2040-hal/examples/gpio_in_out.rs b/rp2040-hal-examples/src/bin/gpio_in_out.rs similarity index 100% rename from rp2040-hal/examples/gpio_in_out.rs rename to rp2040-hal-examples/src/bin/gpio_in_out.rs diff --git a/rp2040-hal/examples/gpio_irq_example.rs b/rp2040-hal-examples/src/bin/gpio_irq_example.rs similarity index 100% rename from rp2040-hal/examples/gpio_irq_example.rs rename to rp2040-hal-examples/src/bin/gpio_irq_example.rs diff --git a/rp2040-hal/examples/i2c.rs b/rp2040-hal-examples/src/bin/i2c.rs similarity index 100% rename from rp2040-hal/examples/i2c.rs rename to rp2040-hal-examples/src/bin/i2c.rs diff --git a/rp2040-hal/examples/i2c_async.rs b/rp2040-hal-examples/src/bin/i2c_async.rs similarity index 100% rename from rp2040-hal/examples/i2c_async.rs rename to rp2040-hal-examples/src/bin/i2c_async.rs diff --git a/rp2040-hal/examples/i2c_async_cancelled.rs b/rp2040-hal-examples/src/bin/i2c_async_cancelled.rs similarity index 100% rename from rp2040-hal/examples/i2c_async_cancelled.rs rename to rp2040-hal-examples/src/bin/i2c_async_cancelled.rs diff --git a/rp2040-hal/examples/lcd_display.rs b/rp2040-hal-examples/src/bin/lcd_display.rs similarity index 100% rename from rp2040-hal/examples/lcd_display.rs rename to rp2040-hal-examples/src/bin/lcd_display.rs diff --git a/rp2040-hal/examples/mem_to_mem_dma.rs b/rp2040-hal-examples/src/bin/mem_to_mem_dma.rs similarity index 100% rename from rp2040-hal/examples/mem_to_mem_dma.rs rename to rp2040-hal-examples/src/bin/mem_to_mem_dma.rs diff --git a/rp2040-hal/examples/multicore_fifo_blink.rs b/rp2040-hal-examples/src/bin/multicore_fifo_blink.rs similarity index 100% rename from rp2040-hal/examples/multicore_fifo_blink.rs rename to rp2040-hal-examples/src/bin/multicore_fifo_blink.rs diff --git a/rp2040-hal/examples/multicore_polyblink.rs b/rp2040-hal-examples/src/bin/multicore_polyblink.rs similarity index 100% rename from rp2040-hal/examples/multicore_polyblink.rs rename to rp2040-hal-examples/src/bin/multicore_polyblink.rs diff --git a/rp2040-hal/examples/pio_blink.rs b/rp2040-hal-examples/src/bin/pio_blink.rs similarity index 100% rename from rp2040-hal/examples/pio_blink.rs rename to rp2040-hal-examples/src/bin/pio_blink.rs diff --git a/rp2040-hal/examples/pio_dma.rs b/rp2040-hal-examples/src/bin/pio_dma.rs similarity index 100% rename from rp2040-hal/examples/pio_dma.rs rename to rp2040-hal-examples/src/bin/pio_dma.rs diff --git a/rp2040-hal/examples/pio_proc_blink.rs b/rp2040-hal-examples/src/bin/pio_proc_blink.rs similarity index 100% rename from rp2040-hal/examples/pio_proc_blink.rs rename to rp2040-hal-examples/src/bin/pio_proc_blink.rs diff --git a/rp2040-hal/examples/pio_side_set.rs b/rp2040-hal-examples/src/bin/pio_side_set.rs similarity index 100% rename from rp2040-hal/examples/pio_side_set.rs rename to rp2040-hal-examples/src/bin/pio_side_set.rs diff --git a/rp2040-hal/examples/pio_synchronized.rs b/rp2040-hal-examples/src/bin/pio_synchronized.rs similarity index 100% rename from rp2040-hal/examples/pio_synchronized.rs rename to rp2040-hal-examples/src/bin/pio_synchronized.rs diff --git a/rp2040-hal/examples/pwm_blink.rs b/rp2040-hal-examples/src/bin/pwm_blink.rs similarity index 100% rename from rp2040-hal/examples/pwm_blink.rs rename to rp2040-hal-examples/src/bin/pwm_blink.rs diff --git a/rp2040-hal/examples/pwm_blink_embedded_hal_1.rs b/rp2040-hal-examples/src/bin/pwm_blink_embedded_hal_1.rs similarity index 100% rename from rp2040-hal/examples/pwm_blink_embedded_hal_1.rs rename to rp2040-hal-examples/src/bin/pwm_blink_embedded_hal_1.rs diff --git a/rp2040-hal/examples/pwm_irq_input.rs b/rp2040-hal-examples/src/bin/pwm_irq_input.rs similarity index 100% rename from rp2040-hal/examples/pwm_irq_input.rs rename to rp2040-hal-examples/src/bin/pwm_irq_input.rs diff --git a/rp2040-hal/examples/rom_funcs.rs b/rp2040-hal-examples/src/bin/rom_funcs.rs similarity index 100% rename from rp2040-hal/examples/rom_funcs.rs rename to rp2040-hal-examples/src/bin/rom_funcs.rs diff --git a/rp2040-hal/examples/rosc_as_system_clock.rs b/rp2040-hal-examples/src/bin/rosc_as_system_clock.rs similarity index 100% rename from rp2040-hal/examples/rosc_as_system_clock.rs rename to rp2040-hal-examples/src/bin/rosc_as_system_clock.rs diff --git a/rp2040-hal/examples/rtc_irq_example.rs b/rp2040-hal-examples/src/bin/rtc_irq_example.rs similarity index 100% rename from rp2040-hal/examples/rtc_irq_example.rs rename to rp2040-hal-examples/src/bin/rtc_irq_example.rs diff --git a/rp2040-hal/examples/rtc_sleep_example.rs b/rp2040-hal-examples/src/bin/rtc_sleep_example.rs similarity index 100% rename from rp2040-hal/examples/rtc_sleep_example.rs rename to rp2040-hal-examples/src/bin/rtc_sleep_example.rs diff --git a/rp2040-hal/examples/spi.rs b/rp2040-hal-examples/src/bin/spi.rs similarity index 100% rename from rp2040-hal/examples/spi.rs rename to rp2040-hal-examples/src/bin/spi.rs diff --git a/rp2040-hal/examples/spi_dma.rs b/rp2040-hal-examples/src/bin/spi_dma.rs similarity index 100% rename from rp2040-hal/examples/spi_dma.rs rename to rp2040-hal-examples/src/bin/spi_dma.rs diff --git a/rp2040-hal/examples/uart.rs b/rp2040-hal-examples/src/bin/uart.rs similarity index 100% rename from rp2040-hal/examples/uart.rs rename to rp2040-hal-examples/src/bin/uart.rs diff --git a/rp2040-hal/examples/uart_dma.rs b/rp2040-hal-examples/src/bin/uart_dma.rs similarity index 100% rename from rp2040-hal/examples/uart_dma.rs rename to rp2040-hal-examples/src/bin/uart_dma.rs diff --git a/rp2040-hal/examples/vector_table.rs b/rp2040-hal-examples/src/bin/vector_table.rs similarity index 100% rename from rp2040-hal/examples/vector_table.rs rename to rp2040-hal-examples/src/bin/vector_table.rs diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal-examples/src/bin/watchdog.rs similarity index 100% rename from rp2040-hal/examples/watchdog.rs rename to rp2040-hal-examples/src/bin/watchdog.rs diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 43a4ae80d..080e1f22f 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -18,59 +18,36 @@ targets = ["thumbv6m-none-eabi"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rp2040-hal-macros = { version = "0.1.0", path = "../rp2040-hal-macros" } -rp-binary-info = { version = "0.1.0", path = "../rp-binary-info" } - +bitfield = { version = "0.14.0" } +chrono = { version = "0.4", default-features = false, optional = true } cortex-m = "0.7.2" -embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = [ - "unproven", -] } +critical-section = { version = "1.0.0" } +defmt = { version = ">=0.2.0, <0.4", optional = true } +embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } +embedded-dma = "0.2.0" embedded-hal = "1.0.0" -embedded-hal-nb = "1.0.0" embedded-hal-async = "1.0.0" -embedded-dma = "0.2.0" +embedded-hal-nb = "1.0.0" embedded-io = "0.6.1" +frunk = { version = "0.4.1", default-features = false } fugit = "0.3.6" +i2c-write-iter = { version = "1.0.0", features = ["async"], optional = true } itertools = { version = "0.10.1", default-features = false } nb = "1.0" -rp2040-pac = { version = "0.6.0", features = ["critical-section"] } paste = "1.0" pio = "0.2.0" +rand_core = "0.6.3" +rp-binary-info = { version = "0.1.0", path = "../rp-binary-info" } +rp2040-hal-macros = { version = "0.1.0", path = "../rp2040-hal-macros" } +rp2040-pac = { version = "0.6.0", features = ["critical-section"] } +rtic-monotonic = { version = "1.0.0", optional = true } usb-device = "0.3" vcell = "0.1" void = { version = "1.0.2", default-features = false } -rand_core = "0.6.3" -critical-section = { version = "1.0.0" } - -chrono = { version = "0.4", default-features = false, optional = true } - -defmt = { version = ">=0.2.0, <0.4", optional = true } - -rtic-monotonic = { version = "1.0.0", optional = true } - -frunk = { version = "0.4.1", default-features = false } - -bitfield = { version = "0.14.0" } - -i2c-write-iter = { version = "1.0.0", features = ["async"], optional = true } [dev-dependencies] -cortex-m-rt = "0.7" -cortex-m-rtic = "1.1.4" -panic-halt = "0.2.0" -rp2040-boot2 = "0.3.0" -hd44780-driver = "0.4.0" pio-proc = "0.2.0" -dht-sensor = "0.2.1" rand = { version = "0.8.5", default-features = false } -nostd_async = { version = "0.6.1", features = ["cortex_m"] } -futures = { version = "0.3.30", default-features = false, features = [ - "async-await", -] } -defmt-rtt = "0.4.0" -panic-probe = { version = "0.3.1", features = ["print-defmt"] } -defmt = "0.3" -embedded-alloc = "0.5.1" [features] # Minimal startup / runtime for Cortex-M microcontrollers @@ -113,159 +90,3 @@ i2c-write-iter = ["dep:i2c-write-iter"] # Requires 'rt' so that the vector table is correctly sized and therefore the # header is within reach of picotool. binary-info = ["rt", "rp-binary-info/binary-info"] - -[[example]] -name = "binary_info_demo" -required-features = ["binary-info", "critical-section-impl"] - -[[example]] -# irq example uses cortex-m-rt::interrupt, need rt feature for that -name = "gpio_irq_example" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# irq example uses cortex-m-rt::interrupt, need rt feature for that -name = "rtc_irq_example" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# irq example uses cortex-m-rt::interrupt, need rt feature for that -name = "rtc_sleep_example" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# pwm irq input example uses cortex-m-rt::interrupt, need rt feature for that -name = "pwm_irq_input" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# vector_table example uses cortex-m-rt::interrupt, need rt feature for that -name = "vector_table" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# adc_fifo_irq example uses cortex-m-rt::interrupt, need rt feature for that -name = "adc_fifo_irq" -required-features = ["rt", "critical-section-impl"] - -[[example]] -# adc_fifo_dma example uses cortex-m-rt::interrupt, need rt feature for that -name = "adc_fifo_dma" -required-features = ["rt", "critical-section-impl"] - -[[example]] -name = "adc" -required-features = ["critical-section-impl"] - -[[example]] -name = "adc_fifo_poll" -required-features = ["critical-section-impl"] - -[[example]] -name = "alloc" -required-features = ["critical-section-impl"] - -[[example]] -name = "blinky" -required-features = ["critical-section-impl"] - -[[example]] -name = "dht11" -required-features = ["critical-section-impl"] - -[[example]] -# dormant_sleep example uses cortex-m-rt::interrupt, need rt feature for that -name = "dormant_sleep" -required-features = ["rt", "critical-section-impl"] - -[[example]] -name = "gpio_in_out" -required-features = ["critical-section-impl"] - -[[example]] -name = "i2c" -required-features = ["critical-section-impl"] - -[[example]] -name = "i2c_async" -required-features = ["critical-section-impl", "rt"] - -[[example]] -name = "i2c_async_cancelled" -required-features = ["critical-section-impl", "rt", "defmt"] - -[[example]] -name = "lcd_display" -required-features = ["critical-section-impl"] - -[[example]] -name = "mem_to_mem_dma" -required-features = ["critical-section-impl"] - -[[example]] -name = "multicore_fifo_blink" -required-features = ["critical-section-impl"] - -[[example]] -name = "multicore_polyblink" -required-features = ["critical-section-impl"] - -[[example]] -name = "pio_blink" -required-features = ["critical-section-impl"] - -[[example]] -name = "pio_dma" -required-features = ["critical-section-impl"] - -[[example]] -name = "pio_proc_blink" -required-features = ["critical-section-impl"] - -[[example]] -name = "pio_side_set" -required-features = ["critical-section-impl"] - -[[example]] -name = "pio_synchronized" -required-features = ["critical-section-impl"] - -[[example]] -name = "pwm_blink" -required-features = ["critical-section-impl"] - -[[example]] -name = "pwm_blink_embedded_hal_1" -required-features = ["critical-section-impl"] - -[[example]] -name = "rom_funcs" -required-features = ["critical-section-impl"] - -[[example]] -name = "rosc_as_system_clock" -required-features = ["critical-section-impl"] - -[[example]] -name = "spi" -required-features = ["critical-section-impl"] - -[[example]] -name = "spi_dma" -required-features = ["critical-section-impl"] - -[[example]] -name = "uart" -required-features = ["critical-section-impl"] - -[[example]] -name = "uart_dma" -required-features = ["critical-section-impl"] - -[[example]] -name = "watchdog" -required-features = ["critical-section-impl"] - -[[example]] -name = "gpio_dyn_pin_array" -required-features = ["critical-section-impl"] diff --git a/rp2040-hal/README.md b/rp2040-hal/README.md index 5776c665a..ac961c0a4 100644 --- a/rp2040-hal/README.md +++ b/rp2040-hal/README.md @@ -28,13 +28,7 @@

Table of Contents

  1. Introduction
  2. -
  3. - Getting Started - -
  4. +
  5. Getting Started
  6. Roadmap
  7. Contributing
  8. License
  9. @@ -81,7 +75,9 @@ $ git clone https://github.com/rp-rs/rp-hal.git ``` For details on how to program an RP2040 microcontroller, see the [top-level -rp-hal README](https://github.com/rp-rs/rp-hal/). +rp-hal README](https://github.com/rp-rs/rp-hal/). To see this HAL in use, +see either the examples in this repository, or the examples included with each +BSP. ## Roadmap @@ -111,8 +107,6 @@ appreciated**. 4. Push to the Branch (`git push origin feature/AmazingFeature`) 5. Open a Pull Request - - ## License @@ -129,9 +123,8 @@ dual licensed as above, without any additional terms or conditions. ## Contact -Project Link: [https://github.com/rp-rs/rp-hal/issues](https://github.com/rp-rs/rp-hal/issues) -Matrix: [#rp-rs:matrix.org](https://matrix.to/#/#rp-rs:matrix.org) - +* Project Link: [https://github.com/rp-rs/rp-hal/issues](https://github.com/rp-rs/rp-hal/issues) +* Matrix: [#rp-rs:matrix.org](https://matrix.to/#/#rp-rs:matrix.org) ## Acknowledgements From e5fcde3140ac59d8cd00d02d13de683c8e6e0ac9 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Fri, 16 Aug 2024 17:41:07 +0100 Subject: [PATCH 2/3] Bump to GHA checkout@v4 Removes node.js deprecation notice. --- .github/workflows/build_and_test.yml | 8 ++++---- .github/workflows/clippy.yml | 2 +- .github/workflows/rustfmt.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index e90213ed3..ec6ca5a36 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -5,7 +5,7 @@ jobs: name: Build rp2040-hal's features runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: target: thumbv6m-none-eabi @@ -26,7 +26,7 @@ jobs: name: Execute host-runable tests runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: target: thumbv6m-none-eabi @@ -49,7 +49,7 @@ jobs: name: Check rp2040-hal for unused dependencies runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: nightly-2024-01-30 @@ -74,7 +74,7 @@ jobs: name: Verify build on MSRV runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: 1.77 diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 0bb56bc80..846673aaa 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -7,7 +7,7 @@ jobs: env: RUSTFLAGS: "-D warnings" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: target: thumbv6m-none-eabi diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index 70b74389a..448a57205 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -7,7 +7,7 @@ jobs: env: RUSTFLAGS: "-D warnings" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: target: thumbv6m-none-eabi From fae6b2507abfe65f21a53ec320b3728f65341f01 Mon Sep 17 00:00:00 2001 From: Jonathan 'theJPster' Pallant Date: Sat, 17 Aug 2024 12:44:47 +0100 Subject: [PATCH 3/3] Reformat all Cargo.toml files Keys are now sorted, and all one-liners. --- on-target-tests/Cargo.toml | 65 ++++++++++++++-------------------- rp2040-hal-examples/Cargo.toml | 26 +++++++------- rp2040-hal-macros/Cargo.toml | 14 +++----- rp2040-hal/Cargo.toml | 45 +++++++++++++---------- 4 files changed, 70 insertions(+), 80 deletions(-) diff --git a/on-target-tests/Cargo.toml b/on-target-tests/Cargo.toml index 2352d9872..02c51a1c6 100644 --- a/on-target-tests/Cargo.toml +++ b/on-target-tests/Cargo.toml @@ -1,82 +1,69 @@ [package] +authors = ["The rp-rs Developers"] +description = "Test cases that run on an RP2040" edition = "2021" +license = "MIT OR Apache-2.0" name = "on-target-tests" -version = "0.1.0" publish = false +readme = "README.md" +repository = "https://github.com/rp-rs/rp-hal" +version = "0.1.0" [[test]] -name = "dma_m2m_u8" harness = false +name = "dma_m2m_u8" [[test]] -name = "dma_m2m_u16" harness = false +name = "dma_m2m_u16" [[test]] -name = "dma_m2m_u32" harness = false +name = "dma_m2m_u32" [[test]] -name = "dma_spi_loopback_u8" harness = false +name = "dma_spi_loopback_u8" [[test]] -name = "dma_spi_loopback_u16" harness = false +name = "dma_spi_loopback_u16" [[test]] -name = "dma_dyn" harness = false +name = "dma_dyn" [[test]] -name = "i2c_loopback" harness = false +name = "i2c_loopback" [[test]] -name = "i2c_loopback_async" harness = false +name = "i2c_loopback_async" [[test]] -name = "gpio" harness = false +name = "gpio" [dependencies] cortex-m = "0.7" cortex-m-rt = "0.7" -embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = [ - "unproven", -] } -embedded-hal = "1.0.0" -embedded-hal-async = "1.0.0" - +critical-section = "1.0.0" defmt = "0.3" defmt-rtt = "0.4" defmt-test = "0.3.1" -panic-probe = { version = "0.3", features = ["print-defmt"] } - -rp2040-hal = { path = "../rp2040-hal", features = [ - "critical-section-impl", - "defmt", - "rt", - "i2c-write-iter", -] } -# Needed to set spi frequencies +embedded-hal = "1.0.0" +embedded-hal-async = "1.0.0" +embedded_hal_0_2 = {package = "embedded-hal", version = "0.2.5", features = ["unproven"]} fugit = "0.3.6" - +futures = {version = "0.3.30", default-features = false, features = ["async-await"]} +heapless = {version = "0.8.0", features = ["portable-atomic-critical-section", "defmt-03"]} +i2c-write-iter = {version = "1.0.0", features = ["async"]} +itertools = {version = "0.12.0", default-features = false} +nostd_async = {version = "0.6.1", features = ["wfe"]} +panic-probe = {version = "0.3", features = ["print-defmt"]} rp2040-boot2 = "0.3.0" -critical-section = "1.0.0" -heapless = { version = "0.8.0", features = [ - "portable-atomic-critical-section", - "defmt-03", -] } -# - `wfe`: we may want to signal between cores with sev -# - `wfe` implies `cortex-m` -nostd_async = { version = "0.6.1", features = ["wfe"] } -futures = { version = "0.3.30", default-features = false, features = [ - "async-await", -] } -i2c-write-iter = { version = "1.0.0", features = ["async"] } -itertools = { version = "0.12.0", default-features = false } +rp2040-hal = {path = "../rp2040-hal", features = ["critical-section-impl", "defmt", "rt", "i2c-write-iter"]} [profile.dev] codegen-units = 1 diff --git a/rp2040-hal-examples/Cargo.toml b/rp2040-hal-examples/Cargo.toml index 495dd16e6..7956ab7ac 100644 --- a/rp2040-hal-examples/Cargo.toml +++ b/rp2040-hal-examples/Cargo.toml @@ -1,36 +1,36 @@ [package] -name = "rp2040-hal-examples" -version = "0.1.0" -edition = "2021" authors = ["The rp-rs Developers"] -homepage = "https://github.com/rp-rs/rp-hal" +categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"] description = "Examples for the rp2040-hal crate" +edition = "2021" +homepage = "https://github.com/rp-rs/rp-hal" +keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"] license = "MIT OR Apache-2.0" -rust-version = "1.77" +name = "rp2040-hal-examples" repository = "https://github.com/rp-rs/rp-hal" -categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"] -keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"] +rust-version = "1.77" +version = "0.1.0" [dependencies] cortex-m = "0.7.2" cortex-m-rt = "0.7" cortex-m-rtic = "1.1.4" -critical-section = { version = "1.0.0" } +critical-section = {version = "1.0.0"} defmt = "0.3" defmt-rtt = "0.4.0" dht-sensor = "0.2.1" -embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } embedded-alloc = "0.5.1" embedded-hal = "1.0.0" embedded-hal-async = "1.0.0" +embedded_hal_0_2 = {package = "embedded-hal", version = "0.2.5", features = ["unproven"]} fugit = "0.3.6" -futures = { version = "0.3.30", default-features = false, features = ["async-await"] } +futures = {version = "0.3.30", default-features = false, features = ["async-await"]} hd44780-driver = "0.4.0" nb = "1.0" -nostd_async = { version = "0.6.1", features = ["cortex_m"] } +nostd_async = {version = "0.6.1", features = ["cortex_m"]} panic-halt = "0.2.0" -panic-probe = { version = "0.3.1", features = ["print-defmt"] } +panic-probe = {version = "0.3.1", features = ["print-defmt"]} pio = "0.2.0" pio-proc = "0.2.0" rp2040-boot2 = "0.3.0" -rp2040-hal = { path = "../rp2040-hal", version = "0.10.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"] } +rp2040-hal = {path = "../rp2040-hal", version = "0.10.0", features = ["binary-info", "critical-section-impl", "rt", "defmt"]} diff --git a/rp2040-hal-macros/Cargo.toml b/rp2040-hal-macros/Cargo.toml index f95327504..f55c4784b 100644 --- a/rp2040-hal-macros/Cargo.toml +++ b/rp2040-hal-macros/Cargo.toml @@ -1,21 +1,17 @@ [package] +authors = ["The rp-rs Developers"] description = "Macros used by rp2040-hal" +edition = "2021" license = "MIT OR Apache-2.0" name = "rp2040-hal-macros" readme = "README.md" -version = "0.1.0" -edition = "2021" repository = "https://github.com/rp-rs/rp-hal" -authors = ["The rp-rs Developers"] +version = "0.1.0" [lib] proc-macro = true [dependencies] -quote = "1.0" proc-macro2 = "1.0" - -[dependencies.syn] -features = ["full"] -version = "2.0" - +quote = "1.0" +syn = {version = "2.0", features = ["full"]} diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index 080e1f22f..c1a07286a 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -1,15 +1,15 @@ [package] -name = "rp2040-hal" -version = "0.10.0" authors = ["The rp-rs Developers"] +categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"] +description = "A Rust Embedded-HAL impl for the rp2040 microcontroller" edition = "2021" homepage = "https://github.com/rp-rs/rp-hal" -description = "A Rust Embedded-HAL impl for the rp2040 microcontroller" +keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"] license = "MIT OR Apache-2.0" -rust-version = "1.77" +name = "rp2040-hal" repository = "https://github.com/rp-rs/rp-hal" -categories = ["embedded", "hardware-support", "no-std", "no-std::no-alloc"] -keywords = ["embedded", "hal", "raspberry-pi", "rp2040", "embedded-hal"] +rust-version = "1.77" +version = "0.10.0" [package.metadata.docs.rs] features = ["rt", "rom-v2-intrinsics", "defmt", "rtic-monotonic"] @@ -18,36 +18,43 @@ targets = ["thumbv6m-none-eabi"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitfield = { version = "0.14.0" } -chrono = { version = "0.4", default-features = false, optional = true } +# Non-optional dependencies. Keep these sorted by name. +bitfield = {version = "0.14.0"} cortex-m = "0.7.2" -critical-section = { version = "1.0.0" } -defmt = { version = ">=0.2.0, <0.4", optional = true } -embedded_hal_0_2 = { package = "embedded-hal", version = "0.2.5", features = ["unproven"] } +critical-section = {version = "1.0.0"} embedded-dma = "0.2.0" embedded-hal = "1.0.0" embedded-hal-async = "1.0.0" embedded-hal-nb = "1.0.0" embedded-io = "0.6.1" -frunk = { version = "0.4.1", default-features = false } +embedded_hal_0_2 = {package = "embedded-hal", version = "0.2.5", features = ["unproven"]} +frunk = {version = "0.4.1", default-features = false} fugit = "0.3.6" -i2c-write-iter = { version = "1.0.0", features = ["async"], optional = true } -itertools = { version = "0.10.1", default-features = false } +itertools = {version = "0.10.1", default-features = false} nb = "1.0" paste = "1.0" pio = "0.2.0" rand_core = "0.6.3" rp-binary-info = { version = "0.1.0", path = "../rp-binary-info" } -rp2040-hal-macros = { version = "0.1.0", path = "../rp2040-hal-macros" } -rp2040-pac = { version = "0.6.0", features = ["critical-section"] } -rtic-monotonic = { version = "1.0.0", optional = true } +rp2040-hal-macros = {version = "0.1.0", path = "../rp2040-hal-macros"} +rp2040-pac = {version = "0.6.0", features = ["critical-section"]} usb-device = "0.3" vcell = "0.1" -void = { version = "1.0.2", default-features = false } +void = {version = "1.0.2", default-features = false} + +# Optional dependencies. Keep these sorted by name. +chrono = {version = "0.4", default-features = false, optional = true} +defmt = {version = ">=0.2.0, <0.4", optional = true} +i2c-write-iter = {version = "1.0.0", features = ["async"], optional = true} +rtic-monotonic = {version = "1.0.0", optional = true} [dev-dependencies] +# Non-optional dependencies. Keep these sorted by name. pio-proc = "0.2.0" -rand = { version = "0.8.5", default-features = false } +rand = {version = "0.8.5", default-features = false} + +# Optional dependencies. Keep these sorted by name. +# None [features] # Minimal startup / runtime for Cortex-M microcontrollers