Compare commits

..

2 Commits

12 changed files with 6 additions and 11866 deletions

2
Cargo.lock generated
View File

@ -1,7 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
[[package]] [[package]]
name = "adc2tcp" name = "thermostat"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,18 +1,14 @@
[package] [package]
categories = ["embedded", "no-std"] categories = ["embedded", "no-std"]
name = "adc2tcp" name = "thermostat"
description = "Poll ADC pin, report over TCP" description = "Thermostat firmware"
license = "GPL-3.0-only" license = "GPL-3.0-only"
authors = ["Astro <astro@spaceboyz.net>"] authors = ["Astro <astro@spaceboyz.net>"]
version = "0.0.0" version = "0.0.0"
keywords = ["ethernet", "eth", "stm32", "adc", "tcp"] keywords = ["thermostat", "laser", "physics"]
repository = "https://github.com/m-labs/adc2tcp" repository = "https://git.m-labs.hk/M-Labs/thermostat"
edition = "2018" edition = "2018"
[badges]
travis-ci = { repository = "astro/adc2tcp", branch = "master" }
maintenance = { status = "experimental" }
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = [] features = []
default-target = "thumbv7em-none-eabihf" default-target = "thumbv7em-none-eabihf"

View File

@ -1,67 +0,0 @@
# Synopsis
Exposes readings from an ADC pin (currently: *PA3*) of the board via a
TCP service on the Ethernet port.
# Network Protocol
Sensor readings produce lines of `key=value` pairs, joined by `,`,
terminated by `"\r\n"`.
```
t=21000,pa3=685
t=22000,pa3=684
t=23000,pa3=681
t=24000,pa3=696
t=25000,pa3=673
t=26000,pa3=689
t=27000,pa3=657
t=28000,pa3=654
t=29000,pa3=652
t=30000,pa3=662
t=31000,pa3=663
```
| Key | Value | Unit |
|:---:|-------------|------|
| t | Time | ms |
| pa3 | ADC reading | mV |
# LEDs
Colors indicate what the MCU is occupied with.
| Color | Indication |
|:-------:|-------------------|
| Green | WFI (idle) |
| Blue | Network poll |
| Red | Message broadcast |
# Crate features
* `semihosting` enables log output via the **cortex-m-semihosting**
crate. Use only in development! MCU will hang when no OpenOCD is
running.
* `generate-hwaddr` generates an Ethernet MAC address by hashing the
unique device ID from flash memory.
# Instructions
![Made for NixOS](https://nixos.org/logo/nixos-lores.png)
## Build the firmware with `default.nix`
* `nix-build`
* This uses **cargo-vendor** to bundle dependencies, so that unstable versions from git can be used.
* Run `result/bin/flash-adc2tcp` to flash a devboard with OpenOCD and quit.
## Development environment with `shell.nix`
* `nix-shell`
* Spawning `openocd`, the devboard should be connected already.
* Instructions (`cargo run --release`) are printed.

View File

@ -1,47 +0,0 @@
{ # Use master branch of the overlay by default
mozillaOverlay ? import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz),
rustManifest ? builtins.fetchurl "https://static.rust-lang.org/dist/channel-rust-nightly.toml"
}:
let
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
in
with pkgs;
let
rustPlatform = recurseIntoAttrs (callPackage ./nix/rustPlatform.nix {
inherit rustManifest;
});
adc2tcp = callPackage ./nix/adc2tcp.nix { inherit rustPlatform; };
openocd = callPackage ./nix/openocd.nix {};
in
stdenv.mkDerivation {
name = "adc2tcp-dist";
buildInputs = [
adc2tcp
openocd
makeWrapper
];
src = ./.;
dontBuild = true;
installPhase =
let
firmwareBinary = "$out/lib/adc2tcp.elf";
openOcdFlags = [
"-c" "reset halt"
"-c" "flash write_image erase ${firmwareBinary}"
"-c" "verify_image ${firmwareBinary}"
"-c" "reset run"
"-c" "shutdown"
];
in ''
mkdir -p $out/bin $out/lib $out/nix-support
ln -s ${adc2tcp}/lib/adc2tcp ${firmwareBinary}
makeWrapper ${openocd}/bin/openocd-nucleo-f429zi $out/bin/flash-adc2tcp \
--add-flags "${lib.escapeShellArgs openOcdFlags}"
echo file binary-dist ${firmwareBinary} >> $out/nix-support/hydra-build-products
'';
}

View File

