From 7b20279ce08d5ec867edff29ede1e67f493d3945 Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sat, 10 Jul 2021 13:24:27 -0700 Subject: [PATCH 1/9] initial commit --- NOTES.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 NOTES.md diff --git a/NOTES.md b/NOTES.md new file mode 100644 index 0000000..9605df6 --- /dev/null +++ b/NOTES.md @@ -0,0 +1,28 @@ +# RTOS and bare metal options for SAMD21 + +[Zephyr](https://www.zephyrproject.org/] + +[Zephyr on Feather](https://learn.adafruit.com/blinking-led-with-zephyr-rtos) + +https://github.com/ataradov/mcu-starter-projects + +# Referenes on SAMD21 and Feather ecosystem + + +[Zephy / Boards / feather m0](https://docs.zephyrproject.org/latest/boards/arm/adafruit_feather_m0_basic_proto/doc/index.html) + - documents the port assignments on the SAMD21 and interconnect on Feather + + +# LoRa, LoRaWAN, and Feather + +https://github.com/svcguy/lorawanFeather + +https://github.com/kisom/lora-modem + +https://github.com/MKme/lora + +https://github.com/cbleg98/LoRa-High-Altitude-Balloon + +https://learn.adafruit.com/adafruit-feather-m0-radio-with-lora-radio-module/using-the-rfm-9x-radio + + -- 2.45.1 From 882e8be16da3fe125ad4d7947f8fb0d81276f2cb Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sat, 10 Jul 2021 13:25:08 -0700 Subject: [PATCH 2/9] rust samd21 skeleton --- rs-lorachat/Cargo.toml | 8 ++++++++ rs-lorachat/src/main.rs | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 rs-lorachat/Cargo.toml create mode 100644 rs-lorachat/src/main.rs diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml new file mode 100644 index 0000000..85fa008 --- /dev/null +++ b/rs-lorachat/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rs-lorachat" +version = "0.1.0" +authors = ["Andy Isaacson "] +edition = "2018" + +[dependencies] +feather_m0 = { git = "https://github.com/atsamd-rs/atsamd" } diff --git a/rs-lorachat/src/main.rs b/rs-lorachat/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/rs-lorachat/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} -- 2.45.1 From 65a1447f284f65f006b2c777ffe9dc15e215702c Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sat, 10 Jul 2021 14:37:59 -0700 Subject: [PATCH 3/9] further work on getting rust build for m0 --- .gitignore | 2 ++ rs-lorachat/.cargo/config | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .gitignore create mode 100644 rs-lorachat/.cargo/config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..756e9c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +target +.*.sw? diff --git a/rs-lorachat/.cargo/config b/rs-lorachat/.cargo/config new file mode 100644 index 0000000..6ac6920 --- /dev/null +++ b/rs-lorachat/.cargo/config @@ -0,0 +1,13 @@ +[build] +target = "thumbv6m-none-eabi" + +[target.thumbv6m-none-eabi] +runner = 'arm-none-eabi-gdb' +rustflags = [ + + # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x + # See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 + "-C", "link-arg=--nmagic", + + "-C", "link-arg=-Tlink.x", +] -- 2.45.1 From 7ca2acacf40053d56427ec1ca0eab6d0ec1c67d7 Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sat, 10 Jul 2021 14:49:16 -0700 Subject: [PATCH 4/9] working blinky --- rs-lorachat/Cargo.toml | 18 +++++++++++++++++ rs-lorachat/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml index 85fa008..f64427c 100644 --- a/rs-lorachat/Cargo.toml +++ b/rs-lorachat/Cargo.toml @@ -6,3 +6,21 @@ edition = "2018" [dependencies] feather_m0 = { git = "https://github.com/atsamd-rs/atsamd" } + + +[dependencies.cortex-m-rt] +version = "0.6.12" +optional = true + +[dependencies.atsamd-hal] +version = "0.12" +default-features = false + +[dependencies.panic-halt] +version = "0.2" +optional = true + +[features] +default = ["rt", "atsamd-hal/samd21g", "panic_halt"] +rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"] +panic_halt = ["panic-halt"] diff --git a/rs-lorachat/src/main.rs b/rs-lorachat/src/main.rs index e7a11a9..a0395d5 100644 --- a/rs-lorachat/src/main.rs +++ b/rs-lorachat/src/main.rs @@ -1,3 +1,42 @@ -fn main() { - println!("Hello, world!"); +#![no_std] +#![no_main] + +use panic_halt as _; + +use bsp::hal; +use bsp::pac; +use feather_m0 as bsp; + +use bsp::entry; +use hal::clock::GenericClockController; +use hal::delay::Delay; +use hal::prelude::*; +use pac::{CorePeripherals, Peripherals}; + +#[entry] +fn main() -> ! { + let mut peripherals = Peripherals::take().unwrap(); + let core = CorePeripherals::take().unwrap(); + let mut clocks = GenericClockController::with_external_32kosc( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + let pins = bsp::Pins::new(peripherals.PORT); + let mut red_led: bsp::RedLed = pins.d13.into(); + let mut delay = Delay::new(core.SYST, &mut clocks); + loop { + delay.delay_ms(250u8); + delay.delay_ms(250u8); + delay.delay_ms(250u8); + delay.delay_ms(250u8); + red_led.set_high().unwrap(); + delay.delay_ms(100u8); + red_led.set_low().unwrap(); + delay.delay_ms(100u8); + red_led.set_high().unwrap(); + delay.delay_ms(100u8); + red_led.set_low().unwrap(); + } } -- 2.45.1 From 726df4b11c6b68e05815efd162506272913f715f Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sun, 11 Jul 2021 19:55:41 -0700 Subject: [PATCH 5/9] wip on getting this thing to do USB --- rs-lorachat/Cargo.toml | 28 ++++++++++++++++++++++++++-- rs-lorachat/src/main.rs | 30 +++++++++++++++++------------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml index f64427c..cff8d1a 100644 --- a/rs-lorachat/Cargo.toml +++ b/rs-lorachat/Cargo.toml @@ -6,7 +6,9 @@ edition = "2018" [dependencies] feather_m0 = { git = "https://github.com/atsamd-rs/atsamd" } - +# feather_m0 = { path = "/home/adi/opp/atsamd" } +cortex-m = "0.6" +embedded-hal = "0.2.3" [dependencies.cortex-m-rt] version = "0.6.12" @@ -14,13 +16,35 @@ optional = true [dependencies.atsamd-hal] version = "0.12" -default-features = false [dependencies.panic-halt] version = "0.2" optional = true +[dependencies.usb-device] +version = "0.2" +optional = true + +[dependencies.rtic-monotonic] +version = "=0.1.0-alpha.1" +optional = true + +[dependencies.usbd-serial] +version = "0.1" +optional = true + +[dev-dependencies] +cortex-m-semihosting = "0.3" +heapless = "0.5" + +[dev-dependencies.cortex-m-rtic] +version = "0.6.0-alpha.4" + [features] default = ["rt", "atsamd-hal/samd21g", "panic_halt"] rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"] panic_halt = ["panic-halt"] +usb = ["atsamd-hal/usb", "usb-device", "usbd-serial"] +unproven = ["atsamd-hal/unproven"] +# Enable pins for the radio on "RadioFruits" with RFM95, RFM96, RFM69 +rfm = [] diff --git a/rs-lorachat/src/main.rs b/rs-lorachat/src/main.rs index a0395d5..92e4f45 100644 --- a/rs-lorachat/src/main.rs +++ b/rs-lorachat/src/main.rs @@ -4,14 +4,13 @@ use panic_halt as _; use bsp::hal; -use bsp::pac; use feather_m0 as bsp; use bsp::entry; -use hal::clock::GenericClockController; +use hal::clock::{GenericClockController}; use hal::delay::Delay; +use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; -use pac::{CorePeripherals, Peripherals}; #[entry] fn main() -> ! { @@ -24,19 +23,24 @@ fn main() -> ! { &mut peripherals.NVMCTRL, ); let pins = bsp::Pins::new(peripherals.PORT); - let mut red_led: bsp::RedLed = pins.d13.into(); let mut delay = Delay::new(core.SYST, &mut clocks); + let mut red_led = pins.d13.into_push_pull_output(); + + + red_led.set_high().unwrap(); + delay.delay_ms(500_u32); + red_led.set_low().unwrap(); + delay.delay_ms(500_u32); + red_led.set_high().unwrap(); + + red_led.set_low().unwrap(); + delay.delay_ms(500_u32); + + loop { - delay.delay_ms(250u8); - delay.delay_ms(250u8); - delay.delay_ms(250u8); - delay.delay_ms(250u8); - red_led.set_high().unwrap(); - delay.delay_ms(100u8); - red_led.set_low().unwrap(); - delay.delay_ms(100u8); + delay.delay_ms(1_000_u32); red_led.set_high().unwrap(); - delay.delay_ms(100u8); + delay.delay_ms(1_000_u32); red_led.set_low().unwrap(); } } -- 2.45.1 From 99a9806b9b2b042d168f32ae10dd4b89a3295021 Mon Sep 17 00:00:00 2001 From: Andy Isaacson Date: Sun, 11 Jul 2021 20:11:31 -0700 Subject: [PATCH 6/9] import 0.12 (?) usb_echo wholesale --- rs-lorachat/Cargo.toml | 8 +- rs-lorachat/src/lib.rs | 226 ++++++++++++++++++++++++++++++++++++++++ rs-lorachat/src/main.rs | 105 ++++++++++++++----- 3 files changed, 307 insertions(+), 32 deletions(-) create mode 100644 rs-lorachat/src/lib.rs diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml index cff8d1a..b76ed91 100644 --- a/rs-lorachat/Cargo.toml +++ b/rs-lorachat/Cargo.toml @@ -16,6 +16,7 @@ optional = true [dependencies.atsamd-hal] version = "0.12" +default-features = false [dependencies.panic-halt] version = "0.2" @@ -25,10 +26,6 @@ optional = true version = "0.2" optional = true -[dependencies.rtic-monotonic] -version = "=0.1.0-alpha.1" -optional = true - [dependencies.usbd-serial] version = "0.1" optional = true @@ -37,9 +34,6 @@ optional = true cortex-m-semihosting = "0.3" heapless = "0.5" -[dev-dependencies.cortex-m-rtic] -version = "0.6.0-alpha.4" - [features] default = ["rt", "atsamd-hal/samd21g", "panic_halt"] rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"] diff --git a/rs-lorachat/src/lib.rs b/rs-lorachat/src/lib.rs new file mode 100644 index 0000000..ad9b80c --- /dev/null +++ b/rs-lorachat/src/lib.rs @@ -0,0 +1,226 @@ +#![no_std] + +extern crate atsamd_hal as hal; + +#[cfg(feature = "rt")] +extern crate cortex_m_rt; +#[cfg(feature = "rt")] +pub use cortex_m_rt::entry; + +use hal::prelude::*; +use hal::*; + +pub use hal::common::*; +pub use hal::samd21::*; +pub use hal::target_device as pac; + +use gpio::{Floating, Input, PfC, Port}; +use hal::clock::GenericClockController; +use hal::sercom::{I2CMaster3, PadPin, SPIMaster4, UART0}; +use hal::time::Hertz; + +#[cfg(feature = "usb")] +use hal::usb::usb_device::bus::UsbBusAllocator; +#[cfg(feature = "usb")] +pub use hal::usb::UsbBus; + +define_pins!( + /// Maps the pins to their arduino names and + /// the numbers printed on the board. + struct Pins, + target_device: target_device, + + /// AREF pin - has 1uF capacitor to ground + pin aref = a3, + + /// Analog pin 0. Can act as a true analog output + /// as it has a DAC (which is not currently supported + /// by this hal) as well as input. + pin a0 = a2, + + /// Analog Pin 1 + pin a1 = b8, + /// Analog Pin 2 + pin a2 = b9, + /// Analog Pin 3 + pin a3 = a4, + /// Analog Pin 4 + pin a4 = a5, + /// Analog Pin 5 + pin a5 = b2, + + /// Pin 0, rx + pin d0 = a11, + /// Pin 1, tx + pin d1 = a10, + /// Pin 5, PWM capable + pin d5 = a15, + /// Pin 6, PWM capable + pin d6 = a20, + /// Pin 9, PWM capable. Also analog input (A7) + pin d9 = a7, + /// Pin 10, PWM capable + pin d10 = a18, + /// Pin 11, PWM capable + pin d11 = a16, + /// Pin 12, PWM capable + pin d12 = a19, + /// Pin 13, which is also attached to + /// the red LED. PWM capable. + pin d13 = a17, + + /// The I2C data line + pin sda = a22, + /// The I2C clock line + pin scl = a23, + + /// The SPI SCK + pin sck = b11, + /// The SPI MOSI + pin mosi = b10, + /// The SPI MISO + pin miso = a12, + + /// The USB D- pad + pin usb_dm = a24, + /// The USB D+ pad + pin usb_dp = a25, + + /// SPI chip select for the RFM module + #[cfg(feature = "rfm")] + pin rfm_cs = a6, + + /// Reset for the RFM module + #[cfg(feature = "rfm")] + pin rfm_reset = a8, + + /// Interrupt from the RFM module + #[cfg(feature = "rfm")] + pin rfm_irq = a9, + + /// Neopixel data + #[cfg(feature = "express")] + pin neopixel = a6, + + /// SPI clock for the external flash + #[cfg(feature = "express")] + pin flash_sck = a9, + + /// SPI MOSI for the external flash + #[cfg(feature = "express")] + pin flash_mosi = a8, + + /// SPI MISO for the external flash + #[cfg(feature = "express")] + pin flash_miso = a14, + + /// SPI chip select for the external flash + #[cfg(feature = "express")] + pin flash_cs = a13, +); + +/// Convenience for setting up the labelled SPI peripheral. +/// This powers up SERCOM4 and configures it for use as an +/// SPI Master in SPI Mode 0. +pub fn spi_master>( + clocks: &mut GenericClockController, + bus_speed: F, + sercom4: pac::SERCOM4, + pm: &mut pac::PM, + sck: gpio::Pb11>, + mosi: gpio::Pb10>, + miso: gpio::Pa12>, + port: &mut Port, +) -> SPIMaster4< + hal::sercom::Sercom4Pad0>, + hal::sercom::Sercom4Pad2>, + hal::sercom::Sercom4Pad3>, +> { + let gclk0 = clocks.gclk0(); + SPIMaster4::new( + &clocks.sercom4_core(&gclk0).unwrap(), + bus_speed.into(), + hal::hal::spi::Mode { + phase: hal::hal::spi::Phase::CaptureOnFirstTransition, + polarity: hal::hal::spi::Polarity::IdleLow, + }, + sercom4, + pm, + (miso.into_pad(port), mosi.into_pad(port), sck.into_pad(port)), + ) +} + +/// Convenience for setting up the labelled SDA, SCL pins to +/// operate as an I2C master running at the specified frequency. +pub fn i2c_master>( + clocks: &mut GenericClockController, + bus_speed: F, + sercom3: pac::SERCOM3, + pm: &mut pac::PM, + sda: gpio::Pa22>, + scl: gpio::Pa23>, + port: &mut Port, +) -> I2CMaster3< + hal::sercom::Sercom3Pad0>, + hal::sercom::Sercom3Pad1>, +> { + let gclk0 = clocks.gclk0(); + I2CMaster3::new( + &clocks.sercom3_core(&gclk0).unwrap(), + bus_speed.into(), + sercom3, + pm, + sda.into_pad(port), + scl.into_pad(port), + ) +} + +/// Convenience for setting up the labelled RX, TX pins to +/// operate as a UART device running at the specified baud. +pub fn uart>( + clocks: &mut GenericClockController, + baud: F, + sercom0: pac::SERCOM0, + pm: &mut pac::PM, + d0: gpio::Pa11>, + d1: gpio::Pa10>, + port: &mut Port, +) -> UART0< + hal::sercom::Sercom0Pad3>, + hal::sercom::Sercom0Pad2>, + (), + (), +> { + let gclk0 = clocks.gclk0(); + + UART0::new( + &clocks.sercom0_core(&gclk0).unwrap(), + baud.into(), + sercom0, + pm, + (d0.into_pad(port), d1.into_pad(port)), + ) +} + +#[cfg(feature = "usb")] +pub fn usb_allocator( + usb: pac::USB, + clocks: &mut GenericClockController, + pm: &mut pac::PM, + dm: gpio::Pa24>, + dp: gpio::Pa25>, + port: &mut Port, +) -> UsbBusAllocator { + use gpio::IntoFunction; + + let gclk0 = clocks.gclk0(); + let usb_clock = &clocks.usb(&gclk0).unwrap(); + + UsbBusAllocator::new(UsbBus::new( + usb_clock, + pm, + dm.into_function(port), + dp.into_function(port), + usb, + )) +} diff --git a/rs-lorachat/src/main.rs b/rs-lorachat/src/main.rs index 92e4f45..89ad868 100644 --- a/rs-lorachat/src/main.rs +++ b/rs-lorachat/src/main.rs @@ -1,46 +1,101 @@ #![no_std] #![no_main] -use panic_halt as _; +extern crate cortex_m; +extern crate feather_m0 as hal; +extern crate panic_halt; +extern crate usb_device; +extern crate usbd_serial; -use bsp::hal; -use feather_m0 as bsp; - -use bsp::entry; -use hal::clock::{GenericClockController}; -use hal::delay::Delay; -use hal::pac::{CorePeripherals, Peripherals}; +use hal::clock::GenericClockController; +use hal::entry; +use hal::pac::{interrupt, CorePeripherals, Peripherals}; use hal::prelude::*; +use hal::usb::UsbBus; +use usb_device::bus::UsbBusAllocator; + +use usb_device::prelude::*; +use usbd_serial::{SerialPort, USB_CLASS_CDC}; + +use cortex_m::asm::delay as cycle_delay; +use cortex_m::peripheral::NVIC; + #[entry] fn main() -> ! { let mut peripherals = Peripherals::take().unwrap(); - let core = CorePeripherals::take().unwrap(); - let mut clocks = GenericClockController::with_external_32kosc( + let mut core = CorePeripherals::take().unwrap(); + let mut clocks = GenericClockController::with_internal_32kosc( peripherals.GCLK, &mut peripherals.PM, &mut peripherals.SYSCTRL, &mut peripherals.NVMCTRL, ); - let pins = bsp::Pins::new(peripherals.PORT); - let mut delay = Delay::new(core.SYST, &mut clocks); - let mut red_led = pins.d13.into_push_pull_output(); + let mut pins = hal::Pins::new(peripherals.PORT); + let mut red_led = pins.d13.into_open_drain_output(&mut pins.port); + let bus_allocator = unsafe { + USB_ALLOCATOR = Some(hal::usb_allocator( + peripherals.USB, + &mut clocks, + &mut peripherals.PM, + pins.usb_dm, + pins.usb_dp, + &mut pins.port, + )); + USB_ALLOCATOR.as_ref().unwrap() + }; - red_led.set_high().unwrap(); - delay.delay_ms(500_u32); - red_led.set_low().unwrap(); - delay.delay_ms(500_u32); - red_led.set_high().unwrap(); - - red_led.set_low().unwrap(); - delay.delay_ms(500_u32); + unsafe { + USB_SERIAL = Some(SerialPort::new(&bus_allocator)); + USB_BUS = Some( + UsbDeviceBuilder::new(&bus_allocator, UsbVidPid(0x16c0, 0x27dd)) + .manufacturer("Fake company") + .product("Serial port") + .serial_number("TEST") + .device_class(USB_CLASS_CDC) + .build(), + ); + } + unsafe { + core.NVIC.set_priority(interrupt::USB, 1); + NVIC::unmask(interrupt::USB); + } + // Flash the LED in a spin loop to demonstrate that USB is + // entirely interrupt driven. loop { - delay.delay_ms(1_000_u32); - red_led.set_high().unwrap(); - delay.delay_ms(1_000_u32); - red_led.set_low().unwrap(); + cycle_delay(15 * 1024 * 1024); + red_led.toggle(); } } + +static mut USB_ALLOCATOR: Option> = None; +static mut USB_BUS: Option> = None; +static mut USB_SERIAL: Option> = None; + +fn poll_usb() { + unsafe { + USB_BUS.as_mut().map(|usb_dev| { + USB_SERIAL.as_mut().map(|serial| { + usb_dev.poll(&mut [serial]); + let mut buf = [0u8; 64]; + + if let Ok(count) = serial.read(&mut buf) { + for (i, c) in buf.iter().enumerate() { + if i >= count { + break; + } + serial.write(&[c.clone()]); + } + }; + }); + }); + }; +} + +#[interrupt] +fn USB() { + poll_usb(); +} -- 2.45.1 From 0c4201c35eed75b16a44bb5a1054d1a6e9d5e5aa Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Sun, 11 Jul 2021 22:02:54 -0700 Subject: [PATCH 7/9] base flake.nix & direnv configuration for editors add - flake.nix w/ rust, gcc-arm-embedded, & cargo utilities - add .envrc for direnv configuration (emacs, vscode, etc..) - add .direnv to .gitignore to prevent cross-contamination --- .gitignore | 1 + flake.lock | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 39 +++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 756e9c6..b51e51a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target .*.sw? +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6b6c79b --- /dev/null +++ b/flake.lock @@ -0,0 +1,92 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1623875721, + "narHash": "sha256-A8BU7bjS5GirpAUv4QA+QnJ4CceLHkcXdRp4xITDB0s=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f7e004a55b120c02ecb6219596820fcd32ca8772", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1614513358, + "narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5466c5bbece17adaab2d82fae80b46e807611bf3", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1625950041, + "narHash": "sha256-AG5nHJFa5ZYTS4XvPIQjLp6PRDaXw8ufzuSgQrsPFxk=", + "owner": "patrickod", + "repo": "nixpkgs", + "rev": "8526fbfca0d4a6cff72d85844e02ae0c8dbbfee2", + "type": "github" + }, + "original": { + "owner": "patrickod", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1617325113, + "narHash": "sha256-GksR0nvGxfZ79T91UUtWjjccxazv6Yh/MvEJ82v1Xmw=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "54c1e44240d8a527a8f4892608c4bce5440c3ecb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1626055976, + "narHash": "sha256-JWqjfR0eeE505Xp26d3z/0T8+YljjHlS8VX/yCknskY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "ecb9af08bc7ce17a4c51378c7a301925d4c4344c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..d9ef43b --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "rust ARM M-0 development"; + inputs = { + nixpkgs.url = "github:patrickod/nixpkgs"; + rust-overlay.url = "github:oxalica/rust-overlay"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + rust = pkgs.rust-bin.nightly.latest.default.override { + extensions = [ + "clippy-preview" + "rust-src" + "rustfmt-preview" + "rust-analyzer-preview" + ]; + targets = [ + "thumbv6m-none-eabi" + ]; + }; + in + { + devShell = pkgs.mkShell { + buildInputs = [ + pkgs.gcc-arm-embedded + pkgs.probe-run + pkgs.cargo-hf2 + rust + ]; + }; + } + ); +} -- 2.45.1 From 8b63499a590ecf56e52bb867684d2f669e575954 Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Tue, 13 Jul 2021 00:06:19 -0700 Subject: [PATCH 8/9] working main.rs build * resolve import issues in main.rs to get a clean build * condense dependencies list in cargo.toml * add direnv configuration to point to nix flake env --- .envrc | 1 + rs-lorachat/Cargo.lock | 375 ++++++++++++++++++++++++++++++++++++++++ rs-lorachat/Cargo.toml | 28 +-- rs-lorachat/src/main.rs | 12 +- 4 files changed, 386 insertions(+), 30 deletions(-) create mode 100644 .envrc create mode 100644 rs-lorachat/Cargo.lock diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/rs-lorachat/Cargo.lock b/rs-lorachat/Cargo.lock new file mode 100644 index 0000000..2d990ec --- /dev/null +++ b/rs-lorachat/Cargo.lock @@ -0,0 +1,375 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aligned" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19796bd8d477f1a9d4ac2465b464a8b1359474f06a96bb3cda650b4fca309bf" +dependencies = [ + "as-slice", +] + +[[package]] +name = "as-slice" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45403b49e3954a4b8428a0ac21a4b7afadccf92bfd96273f1a58cd4812496ae0" +dependencies = [ + "generic-array 0.12.4", + "generic-array 0.13.3", + "generic-array 0.14.4", + "stable_deref_trait", +] + +[[package]] +name = "atsamd-hal" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "868f22ff864d664efd9a0134cad0905d918f62f3b14d7761ca6d64bdcb1df96b" +dependencies = [ + "atsamd21g", + "bitfield", + "cortex-m 0.6.7", + "embedded-hal", + "nb 0.1.3", + "paste", + "rand_core", + "usb-device", + "vcell", + "void", +] + +[[package]] +name = "atsamd21g" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d4092551cf82644de22191ad79c734adbd88df8e2b861e7b614d7e7891c83c7" +dependencies = [ + "bare-metal", + "cortex-m 0.6.7", + "cortex-m-rt", + "vcell", +] + +[[package]] +name = "bare-metal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5deb64efa5bd81e31fcd1938615a6d98c82eafcbcd787162b6f63b91d6bac5b3" +dependencies = [ + "rustc_version", +] + +[[package]] +name = "bitfield" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46afbd2983a5d5a7bd740ccb198caf5b82f45c40c09c0eed36052d91cb92e719" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cortex-m" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9075300b07c6a56263b9b582c214d0ff037b00d45ec9fde1cc711490c56f1bb9" +dependencies = [ + "aligned", + "bare-metal", + "bitfield", + "cortex-m 0.7.3", + "volatile-register", +] + +[[package]] +name = "cortex-m" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ac919ef424449ec8c08d515590ce15d9262c0ca5f0da5b0c901e971a3b783b3" +dependencies = [ + "bare-metal", + "bitfield", + "embedded-hal", + "volatile-register", +] + +[[package]] +name = "cortex-m-rt" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d8353767db816419630a76d5f1ad5b09610d22b67ceb59647df6a8abc667f8" +dependencies = [ + "cortex-m-rt-macros", + "r0", +] + +[[package]] +name = "cortex-m-rt-macros" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4717562afbba06e760d34451919f5c3bf3ac15c7bb897e8b04862a7428378647" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "cortex-m-semihosting" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bffa6c1454368a6aa4811ae60964c38e6996d397ff8095a8b9211b1c1f749bc" +dependencies = [ + "cortex-m 0.7.3", +] + +[[package]] +name = "embedded-hal" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db184d3fa27bc7a2344250394c0264144dfe0bc81a4401801dcb964b8dd172ad" +dependencies = [ + "nb 0.1.3", + "void", +] + +[[package]] +name = "feather_m0" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2340b26e52342f2ddadbaed755ecf0a7993b5a2b59912840afe06c33dd22b6a6" +dependencies = [ + "atsamd-hal", + "cortex-m 0.6.7", + "cortex-m-rt", + "embedded-hal", + "nb 0.1.3", + "panic-halt", + "usb-device", + "usbd-serial", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f797e67af32588215eaaab8327027ee8e71b9dd0b2b26996aedf20c030fce309" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "hash32" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc" +dependencies = [ + "byteorder", +] + +[[package]] +name = "heapless" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1" +dependencies = [ + "as-slice", + "generic-array 0.13.3", + "hash32", + "stable_deref_trait", +] + +[[package]] +name = "nb" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "801d31da0513b6ec5214e9bf433a77966320625a37860f910be265be6e18d06f" +dependencies = [ + "nb 1.0.0", +] + +[[package]] +name = "nb" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" + +[[package]] +name = "panic-halt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" + +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + +[[package]] +name = "proc-macro2" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r0" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2a38df5b15c8d5c7e8654189744d8e396bddc18ad48041a500ce52d6948941f" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rs-lorachat" +version = "0.1.0" +dependencies = [ + "atsamd-hal", + "cortex-m 0.6.7", + "cortex-m-rt", + "cortex-m-semihosting", + "embedded-hal", + "feather_m0", + "heapless", + "panic-halt", + "usb-device", + "usbd-serial", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "syn" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "usb-device" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6be90410d4772074ea49525e2e753b65920b94b57eee21a6ef7b6a6fe6296245" + +[[package]] +name = "usbd-serial" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db75519b86287f12dcf0d171c7cf4ecc839149fe9f3b720ac4cfce52959e1dfe" +dependencies = [ + "embedded-hal", + "nb 0.1.3", + "usb-device", +] + +[[package]] +name = "vcell" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77439c1b53d2303b20d9459b1ade71a83c716e3f9c34f3228c00e6f185d6c002" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" + +[[package]] +name = "volatile-register" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d67cb4616d99b940db1d6bd28844ff97108b498a6ca850e5b6191a532063286" +dependencies = [ + "vcell", +] diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml index b76ed91..904d7e8 100644 --- a/rs-lorachat/Cargo.toml +++ b/rs-lorachat/Cargo.toml @@ -5,30 +5,14 @@ authors = ["Andy Isaacson "] edition = "2018" [dependencies] -feather_m0 = { git = "https://github.com/atsamd-rs/atsamd" } -# feather_m0 = { path = "/home/adi/opp/atsamd" } +feather_m0 = { version = "0.9.0", features = ["usb"] } cortex-m = "0.6" embedded-hal = "0.2.3" - -[dependencies.cortex-m-rt] -version = "0.6.12" -optional = true - -[dependencies.atsamd-hal] -version = "0.12" -default-features = false - -[dependencies.panic-halt] -version = "0.2" -optional = true - -[dependencies.usb-device] -version = "0.2" -optional = true - -[dependencies.usbd-serial] -version = "0.1" -optional = true +cortex-m-rt = { version = "0.6.12", optional = true } +atsamd-hal = "0.12" +panic-halt = { version = "0.2", optional = true } +usb-device = { version = "0.2", optional = true } +usbd-serial = { version = "0.1", optional = true } [dev-dependencies] cortex-m-semihosting = "0.3" diff --git a/rs-lorachat/src/main.rs b/rs-lorachat/src/main.rs index 89ad868..1331552 100644 --- a/rs-lorachat/src/main.rs +++ b/rs-lorachat/src/main.rs @@ -1,16 +1,12 @@ #![no_std] #![no_main] -extern crate cortex_m; -extern crate feather_m0 as hal; -extern crate panic_halt; -extern crate usb_device; -extern crate usbd_serial; +use panic_halt as _; +use feather_m0 as hal; +use hal::entry; use hal::clock::GenericClockController; -use hal::entry; use hal::pac::{interrupt, CorePeripherals, Peripherals}; -use hal::prelude::*; use hal::usb::UsbBus; use usb_device::bus::UsbBusAllocator; @@ -98,4 +94,4 @@ fn poll_usb() { #[interrupt] fn USB() { poll_usb(); -} +} \ No newline at end of file -- 2.45.1 From 42aedd4f89a19f887b736e4869eb09b38aa4350f Mon Sep 17 00:00:00 2001 From: Patrick O'Doherty Date: Tue, 13 Jul 2021 00:17:42 -0700 Subject: [PATCH 9/9] specify usb,unproven as default features to stop CLI arg repetition add VSCode settings to point rust-analyzer at the appropriate target & get analysis results. --- rs-lorachat/.vscode/settings.json | 10 ++++++++++ rs-lorachat/Cargo.toml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 rs-lorachat/.vscode/settings.json diff --git a/rs-lorachat/.vscode/settings.json b/rs-lorachat/.vscode/settings.json new file mode 100644 index 0000000..0a5b8c6 --- /dev/null +++ b/rs-lorachat/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + // override the default setting (`cargo check --all-targets`) which produces the following error + // "can't find crate for `test`" when the default compilation target is a no_std target + // with these changes RA will call `cargo check --bins` on save + "rust-analyzer.checkOnSave.allTargets": false, + "rust-analyzer.checkOnSave.extraArgs": [ + "--target", + "thumbv6m-none-eabi" + ] +} diff --git a/rs-lorachat/Cargo.toml b/rs-lorachat/Cargo.toml index 904d7e8..849d901 100644 --- a/rs-lorachat/Cargo.toml +++ b/rs-lorachat/Cargo.toml @@ -19,7 +19,7 @@ cortex-m-semihosting = "0.3" heapless = "0.5" [features] -default = ["rt", "atsamd-hal/samd21g", "panic_halt"] +default = ["rt", "atsamd-hal/samd21g", "panic_halt", "usb", "unproven"] rt = ["cortex-m-rt", "atsamd-hal/samd21g-rt"] panic_halt = ["panic-halt"] usb = ["atsamd-hal/usb", "usb-device", "usbd-serial"] -- 2.45.1