diff --git a/bittide-instances/bittide-instances.cabal b/bittide-instances/bittide-instances.cabal index cba26fa29..be398a107 100644 --- a/bittide-instances/bittide-instances.cabal +++ b/bittide-instances/bittide-instances.cabal @@ -222,6 +222,7 @@ library Bittide.Instances.Pnr.Si539xSpi Bittide.Instances.Pnr.Switch Bittide.Instances.Pnr.Synchronizer + Bittide.Instances.Tests.ClockControlWb Bittide.Instances.Tests.ElasticBufferWb Bittide.Instances.Tests.NestedInterconnect Bittide.Instances.Tests.RegisterWb diff --git a/bittide-instances/src/Bittide/Instances/MemoryMaps.hs b/bittide-instances/src/Bittide/Instances/MemoryMaps.hs index bb1414f65..f5e25f392 100644 --- a/bittide-instances/src/Bittide/Instances/MemoryMaps.hs +++ b/bittide-instances/src/Bittide/Instances/MemoryMaps.hs @@ -25,6 +25,7 @@ import qualified Bittide.Instances.Hitl.Si539xConfiguration as Si539xConfigurati import qualified Bittide.Instances.Hitl.SoftUgnDemo.MemoryMaps as SoftUgnDemo import qualified Bittide.Instances.Hitl.SwitchDemo.MemoryMaps as SwitchDemo import qualified Bittide.Instances.Hitl.SwitchDemoGppe.MemoryMaps as SwitchDemoGppe +import qualified Bittide.Instances.Tests.ClockControlWb as ClockControlWb import qualified Bittide.Instances.Tests.ElasticBufferWb as ElasticBufferWb import qualified Bittide.Instances.Tests.NestedInterconnect as NestedInterconnect import qualified Bittide.Instances.Tests.RegisterWb as RegisterWb @@ -42,7 +43,8 @@ $( do -- Add new memory maps here -- ------------------------------- let memoryMaps = - [ ("Ethernet", vexRiscvEthernetMM) + [ ("ClockControlWb", ClockControlWb.dutMm) + , ("Ethernet", vexRiscvEthernetMM) , ("ElasticBufferWbTest", ElasticBufferWb.dutMM) , ("Freeze", freezeMM) , ("NestedInterconnect", NestedInterconnect.nestedInterconnectMm) diff --git a/bittide-instances/src/Bittide/Instances/Tests/ClockControlWb.hs b/bittide-instances/src/Bittide/Instances/Tests/ClockControlWb.hs new file mode 100644 index 000000000..4bddadc1e --- /dev/null +++ b/bittide-instances/src/Bittide/Instances/Tests/ClockControlWb.hs @@ -0,0 +1,94 @@ +-- SPDX-FileCopyrightText: 2026 Google LLC +-- +-- SPDX-License-Identifier: Apache-2.0 +module Bittide.Instances.Tests.ClockControlWb where + +import Clash.Prelude + +import Bittide.ClockControl.Registers (ClockControlData, clockControlWb) +import Bittide.Cpus.Riscv32imc (vexRiscv0) +import Bittide.DoubleBufferedRam +import Bittide.Instances.Hitl.Setup hiding (linkMask) +import Bittide.ProcessingElement +import Bittide.ProcessingElement.Util +import Bittide.SharedTypes (withBittideByteOrder) +import Bittide.Wishbone hiding (MemoryMap) +import Clash.Class.BitPackC (ByteOrder (BigEndian)) +import GHC.Stack (HasCallStack) +import Project.FilePath +import Protocols +import Protocols.Idle +import Protocols.MemoryMap +import System.FilePath +import System.IO.Unsafe (unsafePerformIO) +import VexRiscv (DumpVcd (NoDumpVcd)) + +linkMask :: BitVector LinkCount +linkMask = 0b1011011 + +linksOk :: BitVector LinkCount +linksOk = 0b1111000 + +dataCounts :: Vec LinkCount (Signed 32) +dataCounts = iterateI (satSucc SatWrap) 0 + +type IMemWords = DivRU (64 * 1024) 4 +type DMemWords = DivRU (32 * 1024) 4 + +dut :: + (HasCallStack) => + Circuit (ToConstBwd Mm) (Df System (BitVector 8), CSignal System (ClockControlData LinkCount)) +dut = + withBittideByteOrder + $ withClockResetEnable clockGen (resetGenN d2) enableGen + $ circuit + $ \mm -> do + (uartRx, jtag) <- idleSource + [uartBus, (mmCC, ccWb)] <- processingElement NoDumpVcd peConfig -< (mm, jtag) + (uartTx, _uartStatus) <- uartInterfaceWb d2 d2 uartBytes -< (uartBus, uartRx) + + ccd <- + clockControlWb + (pure linkMask) + (pure linksOk) + (pure <$> dataCounts) + -< (mmCC, ccWb) + + idC -< (uartTx, ccd) + where + peConfig = unsafePerformIO $ do + root <- findParentContaining "cabal.project" + let + elfDir = root firmwareBinariesDir "riscv32imc" Release + elfPath = elfDir "clock-control-wb" + pure + PeConfig + { cpu = vexRiscv0 + , initI = + Reloadable @IMemWords + $ Vec + $ unsafePerformIO + $ vecFromElfInstr BigEndian elfPath + , initD = + Reloadable @DMemWords + $ Vec + $ unsafePerformIO + $ vecFromElfData BigEndian elfPath + , iBusTimeout = d0 + , dBusTimeout = d0 + , includeIlaWb = False + } +{-# OPAQUE dut #-} + +dutMm :: (HasCallStack) => MemoryMap +dutMm = mm + where + Circuit circuitFn = dut + (SimOnly mm, _) = circuitFn ((), (pure $ deepErrorX "uart_bwd", ())) + +dutNoMm :: + (HasCallStack) => Circuit () (Df System (BitVector 8), CSignal System (ClockControlData LinkCount)) +dutNoMm = Circuit circuitFnNoMm + where + Circuit circuitFn = dut + circuitFnNoMm (fwdL, bwdR) = let (_, fwdR) = circuitFn (fwdL, bwdR) in ((), fwdR) diff --git a/bittide-instances/tests/Tests/ClockControlWb.hs b/bittide-instances/tests/Tests/ClockControlWb.hs index 3691fac6e..9ff841fd6 100644 --- a/bittide-instances/tests/Tests/ClockControlWb.hs +++ b/bittide-instances/tests/Tests/ClockControlWb.hs @@ -10,34 +10,21 @@ import Clash.Explicit.Prelude hiding (PeriodToCycles, many) -- external imports -import Bittide.Cpus.Riscv32imc (vexRiscv0) -import Clash.Class.BitPackC (ByteOrder (BigEndian)) -import Clash.Signal (withClockResetEnable) import Data.Char (chr) import Data.Maybe (catMaybes, mapMaybe) import Data.String.Interpolate -import Project.FilePath import Protocols -import Protocols.Idle -import Protocols.MemoryMap -import System.FilePath -import System.IO.Unsafe (unsafePerformIO) import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.TH import Text.Parsec import Text.Parsec.String -import VexRiscv (DumpVcd (NoDumpVcd)) -- internal imports import Bittide.Arithmetic.Time (PeriodToCycles) -import Bittide.ClockControl.Registers (ClockControlData (clockMod), clockControlWb) -import Bittide.DoubleBufferedRam +import Bittide.ClockControl.Registers (ClockControlData (clockMod)) import Bittide.Instances.Hitl.Setup (LinkCount) -import Bittide.ProcessingElement -import Bittide.ProcessingElement.Util -import Bittide.SharedTypes (withBittideByteOrder) -import Bittide.Wishbone +import Bittide.Instances.Tests.ClockControlWb -- qualified imports import qualified Data.List as L @@ -61,7 +48,7 @@ sim = putStr $ fmap (chr . fromIntegral) $ catMaybes - $ fst (sampleC def dut) + $ fst (sampleC def dutNoMm) case_clock_control_wb_self_test :: Assertion case_clock_control_wb_self_test = do @@ -89,7 +76,7 @@ case_clock_control_wb_self_test = do assertEqual "Expected and actual differ" expected actual where uartString = chr . fromIntegral <$> catMaybes uartStream - (uartStream, ccData) = sampleC def dut + (uartStream, ccData) = sampleC def dutNoMm type Margin = SNat 2 type Framesize = PeriodToCycles System (Seconds 1) @@ -103,68 +90,15 @@ framesize = SNat linkCount :: Int linkCount = snatToNum (SNat @LinkCount) -linkMask :: BitVector LinkCount -linkMask = 0b1011011 - -linksOk :: BitVector LinkCount -linksOk = 0b1111000 - linkMaskPopcnt :: Int linkMaskPopcnt = fromIntegral $ popCount linkMask -dataCounts :: Vec LinkCount (Signed 27) -dataCounts = iterateI (satSucc SatWrap) 0 - expectedDataCounts :: [(Int, Int)] expectedDataCounts = L.zip [0 ..] $ toList $ applyMask linkMask dataCounts where applyMask m = zipWith go (bitCoerce m) go m v = if m then fromIntegral v else 0 -dut :: Circuit () (Df System (BitVector 8), CSignal System (ClockControlData LinkCount)) -dut = - withBittideByteOrder - $ withClockResetEnable clockGen (resetGenN d2) enableGen - $ circuit - $ \_unit -> do - (uartRx, jtag) <- idleSource - [ uartBus - , (mmCC, ccWb) - ] <- - processingElement NoDumpVcd peConfig -< (mm, jtag) - (uartTx, _uartStatus) <- uartInterfaceWb d2 d2 uartBytes -< (uartBus, uartRx) - - mm <- ignoreMM - - ccd <- - clockControlWb - (pure linkMask) - (pure linksOk) - (pure <$> dataCounts) - -< (mmCC, ccWb) - - idC -< (uartTx, ccd) - where - peConfig = unsafePerformIO $ do - root <- findParentContaining "cabal.project" - let - elfDir = root firmwareBinariesDir "riscv32imc" Release - elfPath = elfDir "clock-control-wb" - (iMem, dMem) <- vecsFromElf @IMemWords @DMemWords BigEndian elfPath Nothing - pure - PeConfig - { cpu = vexRiscv0 - , initI = Reloadable (Vec iMem) - , initD = Reloadable (Vec dMem) - , iBusTimeout = d0 - , dBusTimeout = d0 - , includeIlaWb = False - } -{-# OPAQUE dut #-} - -type IMemWords = DivRU (64 * 1024) 4 -type DMemWords = DivRU (32 * 1024) 4 - -- | Parse the output of the UART resultParser :: Parser SerialResult resultParser = do diff --git a/firmware-binaries/Cargo.toml b/firmware-binaries/Cargo.toml index 66c14bbc6..9af413624 100644 --- a/firmware-binaries/Cargo.toml +++ b/firmware-binaries/Cargo.toml @@ -45,3 +45,8 @@ members = [ "demos/switch-demo2-gppe", ] resolver = "2" + +[workspace.lints.clippy] +format_push_string = "forbid" +print_literal = "forbid" +uninlined_format_args = "forbid" diff --git a/firmware-binaries/demos/clock-control/Cargo.toml b/firmware-binaries/demos/clock-control/Cargo.toml index a880a423f..f44aeef5b 100644 --- a/firmware-binaries/demos/clock-control/Cargo.toml +++ b/firmware-binaries/demos/clock-control/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/demos/soft-ugn-gppe/Cargo.toml b/firmware-binaries/demos/soft-ugn-gppe/Cargo.toml index 7bb6c055d..fee09b37e 100644 --- a/firmware-binaries/demos/soft-ugn-gppe/Cargo.toml +++ b/firmware-binaries/demos/soft-ugn-gppe/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/demos/soft-ugn-gppe/src/main.rs b/firmware-binaries/demos/soft-ugn-gppe/src/main.rs index 96f60c1f9..dd63c9cac 100644 --- a/firmware-binaries/demos/soft-ugn-gppe/src/main.rs +++ b/firmware-binaries/demos/soft-ugn-gppe/src/main.rs @@ -27,7 +27,8 @@ fn main() -> ! { } #[panic_handler] -#[allow(clippy::empty_loop)] fn panic_handler(_: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/demos/soft-ugn-mu/Cargo.toml b/firmware-binaries/demos/soft-ugn-mu/Cargo.toml index 267fc87c6..01b304378 100644 --- a/firmware-binaries/demos/soft-ugn-mu/Cargo.toml +++ b/firmware-binaries/demos/soft-ugn-mu/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/demos/soft-ugn-mu/src/main.rs b/firmware-binaries/demos/soft-ugn-mu/src/main.rs index 2e7457153..34005aba4 100644 --- a/firmware-binaries/demos/soft-ugn-mu/src/main.rs +++ b/firmware-binaries/demos/soft-ugn-mu/src/main.rs @@ -187,5 +187,7 @@ fn main() -> ! { #[panic_handler] fn panic_handler(_: &PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/demos/switch-demo1-boot/Cargo.toml b/firmware-binaries/demos/switch-demo1-boot/Cargo.toml index d30fd4d37..eb79c4f6d 100644 --- a/firmware-binaries/demos/switch-demo1-boot/Cargo.toml +++ b/firmware-binaries/demos/switch-demo1-boot/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/demos/switch-demo1-boot/src/main.rs b/firmware-binaries/demos/switch-demo1-boot/src/main.rs index 53b2a648e..ea673c717 100644 --- a/firmware-binaries/demos/switch-demo1-boot/src/main.rs +++ b/firmware-binaries/demos/switch-demo1-boot/src/main.rs @@ -56,12 +56,14 @@ fn main() -> ! { } uwriteln!(uart, "Going into infinite loop..").unwrap(); - #[allow(clippy::empty_loop)] - loop {} + loop { + continue; + } } #[panic_handler] fn panic_handler(_info: &PanicInfo) -> ! { - #[allow(clippy::empty_loop)] - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/demos/switch-demo1-mu/Cargo.toml b/firmware-binaries/demos/switch-demo1-mu/Cargo.toml index 212de9f8b..18a68c1d0 100644 --- a/firmware-binaries/demos/switch-demo1-mu/Cargo.toml +++ b/firmware-binaries/demos/switch-demo1-mu/Cargo.toml @@ -10,6 +10,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/demos/switch-demo1-mu/src/main.rs b/firmware-binaries/demos/switch-demo1-mu/src/main.rs index fd2245de3..c051003b4 100644 --- a/firmware-binaries/demos/switch-demo1-mu/src/main.rs +++ b/firmware-binaries/demos/switch-demo1-mu/src/main.rs @@ -115,6 +115,7 @@ fn main() -> ! { #[panic_handler] fn panic_handler(_: &PanicInfo) -> ! { - #[allow(clippy::empty_loop)] - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/demos/switch-demo2-gppe/Cargo.toml b/firmware-binaries/demos/switch-demo2-gppe/Cargo.toml index c38e4b106..972ef2108 100644 --- a/firmware-binaries/demos/switch-demo2-gppe/Cargo.toml +++ b/firmware-binaries/demos/switch-demo2-gppe/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/demos/switch-demo2-gppe/src/main.rs b/firmware-binaries/demos/switch-demo2-gppe/src/main.rs index 2948e253d..2398cbd4f 100644 --- a/firmware-binaries/demos/switch-demo2-gppe/src/main.rs +++ b/firmware-binaries/demos/switch-demo2-gppe/src/main.rs @@ -12,17 +12,19 @@ use riscv_rt::entry; const INSTANCES: hal::DeviceInstances = unsafe { hal::DeviceInstances::new() }; #[cfg_attr(not(test), entry)] -#[allow(clippy::empty_loop)] fn main() -> ! { let uart = &mut INSTANCES.uart; ufmt::uwriteln!(uart, "Hello!").unwrap(); - loop {} + loop { + continue; + } } #[panic_handler] -#[allow(clippy::empty_loop)] fn panic_handler(_: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/demos/switch-demo2-mu/Cargo.toml b/firmware-binaries/demos/switch-demo2-mu/Cargo.toml index 5d166fd3c..ca248d649 100644 --- a/firmware-binaries/demos/switch-demo2-mu/Cargo.toml +++ b/firmware-binaries/demos/switch-demo2-mu/Cargo.toml @@ -10,6 +10,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/demos/switch-demo2-mu/src/main.rs b/firmware-binaries/demos/switch-demo2-mu/src/main.rs index 2dcb8ad4a..3abe1885d 100644 --- a/firmware-binaries/demos/switch-demo2-mu/src/main.rs +++ b/firmware-binaries/demos/switch-demo2-mu/src/main.rs @@ -119,12 +119,14 @@ fn main() -> ! { } uwriteln!(uart, "All UGNs captured").unwrap(); - #[allow(clippy::empty_loop)] - loop {} + loop { + continue; + } } #[panic_handler] fn panic_handler(_: &PanicInfo) -> ! { - #[allow(clippy::empty_loop)] - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/examples/c_hello/Cargo.toml b/firmware-binaries/examples/c_hello/Cargo.toml index 4743fffa6..c2c3318e1 100644 --- a/firmware-binaries/examples/c_hello/Cargo.toml +++ b/firmware-binaries/examples/c_hello/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" diff --git a/firmware-binaries/examples/c_hello/src/main.rs b/firmware-binaries/examples/c_hello/src/main.rs index 1ba4a90e4..759c107c5 100644 --- a/firmware-binaries/examples/c_hello/src/main.rs +++ b/firmware-binaries/examples/c_hello/src/main.rs @@ -21,5 +21,7 @@ fn main() -> ! { // Panic handler required for no_std #[panic_handler] fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/examples/smoltcp_client/Cargo.toml b/firmware-binaries/examples/smoltcp_client/Cargo.toml index af8ecfd04..456ab49da 100644 --- a/firmware-binaries/examples/smoltcp_client/Cargo.toml +++ b/firmware-binaries/examples/smoltcp_client/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/examples/smoltcp_client/src/main.rs b/firmware-binaries/examples/smoltcp_client/src/main.rs index e7eaabcf9..6faa503f8 100644 --- a/firmware-binaries/examples/smoltcp_client/src/main.rs +++ b/firmware-binaries/examples/smoltcp_client/src/main.rs @@ -4,8 +4,6 @@ #![no_std] #![no_main] -#![allow(unused_mut)] -#![allow(clippy::collapsible_if)] #![feature(sync_unsafe_cell)] use bittide_hal::hals::ethernet as hal; @@ -71,9 +69,9 @@ fn main() -> ! { uwriteln!(INSTANCES.uart, "Initializing peripherals").unwrap(); // Initialize peripherals - let mut timer = INSTANCES.timer; + let timer = INSTANCES.timer; // TODO: Use EthMacStatus instead of MacStatus - let mut _mac = INSTANCES.mac_status; + let _mac = INSTANCES.mac_status; let axi_tx = unsafe { AxiTx::new(TX_AXI_ADDR) }; let axi_rx: AxiRx = unsafe { AxiRx::new(RX_AXI_ADDR) }; @@ -94,13 +92,13 @@ fn main() -> ! { let mut eth_addr = EthernetAddress::from_bytes(&dna[0..6]); set_unicast(&mut eth_addr); set_local(&mut eth_addr); - let mut config = Config::new(eth_addr.into()); + let config = Config::new(eth_addr.into()); let mut eth: AxiEthernet = AxiEthernet::new(Medium::Ethernet, axi_rx, axi_tx, None); let now = to_smoltcp_instant(timer.now()); let mut iface = Interface::new(config, &mut eth, now); // Create sockets - let mut dhcp_socket = dhcpv4::Socket::new(); + let dhcp_socket = dhcpv4::Socket::new(); let client_socket = { // It is not strictly necessary to use a `static mut` and unsafe code here, but // on embedded systems that smoltcp targets it is far better to allocate the data @@ -143,25 +141,22 @@ fn main() -> ! { info!("{}, IP address: {}", timer.now(), my_ip.unwrap()); let now = timer.now(); stress_test_end = now + stress_test_duration; - info!("{}, Stress test will end at {}", now, stress_test_end); + info!("{now}, Stress test will end at {stress_test_end}"); } - let mut socket = sockets.get_mut::(client_handle); + let socket = sockets.get_mut::(client_handle); let cx = iface.context(); if !socket.is_open() { debug!("{}, Opening socket", timer.now()); if !socket.is_active() { mac_status = unsafe { MAC_ADDR.read_volatile() }; debug!( - "Connecting from {:?}:{} to {}:{}", + "Connecting from {:?}:1234 to {SERVER_IP}:{SERVER_PORT}", my_ip.unwrap().octets(), - 1234, - SERVER_IP, - SERVER_PORT ); match socket.connect(cx, (SERVER_IP, SERVER_PORT), 1234) { Ok(_) => debug!("Connected to {SERVER_IP}:{SERVER_PORT}"), - Err(e) => debug!("Error connecting: {:?}", e), + Err(e) => debug!("Error connecting: {e:?}"), } } } @@ -169,11 +164,11 @@ fn main() -> ! { debug!("Sending data"); match socket.send_slice(&[0; CHUNK_SIZE]) { Ok(n) => debug!("Sent {n} bytes"), - Err(e) => debug!("Error sending data: {:?}", e), + Err(e) => debug!("Error sending data: {e:?}"), } let now = timer.now(); if now > stress_test_end { - info!("{}, Stress test complete", now); + info!("{now}, Stress test complete"); socket.close(); let new_mac_status = unsafe { MAC_ADDR.read_volatile() }; uwriteln!(uart, "{:?}", new_mac_status - mac_status).unwrap(); @@ -183,7 +178,7 @@ fn main() -> ! { Some(smoltcp::time::Duration::ZERO) => {} Some(smoltcp_delay) => { let delay = from_smoltcp_duration(smoltcp_delay); - debug!("sleeping for {} ms", delay); + debug!("sleeping for {delay} ms"); timer.wait(delay); debug!("done sleeping"); } @@ -220,7 +215,7 @@ fn update_dhcp(iface: &mut Interface, socket: &mut dhcpv4::Socket) { }); if let Some(router) = config.router { - debug!("Default gateway: {}", router); + debug!("Default gateway: {router}"); iface.routes_mut().add_default_ipv4_route(router).unwrap(); } else { debug!("Default gateway: None"); @@ -228,7 +223,7 @@ fn update_dhcp(iface: &mut Interface, socket: &mut dhcpv4::Socket) { } for (i, s) in config.dns_servers.iter().enumerate() { - debug!("DNS server {}: {}", i, s); + debug!("DNS server {i}: {s}"); } } Some(dhcpv4::Event::Deconfigured) => { diff --git a/firmware-binaries/hitl-tests/clock-board/Cargo.toml b/firmware-binaries/hitl-tests/clock-board/Cargo.toml index c08d8ce7f..eee7bddd4 100644 --- a/firmware-binaries/hitl-tests/clock-board/Cargo.toml +++ b/firmware-binaries/hitl-tests/clock-board/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/hitl-tests/vexriscv-hello/Cargo.toml b/firmware-binaries/hitl-tests/vexriscv-hello/Cargo.toml index ff2f4d530..4886fcc98 100644 --- a/firmware-binaries/hitl-tests/vexriscv-hello/Cargo.toml +++ b/firmware-binaries/hitl-tests/vexriscv-hello/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/axi_stream_self_test/Cargo.toml b/firmware-binaries/sim-tests/axi_stream_self_test/Cargo.toml index 71bf76e3f..99ab1c9be 100644 --- a/firmware-binaries/sim-tests/axi_stream_self_test/Cargo.toml +++ b/firmware-binaries/sim-tests/axi_stream_self_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/c_registerwb_test/Cargo.toml b/firmware-binaries/sim-tests/c_registerwb_test/Cargo.toml index 6fb8c12b7..5926bb780 100644 --- a/firmware-binaries/sim-tests/c_registerwb_test/Cargo.toml +++ b/firmware-binaries/sim-tests/c_registerwb_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/sim-tests/c_registerwb_test/src/main.rs b/firmware-binaries/sim-tests/c_registerwb_test/src/main.rs index 1ba4a90e4..759c107c5 100644 --- a/firmware-binaries/sim-tests/c_registerwb_test/src/main.rs +++ b/firmware-binaries/sim-tests/c_registerwb_test/src/main.rs @@ -21,5 +21,7 @@ fn main() -> ! { // Panic handler required for no_std #[panic_handler] fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/sim-tests/c_scatter_gather_test/Cargo.toml b/firmware-binaries/sim-tests/c_scatter_gather_test/Cargo.toml index 73df37314..3e6034abe 100644 --- a/firmware-binaries/sim-tests/c_scatter_gather_test/Cargo.toml +++ b/firmware-binaries/sim-tests/c_scatter_gather_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/sim-tests/c_scatter_gather_test/src/main.rs b/firmware-binaries/sim-tests/c_scatter_gather_test/src/main.rs index 1ba4a90e4..759c107c5 100644 --- a/firmware-binaries/sim-tests/c_scatter_gather_test/src/main.rs +++ b/firmware-binaries/sim-tests/c_scatter_gather_test/src/main.rs @@ -21,5 +21,7 @@ fn main() -> ! { // Panic handler required for no_std #[panic_handler] fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/sim-tests/c_timer_wb/Cargo.toml b/firmware-binaries/sim-tests/c_timer_wb/Cargo.toml index 0e713cfe3..a3ffe046a 100644 --- a/firmware-binaries/sim-tests/c_timer_wb/Cargo.toml +++ b/firmware-binaries/sim-tests/c_timer_wb/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/sim-tests/c_timer_wb/src/main.rs b/firmware-binaries/sim-tests/c_timer_wb/src/main.rs index 1ba4a90e4..759c107c5 100644 --- a/firmware-binaries/sim-tests/c_timer_wb/src/main.rs +++ b/firmware-binaries/sim-tests/c_timer_wb/src/main.rs @@ -21,5 +21,7 @@ fn main() -> ! { // Panic handler required for no_std #[panic_handler] fn panic_handler(_info: &core::panic::PanicInfo) -> ! { - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/sim-tests/capture_ugn_test/Cargo.toml b/firmware-binaries/sim-tests/capture_ugn_test/Cargo.toml index 35eb4db34..4561f76cf 100644 --- a/firmware-binaries/sim-tests/capture_ugn_test/Cargo.toml +++ b/firmware-binaries/sim-tests/capture_ugn_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/clock-control-wb/Cargo.toml b/firmware-binaries/sim-tests/clock-control-wb/Cargo.toml index 84c823ba6..656326fc5 100644 --- a/firmware-binaries/sim-tests/clock-control-wb/Cargo.toml +++ b/firmware-binaries/sim-tests/clock-control-wb/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/clock-control-wb/src/main.rs b/firmware-binaries/sim-tests/clock-control-wb/src/main.rs index 71c2dcf2c..4234e84e3 100644 --- a/firmware-binaries/sim-tests/clock-control-wb/src/main.rs +++ b/firmware-binaries/sim-tests/clock-control-wb/src/main.rs @@ -7,8 +7,6 @@ use core::panic::PanicInfo; -use bittide_hal::shared_devices::clock_control::ClockControl; -use bittide_hal::shared_devices::uart::Uart; use bittide_hal::types::SpeedChange; use core::fmt::Write; use rand::{distributions::Uniform, rngs::SmallRng, Rng, SeedableRng}; @@ -16,6 +14,8 @@ use rand::{distributions::Uniform, rngs::SmallRng, Rng, SeedableRng}; #[cfg(not(test))] use riscv_rt::entry; +use bittide_hal::hals::clock_control_wb as hal; + const RNG_SEED: [u8; 16] = { let rng_seed = core::env!("RNG_SEED").as_bytes(); let mut out = [0; 16]; @@ -37,11 +37,10 @@ const RNG_SEED: [u8; 16] = { }; #[cfg_attr(not(test), entry)] -#[allow(clippy::empty_loop)] fn main() -> ! { - #[allow(clippy::zero_ptr)] // we might want to change the address! - let mut uart = unsafe { Uart::new((0b010 << 29) as *mut u8) }; - let cc = unsafe { ClockControl::new((0b011 << 29) as *mut u8) }; + let peripherals = unsafe { hal::DeviceInstances::new() }; + let mut uart = peripherals.uart; + let cc = peripherals.clock_control; writeln!(uart, "nLinks: {}", cc.n_links()).unwrap(); writeln!(uart, "linkMask: {}", cc.link_mask()[0]).unwrap(); @@ -78,7 +77,9 @@ fn main() -> ! { cc.set_change_speed(SpeedChange::NoChange); } - loop {} + loop { + continue; + } } #[panic_handler] diff --git a/firmware-binaries/sim-tests/dna_port_e2_test/Cargo.toml b/firmware-binaries/sim-tests/dna_port_e2_test/Cargo.toml index d00dbf9ce..744841573 100644 --- a/firmware-binaries/sim-tests/dna_port_e2_test/Cargo.toml +++ b/firmware-binaries/sim-tests/dna_port_e2_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/elastic_buffer_wb_test/Cargo.toml b/firmware-binaries/sim-tests/elastic_buffer_wb_test/Cargo.toml index e0ee35778..71425a76b 100644 --- a/firmware-binaries/sim-tests/elastic_buffer_wb_test/Cargo.toml +++ b/firmware-binaries/sim-tests/elastic_buffer_wb_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/nested_interconnect_test/Cargo.toml b/firmware-binaries/sim-tests/nested_interconnect_test/Cargo.toml index ed616a89f..f4cc536f1 100644 --- a/firmware-binaries/sim-tests/nested_interconnect_test/Cargo.toml +++ b/firmware-binaries/sim-tests/nested_interconnect_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + [dependencies] riscv-rt = "0.11.0" bittide-sys = { path = "../../../firmware-support/bittide-sys" } diff --git a/firmware-binaries/sim-tests/nested_interconnect_test/src/main.rs b/firmware-binaries/sim-tests/nested_interconnect_test/src/main.rs index a4cfbab76..8e416d354 100644 --- a/firmware-binaries/sim-tests/nested_interconnect_test/src/main.rs +++ b/firmware-binaries/sim-tests/nested_interconnect_test/src/main.rs @@ -1,7 +1,6 @@ #![no_std] #![cfg_attr(not(test), no_main)] #![allow(const_item_mutation)] -#![allow(clippy::empty_loop)] // SPDX-FileCopyrightText: 2025 Google LLC // @@ -20,7 +19,9 @@ const INSTANCES: hal::DeviceInstances = unsafe { hal::DeviceInstances::new() }; fn test_result(result: &str) -> ! { let uart = &mut INSTANCES.uart; uwriteln!(uart, "RESULT: {}", result).unwrap(); - loop {} + loop { + continue; + } } fn test_ok() -> ! { @@ -29,7 +30,7 @@ fn test_ok() -> ! { fn test_fail(msg: &str) -> ! { let mut full_msg = heapless::String::<150>::new(); - write!(full_msg, "FAIL: {}", msg).unwrap(); + write!(full_msg, "FAIL: {msg}").unwrap(); test_result(&full_msg) } @@ -70,23 +71,23 @@ fn main() -> ! { let mut name_buf = heapless::String::<50>::new(); // Read initial values (should be 0) - write!(name_buf, "peripheral{}.status.init", i).unwrap(); + write!(name_buf, "peripheral{i}.status.init").unwrap(); expect(&name_buf, 0u32, peripheral.status()); name_buf.clear(); - write!(name_buf, "peripheral{}.control.init", i).unwrap(); + write!(name_buf, "peripheral{i}.control.init").unwrap(); expect(&name_buf, 0u32, peripheral.control()); name_buf.clear(); // Write and read back status peripheral.set_status(*status_val); - write!(name_buf, "peripheral{}.status.readback", i).unwrap(); + write!(name_buf, "peripheral{i}.status.readback").unwrap(); expect(&name_buf, *status_val, peripheral.status()); name_buf.clear(); // Write and read back control peripheral.set_control(*control_val); - write!(name_buf, "peripheral{}.control.readback", i).unwrap(); + write!(name_buf, "peripheral{i}.control.readback").unwrap(); expect(&name_buf, *control_val, peripheral.control()); } @@ -95,7 +96,7 @@ fn main() -> ! { peripherals.iter_mut().zip(test_values.iter()).enumerate() { let mut name_buf = heapless::String::<50>::new(); - write!(name_buf, "peripheral{}.status.final", i).unwrap(); + write!(name_buf, "peripheral{i}.status.final").unwrap(); expect(&name_buf, *status_val, peripheral.status()); } @@ -106,5 +107,7 @@ fn main() -> ! { fn panic_handler(_info: &core::panic::PanicInfo) -> ! { let uart = unsafe { &mut hal::DeviceInstances::new().uart }; uwriteln!(uart, "RESULT: PANIC").unwrap(); - loop {} + loop { + continue; + } } diff --git a/firmware-binaries/sim-tests/registerwb_test/Cargo.toml b/firmware-binaries/sim-tests/registerwb_test/Cargo.toml index 5aeecb9c9..6c7928c99 100644 --- a/firmware-binaries/sim-tests/registerwb_test/Cargo.toml +++ b/firmware-binaries/sim-tests/registerwb_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/registerwb_test/src/main.rs b/firmware-binaries/sim-tests/registerwb_test/src/main.rs index f196f3206..2e0b2f273 100644 --- a/firmware-binaries/sim-tests/registerwb_test/src/main.rs +++ b/firmware-binaries/sim-tests/registerwb_test/src/main.rs @@ -1,7 +1,6 @@ #![no_std] #![cfg_attr(not(test), no_main)] #![allow(const_item_mutation)] -#![allow(clippy::empty_loop)] #![allow(clippy::approx_constant)] // SPDX-FileCopyrightText: 2025 Google LLC @@ -29,7 +28,9 @@ where let uart = &mut INSTANCES.uart; uwrite!(uart, "RESULT: ").unwrap(); result(uart); - loop {} + loop { + continue; + } } fn test_ok() -> ! { diff --git a/firmware-binaries/sim-tests/scatter_gather_test/Cargo.toml b/firmware-binaries/sim-tests/scatter_gather_test/Cargo.toml index 9451787a0..f706dee69 100644 --- a/firmware-binaries/sim-tests/scatter_gather_test/Cargo.toml +++ b/firmware-binaries/sim-tests/scatter_gather_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/scatter_gather_test/src/main.rs b/firmware-binaries/sim-tests/scatter_gather_test/src/main.rs index badf44426..dc8243905 100644 --- a/firmware-binaries/sim-tests/scatter_gather_test/src/main.rs +++ b/firmware-binaries/sim-tests/scatter_gather_test/src/main.rs @@ -59,9 +59,9 @@ fn main() -> ! { } else { writeln!(uart, "Could not read back written data").unwrap(); writeln!(uart, "Written to gather memory:").unwrap(); - writeln!(uart, "{:?}", source).unwrap(); + writeln!(uart, "{source:?}").unwrap(); writeln!(uart, "Read from scatter memory:").unwrap(); - writeln!(uart, "{:?}", destination).unwrap(); + writeln!(uart, "{destination:?}").unwrap(); } loop { continue; diff --git a/firmware-binaries/sim-tests/switch_calendar_test/Cargo.toml b/firmware-binaries/sim-tests/switch_calendar_test/Cargo.toml index a74b52176..b52716ee4 100644 --- a/firmware-binaries/sim-tests/switch_calendar_test/Cargo.toml +++ b/firmware-binaries/sim-tests/switch_calendar_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/switch_calendar_test/src/main.rs b/firmware-binaries/sim-tests/switch_calendar_test/src/main.rs index e833163bc..5cd47517c 100644 --- a/firmware-binaries/sim-tests/switch_calendar_test/src/main.rs +++ b/firmware-binaries/sim-tests/switch_calendar_test/src/main.rs @@ -4,7 +4,6 @@ #![no_std] #![cfg_attr(not(test), no_main)] #![allow(const_item_mutation)] -#![allow(clippy::empty_loop)] #![allow(clippy::approx_constant)] // Non-aliased imports @@ -26,7 +25,9 @@ const INSTANCES: hal::DeviceInstances = unsafe { hal::DeviceInstances::new() }; fn test_result(result: &str) -> ! { let uart = &mut INSTANCES.uart; uwriteln!(uart, "RESULT: {}", result).unwrap(); - loop {} + loop { + continue; + } } fn test_ok() -> ! { diff --git a/firmware-binaries/sim-tests/switch_demo_pe_test/Cargo.toml b/firmware-binaries/sim-tests/switch_demo_pe_test/Cargo.toml index a2dae01d9..efbe4399a 100644 --- a/firmware-binaries/sim-tests/switch_demo_pe_test/Cargo.toml +++ b/firmware-binaries/sim-tests/switch_demo_pe_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/time_self_test/Cargo.toml b/firmware-binaries/sim-tests/time_self_test/Cargo.toml index 39098e692..c18ec7086 100644 --- a/firmware-binaries/sim-tests/time_self_test/Cargo.toml +++ b/firmware-binaries/sim-tests/time_self_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/watchdog_test/Cargo.toml b/firmware-binaries/sim-tests/watchdog_test/Cargo.toml index 3002eb129..eb8851d03 100644 --- a/firmware-binaries/sim-tests/watchdog_test/Cargo.toml +++ b/firmware-binaries/sim-tests/watchdog_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-binaries/sim-tests/wb_to_df_test/Cargo.toml b/firmware-binaries/sim-tests/wb_to_df_test/Cargo.toml index c1f63034c..56c4a3de7 100644 --- a/firmware-binaries/sim-tests/wb_to_df_test/Cargo.toml +++ b/firmware-binaries/sim-tests/wb_to_df_test/Cargo.toml @@ -9,6 +9,9 @@ edition = "2021" license = "Apache-2.0" authors = ["Google LLC"] +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-support/Cargo.toml b/firmware-support/Cargo.toml index 79ec2199b..572d8ebe4 100644 --- a/firmware-support/Cargo.toml +++ b/firmware-support/Cargo.toml @@ -13,3 +13,8 @@ members = [ ] resolver = "2" + +[workspace.lints.clippy] +format_push_string = "forbid" +print_literal = "forbid" +uninlined_format_args = "forbid" diff --git a/firmware-support/bittide-hal-c/Cargo.toml b/firmware-support/bittide-hal-c/Cargo.toml index 14039baaa..c719d51e7 100644 --- a/firmware-support/bittide-hal-c/Cargo.toml +++ b/firmware-support/bittide-hal-c/Cargo.toml @@ -7,6 +7,9 @@ name = "bittide-hal-c" version = "0.1.0" edition = "2021" +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] diff --git a/firmware-support/bittide-hal-c/build.rs b/firmware-support/bittide-hal-c/build.rs index 000409ffe..3936a5c36 100644 --- a/firmware-support/bittide-hal-c/build.rs +++ b/firmware-support/bittide-hal-c/build.rs @@ -40,8 +40,8 @@ fn main() { let (shared, deduped_hals) = match deduplicate(&ctx, &input_mapping, hals.iter()) { Ok(result) => result, Err(err) => { - println!("ERROR while deduplicating!! {:?}", err); - panic!("ERROR {:?}", err) + println!("ERROR while deduplicating!! {err:?}"); + panic!("ERROR {err:?}") } }; @@ -126,7 +126,7 @@ fn main() { generate_type_ref_imports(&ctx, &refs, file); writeln!(file).unwrap(); - writeln!(file, "{}", code).unwrap(); + writeln!(file, "{code}").unwrap(); }, ); } @@ -144,7 +144,7 @@ fn main() { writeln!(file, "{}", gen_imports()).unwrap(); generate_type_ref_imports(&ctx, &refs, file); - writeln!(file, "{}", code).unwrap(); + writeln!(file, "{code}").unwrap(); }); } } @@ -167,7 +167,7 @@ fn main() { let (dev_name, code, refs) = backend_c::device_desc::generate_device_desc(&ctx, &varis, *dev); let file_name = ident(IdentType::Module, dev_name); - let file_path = shared_devices_path.join(format!("{}.h", file_name)); + let file_path = shared_devices_path.join(format!("{file_name}.h")); let mut file = File::create(&file_path).unwrap(); with_guard( &mut file, @@ -178,7 +178,7 @@ fn main() { generate_type_ref_imports(&ctx, &refs, file); writeln!(file).unwrap(); - write!(file, "{}", code).unwrap(); + write!(file, "{code}").unwrap(); }, ); } @@ -216,7 +216,7 @@ fn main() { let (dev_name, code, refs) = backend_c::device_desc::generate_device_desc(&ctx, &varis, *dev); let file_name = ident(IdentType::Module, dev_name); - let file_path = hal_path.join("devices").join(format!("{}.h", file_name)); + let file_path = hal_path.join("devices").join(format!("{file_name}.h")); let mut file = File::create(&file_path).unwrap(); with_guard( &mut file, @@ -230,7 +230,7 @@ fn main() { generate_type_ref_imports(&ctx, &refs, file); writeln!(file).unwrap(); - write!(file, "{}", code).unwrap(); + write!(file, "{code}").unwrap(); }, ); } @@ -262,7 +262,7 @@ fn generate_type_ref_imports(ctx: &IrCtx, refs: &backend_c::TypeReferences, file for ty in &refs.references { let name = &ctx.type_names[*ty]; let mod_name = ident(IdentType::Module, &name.base); - writeln!(file, "#include \"types/{}.h\"", mod_name).unwrap(); + writeln!(file, "#include \"types/{mod_name}.h\"").unwrap(); } } diff --git a/firmware-support/bittide-hal/Cargo.toml b/firmware-support/bittide-hal/Cargo.toml index 3381e81c5..33cfafa54 100644 --- a/firmware-support/bittide-hal/Cargo.toml +++ b/firmware-support/bittide-hal/Cargo.toml @@ -7,6 +7,9 @@ name = "bittide-hal" version = "0.1.0" edition = "2021" +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-support/bittide-hal/build.rs b/firmware-support/bittide-hal/build.rs index d2cd6bb67..91cdcee73 100644 --- a/firmware-support/bittide-hal/build.rs +++ b/firmware-support/bittide-hal/build.rs @@ -63,8 +63,8 @@ fn main() { let (shared, deduped_hals) = match deduplicate(&ctx, &input_mapping, hals.iter()) { Ok(result) => result, Err(err) => { - println!("ERROR!! {:?}", err); - panic!("ERROR {:?}", err) + println!("ERROR!! {err:?}"); + panic!("ERROR {err:?}") } }; @@ -158,7 +158,7 @@ fn main() { writeln!(file, "{}", lint_disables_generated_code()).unwrap(); writeln!(file, "{}", generate_type_ref_imports(&ctx, &refs)).unwrap(); - writeln!(file, "{}", code).unwrap(); + writeln!(file, "{code}").unwrap(); } } @@ -182,11 +182,11 @@ fn main() { let (dev_name, code, refs) = backend_rust::generate_device_desc(&ctx, &varis, *dev); let file_name = ident(IdentType::Module, dev_name); - let file_path = shared_devices_path.join(format!("{}.rs", file_name)); + let file_path = shared_devices_path.join(format!("{file_name}.rs")); let mut file = File::create(&file_path).unwrap(); writeln!(file, "{}", lint_disables_generated_code()).unwrap(); writeln!(file, "{}", generate_type_ref_imports(&ctx, &refs)).unwrap(); - write!(file, "{}", code).unwrap(); + write!(file, "{code}").unwrap(); generated_files.push(file_path); writeln!(mod_file, "pub mod {file_name};").unwrap(); @@ -235,13 +235,13 @@ fn main() { } let (dev_name, code, refs) = backend_rust::generate_device_desc(&ctx, &varis, *dev); let file_name = ident(IdentType::Module, dev_name); - let file_path = hal_path.join("devices").join(format!("{}.rs", file_name)); + let file_path = hal_path.join("devices").join(format!("{file_name}.rs")); let mut file = File::create(&file_path).unwrap(); writeln!(file, "{}", lint_disables_generated_code()).unwrap(); writeln!(file, "{}", generate_type_ref_imports(&ctx, &refs)).unwrap(); - write!(file, "{}", code).unwrap(); + write!(file, "{code}").unwrap(); generated_files.push(file_path); writeln!(mod_file, "pub mod {file_name};").unwrap(); diff --git a/firmware-support/bittide-hal/src/manual_additions/si539x_spi.rs b/firmware-support/bittide-hal/src/manual_additions/si539x_spi.rs index 31a657fd4..9e20ab98e 100644 --- a/firmware-support/bittide-hal/src/manual_additions/si539x_spi.rs +++ b/firmware-support/bittide-hal/src/manual_additions/si539x_spi.rs @@ -22,13 +22,12 @@ pub struct ConfigEntry { pub data: u8, } -#[allow(clippy::from_over_into)] -impl Into for ConfigEntry { - fn into(self) -> RegisterOperation { +impl From for RegisterOperation { + fn from(value: ConfigEntry) -> Self { RegisterOperation { - page: [self.page], - address: [self.address], - write: Just([self.data]), + page: [value.page], + address: [value.address], + write: Just([value.data]), } } } diff --git a/firmware-support/bittide-macros/Cargo.toml b/firmware-support/bittide-macros/Cargo.toml index 5b8e8f7e4..198b8cd56 100644 --- a/firmware-support/bittide-macros/Cargo.toml +++ b/firmware-support/bittide-macros/Cargo.toml @@ -6,6 +6,9 @@ name = "bittide-macros" version = "0.1.0" edition = "2024" +[lints] +workspace = true + [lib] proc-macro = true diff --git a/firmware-support/bittide-sys/Cargo.toml b/firmware-support/bittide-sys/Cargo.toml index e58d240d0..3d10cfeee 100644 --- a/firmware-support/bittide-sys/Cargo.toml +++ b/firmware-support/bittide-sys/Cargo.toml @@ -10,6 +10,9 @@ license = "Apache-2.0" authors = ["Google LLC"] resolver = "2" +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] diff --git a/firmware-support/bittide-sys/tests/elf_common.rs b/firmware-support/bittide-sys/tests/elf_common.rs index 123c4e345..761cb5014 100644 --- a/firmware-support/bittide-sys/tests/elf_common.rs +++ b/firmware-support/bittide-sys/tests/elf_common.rs @@ -187,14 +187,10 @@ pub unsafe fn with_32bit_addr_buffer(size: u32, f: impl FnOnce(&mut } pub fn mem_config_from_segs(segs: &[Segment]) -> MemoryConfiguration { - // The ranges are inversed so that they don't default to 0..MAX - // but instead are properly read from the segments. - // Since they are not used as iterators but instead as a pair, it does not - // matter that they yield no values when iterated. - #[allow(clippy::reversed_empty_ranges)] + // Assume that instr and data memory are empty at first, and correct the start and end later let mut config = MemoryConfiguration { - instruction_memory: u32::MAX..0, - data_memory: u32::MAX..0, + instruction_memory: 0..0, + data_memory: 0..0, }; for seg in segs { diff --git a/firmware-support/gdb-trace/Cargo.toml b/firmware-support/gdb-trace/Cargo.toml index 674b66146..5610d72c7 100644 --- a/firmware-support/gdb-trace/Cargo.toml +++ b/firmware-support/gdb-trace/Cargo.toml @@ -7,6 +7,9 @@ name = "gdb-trace" version = "0.1.0" edition = "2021" +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-support/gdb-trace/src/lib.rs b/firmware-support/gdb-trace/src/lib.rs index 27803ed5a..cf4a655f1 100644 --- a/firmware-support/gdb-trace/src/lib.rs +++ b/firmware-support/gdb-trace/src/lib.rs @@ -10,11 +10,12 @@ use core::{fmt::Write, panic::PanicInfo}; /// the panic info to the provided write-able interface. It's expected that the user will /// be running a GDB process and set a breakpoint to the panic handler so that the output /// can be read. -#[allow(clippy::empty_loop)] pub fn gdb_panic_internal(writer: &mut W, info: &PanicInfo) -> ! { riscv::interrupt::machine::disable(); - writeln!(writer, "{:?}", info).unwrap(); - loop {} + writeln!(writer, "{info:?}").unwrap(); + loop { + continue; + } } #[macro_export] diff --git a/firmware-support/memmap-generate/Cargo.toml b/firmware-support/memmap-generate/Cargo.toml index 6b257ca78..be35c9f34 100644 --- a/firmware-support/memmap-generate/Cargo.toml +++ b/firmware-support/memmap-generate/Cargo.toml @@ -7,6 +7,9 @@ name = "memmap-generate" version = "0.1.0" edition = "2021" +[lints] +workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/firmware-support/memmap-generate/src/backends/c/device_instances.rs b/firmware-support/memmap-generate/src/backends/c/device_instances.rs index e24bd2d4a..11ac6f617 100644 --- a/firmware-support/memmap-generate/src/backends/c/device_instances.rs +++ b/firmware-support/memmap-generate/src/backends/c/device_instances.rs @@ -69,7 +69,7 @@ pub fn generate_device_instances( } }; - let hex_addr = format!("0x{:X}", addr); + let hex_addr = format!("0x{addr:X}"); writeln!(device_type, " {dev_ident} {instance_name};").unwrap(); diff --git a/firmware-support/memmap-generate/src/backends/c/mod.rs b/firmware-support/memmap-generate/src/backends/c/mod.rs index f705f33d4..fb2a7d684 100644 --- a/firmware-support/memmap-generate/src/backends/c/mod.rs +++ b/firmware-support/memmap-generate/src/backends/c/mod.rs @@ -347,7 +347,7 @@ fn type_to_ident(ctx: &IrCtx, ty: Handle) -> String { let name = &ctx.identifiers[*handle]; format!("var_{name}") } - TypeRef::Nat(n) => format!("{}", n), + TypeRef::Nat(n) => format!("{n}"), TypeRef::Reference { name, args } => { let type_name = &ctx.type_names[*name]; let mut ident = type_name.base.clone(); diff --git a/firmware-support/memmap-generate/src/backends/rust/mod.rs b/firmware-support/memmap-generate/src/backends/rust/mod.rs index a08512832..9cc49638f 100644 --- a/firmware-support/memmap-generate/src/backends/rust/mod.rs +++ b/firmware-support/memmap-generate/src/backends/rust/mod.rs @@ -154,7 +154,7 @@ pub fn generate_device_instances( }; use std::str::FromStr; - let addr = Literal::from_str(&format!("0x{:X}", abs_addr)).unwrap(); + let addr = Literal::from_str(&format!("0x{abs_addr:X}")).unwrap(); let field_def = quote! { pub #instance_name_ident: #dev_ident }; let field_init = @@ -396,7 +396,7 @@ fn generate_repr(ctx: &IrCtx, desc: &TypeDescription) -> TokenStream { .map(|handle| &ctx.type_constructors[handle]) .all(|con| con.field_types.len == 0); let n = po2_type(constructors.len.ilog2() as u64); - let repr = ident(IdentType::Raw, format!("u{}", n)); + let repr = ident(IdentType::Raw, format!("u{n}")); if fieldless { quote! { #[repr(#repr) ]} @@ -888,7 +888,7 @@ fn type_to_ident(ctx: &IrCtx, ty: Handle) -> String { let name = &ctx.identifiers[*handle]; format!("var_{name}") } - TypeRef::Nat(n) => format!("{}", n), + TypeRef::Nat(n) => format!("{n}"), TypeRef::Reference { name, args } => { let type_name = &ctx.type_names[*name]; let mut ident = type_name.base.clone(); diff --git a/firmware-support/memmap-generate/src/build_utils.rs b/firmware-support/memmap-generate/src/build_utils.rs index 04d308307..875312574 100644 --- a/firmware-support/memmap-generate/src/build_utils.rs +++ b/firmware-support/memmap-generate/src/build_utils.rs @@ -79,12 +79,12 @@ pub fn standard_memmap_build( /// * `source_file` - The name of the source file to read (e.g., "memory.x") pub fn standard_static_memory_build(source_file: &str) { let memory_x_content = - fs::read(source_file).unwrap_or_else(|_| panic!("Could not read file: {}", source_file)); + fs::read(source_file).unwrap_or_else(|_| panic!("Could not read file: {source_file}")); let out_dir = env::var("OUT_DIR").expect("No out dir"); let dest_path = Path::new(&out_dir).join("memory.x"); fs::write(dest_path, memory_x_content).expect("Could not write file"); setup_riscv_linker(&out_dir); - println!("cargo:rerun-if-changed={}", source_file); + println!("cargo:rerun-if-changed={source_file}"); } diff --git a/firmware-support/memmap-generate/src/deprecated/generators/device_instances.rs b/firmware-support/memmap-generate/src/deprecated/generators/device_instances.rs index 798477138..992e99540 100644 --- a/firmware-support/memmap-generate/src/deprecated/generators/device_instances.rs +++ b/firmware-support/memmap-generate/src/deprecated/generators/device_instances.rs @@ -38,7 +38,7 @@ pub fn generate_device_instances_struct( let instance_name = match name_idx { Some(n) => { name_idx = Some(n + 1); - &format!("{}_{}", device_name, n) + &format!("{device_name}_{n}") } None => { name_idx = Some(1); @@ -69,7 +69,7 @@ pub fn generate_device_instances_struct( let instance_name = match name_idx { Some(n) => { name_idx = Some(n + 1); - &format!("{}_{}", device_name, n) + &format!("{device_name}_{n}") } None => { name_idx = Some(1); diff --git a/firmware-support/memmap-generate/src/deprecated/generators/mod.rs b/firmware-support/memmap-generate/src/deprecated/generators/mod.rs index 4d0e65d13..aa6fe7837 100644 --- a/firmware-support/memmap-generate/src/deprecated/generators/mod.rs +++ b/firmware-support/memmap-generate/src/deprecated/generators/mod.rs @@ -129,12 +129,12 @@ pub(crate) fn generate_tag_docs<'a>( toks.extend(quote::quote! { #[doc = ""] }); for tag in tags { - let msg = format!(" - `{}`", tag); + let msg = format!(" - `{tag}`"); toks.extend(quote::quote! { #[doc = #msg] }); } for tag in ann_tags { - let msg = format!(" - `{}`", tag); + let msg = format!(" - `{tag}`"); toks.extend(quote::quote! { #[doc = #msg] }); } diff --git a/firmware-support/memmap-generate/src/deprecated/generators/types.rs b/firmware-support/memmap-generate/src/deprecated/generators/types.rs index 90b93c069..1a0b7ba43 100644 --- a/firmware-support/memmap-generate/src/deprecated/generators/types.rs +++ b/firmware-support/memmap-generate/src/deprecated/generators/types.rs @@ -420,7 +420,7 @@ impl TypeGenerator { Constructor::Record { fields } => fields.is_empty(), }); let n = clog2(&(named_constructors.len() as u64)); - let repr = ident(IdentType::Raw, format!("u{}", n)); + let repr = ident(IdentType::Raw, format!("u{n}")); if fieldless { quote! { #[repr(#repr)] } } else { diff --git a/firmware-support/memmap-generate/src/format.rs b/firmware-support/memmap-generate/src/format.rs index 325b235a0..69bd7cc17 100644 --- a/firmware-support/memmap-generate/src/format.rs +++ b/firmware-support/memmap-generate/src/format.rs @@ -19,7 +19,7 @@ fn rustfmt_files(files: &[impl AsRef]) -> Result<(), String> { let status = command.status().expect("failed to run rustfmt"); if !status.success() { - return Err(format!("`rustfmt` failed: {:?}", command)); + return Err(format!("`rustfmt` failed: {command:?}")); } Ok(()) diff --git a/firmware-support/memmap-generate/src/ir/input_to_ir.rs b/firmware-support/memmap-generate/src/ir/input_to_ir.rs index aa48314c9..2ddd686a4 100644 --- a/firmware-support/memmap-generate/src/ir/input_to_ir.rs +++ b/firmware-support/memmap-generate/src/ir/input_to_ir.rs @@ -231,7 +231,7 @@ impl IrCtx { } TypeRef::Tuple(handle_range) => *handle_range = range, TypeRef::Reference { name: _, args } => *args = range, - other => panic!("Shouldn't need patching: {:?}", other), + other => panic!("Shouldn't need patching: {other:?}"), } } } diff --git a/firmware-support/memmap-generate/src/lib.rs b/firmware-support/memmap-generate/src/lib.rs index 49c8a8520..4ed702fca 100644 --- a/firmware-support/memmap-generate/src/lib.rs +++ b/firmware-support/memmap-generate/src/lib.rs @@ -98,14 +98,12 @@ fn memory_x_file( writeln!(buf, "{{").unwrap(); writeln!( buf, - " IMEM : ORIGIN = 0x{:X}, LENGTH = 0x{:X}", - instr_mem_address, instr_mem_size + " IMEM : ORIGIN = 0x{instr_mem_address:X}, LENGTH = 0x{instr_mem_size:X}", ) .unwrap(); writeln!( buf, - " DMEM : ORIGIN = 0x{:X}, LENGTH = 0x{:X}", - data_mem_address, data_mem_size + " DMEM : ORIGIN = 0x{data_mem_address:X}, LENGTH = 0x{data_mem_size:X}", ) .unwrap(); writeln!( diff --git a/firmware-support/memmap-generate/src/storage.rs b/firmware-support/memmap-generate/src/storage.rs index c177f32e1..df95a7185 100644 --- a/firmware-support/memmap-generate/src/storage.rs +++ b/firmware-support/memmap-generate/src/storage.rs @@ -261,15 +261,6 @@ impl Storage { self.0.get_mut(idx.0) } - /// Iterator over all the elements in the storage, consuming the storage. - #[allow(clippy::should_implement_trait)] - pub fn into_iter(self) -> impl DoubleEndedIterator, T)> + ExactSizeIterator { - self.0 - .into_iter() - .enumerate() - .map(|(idx, val)| (Handle(idx, PhantomData), val)) - } - /// Iterator over all the elements in the storage. pub fn iter(&self) -> impl DoubleEndedIterator, &T)> + ExactSizeIterator { self.0 @@ -355,6 +346,19 @@ impl IndexMut> for Storage { } } +impl IntoIterator for Storage { + type Item = (Handle, T); + type IntoIter = + std::iter::Map>, fn((usize, T)) -> Self::Item>; + + fn into_iter(self) -> Self::IntoIter { + self.0 + .into_iter() + .enumerate() + .map(|(idx, val)| (Handle(idx, PhantomData), val)) + } +} + /// Build a [HandleRange] for newly added elements to a [Storage] /// /// See [Storage::range_counter]