@ -1,45 +0,0 @@
{ stdenv, rustPlatform, cacert, git, cargo-vendor }:
with rustPlatform;
let
sha256 = "1i9p5d5n01ajbp8lmavyway6vr1mmy107qnccff9glvr91rqx352";
fetchcargo = import ./fetchcargo.nix {
inherit stdenv cacert git cargo-vendor;
inherit (rust) cargo;
};
adc2tcpDeps = fetchcargo {
name = "adc2tcp";
src = ../.;
inherit sha256;
};
in
buildRustPackage rec {
name = "adc2tcp";
version = "0.0.0";
src = ../.;
cargoSha256 = sha256;
buildInputs = [ adc2tcpDeps ];
patchPhase = ''
cat >> .cargo/config <<EOF
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "${adc2tcpDeps}"
EOF
'';
buildPhase = ''
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cargo build --release
'';
doCheck = false;
installPhase = ''
mkdir -p $out/lib
cp target/thumbv7em-none-eabihf/release/adc2tcp $out/lib/
'';
}

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
{ stdenv, cacert, git, cargo, cargo-vendor }:
{ name, src, sha256 }:
let
# `src` restricted to the two files that define dependencies
cargoOnlySrc = stdenv.mkDerivation {
name = "${name}-cargo";
inherit src;
phases = "installPhase";
installPhase = ''
mkdir $out
cp ${src}/Cargo.{toml,lock} $out/
mkdir $out/src
touch $out/src/main.rs
'';
};
in
stdenv.mkDerivation {
name = "${name}-vendor";
nativeBuildInputs = [ cacert git cargo cargo-vendor ];
src = cargoOnlySrc;
phases = "unpackPhase patchPhase installPhase";
installPhase = ''
if [[ ! -f Cargo.lock ]]; then
echo
echo "ERROR: The Cargo.lock file doesn't exist"
echo
echo "Cargo.lock is needed to make sure that cargoSha256 doesn't change"
echo "when the registry is updated."
echo
exit 1
fi
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cargo vendor
cp -ar vendor $out
'';
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = sha256;
impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars;
preferLocalBuild = true;
}

View File

@ -1,24 +0,0 @@
{ stdenv, lib, openocd, makeWrapper }:
stdenv.mkDerivation {
name = "openocd-nucleo-f429zi";
buildInputs = [
openocd
makeWrapper
];
src = openocd;
noBuild = true;
installPhase =
let
openOcdFlags = [
"-f" "${openocd}/share/openocd/scripts/interface/stlink-v2-1.cfg"
"-f" "${openocd}/share/openocd/scripts/target/stm32f4x.cfg"
"-c" "init"
];
in ''
mkdir -p $out/bin
makeWrapper ${openocd}/bin/openocd $out/bin/openocd-nucleo-f429zi \
--add-flags "${lib.escapeShellArgs openOcdFlags}"
'';
}

View File

@ -1,27 +0,0 @@
{ recurseIntoAttrs, stdenv, lib,
makeRustPlatform,
fetchurl, patchelf,
rustManifest ? ./channel-rust-nightly.toml
}:
let
targets = [
# "x86_64-unknown-linux-gnu"
# "thumbv6m-none-eabi"
# "thumbv7m-none-eabi"
# "thumbv7em-none-eabi"
"thumbv7em-none-eabihf"
];
rustChannel =
lib.rustLib.fromManifestFile rustManifest {
inherit stdenv fetchurl patchelf;
};
rust =
rustChannel.rust.override {
inherit targets;
};
in
makeRustPlatform {
rustc = rust;
cargo = rust;
}

View File

@ -1,15 +0,0 @@
# For running on Hydra
{ pkgs ? import <nixpkgs> {},
rustManifest ? ./nix/channel-rust-nightly.toml
}:
with pkgs;
let
adc2tcp = callPackage ./default.nix {
inherit rustManifest;
mozillaOverlay = import <mozillaOverlay>;
};
in
{
build = lib.hydraJob adc2tcp;
}

View File

@ -1,30 +0,0 @@
{ rustChannel ? "nightly" }:
let
mozillaOverlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> { overlays = [ mozillaOverlay ]; };
in
with pkgs;
let
rustPlatform = callPackage ./nix/rustPlatform.nix {};
openocd = callPackage ./nix/openocd.nix {};
in
stdenv.mkDerivation {
name = "adc2tcp-env";
buildInputs = with rustPlatform.rust; [
rustc cargo pkgs.gdb
];
# Set Environment Variables
RUST_BACKTRACE = 1;
shellHook = ''
echo "Starting openocd"
${openocd}/bin/openocd-nucleo-f429zi &
# Let openocd output scroll by
sleep 1
echo "Run 'cargo run --release --features=semihosting'"
'';
}

View File

@ -67,7 +67,7 @@ fn init_log() {
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
init_log(); init_log();
info!("adc2tcp"); info!("Thermostat firmware");
let mut cp = CorePeripherals::take().unwrap(); let mut cp = CorePeripherals::take().unwrap();
cp.SCB.enable_icache(); cp.SCB.enable_icache();