Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an implementation for the QT Py CH32V203 RISC-V dev board #5

Merged
merged 8 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-attiny85.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Build
run: nix develop '.#attiny85' --command just build attiny85 release
run: nix build '.#pwm-fan-controller-attiny85'
- name: Upload firmware
uses: actions/upload-artifact@v4
with:
name: pwm-fan-controller-attiny85
path: |
boards/attiny85/target/avr-unknown-none-attiny85/release/pwm-fan-controller-attiny85.elf
boards/attiny85/pwm-fan-controller-attiny85.hex
result/bin/pwm-fan-controller-attiny85.elf
result/bin/pwm-fan-controller-attiny85.hex
4 changes: 3 additions & 1 deletion .github/workflows/build-pico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ name: Build Rasbperry Pi Pico
- boards/pico/Cargo.lock
- boards/pico/Cargo.toml
- boards/pico/default.nix
- boards/pico/rust-toolchain.toml
- boards/pico/src/**
push:
branches: ["main"]
Expand All @@ -28,6 +29,7 @@ name: Build Rasbperry Pi Pico
- boards/pico/Cargo.lock
- boards/pico/Cargo.toml
- boards/pico/default.nix
- boards/pico/rust-toolchain.toml
- boards/pico/src/**
workflow_dispatch:

Expand All @@ -48,4 +50,4 @@ jobs:
name: pwm-fan-controller-pico
path: |
result/bin/pwm-fan-controller-pico
pwm-fan-controller-pico.uf2
result/bin/pwm-fan-controller-pico.uf2
50 changes: 50 additions & 0 deletions .github/workflows/build-qt-py-ch32v203.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build QT Py CH32V203

"on":
pull_request:
branches: ["main"]
paths:
- .github/workflows/build-qt-py-ch32v203.yaml
- .justfile
- flake.lock
- flake.nix
- boards/qt-py-ch32v203/.cargo/**
- boards/qt-py-ch32v203/build.rs
- boards/qt-py-ch32v203/memory.x
- boards/qt-py-ch32v203/Cargo.lock
- boards/qt-py-ch32v203/Cargo.toml
- boards/qt-py-ch32v203/default.nix
- boards/qt-py-ch32v203/rust-toolchain.toml
- boards/qt-py-ch32v203/src/**
push:
branches: ["main"]
paths:
- .github/workflows/build-qt-py-ch32v203.yaml
- .justfile
- flake.lock
- flake.nix
- boards/qt-py-ch32v203/.cargo/**
- boards/qt-py-ch32v203/build.rs
- boards/qt-py-ch32v203/memory.x
- boards/qt-py-ch32v203/Cargo.lock
- boards/qt-py-ch32v203/Cargo.toml
- boards/qt-py-ch32v203/default.nix
- boards/qt-py-ch32v203/rust-toolchain.toml
- boards/qt-py-ch32v203/src/**
workflow_dispatch:

jobs:
build-qt-py-ch32v203:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@v14
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Build
run: nix build '.#pwm-fan-controller-qt-py-ch32v203'
- name: Upload firmware
uses: actions/upload-artifact@v4
with:
name: pwm-fan-controller-qt-py-ch32v203
path: |
result/bin/pwm-fan-controller-qt-py-ch32v203
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ repos:
language: system
types: [file, rust]
pass_filenames: true
- id: rust-clippy-attiny85
name: Rust clippy ATtiny85
description: Run cargo clippy on files included in the commit.
language: system
entry: nix develop --command cargo clippy --all-targets --all-features --manifest-path boards/attiny85/Cargo.toml -- -Dclippy::all
pass_filenames: false
types: [file, rust]
# - id: rust-clippy-attiny85
# name: Rust clippy ATtiny85
# description: Run cargo clippy on files included in the commit.
# language: system
# entry: nix develop '.#attiny85' --command cargo clippy --all-targets --all-features --manifest-path boards/attiny85/Cargo.toml -- -Dclippy::all
# pass_filenames: false
# types: [file, rust]
# - id: rust-clippy-pico
# name: Rust clippy Pico
# description: Run cargo clippy on files included in the commit.
# entry: nix develop --command cargo clippy --all-targets --all-features --manifest-path boards/pico/Cargo.toml -- -Dclippy::all
# entry: nix develop '.#pico' --command cargo clippy --all-targets --all-features --manifest-path boards/pico/Cargo.toml -- -Dclippy::all
# pass_filenames: false
# types: [file, rust]
# language: system
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"udev",
"udisksctl",
"usermod",
"VBUS"
"VBUS",
"wchisp"
],
"asciidoc.antora.enableAntoraSupport": false
}
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ifdef::env-github[]
:warning-caption: :warning:
endif::[]
:Asciidoctor-link: https://asciidoctor.org[Asciidoctor]
:fish: https://fishshell.com/[fish]
:direnv: https://direnv.net/[direnv]
:Git: https://git-scm.com/[Git]
:just: https://just.systems/[just]
Expand All @@ -23,9 +22,10 @@ endif::[]
image:https://github.com/jwillikers/pwm-fan-controller/actions/workflows/build-attiny85.yaml/badge.svg[ATtiny85 Build, link=https://github.com/jwillikers/pwm-fan-controller/actions/workflows/build-attiny85.yaml]
image:https://github.com/jwillikers/pwm-fan-controller/actions/workflows/build-pico.yaml/badge.svg[Pico Build, link=https://github.com/jwillikers/pwm-fan-controller/actions/workflows/build-pico.yaml]

PWM fan controller projects written in {Rust} targeting different microcontrollers.
PWM fan controller written in {Rust} targeting different microcontrollers.
Currently, these are basic examples for setting the {Noctua-NF-P12-redux-1700-PWM-Fan} to a quiescent 40% speed.
Implementations for specific boards can be found in the `boards` directory.
The implementations include boards targeting the Arm, AVR, and RISC-V architectures.

ifdef::env-github[]
++++
Expand Down Expand Up @@ -131,6 +131,7 @@ sudo usermod --append --groups dialout $USER

* link:boards/attiny85/README.adoc[ATtiny85]
* link:boards/pico/README.adoc[Raspberry Pi Pico]
* link:boards/qt-py-ch32v203/README.adoc[Adafruit QT Py CH32V203]

== Contributing

Expand All @@ -143,7 +144,6 @@ This project is built on the hard work of countless open source contributors.
Several of these projects are enumerated below.

* {Asciidoctor-link}
* {fish}
* {direnv}
* {Git}
* {Linux}
Expand Down
2 changes: 1 addition & 1 deletion boards/attiny85/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

use flake .#attiny85
use flake ../..#attiny85
4 changes: 1 addition & 3 deletions boards/attiny85/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ endif::[]
:AVR-Libc: https://www.nongnu.org/avr-libc/[AVR Libc]
:avrdude: https://github.com/avrdudes/avrdude[avrdude]
:cargo-binutils: https://github.com/rust-embedded/cargo-binutils[cargo-binutils]
:fish: https://fishshell.com/[fish]
:Git: https://git-scm.com/[Git]
:Noctua-NF-P12-redux-1700-PWM-Fan: https://noctua.at/en/nf-p12-redux-1700-pwm[Noctua NF-P12 redux-1700 PWM Fan]
:Rust: https://www.rust-lang.org/[Rust]
Expand Down Expand Up @@ -173,7 +172,7 @@ cd pwm-fan-controller/boards/attiny85
+
[,sh]
----
nix develop '.#attiny85' --command just flash
nix run '../..#attiny85.flash.avrdude'
----

== Todo
Expand Down Expand Up @@ -208,7 +207,6 @@ Several of these projects are enumerated below.
* {avrdude}
* {AVR-Libc}
* {cargo-binutils}
* {fish}
* {Git}
* {Rust}

Expand Down
5 changes: 2 additions & 3 deletions boards/attiny85/avr-unknown-none-attiny85.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tier": null
},
"no-default-libraries": false,
"os": "none",
"pre-link-args": {
"gnu-cc": [
"-mmcu=attiny85",
Expand All @@ -38,7 +39,5 @@
"relocation-model": "static",
"target-c-int-width": "16",
"target-pointer-width": "16",
"target-family": "avr",
"vendor": "unknown",
"os": "none"
"vendor": "unknown"
}
64 changes: 10 additions & 54 deletions boards/attiny85/default.nix
Original file line number Diff line number Diff line change
@@ -1,63 +1,19 @@
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/rust/build-rust-package/sysroot/default.nix
{ stdenv
, cargo-binutils
, pkgs
, rustToolchain
# , rust-bin
{
craneLib
, cargoArtifacts
, commonArgs
, stdenv
}:
craneLib.buildPackage commonArgs // {
inherit cargoArtifacts;

let
# rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;
# rustc = rust-bin.stable.latest.minimal;
# cargo = rust-bin.stable.latest.minimal;
};
in
rustPlatform.buildRustPackage {
pname = "pwm-fan-controller-attiny85";
version = "0.0.1";
src = ./.;
cargoLock = {
allowBuiltinFetchGit = true;
lockFile = ./Cargo.lock;
};
__internal_dontAddSysroot = true;
# useSysroot = false;
# env.CARGO_BUILD_TARGET = "${./avr-specs/avr-attiny85.json}";
# CARGO_BUILD_TARGET = "${./avr-specs/avr-attiny85.json}";
doCheck = false;
RUSTC_BOOTSTRAP = 1;
cargoExtraArgs = "-Z build-std=core";
# cargoExtraArgs = "--target avr-specs/avr-attiny85.json";
# postPatch = ''
# ln -s ${./Cargo.lock} Cargo.lock
# '';
# buildPhase = ''
# cargoBuildHook
# '';
# ${rust.envVars.setEnv} cargo cbuild -j $NIX_BUILD_CORES --release --frozen --prefix=${placeholder "out"} --target avr-specs/avr-attiny85.json
buildPhase = ''
runHook preBuild
cargo build -j $NIX_BUILD_CORES --release --frozen --target ${./avr-unknown-none-attiny85.json} -Z build-std=core
cargo objcopy -- -O ihex pwm-fan-controller-attiny85.hex
runHook postBuild
'';

postBuild = ''
cargo objcopy -- -O ihex pwm-fan-controller-attiny85.hex
'';
installPhase = ''
mkdir --parents $out/bin

postInstall = ''
mv pwm-fan-controller-attiny85.hex $out/bin/
'';
buildInputs = [
];
nativeBuildInputs = [
# pkgs.buildPackages.stdenv.cc
cargo-binutils
# rust-bin.stable.latest.minimal
rustToolchain
];
# auditable = false;
}
1 change: 1 addition & 0 deletions boards/attiny85/rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
channel = "nightly-2024-03-22"
components = ["llvm-tools-preview", "rust-src"]
profile = "minimal"
targets = ["avr-unknown-none-attiny85.json"]
2 changes: 1 addition & 1 deletion boards/pico/.envrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
fi

use flake .#pico
use flake ../..#pico
13 changes: 4 additions & 9 deletions boards/pico/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ endif::[]
:Asciidoctor-link: https://asciidoctor.org[Asciidoctor]
:cargo-embed: https://github.com/probe-rs/cargo-embed[cargo-embed]
:elf2uf2-rs: https://github.com/JoNil/elf2uf2-rs[elf2uf2-rs]
:fish: https://fishshell.com/[fish]
:flip-link: https://github.com/knurling-rs/flip-link[flip-link]
:Git: https://git-scm.com/[Git]
:Noctua-NF-P12-redux-1700-PWM-Fan: https://noctua.at/en/nf-p12-redux-1700-pwm[Noctua NF-P12 redux-1700 PWM Fan]
Expand Down Expand Up @@ -114,7 +113,7 @@ udisksctl mount --block-device /dev/sda1
+
[,sh]
----
nix run '.#pico.flash.elf2uf2-rs'
nix run '../..#pico.flash.elf2uf2-rs'
----

// == Develop
Expand Down Expand Up @@ -197,14 +196,11 @@ curl --location --output-dir=/run/media/$USER/RPI-RP2 --remote-name \

== Todo

* Document connections with the 1787AHC125.
* Document how to use a debug probe with cargo-embed.
* Document how to use the probe-rs-debugger VSCode extension.
* Measure power efficiency.
* Document connections with the 74AHCT125.

== References

* https://www.ti.com/lit/ds/symlink/sn74ahct125.pdf[1787AHC125 Datasheet]
* https://www.ti.com/lit/ds/symlink/sn74ahct125.pdf[SN74AHCT125 Datasheet]
* https://en.wikipedia.org/wiki/Computer_fan_control#Pulse-width_modulation[Computer Fan Control: Pulse-width modulation]
* https://github.com/rp-rs/rp2040-project-template[Project template for rp2040-hal]
* {Picoprobe-Wiring}
Expand All @@ -216,7 +212,7 @@ curl --location --output-dir=/run/media/$USER/RPI-RP2 --remote-name \
.Rust Docs
* https://docs.rs/embedded-hal/latest/embedded_hal/[embedded-hal]
* https://docs.rs/fugit/latest/fugit/[fugit]
* https://docs.rs/rp-pico/0.5.0/rp_pico/[rp-pico]
* https://docs.rs/rp-pico/latest/rp_pico/[rp-pico]
* https://docs.rs/rp2040-hal/latest/rp2040_hal/[rp2040-hal]

== Contributing
Expand All @@ -231,7 +227,6 @@ Several of these projects are enumerated below.

* {Asciidoctor-link}
* {elf2uf2-rs}
* {fish}
* {flip-link}
* {Git}
* {probe-run}
Expand Down
41 changes: 0 additions & 41 deletions boards/pico/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,10 @@ craneLib.buildPackage {
rm --force --recursive $out/src/bin/crane-dummy-*
'';

# Build-time tools which are target agnostic. build = host = target = your-machine.
# Emulators should essentially also go `nativeBuildInputs`. But with some packaging issue,
# currently it would cause some rebuild.
# We put them here just for a workaround.
# See: https://github.com/NixOS/nixpkgs/pull/146583
depsBuildBuild = [
];

# Dependencies which need to be build for the current platform
# on which we are doing the cross compilation. In this case,
# pkg-config needs to run on the build platform so that the build
# script can find the location of openssl. Note that we don't
# need to specify the rustToolchain here since it was already
# overridden above.
nativeBuildInputs = [
stdenv.cc
pkgs.flip-link
];

# Dependencies which need to be built for the platform on which
# the binary will run. In this case, we need to compile openssl
# so that it can be linked with our executable.
# buildInputs = [
# # Add additional build inputs here
# openssl
# ];

# Tell cargo about the linker and an optional emulater. So they can be used in `cargo build`
# and `cargo run`.
# Environment variables are in format `CARGO_TARGET_<UPPERCASE_UNDERSCORE_RUST_TRIPLE>_LINKER`.
# They are also be set in `.cargo/config.toml` instead.
# See: https://doc.rust-lang.org/cargo/reference/config.html#target
# CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
# CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER = "qemu-aarch64";

# Tell cargo which target we want to build (so it doesn't default to the build system).
# We can either set a cargo flag explicitly with a flag or with an environment variable.
cargoExtraArgs = "--target thumbv6m-none-eabi";
# CARGO_BUILD_TARGET = "thumbv6m-none-eabi";

# These environment variables may be necessary if any of your dependencies use a
# build-script which invokes the `cc` crate to build some other code. The `cc` crate
# should automatically pick up on our target-specific linker above, but this may be
# necessary if the build script needs to compile and run some extra code on the build
# system.
# HOST_CC = "${stdenv.cc.nativePrefix}cc";
# TARGET_CC = "${stdenv.cc.targetPrefix}cc";
}
Loading