Skip to content

Commit

Permalink
RISC-V support over CLINT (#815)
Browse files Browse the repository at this point in the history
* Rebase to master

* using interrupt_mod

* bug fixes

* fix other backends

* Add changelog

* forgot about rtic-macros

* backend-specific configuration

* core peripherals optional over macro argument

* pre_init_preprocessing binding

* CI for RISC-V (WIP)

* separation of concerns

* add targets for RISC-V examples

* remove qemu feature

* prepare examples folder

* move examples all together

* move ci out of examples

* minor changes

* add cortex-m

* new xtask: proof of concept

* fix build.yml

* feature typo

* clean rtic examples

* reproduce weird issue

* remove unsafe code in user app

* update dependencies

* allow builds on riscv32imc

* let's fix QEMU

* Update .github/workflows/build.yml

Co-authored-by: Henrik Tjäder <henrik@tjaders.com>

* New build.rs

* removing test features

* adapt ui test to new version of clippy

* add more examples to RISC-V backend

* proper configuration of heapless for riscv32imc

* opt-out examples for riscv32imc

* point to new version of riscv-slic

* adapt new macro bindings

* adapt examples and CI to stable

* fix cortex-m CI

* Review

---------

Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
  • Loading branch information
romancardenas and AfoHT authored Mar 20, 2024
1 parent 22ac33a commit 4060c3d
Show file tree
Hide file tree
Showing 166 changed files with 2,308 additions and 301 deletions.
150 changes: 113 additions & 37 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ jobs:
- name: cargo xtask fmt
run: cargo xtask --verbose fmt -c

# Compilation check
check:
name: check
# Compilation check (lm3s6965)
checklm3s6965:
name: check (lm3s6965)
runs-on: ubuntu-22.04
strategy:
matrix:
Expand Down Expand Up @@ -62,11 +62,14 @@ jobs:
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2

- run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} check
- run: cargo xtask --deny-warnings --platform lm3s6965 --backend ${{ matrix.backend }} check

# Clippy
clippy:
name: clippy
# Compilation check (hifive1) TODO
# checkhifive1:

# Clippy (lm3s6965)
clippylm3s6965:
name: clippy (lm3s6965)
runs-on: ubuntu-22.04
strategy:
matrix:
Expand Down Expand Up @@ -98,11 +101,14 @@ jobs:
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2

- run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} clippy
- run: cargo xtask --deny-warnings --platform lm3s6965 --backend ${{ matrix.backend }} clippy

# Clippy (hifive1) TODO
# clippyhifive1:

# Verify all examples, checks
checkexamples:
name: check examples
# Platform lm3s6965: verify all examples, checks
checkexampleslm3s6965:
name: check examples (lm3s6965)
runs-on: ubuntu-22.04
strategy:
matrix:
Expand Down Expand Up @@ -133,44 +139,46 @@ jobs:

- name: Check the examples
if: ${{ matrix.backend == 'thumbv8-base' }}
run: cargo xtask --backend ${{ matrix.backend }} --exampleexclude pool example-check
run: cargo xtask --platform lm3s6965 --backend ${{ matrix.backend }} --exampleexclude pool example-check

- name: Check the examples
if: ${{ matrix.backend != 'thumbv8-base' }}
run: cargo xtask --backend ${{ matrix.backend }} example-check

# Check that the usage examples build
usageexamples:
name: Build usage examples
run: cargo xtask --platform lm3s6965 --backend ${{ matrix.backend }} example-check
# Platform hifive1: verify all examples, checks
checkexampleshifive1:
name: check examples (hifive1)
runs-on: ubuntu-22.04
strategy:
matrix:
backend:
- riscv32-imc-clint
- riscv32-imac-clint
toolchain:
- stable
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install rust ${{ matrix.toolchain }}
- name: Install Rust ${{ matrix.toolchain }}
run: |
rustup set profile minimal
rustup override set ${{ matrix.toolchain }}
- name: Configure rust target (v6, v7)
- name: Configure Rust target
run: |
rustup target add thumbv7em-none-eabihf
rustup target add thumbv7m-none-eabi
rustup target add thumbv6m-none-eabi
rustup component add rust-src
rustup target add riscv32imac-unknown-none-elf
rustup target add riscv32imc-unknown-none-elf
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2

- name: Install flip-link
run: cargo install flip-link

- name: Check the examples
if: ${{ matrix.backend == 'riscv32-imc-clint' }}
run: cargo xtask --platform hifive1 --backend ${{ matrix.backend }} --exampleexclude static example-check

- name: Check the examples
run: cargo xtask usage-example-build
if: ${{ matrix.backend != 'riscv32-imc-clint' }}
run: cargo xtask --platform hifive1 --backend ${{ matrix.backend }} example-check

