From 14bae099355bda4df6817dbf21031879af57676e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Sun, 28 Mar 2021 20:32:50 +0200 Subject: [PATCH 01/19] load process into itcm needs newer fixed cortex-m-rt 0.6.13+unreleased relevant? https://reviews.llvm.org/D81986 --- .cargo/config | 1 + Cargo.lock | 20 ++++++++------------ Cargo.toml | 25 +++++++++++++++++-------- build.rs | 9 +++++++++ memory.x | 23 ++++++++++++++++++----- src/bin/dual-iir.rs | 2 ++ src/hardware/mod.rs | 4 ++-- src/startup.S | 28 ++++++++++++++++++++++++++++ 8 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 build.rs create mode 100644 src/startup.S diff --git a/.cargo/config b/.cargo/config index deffdfc..ad2c024 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,6 +1,7 @@ [target.'cfg(all(target_arch = "arm", target_os = "none"))'] runner = "gdb-multiarch -q -x openocd.gdb" rustflags = [ + "-C", "link-arg=--nmagic", "-C", "link-arg=-Tlink.x", # The target (below) defaults to cortex-m4 # There currently are two different options to go beyond that: diff --git a/Cargo.lock b/Cargo.lock index 946a634..03a8558 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,6 +100,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "cc" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" + [[package]] name = "cfg-if" version = "1.0.0" @@ -145,18 +151,13 @@ dependencies = [ [[package]] name = "cortex-m-rt" version = "0.6.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980c9d0233a909f355ed297ef122f257942de5e0a2cb1c39f60684b65bcb90fb" 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" +version = "0.6.11" dependencies = [ "proc-macro2", "quote", @@ -572,12 +573,6 @@ 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" version = "0.8.3" @@ -720,6 +715,7 @@ version = "0.4.1" dependencies = [ "ad9959", "asm-delay", + "cc", "cortex-m 0.6.7", "cortex-m-log", "cortex-m-rt", diff --git a/Cargo.toml b/Cargo.toml index 8d32d80..a18e595 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,23 @@ smoltcp-nal = "0.1.0" miniconf = "0.1" generic-array = "0.14" +[dependencies.mcp23017] +git = "https://github.com/mrd0ll4r/mcp23017.git" + +[dependencies.stm32h7xx-hal] +features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] +git = "https://github.com/stm32-rs/stm32h7xx-hal" +branch = "master" + +[build-dependencies] +cc = "1.0" + +[patch.crates-io.cortex-m-rt] +path = "../cortex-m-rt" +# 0.6.13 +# git = "https://github.com/rust-embedded/cortex-m-rt.git" +# rev = "8c90451" + [patch.crates-io.miniconf] git = "https://github.com/quartiq/miniconf.git" branch = "develop" @@ -67,14 +84,6 @@ branch = "master" # a new release of smoltcp is made, we can remove this patch. git = "https://github.com/smoltcp-rs/smoltcp.git" -[dependencies.mcp23017] -git = "https://github.com/mrd0ll4r/mcp23017.git" - -[dependencies.stm32h7xx-hal] -features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] -git = "https://github.com/stm32-rs/stm32h7xx-hal" -branch = "master" - [features] semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] bkpt = [ ] diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..3f9eaf9 --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +fn main() { + println!("cargo:rerun-if-changed=memory.x"); + + cc::Build::new() + .file("src/startup.S") + .compile("startup"); + println!("cargo:rerun-if-changed=src/startup.S"); +} + diff --git a/memory.x b/memory.x index c1569ce..a132517 100644 --- a/memory.x +++ b/memory.x @@ -13,10 +13,6 @@ MEMORY } SECTIONS { - .itcm : ALIGN(8) { - *(.itcm .itcm.*); - . = ALIGN(8); - } > ITCM .axisram (NOLOAD) : ALIGN(8) { *(.axisram .axisram.*); . = ALIGN(8); @@ -33,4 +29,21 @@ SECTIONS { *(.sram3 .sram3.*); . = ALIGN(4); } > SRAM3 -} INSERT AFTER .bss; + .itcm : ALIGN(8) { + . = ALIGN(8); + __sitcm = .; + *(.itcm .itcm.*); + . = ALIGN(8); + __eitcm = .; + } > ITCM AT>FLASH + __siitcm = LOADADDR(.itcm); + +/* This may be the only insert location that doesn't affect those __[es]... + * that are (unfortunately) placed outside their sections */ +} INSERT BEFORE .uninit; + +ASSERT(__sitcm % 8 == 0 && __eitcm % 8 == 0, " +BUG(cortex-m-rt): .itcm is not 8-byte aligned"); + +ASSERT(__siitcm % 4 == 0, " +BUG(cortex-m-rt): the LMA of .itcm is not 4-byte aligned"); diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 4a27d48..5a878dc 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -110,6 +110,8 @@ const APP: () = { /// Because the ADC and DAC operate at the same rate, these two constraints actually implement /// the same time bounds, meeting one also means the other is also met. #[task(binds=DMA1_STR4, resources=[adcs, dacs, iir_state, iir_ch], priority=2)] + #[inline(never)] + #[link_section = ".itcm.process"] fn process(c: process::Context) { let adc_samples = [ c.resources.adcs.0.acquire_buffer(), diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index cc7a34a..a83c9d6 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -58,11 +58,11 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { } #[cortex_m_rt::exception] -fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! { +unsafe fn HardFault(ef: &cortex_m_rt::ExceptionFrame) -> ! { panic!("HardFault at {:#?}", ef); } #[cortex_m_rt::exception] -fn DefaultHandler(irqn: i16) { +unsafe fn DefaultHandler(irqn: i16) { panic!("Unhandled exception (IRQn = {})", irqn); } diff --git a/src/startup.S b/src/startup.S new file mode 100644 index 0000000..b85bf11 --- /dev/null +++ b/src/startup.S @@ -0,0 +1,28 @@ +.cfi_sections .debug_frame + +# .thumb +.section .text.pre_init, "ax" +.globl __pre_init +.type __pre_init,%function +.thumb_func +.cfi_startproc +__pre_init: + # Analogous to cortex-m-rt Reset code for .data copying. + # Initialise .itcm code. `__sitcm`, `__siitcm`, and `__eitcm` come from the + # linker script. Copy from r2 into r0 until r0 reaches r1. + ldr r0,=__sitcm + ldr r1,=__eitcm + ldr r2,=__siitcm +1: + cmp r1, r0 + beq 2f + # load 1 word from r2 to r3, inc r2 + ldm r2!, {r3} + # store 1 word from r3 to r0, inc r0 + stm r0!, {r3} + b 1b +2: + dsb + isb + bx lr +.cfi_endproc From fc7374424a75876c67cafac877fbbc03aba39bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 29 Mar 2021 18:51:50 +0200 Subject: [PATCH 02/19] enable itcm/dtcm explicitly --- src/startup.S | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/startup.S b/src/startup.S index b85bf11..3a5b6ea 100644 --- a/src/startup.S +++ b/src/startup.S @@ -7,6 +7,22 @@ .thumb_func .cfi_startproc __pre_init: + + # Enable ITCM and DTCM + ldr r0, =1 + ldr r1, =0xE000EF90 + ldr r2, [r1] + # Set ITCMCR.EN + orr r2, r2, r0 + str r2, [r1] + ldr r1, =0xE000EF94 + ldr r2, [r1] + # Set DTCMCR.EN + orr r2, r2, r0 + str r2, [r1] + dsb + isb + # Analogous to cortex-m-rt Reset code for .data copying. # Initialise .itcm code. `__sitcm`, `__siitcm`, and `__eitcm` come from the # linker script. Copy from r2 into r0 until r0 reaches r1. From cd3cfa63e6248c66e34ea1fe0af1fcb72a74c58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Tue, 20 Apr 2021 13:26:07 +0200 Subject: [PATCH 03/19] memory.x: remove comment about old cortex-m-rt --- memory.x | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/memory.x b/memory.x index a132517..d87640a 100644 --- a/memory.x +++ b/memory.x @@ -37,10 +37,7 @@ SECTIONS { __eitcm = .; } > ITCM AT>FLASH __siitcm = LOADADDR(.itcm); - -/* This may be the only insert location that doesn't affect those __[es]... - * that are (unfortunately) placed outside their sections */ -} INSERT BEFORE .uninit; +} INSERT AFTER .uninit; ASSERT(__sitcm % 8 == 0 && __eitcm % 8 == 0, " BUG(cortex-m-rt): .itcm is not 8-byte aligned"); From 9e66054d211870441f9a8429d443c5796bfe1674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 29 Apr 2021 16:39:01 +0200 Subject: [PATCH 04/19] bump cortex-m-rt to 0.6.13+git --- Cargo.lock | 2 ++ Cargo.toml | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03a8558..d8e7782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,7 @@ dependencies = [ [[package]] name = "cortex-m-rt" version = "0.6.13" +source = "git+https://github.com/rust-embedded/cortex-m-rt.git?rev=a2e3ad5#a2e3ad54478c6b98e519a1b0946395d790c0b6c7" dependencies = [ "cortex-m-rt-macros", ] @@ -158,6 +159,7 @@ dependencies = [ [[package]] name = "cortex-m-rt-macros" version = "0.6.11" +source = "git+https://github.com/rust-embedded/cortex-m-rt.git?rev=a2e3ad5#a2e3ad54478c6b98e519a1b0946395d790c0b6c7" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a18e595..e6559a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,10 +59,8 @@ branch = "master" cc = "1.0" [patch.crates-io.cortex-m-rt] -path = "../cortex-m-rt" -# 0.6.13 -# git = "https://github.com/rust-embedded/cortex-m-rt.git" -# rev = "8c90451" +git = "https://github.com/rust-embedded/cortex-m-rt.git" +rev = "a2e3ad5" [patch.crates-io.miniconf] git = "https://github.com/quartiq/miniconf.git" From 23bdd816a7c70cda274f83d47f4ff3dacae63611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 29 Apr 2021 16:44:12 +0200 Subject: [PATCH 05/19] dependencies: align with master --- Cargo.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e6559a0..3499ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,14 +47,6 @@ smoltcp-nal = "0.1.0" miniconf = "0.1" generic-array = "0.14" -[dependencies.mcp23017] -git = "https://github.com/mrd0ll4r/mcp23017.git" - -[dependencies.stm32h7xx-hal] -features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] -git = "https://github.com/stm32-rs/stm32h7xx-hal" -branch = "master" - [build-dependencies] cc = "1.0" @@ -82,6 +74,14 @@ branch = "master" # a new release of smoltcp is made, we can remove this patch. git = "https://github.com/smoltcp-rs/smoltcp.git" +[dependencies.mcp23017] +git = "https://github.com/mrd0ll4r/mcp23017.git" + +[dependencies.stm32h7xx-hal] +features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] +git = "https://github.com/stm32-rs/stm32h7xx-hal" +branch = "master" + [features] semihosting = ["panic-semihosting", "cortex-m-log/semihosting"] bkpt = [ ] From 780b3441a21dbdbc3782a52d400cb7d1d84344f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 29 Apr 2021 17:33:20 +0200 Subject: [PATCH 06/19] fmt --- build.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 3f9eaf9..d0c281d 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,6 @@ fn main() { println!("cargo:rerun-if-changed=memory.x"); - cc::Build::new() - .file("src/startup.S") - .compile("startup"); + cc::Build::new().file("src/startup.S").compile("startup"); println!("cargo:rerun-if-changed=src/startup.S"); } - From b8b3bc0873267a055a2a3709043d8b28baf44ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 29 Apr 2021 17:44:54 +0200 Subject: [PATCH 07/19] gha: install gcc --- .github/workflows/ci.yml | 2 ++ .github/workflows/release.yml | 1 + 2 files changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf68b3f..be5ebcc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: stable @@ -51,6 +52,7 @@ jobs: features: nightly steps: - uses: actions/checkout@v2 + - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5be1311..50e0dd8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: stable From ff5f3af8a49b0472be0c3e60a2d5925f237d2f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Thu, 13 May 2021 15:22:44 +0200 Subject: [PATCH 08/19] remove duplicate linker option --- .cargo/config | 1 - 1 file changed, 1 deletion(-) diff --git a/.cargo/config b/.cargo/config index 0682cd0..82780fa 100644 --- a/.cargo/config +++ b/.cargo/config @@ -2,7 +2,6 @@ runner = "probe-run --chip STM32H743ZITx --speed 30000" # runner = "gdb-multiarch -q -x openocd.gdb" rustflags = [ - "-C", "link-arg=--nmagic", "-C", "link-arg=-Tlink.x", "-C", "link-arg=--nmagic", "-C", "target-cpu=cortex-m7", From 4d5f1ab5e916494adeaff8f917548d8335b4191b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 14 May 2021 17:20:08 +0200 Subject: [PATCH 09/19] itcm: implement in rust and execute during setup() --- .github/workflows/ci.yml | 2 -- .github/workflows/release.yml | 1 - Cargo.lock | 7 ------ Cargo.toml | 3 --- build.rs | 3 --- src/hardware/configuration.rs | 30 ++++++++++++++++++++++++ src/startup.S | 44 ----------------------------------- 7 files changed, 30 insertions(+), 60 deletions(-) delete mode 100644 src/startup.S diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index be5ebcc..cf68b3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: stable @@ -52,7 +51,6 @@ jobs: features: nightly steps: - uses: actions/checkout@v2 - - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0463aa6..475c05e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: sudo apt install gcc-arm-none-eabi - uses: actions-rs/toolchain@v1 with: toolchain: stable diff --git a/Cargo.lock b/Cargo.lock index a10d3c1..a85ba18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,12 +102,6 @@ dependencies = [ "rustc_version", ] -[[package]] -name = "cc" -version = "1.0.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" - [[package]] name = "cfg-if" version = "1.0.0" @@ -756,7 +750,6 @@ version = "0.5.0" dependencies = [ "ad9959", "asm-delay", - "cc", "cortex-m 0.7.2", "cortex-m-rt", "cortex-m-rtic", diff --git a/Cargo.toml b/Cargo.toml index 9fcec81..63c1846 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,9 +58,6 @@ rev = "61933f857a" features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] version = "0.9.0" -[build-dependencies] -cc = "1.0" - [patch.crates-io.cortex-m-rt] git = "https://github.com/rust-embedded/cortex-m-rt.git" rev = "a2e3ad5" diff --git a/build.rs b/build.rs index d0c281d..e71f6a6 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,3 @@ fn main() { println!("cargo:rerun-if-changed=memory.x"); - - cc::Build::new().file("src/startup.S").compile("startup"); - println!("cargo:rerun-if-changed=src/startup.S"); } diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index f48b3d2..f762d48 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -105,6 +105,32 @@ pub struct PounderDevices { /// Static storage for the ethernet DMA descriptor ring. static mut DES_RING: ethernet::DesRing = ethernet::DesRing::new(); +/// Setup ITCM and load its code from flash +unsafe fn setup_itcm() { + extern "C" { + static mut __sitcm: u32; + static mut __eitcm: u32; + static mut __siitcm: u32; + } + use core::{ptr, slice, sync::atomic}; + + // ITCM is enabled on reset on our CPU but might not be on others. + // Keep for completeness. + const ITCMCR: *mut u32 = 0xE000_EF90usize as _; + ptr::write_volatile(ITCMCR, ptr::read_volatile(ITCMCR) | 1); + atomic::fence(atomic::Ordering::SeqCst); + + let len = + (&__eitcm as *const u32).offset_from(&__sitcm as *const _) as usize; + let dst = slice::from_raw_parts_mut(&mut __sitcm as *mut _, len); + let src = slice::from_raw_parts(&__siitcm as *const _, len); + dst.copy_from_slice(src); + + atomic::fence(atomic::Ordering::SeqCst); + cortex_m::asm::dsb(); + cortex_m::asm::isb(); +} + /// Configure the stabilizer hardware for operation. /// /// # Args @@ -160,6 +186,10 @@ pub fn setup( log::info!("starting..."); } + unsafe { + setup_itcm(); + } + // Set up the system timer for RTIC scheduling. { let tim15 = diff --git a/src/startup.S b/src/startup.S deleted file mode 100644 index 3a5b6ea..0000000 --- a/src/startup.S +++ /dev/null @@ -1,44 +0,0 @@ -.cfi_sections .debug_frame - -# .thumb -.section .text.pre_init, "ax" -.globl __pre_init -.type __pre_init,%function -.thumb_func -.cfi_startproc -__pre_init: - - # Enable ITCM and DTCM - ldr r0, =1 - ldr r1, =0xE000EF90 - ldr r2, [r1] - # Set ITCMCR.EN - orr r2, r2, r0 - str r2, [r1] - ldr r1, =0xE000EF94 - ldr r2, [r1] - # Set DTCMCR.EN - orr r2, r2, r0 - str r2, [r1] - dsb - isb - - # Analogous to cortex-m-rt Reset code for .data copying. - # Initialise .itcm code. `__sitcm`, `__siitcm`, and `__eitcm` come from the - # linker script. Copy from r2 into r0 until r0 reaches r1. - ldr r0,=__sitcm - ldr r1,=__eitcm - ldr r2,=__siitcm -1: - cmp r1, r0 - beq 2f - # load 1 word from r2 to r3, inc r2 - ldm r2!, {r3} - # store 1 word from r3 to r0, inc r0 - stm r0!, {r3} - b 1b -2: - dsb - isb - bx lr -.cfi_endproc From 75a38dfba963a4d447b2a3af8cb7e86c3d7d7796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 14 May 2021 17:36:47 +0200 Subject: [PATCH 10/19] deps: add rationales for git dependencies --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 63c1846..00acb22 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,10 +46,12 @@ miniconf = "0.1.0" shared-bus = {version = "0.2.2", features = ["cortex-m"] } serde-json-core = "0.3" +# rtt-target bump [dependencies.rtt-logger] git = "https://github.com/quartiq/rtt-logger.git" rev = "70b0eb5" +# rewrite [dependencies.mcp23017] git = "https://github.com/mrd0ll4r/mcp23017.git" rev = "61933f857a" @@ -58,6 +60,7 @@ rev = "61933f857a" features = ["stm32h743v", "rt", "unproven", "ethernet", "quadspi"] version = "0.9.0" +# link.x section start/end [patch.crates-io.cortex-m-rt] git = "https://github.com/rust-embedded/cortex-m-rt.git" rev = "a2e3ad5" From 23a93e913511c2d158f9a2c66f64933322ca9f1e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 26 May 2021 13:05:54 +0200 Subject: [PATCH 11/19] Removing spurious settings updates --- src/bin/dual-iir.rs | 9 ++++++--- src/bin/lockin.rs | 9 ++++++--- src/net/mod.rs | 15 ++++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 29eb474..012cdde 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -13,7 +13,7 @@ use hardware::{ DigitalInput0, DigitalInput1, InputPin, SystemTimer, AFE0, AFE1, }; -use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}; +use net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer}; const SCALE: f32 = i16::MAX as _; @@ -171,8 +171,11 @@ const APP: () = { fn idle(mut c: idle::Context) -> ! { loop { match c.resources.network.lock(|net| net.update()) { - UpdateState::Updated => c.spawn.settings_update().unwrap(), - UpdateState::NoChange => cortex_m::asm::wfi(), + NetworkState::SettingsChanged => { + c.spawn.settings_update().unwrap() + } + NetworkState::Updated => {} + NetworkState::NoChange => cortex_m::asm::wfi(), } } } diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index a187767..7200eb4 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -17,7 +17,7 @@ use stabilizer::hardware::{ }; use miniconf::Miniconf; -use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}; +use net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer}; // A constant sinusoid to send on the DAC output. // Full-scale gives a +/- 10.24V amplitude waveform. Scale it down to give +/- 1V. @@ -248,8 +248,11 @@ const APP: () = { fn idle(mut c: idle::Context) -> ! { loop { match c.resources.network.lock(|net| net.update()) { - UpdateState::Updated => c.spawn.settings_update().unwrap(), - UpdateState::NoChange => cortex_m::asm::wfi(), + NetworkState::SettingsChanged => { + c.spawn.settings_update().unwrap() + } + NetworkState::Updated => {} + NetworkState::NoChange => cortex_m::asm::wfi(), } } } diff --git a/src/net/mod.rs b/src/net/mod.rs index 38499ca..64c9401 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -33,6 +33,12 @@ pub enum UpdateState { Updated, } +#[derive(Copy, Clone, PartialEq)] +pub enum NetworkState { + SettingsChanged, + Updated, + NoChange, +} /// A structure of Stabilizer's default network users. pub struct NetworkUsers { pub miniconf: MiniconfClient, @@ -98,15 +104,18 @@ where /// /// # Returns /// An indication if any of the network users indicated a state change. - pub fn update(&mut self) -> UpdateState { + pub fn update(&mut self) -> NetworkState { // Poll for incoming data. - let poll_result = self.processor.update(); + let poll_result = match self.processor.update() { + UpdateState::NoChange => NetworkState::NoChange, + UpdateState::Updated => NetworkState::Updated, + }; // Update the MQTT clients. self.telemetry.update(); match self.miniconf.update() { - UpdateState::Updated => UpdateState::Updated, + UpdateState::Updated => NetworkState::SettingsChanged, UpdateState::NoChange => poll_result, } } From f10bce709fcf486cdd7da7fe34127e99521f7ba3 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 27 May 2021 13:42:52 +0200 Subject: [PATCH 12/19] Updating the embedded-nal --- Cargo.lock | 62 ++++++++++++++++++++++++-------------- Cargo.toml | 4 +-- src/net/miniconf_client.rs | 9 +++--- src/net/shared.rs | 14 ++++----- src/net/telemetry.rs | 6 ++-- 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 274b2bb..5402ed9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,6 +42,15 @@ dependencies = [ "embedded-hal", ] +[[package]] +name = "atomic-polyfill" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30302dda7a66f8c55932ebf208f7def840743ff64d495e9ceffcd97c18f11d39" +dependencies = [ + "cortex-m 0.7.2", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -240,11 +249,11 @@ dependencies = [ [[package]] name = "embedded-nal" -version = "0.1.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae46eb1b02de5a76d9d0ea21d657ff5b0ad2cc47f3a7723608227b1dd1b3eb18" +checksum = "db9efecb57ab54fa918730f2874d7d37647169c50fa1357fecb81abee840b113" dependencies = [ - "heapless 0.5.6", + "heapless 0.7.1", "nb 1.0.0", "no-std-net", ] @@ -317,24 +326,21 @@ dependencies = [ "byteorder", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" -[[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 = "heapless" version = "0.6.1" @@ -343,11 +349,22 @@ checksum = "634bd4d29cbf24424d0a4bfcbf80c6960129dc24424752a7d1d1390607023422" dependencies = [ "as-slice", "generic-array 0.14.4", - "hash32", + "hash32 0.1.1", "serde", "stable_deref_trait", ] +[[package]] +name = "heapless" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7ee8a997d259962217f40279f34201fdf06e669bafa69d7c1f4c7ff1893b5f6" +dependencies = [ + "atomic-polyfill", + "hash32 0.2.1", + "stable_deref_trait", +] + [[package]] name = "indexmap" version = "1.6.2" @@ -409,13 +426,12 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "git+https://github.com/quartiq/minimq.git?rev=d2ec3e8#d2ec3e8351fa403ea96defd98c0b4410cbaa18a4" +source = "git+https://github.com/quartiq/minimq.git?branch=feature/nal-update#98c1dffc4b0eeeaadf696320e1ce4234d5b52de0" dependencies = [ "bit_field", "embedded-nal", "enum-iterator", - "generic-array 0.14.4", - "heapless 0.6.1", + "heapless 0.7.1", ] [[package]] @@ -454,9 +470,9 @@ dependencies = [ [[package]] name = "no-std-net" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2178127478ae4ee9be7180bc9c3bffb6354dd7238400db567102f98c413a9f35" +checksum = "1bcece43b12349917e096cddfa66107277f123e6c96a5aea78711dc601a47152" [[package]] name = "num" @@ -745,10 +761,10 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=4a1711c#4a1711c54cdf79f5ee8c1c99a1e8984f5944270c" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/nal-update#65d94c4ab9e06d2e5c48547a0c9cd6836591e355" dependencies = [ "embedded-nal", - "heapless 0.6.1", + "heapless 0.7.1", "nanorand", "smoltcp", ] diff --git a/Cargo.toml b/Cargo.toml index 790363a..29de739 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ rev = "c6f2b28" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "4a1711c" +branch = "feature/nal-update" [dependencies.minimq] git = "https://github.com/quartiq/minimq.git" -rev = "d2ec3e8" +branch = "feature/nal-update" [features] nightly = ["cortex-m/inline-asm", "dsp/nightly"] diff --git a/src/net/miniconf_client.rs b/src/net/miniconf_client.rs index b809d73..76c64d2 100644 --- a/src/net/miniconf_client.rs +++ b/src/net/miniconf_client.rs @@ -21,7 +21,7 @@ where S: miniconf::Miniconf + Default + Clone, { default_response_topic: String, - mqtt: minimq::MqttClient, + mqtt: minimq::Minimq, settings: S, subscribed: bool, settings_prefix: String, @@ -39,8 +39,7 @@ where /// * `prefix` - The MQTT device prefix to use for this device. pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self { let mqtt = - minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) - .unwrap(); + minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); let mut response_topic: String = String::from(prefix); response_topic.push_str("/log").unwrap(); @@ -62,7 +61,7 @@ where /// # Returns /// An option containing an action that should be completed as a result of network servicing. pub fn update(&mut self) -> UpdateState { - let mqtt_connected = match self.mqtt.is_connected() { + let mqtt_connected = match self.mqtt.client.is_connected() { Ok(connected) => connected, Err(minimq::Error::Network( smoltcp_nal::NetworkError::NoIpAddress, @@ -88,7 +87,7 @@ where // We do not currently handle or process potential subscription failures. Instead, this // failure will be logged through the stabilizer logging interface. - self.mqtt.subscribe(&settings_topic, &[]).unwrap(); + self.mqtt.client.subscribe(&settings_topic, &[]).unwrap(); self.subscribed = true; } diff --git a/src/net/shared.rs b/src/net/shared.rs index e09489b..4f86793 100644 --- a/src/net/shared.rs +++ b/src/net/shared.rs @@ -47,25 +47,25 @@ impl<'a, S> NetworkStackProxy<'a, S> { // proxy structure. macro_rules! forward { ($func:ident($($v:ident: $IT:ty),*) -> $T:ty) => { - fn $func(&self, $($v: $IT),*) -> $T { + fn $func(&mut self, $($v: $IT),*) -> $T { self.mutex.lock(|stack| stack.$func($($v),*)) } } } // Implement a TCP stack for the proxy if the underlying network stack implements it. -impl<'a, S> embedded_nal::TcpStack for NetworkStackProxy<'a, S> +impl<'a, S> embedded_nal::TcpClientStack for NetworkStackProxy<'a, S> where - S: embedded_nal::TcpStack, + S: embedded_nal::TcpClientStack, { type TcpSocket = S::TcpSocket; type Error = S::Error; - forward! {open(mode: embedded_nal::Mode) -> Result} - forward! {connect(socket: S::TcpSocket, remote: embedded_nal::SocketAddr) -> Result} + forward! {socket() -> Result} + forward! {connect(socket: &mut S::TcpSocket, remote: embedded_nal::SocketAddr) -> embedded_nal::nb::Result<(), S::Error>} forward! {is_connected(socket: &S::TcpSocket) -> Result} - forward! {write(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result} - forward! {read(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result} + forward! {send(socket: &mut S::TcpSocket, buffer: &[u8]) -> embedded_nal::nb::Result} + forward! {receive(socket: &mut S::TcpSocket, buffer: &mut [u8]) -> embedded_nal::nb::Result} forward! {close(socket: S::TcpSocket) -> Result<(), S::Error>} } diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index b59b222..b6b9c34 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -21,7 +21,7 @@ use crate::hardware::{ /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { - mqtt: minimq::MqttClient, + mqtt: minimq::Minimq, telemetry_topic: String, _telemetry: core::marker::PhantomData, } @@ -97,8 +97,7 @@ impl TelemetryClient { /// A new telemetry client. pub fn new(stack: NetworkReference, client_id: &str, prefix: &str) -> Self { let mqtt = - minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) - .unwrap(); + minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); let mut telemetry_topic: String = String::from(prefix); telemetry_topic.push_str("/telemetry").unwrap(); @@ -122,6 +121,7 @@ impl TelemetryClient { let telemetry: Vec = serde_json_core::to_vec(telemetry).unwrap(); self.mqtt + .client .publish(&self.telemetry_topic, &telemetry, QoS::AtMostOnce, &[]) .ok(); } From fc2801ecbb4ee6243a2a0173a11ff2157731778a Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 27 May 2021 17:15:31 +0200 Subject: [PATCH 13/19] Updating dependencies --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5402ed9..0bba018 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9a69a963b70ddacfcd382524f72a4576f359af9334b3bf48a79566590bb8bfa" dependencies = [ "bitrate", - "cortex-m 0.7.2", + "cortex-m 0.6.7", "embedded-hal", ] @@ -426,7 +426,7 @@ dependencies = [ [[package]] name = "minimq" version = "0.2.0" -source = "git+https://github.com/quartiq/minimq.git?branch=feature/nal-update#98c1dffc4b0eeeaadf696320e1ce4234d5b52de0" +source = "git+https://github.com/quartiq/minimq.git?rev=dbdbec0#dbdbec0b77d2e134dc6c025018a82c14cbdfbe34" dependencies = [ "bit_field", "embedded-nal", @@ -761,7 +761,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/nal-update#65d94c4ab9e06d2e5c48547a0c9cd6836591e355" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=5e56576#5e56576fbbc594f0a0e1df9222a20eb35c8e7511" dependencies = [ "embedded-nal", "heapless 0.7.1", @@ -810,7 +810,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b672c837e0ee8158ecc7fce0f9a948dd0693a9c588338e728d14b73307a0b7d" dependencies = [ "bare-metal 0.2.5", - "cortex-m 0.7.2", + "cortex-m 0.6.7", "cortex-m-rt", "vcell", ] diff --git a/Cargo.toml b/Cargo.toml index 29de739..14be160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,11 +64,11 @@ rev = "c6f2b28" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "feature/nal-update" +rev = "5e56576" [dependencies.minimq] git = "https://github.com/quartiq/minimq.git" -branch = "feature/nal-update" +rev = "dbdbec0" [features] nightly = ["cortex-m/inline-asm", "dsp/nightly"] From 14c68474690be9ebdb5eeffa3a8a330f1b32c245 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 May 2021 15:53:15 +0000 Subject: [PATCH 14/19] build(deps): bump ndarray from 0.15.1 to 0.15.2 Bumps [ndarray](https://github.com/rust-ndarray/ndarray) from 0.15.1 to 0.15.2. - [Release notes](https://github.com/rust-ndarray/ndarray/releases) - [Changelog](https://github.com/rust-ndarray/ndarray/blob/master/RELEASES.md) - [Commits](https://github.com/rust-ndarray/ndarray/compare/0.15.1...0.15.2) Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bba018..2235321 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,7 +38,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9a69a963b70ddacfcd382524f72a4576f359af9334b3bf48a79566590bb8bfa" dependencies = [ "bitrate", - "cortex-m 0.6.7", + "cortex-m 0.7.2", "embedded-hal", ] @@ -457,9 +457,9 @@ checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" [[package]] name = "ndarray" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1372704f14bb132a49a6701c2238970a359ee0829fed481b522a63bf25456a" +checksum = "02b2e4807aaa21dc6dcc3417e5902dc199c3648043bf27b7af4b202332fe4760" dependencies = [ "matrixmultiply", "num-complex", @@ -810,7 +810,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b672c837e0ee8158ecc7fce0f9a948dd0693a9c588338e728d14b73307a0b7d" dependencies = [ "bare-metal 0.2.5", - "cortex-m 0.6.7", + "cortex-m 0.7.2", "cortex-m-rt", "vcell", ] From c5d3837745e94f71dd01aed644f30edb27bd0aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 28 May 2021 16:03:40 +0200 Subject: [PATCH 15/19] itcm: add some comments, make it safe --- src/hardware/configuration.rs | 53 ++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index f762d48..23121df 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -105,8 +105,17 @@ pub struct PounderDevices { /// Static storage for the ethernet DMA descriptor ring. static mut DES_RING: ethernet::DesRing = ethernet::DesRing::new(); -/// Setup ITCM and load its code from flash -unsafe fn setup_itcm() { +/// Setup ITCM and load its code from flash. +/// +/// For portability and maintainability this is implemented in Rust. +/// Since this is implemented in Rust the compiler may assume that bss and data are set +/// up already. There is no easy way to ensure this implementation will never need bss +/// or data. Hence we can't safely run this as the cortex-m-rt `pre_init` hook before +/// bss/data is setup. +/// +/// Calling (through IRQ or directly) any code in ITCM before having called +/// this method is undefined. +fn load_itcm() { extern "C" { static mut __sitcm: u32; static mut __eitcm: u32; @@ -114,18 +123,29 @@ unsafe fn setup_itcm() { } use core::{ptr, slice, sync::atomic}; - // ITCM is enabled on reset on our CPU but might not be on others. - // Keep for completeness. - const ITCMCR: *mut u32 = 0xE000_EF90usize as _; - ptr::write_volatile(ITCMCR, ptr::read_volatile(ITCMCR) | 1); - atomic::fence(atomic::Ordering::SeqCst); + // NOTE(unsafe): Assuming the address symbols from the linker as well as + // the source instruction data are all valid, this is safe as it only + // copies linker-prepared data to where the code expects it to be. + // Calling it multiple times is safe as well. - let len = - (&__eitcm as *const u32).offset_from(&__sitcm as *const _) as usize; - let dst = slice::from_raw_parts_mut(&mut __sitcm as *mut _, len); - let src = slice::from_raw_parts(&__siitcm as *const _, len); - dst.copy_from_slice(src); + unsafe { + // ITCM is enabled on reset on our CPU but might not be on others. + // Keep for completeness. + const ITCMCR: *mut u32 = 0xE000_EF90usize as _; + ptr::write_volatile(ITCMCR, ptr::read_volatile(ITCMCR) | 1); + // Ensure ITCM is enabled before loading. + atomic::fence(atomic::Ordering::SeqCst); + + let len = + (&__eitcm as *const u32).offset_from(&__sitcm as *const _) as usize; + let dst = slice::from_raw_parts_mut(&mut __sitcm as *mut _, len); + let src = slice::from_raw_parts(&__siitcm as *const _, len); + // Load code into ITCM. + dst.copy_from_slice(src); + } + + // Ensure ITCM is loaded before potentially executing any instructions from it. atomic::fence(atomic::Ordering::SeqCst); cortex_m::asm::dsb(); cortex_m::asm::isb(); @@ -183,12 +203,12 @@ pub fn setup( log::set_logger(&LOGGER) .map(|()| log::set_max_level(log::LevelFilter::Trace)) .unwrap(); - log::info!("starting..."); + log::info!("Starting"); } - unsafe { - setup_itcm(); - } + // Before being able to call any code in ITCM, load that code from flash. + log::info!("Loading ITCM"); + load_itcm(); // Set up the system timer for RTIC scheduling. { @@ -902,6 +922,7 @@ pub fn setup( #[cfg(feature = "pounder_v1_1")] let pounder_stamper = { + logger::info!("Pounder v1.1 or later"); let etr_pin = gpioa.pa0.into_alternate_af3(); // The frequency in the constructor is dont-care, as we will modify the period + clock From 79d30b4c6b454b0b5676331207b72a8a3e0e4072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 28 May 2021 16:32:26 +0200 Subject: [PATCH 16/19] setup: cleanup --- src/hardware/configuration.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index 23121df..e2eb653 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -207,7 +207,6 @@ pub fn setup( } // Before being able to call any code in ITCM, load that code from flash. - log::info!("Loading ITCM"); load_itcm(); // Set up the system timer for RTIC scheduling. @@ -922,7 +921,7 @@ pub fn setup( #[cfg(feature = "pounder_v1_1")] let pounder_stamper = { - logger::info!("Pounder v1.1 or later"); + log::info!("Assuming Pounder v1.1 or later"); let etr_pin = gpioa.pa0.into_alternate_af3(); // The frequency in the constructor is dont-care, as we will modify the period + clock @@ -985,13 +984,13 @@ pub fn setup( digital_inputs, }; + // Enable the instruction cache. + core.SCB.enable_icache(); + // info!("Version {} {}", build_info::PKG_VERSION, build_info::GIT_VERSION.unwrap()); // info!("Built on {}", build_info::BUILT_TIME_UTC); // info!("{} {}", build_info::RUSTC_VERSION, build_info::TARGET); log::info!("setup() complete"); - // Enable the instruction cache. - core.SCB.enable_icache(); - (stabilizer, pounder) } From e9e98678c1130048bbfed05e2776e83a2e13fbe2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 May 2021 14:40:46 +0000 Subject: [PATCH 17/19] build(deps): bump heapless from 0.6.1 to 0.7.1 Bumps [heapless](https://github.com/japaric/heapless) from 0.6.1 to 0.7.1. - [Release notes](https://github.com/japaric/heapless/releases) - [Changelog](https://github.com/japaric/heapless/blob/master/CHANGELOG.md) - [Commits](https://github.com/japaric/heapless/compare/v0.6.1...v0.7.1) Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5791b3a..1c7edfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -347,7 +347,6 @@ dependencies = [ "as-slice", "generic-array 0.14.4", "hash32 0.1.1", - "serde", "stable_deref_trait", ] @@ -359,6 +358,7 @@ checksum = "c7ee8a997d259962217f40279f34201fdf06e669bafa69d7c1f4c7ff1893b5f6" dependencies = [ "atomic-polyfill", "hash32 0.2.1", + "serde", "stable_deref_trait", ] @@ -771,7 +771,7 @@ dependencies = [ "cortex-m-rtic", "dsp", "embedded-hal", - "heapless 0.6.1", + "heapless 0.7.1", "log", "mcp23017", "miniconf", diff --git a/Cargo.toml b/Cargo.toml index 2eb2430..6dedf83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ cortex-m-rt = { version = "0.6", features = ["device"] } log = { version = "0.4", features = ["max_level_trace", "release_max_level_info"] } rtt-target = { version = "0.3", features = ["cortex-m"] } serde = { version = "1.0", features = ["derive"], default-features = false } -heapless = { version = "0.6", features = ["serde"] } +heapless = { version = "0.7", features = ["serde"] } cortex-m-rtic = "0.5.6" embedded-hal = "0.2.5" nb = "1.0.0" From 440e542eaeaf1ffd52fcc535c029fcc197161836 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 May 2021 14:40:51 +0000 Subject: [PATCH 18/19] Bump serde-json-core from 0.3.0 to 0.4.0 Bumps [serde-json-core](https://github.com/rust-embedded-community/serde-json-core) from 0.3.0 to 0.4.0. - [Release notes](https://github.com/rust-embedded-community/serde-json-core/releases) - [Changelog](https://github.com/rust-embedded-community/serde-json-core/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-embedded-community/serde-json-core/compare/v0.3.0...v0.4.0) Signed-off-by: dependabot[bot] --- Cargo.lock | 15 +++++++++++++-- Cargo.toml | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5791b3a..baa6afd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -417,7 +417,7 @@ source = "git+https://github.com/quartiq/miniconf.git?rev=c6f2b28#c6f2b28f735e27 dependencies = [ "derive_miniconf", "serde", - "serde-json-core", + "serde-json-core 0.3.0", ] [[package]] @@ -717,6 +717,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-json-core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8014aeea272bca0f0779778d43253f2f3375b414185b30e6ecc4d3e4a9994781" +dependencies = [ + "heapless 0.7.1", + "ryu", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.126" @@ -782,7 +793,7 @@ dependencies = [ "rtt-logger", "rtt-target", "serde", - "serde-json-core", + "serde-json-core 0.4.0", "shared-bus", "smoltcp-nal", "stm32h7xx-hal", diff --git a/Cargo.toml b/Cargo.toml index 2eb2430..a8b3132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ dsp = { path = "dsp" } ad9959 = { path = "ad9959" } miniconf = "0.1.0" shared-bus = {version = "0.2.2", features = ["cortex-m"] } -serde-json-core = "0.3" +serde-json-core = "0.4" # rtt-target bump [dependencies.rtt-logger] From b8da9961b82d4a82bd2558ca8492b19d363faf83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 28 May 2021 18:34:25 +0200 Subject: [PATCH 19/19] adapt to new heapless/serde-json-core after const-generics --- Cargo.lock | 19 ++++--------------- Cargo.toml | 2 +- src/hardware/configuration.rs | 4 ++-- src/net/messages.rs | 11 +++++------ src/net/miniconf_client.rs | 12 ++++++------ src/net/mod.rs | 8 ++++---- src/net/telemetry.rs | 8 ++++---- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c415e8..d60b5a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,7 +200,7 @@ dependencies = [ [[package]] name = "derive_miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?rev=c6f2b28#c6f2b28f735e27b337eaa986846536e904c6f2bd" +source = "git+https://github.com/quartiq/miniconf.git?rev=2750533#275053396f0334e9efefa1ab2aae4c19b95a9a53" dependencies = [ "proc-macro2", "quote", @@ -413,11 +413,11 @@ dependencies = [ [[package]] name = "miniconf" version = "0.1.0" -source = "git+https://github.com/quartiq/miniconf.git?rev=c6f2b28#c6f2b28f735e27b337eaa986846536e904c6f2bd" +source = "git+https://github.com/quartiq/miniconf.git?rev=2750533#275053396f0334e9efefa1ab2aae4c19b95a9a53" dependencies = [ "derive_miniconf", "serde", - "serde-json-core 0.3.0", + "serde-json-core", ] [[package]] @@ -706,17 +706,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-json-core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39af17f40c2a28d2c9a7918663ddc8a10f54cc6f109ead5c3f010869761df186" -dependencies = [ - "heapless 0.6.1", - "ryu", - "serde", -] - [[package]] name = "serde-json-core" version = "0.4.0" @@ -793,7 +782,7 @@ dependencies = [ "rtt-logger", "rtt-target", "serde", - "serde-json-core 0.4.0", + "serde-json-core", "shared-bus", "smoltcp-nal", "stm32h7xx-hal", diff --git a/Cargo.toml b/Cargo.toml index 66dc0a8..21dbd54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ rev = "a2e3ad5" [patch.crates-io.miniconf] git = "https://github.com/quartiq/miniconf.git" -rev = "c6f2b28" +rev = "2750533" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index e2eb653..02aed76 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -9,7 +9,7 @@ use stm32h7xx_hal::{ const NUM_SOCKETS: usize = 4; -use heapless::{consts, Vec}; +use heapless::Vec; use smoltcp_nal::smoltcp; use embedded_hal::digital::v2::{InputPin, OutputPin}; @@ -642,7 +642,7 @@ pub fn setup( let mut sockets = smoltcp::socket::SocketSet::new(&mut store.sockets[..]); - let mut handles: Vec = + let mut handles: Vec = Vec::new(); for storage in store.socket_storage.iter_mut() { let tcp_socket = { diff --git a/src/net/messages.rs b/src/net/messages.rs index 167e440..3887fef 100644 --- a/src/net/messages.rs +++ b/src/net/messages.rs @@ -1,4 +1,4 @@ -use heapless::{consts, String, Vec}; +use heapless::{String, Vec}; use serde::Serialize; use core::fmt::Write; @@ -12,15 +12,15 @@ pub enum SettingsResponseCode { /// Represents a generic MQTT message. pub struct MqttMessage<'a> { pub topic: &'a str, - pub message: Vec, - pub properties: Vec, consts::U1>, + pub message: Vec, + pub properties: Vec, 1>, } /// The payload of the MQTT response message to a settings update request. #[derive(Serialize)] pub struct SettingsResponse { code: u8, - msg: String, + msg: String<64>, } impl<'a> MqttMessage<'a> { @@ -48,8 +48,7 @@ impl<'a> MqttMessage<'a> { .unwrap_or(&default_response); // Associate any provided correlation data with the response. - let mut correlation_data: Vec, consts::U1> = - Vec::new(); + let mut correlation_data: Vec, 1> = Vec::new(); if let Some(data) = properties .iter() .find(|prop| matches!(prop, minimq::Property::CorrelationData(_))) diff --git a/src/net/miniconf_client.rs b/src/net/miniconf_client.rs index 76c64d2..cc838f6 100644 --- a/src/net/miniconf_client.rs +++ b/src/net/miniconf_client.rs @@ -10,7 +10,7 @@ ///! ///! Respones to settings updates are sent without quality-of-service guarantees, so there's no ///! guarantee that the requestee will be informed that settings have been applied. -use heapless::{consts, String}; +use heapless::String; use super::{MqttMessage, NetworkReference, SettingsResponse, UpdateState}; use crate::hardware::design_parameters::MQTT_BROKER; @@ -20,11 +20,11 @@ pub struct MiniconfClient where S: miniconf::Miniconf + Default + Clone, { - default_response_topic: String, + default_response_topic: String<128>, mqtt: minimq::Minimq, settings: S, subscribed: bool, - settings_prefix: String, + settings_prefix: String<64>, } impl MiniconfClient @@ -41,10 +41,10 @@ where let mqtt = minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); - let mut response_topic: String = String::from(prefix); + let mut response_topic: String<128> = String::from(prefix); response_topic.push_str("/log").unwrap(); - let mut settings_prefix: String = String::from(prefix); + let mut settings_prefix: String<64> = String::from(prefix); settings_prefix.push_str("/settings").unwrap(); Self { @@ -81,7 +81,7 @@ where if !self.subscribed && mqtt_connected { // Note(unwrap): We construct a string with two more characters than the prefix // strucutre, so we are guaranteed to have space for storage. - let mut settings_topic: String = + let mut settings_topic: String<66> = String::from(self.settings_prefix.as_str()); settings_topic.push_str("/#").unwrap(); diff --git a/src/net/mod.rs b/src/net/mod.rs index 64c9401..bdb871f 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -5,7 +5,7 @@ ///! telemetry (via MQTT), configuration of run-time settings (via MQTT + Miniconf), and live data ///! streaming over raw UDP/TCP sockets. This module encompasses the main processing routines ///! related to Stabilizer networking operations. -use heapless::{consts, String}; +use heapless::String; use miniconf::Miniconf; use serde::Serialize; @@ -134,7 +134,7 @@ fn get_client_id( app: &str, client: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, -) -> String { +) -> String<64> { let mut identifier = String::new(); write!(&mut identifier, "{}-{}-{}", app, mac, client).unwrap(); identifier @@ -151,10 +151,10 @@ fn get_client_id( pub fn get_device_prefix( app: &str, mac: smoltcp_nal::smoltcp::wire::EthernetAddress, -) -> String { +) -> String<128> { // Note(unwrap): The mac address + binary name must be short enough to fit into this string. If // they are defined too long, this will panic and the device will fail to boot. - let mut prefix: String = String::new(); + let mut prefix: String<128> = String::new(); write!(&mut prefix, "dt/sinara/{}/{}", app, mac).unwrap(); prefix diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index b6b9c34..d976fee 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -10,7 +10,7 @@ ///! sampling frequency. Instead, the raw codes are stored and the telemetry is generated as ///! required immediately before transmission. This ensures that any slower computation required ///! for unit conversion can be off-loaded to lower priority tasks. -use heapless::{consts, String, Vec}; +use heapless::{String, Vec}; use minimq::QoS; use serde::Serialize; @@ -22,7 +22,7 @@ use crate::hardware::{ /// The telemetry client for reporting telemetry data over MQTT. pub struct TelemetryClient { mqtt: minimq::Minimq, - telemetry_topic: String, + telemetry_topic: String<128>, _telemetry: core::marker::PhantomData, } @@ -99,7 +99,7 @@ impl TelemetryClient { let mqtt = minimq::Minimq::new(MQTT_BROKER.into(), client_id, stack).unwrap(); - let mut telemetry_topic: String = String::from(prefix); + let mut telemetry_topic: String<128> = String::from(prefix); telemetry_topic.push_str("/telemetry").unwrap(); Self { @@ -118,7 +118,7 @@ impl TelemetryClient { /// # Args /// * `telemetry` - The telemetry to report pub fn publish(&mut self, telemetry: &T) { - let telemetry: Vec = + let telemetry: Vec = serde_json_core::to_vec(telemetry).unwrap(); self.mqtt .client