buildqemu:
name: Get modern QEMU, build and store
Expand All @@ -192,7 +200,7 @@ jobs:
- name: Install QEMU to get dependencies
run: |
sudo apt update
sudo apt install -y qemu-system-arm
sudo apt install -y qemu-system-arm qemu-system-riscv32
sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
- if: ${{ steps.cache-qemu.outputs.cache-hit != 'true' }}
Expand Down Expand Up @@ -226,9 +234,9 @@ jobs:
name: qemu
path: qemu.tar

# Verify the example output with run-pass tests
testexamples:
name: QEMU run
# Platform lm3s6965: verify the example output with run-pass tests
testexampleslm3s6965:
name: QEMU run (lm3s6965)
needs: buildqemu
runs-on: ubuntu-22.04
strategy:
Expand Down Expand Up @@ -283,7 +291,71 @@ jobs:
which qemu-system-riscv32
- name: Run-pass tests
run: cargo xtask --deny-warnings --backend ${{ matrix.backend }} qemu
run: cargo xtask --deny-warnings --platform lm3s6965 --backend ${{ matrix.backend }} qemu

# Platform hifive1: verify the example output with run-pass tests
testexampleshifive1:
name: QEMU run (hifive1)
needs: buildqemu
runs-on: ubuntu-22.04
strategy:
matrix:
backend:
- riscv32-imc-clint
- riscv32-imac-clint
toolchain:
- stable
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rust ${{ matrix.toolchain }}
run: |
rustup set profile minimal
rustup override set ${{ matrix.toolchain }}
- name: Configure Rust target
run: |
rustup target add riscv32imac-unknown-none-elf
rustup target add riscv32imc-unknown-none-elf
- name: Add Rust component llvm-tools-preview
run: rustup component add llvm-tools-preview

# Use precompiled binutils
- name: Install cargo-binutils
uses: taiki-e/install-action@v2
with:
tool: cargo-binutils

- name: Cache Dependencies
uses: Swatinem/rust-cache@v2

- name: Install QEMU to get dependencies
run: |
sudo apt update
sudo apt install -y qemu-system-riscv32
- name: Download built QEMU
uses: actions/download-artifact@v4
with:
name: qemu

- name: Extract QEMU into local path
run: tar -xf qemu.tar -C /usr/local/bin

- name: Check which QEMU is used
run: |
which qemu-system-arm
which qemu-system-riscv32
- name: Run-pass tests
if: ${{ matrix.backend == 'riscv32-imc-clint' }}
run: cargo xtask --deny-warnings --platform hifive1 --backend ${{ matrix.backend }} --exampleexclude static qemu

- name: Run-pass tests
if: ${{ matrix.backend != 'riscv32-imc-clint' }}
run: cargo xtask --deny-warnings --platform hifive1 --backend ${{ matrix.backend }} qemu

# Run test suite
tests:
Expand Down Expand Up @@ -719,10 +791,14 @@ jobs:
if: github.event_name == 'push' && success()
needs:
- formatcheck
- check
- clippy
- checkexamples
- testexamples
- checklm3s6965
# checkhifive1 TODO
- clippylm3s6965
# clippyhifive1 TODO
- checkexampleslm3s6965
- checkexampleshifive1
- testexampleslm3s6965
- testexampleshifive1
- tests
- docs
- mdbook
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
Cargo.lock
*.hex
book-target/

.DS_Store
.vscode/
17 changes: 17 additions & 0 deletions ci/expected/hifive1/prio_inheritance.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Idle]: Started
[SoftMedium]: Started
[SoftMedium]: Shared: 1
[SoftHigh]: Started
[SoftHigh]: Shared: 2
[SoftHigh]: Finished
[SoftMedium]: Finished
[SoftLow1]: Started
[SoftLow1]: Shared: 3
[SoftLow1]: Yield
[SoftLow2]: Started
[SoftLow2]: Shared: 4
[SoftLow2]: Yield
[SoftLow1]: Finished
[SoftLow2]: Finished
[Idle]: Shared: 4
[Idle]: Finished
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions ci/expected/lm3s6965/static.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
received message: 1
received message: 2
received message: 3
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions ci/expected/lm3s6965/task.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
foo - start
foo - middle
baz
foo - end
bar
3 changes: 3 additions & 0 deletions ci/expected/lm3s6965/zero-prio-task.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
init
hello from async
hello from async2
11 changes: 11 additions & 0 deletions examples/hifive1/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[target.'cfg(all(target_arch = "riscv32", target_os = "none"))']
runner = "qemu-system-riscv32 -machine sifive_e,revb=true -nographic -semihosting-config enable=on,target=native -kernel"
# runner = "riscv64-unknown-elf-gdb -q -x gdb_init"
rustflags = [
"-C", "link-arg=-Thifive1-link.x",
]

[build]
# Pick ONE of these compilation targets
# target = "riscv32imc-unknown-none-elf" # non-atomic support
target = "riscv32imac-unknown-none-elf" # atomic support (partial)
Loading

0 comments on commit 4060c3d

Please sign in to comment.