From 2336b577dae4112b31288d893133efa37d1e2ee6 Mon Sep 17 00:00:00 2001 From: Leon Schuermann Date: Sat, 4 May 2024 23:33:22 -0400 Subject: [PATCH] Rename nrf52840dk_2 to thread tutorial configuration board --- Cargo.toml | 2 +- .../nrf52840dk-thread-tutorial/Cargo.toml | 18 ++ .../nrf52840dk-thread-tutorial/Makefile | 9 + .../nrf52840dk-thread-tutorial}/README.md | 0 .../jtag/gdbinit_pca10040.jlink | 0 .../jtag/jdbserver_pca10040.sh | 0 .../nrf52840dk-thread-tutorial}/layout.ld | 4 +- .../nrf52840dk-thread-tutorial/src/main.rs | 166 ++++++++++++++++++ boards/nordic/nrf52840dk/src/lib.rs | 19 +- boards/nordic/nrf52840dk_2/Cargo.toml | 14 -- boards/nordic/nrf52840dk_2/Makefile | 39 ---- boards/nordic/nrf52840dk_2/src/main.rs | 85 --------- 12 files changed, 208 insertions(+), 148 deletions(-) create mode 100644 boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Cargo.toml create mode 100644 boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Makefile rename boards/{nordic/nrf52840dk_2 => configurations/nrf52840dk/nrf52840dk-thread-tutorial}/README.md (100%) rename boards/{nordic/nrf52840dk_2 => configurations/nrf52840dk/nrf52840dk-thread-tutorial}/jtag/gdbinit_pca10040.jlink (100%) rename boards/{nordic/nrf52840dk_2 => configurations/nrf52840dk/nrf52840dk-thread-tutorial}/jtag/jdbserver_pca10040.sh (100%) rename boards/{nordic/nrf52840dk_2 => configurations/nrf52840dk/nrf52840dk-thread-tutorial}/layout.ld (72%) create mode 100644 boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/src/main.rs delete mode 100644 boards/nordic/nrf52840dk_2/Cargo.toml delete mode 100644 boards/nordic/nrf52840dk_2/Makefile delete mode 100644 boards/nordic/nrf52840dk_2/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 996c46737d3..0153982b371 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,6 @@ members = [ "boards/wm1110dev", "boards/makepython-nrf52840", "boards/nordic/nrf52840dk", - "boards/nordic/nrf52840dk_2", "boards/nordic/nrf52840_dongle", "boards/nordic/nrf52dk", "boards/sma_q3", @@ -55,6 +54,7 @@ members = [ "boards/weact_f401ccu6/", "boards/configurations/nrf52840dk/nrf52840dk-test-appid-sha256", "boards/configurations/nrf52840dk/nrf52840dk-test-kernel", + "boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial", "capsules/aes_gcm", "capsules/core", "capsules/extra", diff --git a/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Cargo.toml b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Cargo.toml new file mode 100644 index 00000000000..db8081455c5 --- /dev/null +++ b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Cargo.toml @@ -0,0 +1,18 @@ +# Licensed under the Apache License, Version 2.0 or the MIT License. +# SPDX-License-Identifier: Apache-2.0 OR MIT +# Copyright Tock Contributors 2022. + +[package] +name = "nrf52840dk-thread-tutorial" +version.workspace = true +authors.workspace = true +build = "../../../build.rs" +edition.workspace = true + +[dependencies] +kernel = { path = "../../../../kernel" } +nrf52840 = { path = "../../../../chips/nrf52840" } +nrf52840dk = { path = "../../../nordic/nrf52840dk" } +capsules-core = { path = "../../../../capsules/core" } +capsules-extra = { path = "../../../../capsules/extra" } +components = { path = "../../../components" } \ No newline at end of file diff --git a/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Makefile b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Makefile new file mode 100644 index 00000000000..276ab96ab6d --- /dev/null +++ b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/Makefile @@ -0,0 +1,9 @@ +# Licensed under the Apache License, Version 2.0 or the MIT License. +# SPDX-License-Identifier: Apache-2.0 OR MIT +# Copyright Tock Contributors 2022. + +TARGET=thumbv7em-none-eabi +PLATFORM=nrf52840dk-thread-tutorial + +include ../../../Makefile.common +include ../nrf52840dk.mk diff --git a/boards/nordic/nrf52840dk_2/README.md b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/README.md similarity index 100% rename from boards/nordic/nrf52840dk_2/README.md rename to boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/README.md diff --git a/boards/nordic/nrf52840dk_2/jtag/gdbinit_pca10040.jlink b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/jtag/gdbinit_pca10040.jlink similarity index 100% rename from boards/nordic/nrf52840dk_2/jtag/gdbinit_pca10040.jlink rename to boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/jtag/gdbinit_pca10040.jlink diff --git a/boards/nordic/nrf52840dk_2/jtag/jdbserver_pca10040.sh b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/jtag/jdbserver_pca10040.sh similarity index 100% rename from boards/nordic/nrf52840dk_2/jtag/jdbserver_pca10040.sh rename to boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/jtag/jdbserver_pca10040.sh diff --git a/boards/nordic/nrf52840dk_2/layout.ld b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/layout.ld similarity index 72% rename from boards/nordic/nrf52840dk_2/layout.ld rename to boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/layout.ld index 3eccbaa12d2..417a58fe7db 100644 --- a/boards/nordic/nrf52840dk_2/layout.ld +++ b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/layout.ld @@ -2,5 +2,5 @@ /* SPDX-License-Identifier: Apache-2.0 OR MIT */ /* Copyright Tock Contributors 2023. */ -INCLUDE ../nrf52840_chip_layout.ld -INCLUDE ../../kernel_layout.ld +INCLUDE ../../../nordic/nrf52840_chip_layout.ld +INCLUDE ../../../kernel_layout.ld diff --git a/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/src/main.rs b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/src/main.rs new file mode 100644 index 00000000000..d8bbf0206da --- /dev/null +++ b/boards/configurations/nrf52840dk/nrf52840dk-thread-tutorial/src/main.rs @@ -0,0 +1,166 @@ +// Licensed under the Apache License, Version 2.0 or the MIT License. +// SPDX-License-Identifier: Apache-2.0 OR MIT +// Copyright Tock Contributors 2022. + +//! Tock kernel for the Nordic Semiconductor nRF52840 development kit (DK). + +#![no_std] +// Disable this attribute when documenting, as a workaround for +// https://github.com/rust-lang/rust/issues/62184. +#![cfg_attr(not(doc), no_main)] +#![deny(missing_docs)] + +use kernel::platform::{SyscallDriverLookup, KernelResources}; +use kernel::{capabilities, create_capability}; +use kernel::component::Component; +use nrf52840::gpio::Pin; +use nrf52840dk_lib; + +fn crc(s: &'static str) -> u32 { + kernel::utilities::helpers::crc32_posix(s.as_bytes()) +} + +type Screen = components::ssd1306::Ssd1306ComponentType>; +// type ScreenDriver = components::screen::ScreenSharedComponentType; +type ScreenDriver = components::screen::ScreenComponentType; + +struct Platform { + base: nrf52840dk_lib::Platform, + screen: &'static ScreenDriver, +} + +impl SyscallDriverLookup for Platform { + fn with_driver(&self, driver_num: usize, f: F) -> R + where + F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R, + { + match driver_num { + capsules_extra::screen::DRIVER_NUM => f(Some(self.screen)), + _ => self.base.with_driver(driver_num, f), + } + } +} + +type Chip = nrf52840dk_lib::Chip; + +impl KernelResources + for Platform +{ + type SyscallDriverLookup = Self; + type SyscallFilter = >::SyscallFilter; + type ProcessFault = >::ProcessFault; + type Scheduler = >::Scheduler; + type SchedulerTimer = >::SchedulerTimer; + type WatchDog = >::WatchDog; + type ContextSwitchCallback = >::ContextSwitchCallback; + + fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup { + self + } + fn syscall_filter(&self) -> &Self::SyscallFilter { + self.base.syscall_filter() + } + fn process_fault(&self) -> &Self::ProcessFault { + self.base.process_fault() + } + fn scheduler(&self) -> &Self::Scheduler { + self.base.scheduler() + } + fn scheduler_timer(&self) -> &Self::SchedulerTimer { + self.base.scheduler_timer() + } + fn watchdog(&self) -> &Self::WatchDog { + self.base.watchdog() + } + fn context_switch_callback(&self) -> &Self::ContextSwitchCallback { + self.base.context_switch_callback() + } +} + + +/// Main function called after RAM initialized. +#[no_mangle] +pub unsafe fn main() { + let main_loop_capability = create_capability!(capabilities::MainLoopCapability); + + // Create the base board: + let (board_kernel, base_platform, chip, base_peripherals) = nrf52840dk_lib::start(); + + //-------------------------------------------------------------------------- + // SCREEN + //-------------------------------------------------------------------------- + + const SCREEN_I2C_SDA_PIN: Pin = Pin::P1_10; + const SCREEN_I2C_SCL_PIN: Pin = Pin::P1_11; + + let i2c_bus = components::i2c::I2CMuxComponent::new(&base_peripherals.twi0, None) + .finalize(components::i2c_mux_component_static!(nrf52840::i2c::TWI)); + base_peripherals.twi0.configure( + nrf52840::pinmux::Pinmux::new(SCREEN_I2C_SCL_PIN as u32), + nrf52840::pinmux::Pinmux::new(SCREEN_I2C_SDA_PIN as u32), + ); + base_peripherals.twi0.set_speed(nrf52840::i2c::Speed::K400); + + // I2C address is b011110X, and on this board D/C̅ is GND. + let ssd1306_i2c = components::i2c::I2CComponent::new(i2c_bus, 0x3c) + .finalize(components::i2c_component_static!(nrf52840::i2c::TWI)); + + // Create the ssd1306 object for the actual screen driver. + let ssd1306 = components::ssd1306::Ssd1306Component::new(ssd1306_i2c, true) + .finalize(components::ssd1306_component_static!(nrf52840::i2c::TWI)); + + // // Assign screen regions to specific apps. + // let apps_regions = static_init!( + // [capsules_extra::screen_shared::AppScreenRegion; 3], + // [ + // capsules_extra::screen_shared::AppScreenRegion::new( + // kernel::process::ShortID::Fixed(core::num::NonZeroU32::new(crc("circle")).unwrap()), + // 0, // x + // 0, // y + // 8 * 8, // width + // 8 * 8 // height + // ), + // capsules_extra::screen_shared::AppScreenRegion::new( + // kernel::process::ShortID::Fixed(core::num::NonZeroU32::new(crc("count")).unwrap()), + // 8 * 8, // x + // 0, // y + // 8 * 8, // width + // 4 * 8 // height + // ), + // capsules_extra::screen_shared::AppScreenRegion::new( + // kernel::process::ShortID::Fixed( + // core::num::NonZeroU32::new(crc("tock-scroll")).unwrap() + // ), + // 8 * 8, // x + // 4 * 8, // y + // 8 * 8, // width + // 4 * 8 // height + // ) + // ] + // ); + + // let screen = components::screen::ScreenSharedComponent::new( + // board_kernel, + // capsules_extra::screen::DRIVER_NUM, + // ssd1306, + // apps_regions, + // ) + // .finalize(components::screen_shared_component_static!(1032, Screen)); + + let screen = components::screen::ScreenComponent::new( + board_kernel, + capsules_extra::screen::DRIVER_NUM, + ssd1306, + None, + ) + .finalize(components::screen_component_static!(1032)); + + let platform = Platform { + base: base_platform, + screen, + }; + + ssd1306.init_screen(); + + board_kernel.kernel_loop(&platform, chip, Some(&platform.base.ipc), &main_loop_capability); +} diff --git a/boards/nordic/nrf52840dk/src/lib.rs b/boards/nordic/nrf52840dk/src/lib.rs index 92ab5a9d9a3..5429ead3d86 100644 --- a/boards/nordic/nrf52840dk/src/lib.rs +++ b/boards/nordic/nrf52840dk/src/lib.rs @@ -90,8 +90,12 @@ use kernel::scheduler::round_robin::RoundRobinSched; use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init}; use nrf52840::gpio::Pin; use nrf52840::interrupt_service::Nrf52840DefaultPeripherals; +use nrf52840::chip::Nrf52DefaultPeripherals; use nrf52_components::{UartChannel, UartPins}; +/// The parametrized chip type: +pub type Chip = nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>; + // The nRF52840DK LEDs (see back of board) const LED1_PIN: Pin = Pin::P0_13; const LED2_PIN: Pin = Pin::P0_14; @@ -148,7 +152,7 @@ const NUM_PROCS: usize = 8; static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] = [None; NUM_PROCS]; -static mut CHIP: Option<&'static nrf52840::chip::NRF52> = None; +static mut CHIP: Option<&'static Chip> = None; static mut PROCESS_PRINTER: Option<&'static kernel::process::ProcessPrinterText> = None; /// Dummy buffer that causes the linker to reserve enough space for the stack. @@ -282,7 +286,7 @@ impl SyscallDriverLookup for Platform { } } -impl KernelResources>> +impl KernelResources for Platform { type SyscallDriverLookup = Self; @@ -323,7 +327,8 @@ impl KernelResources ( &'static kernel::Kernel, Platform, - &'static nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>, + &'static Chip, + &'static Nrf52DefaultPeripherals<'static>, ) { //-------------------------------------------------------------------------- // INITIAL SETUP @@ -381,7 +386,7 @@ pub unsafe fn start() -> ( // Create (and save for panic debugging) a chip object to setup low-level // resources (e.g. MPU, systick). let chip = static_init!( - nrf52840::chip::NRF52, + Chip, nrf52840::chip::NRF52::new(nrf52840_peripherals) ); CHIP = Some(chip); @@ -425,8 +430,8 @@ pub unsafe fn start() -> ( 5 => &nrf52840_peripherals.gpio_port[Pin::P1_06], 6 => &nrf52840_peripherals.gpio_port[Pin::P1_07], 7 => &nrf52840_peripherals.gpio_port[Pin::P1_08], - 8 => &nrf52840_peripherals.gpio_port[Pin::P1_10], - 9 => &nrf52840_peripherals.gpio_port[Pin::P1_11], + // 8 => &nrf52840_peripherals.gpio_port[Pin::P1_10], + // 9 => &nrf52840_peripherals.gpio_port[Pin::P1_11], 10 => &nrf52840_peripherals.gpio_port[Pin::P1_12], 11 => &nrf52840_peripherals.gpio_port[Pin::P1_13], 12 => &nrf52840_peripherals.gpio_port[Pin::P1_14], @@ -964,5 +969,5 @@ pub unsafe fn start() -> ( debug!("{:?}", err); }); - (board_kernel, platform, chip) + (board_kernel, platform, chip, base_peripherals) } diff --git a/boards/nordic/nrf52840dk_2/Cargo.toml b/boards/nordic/nrf52840dk_2/Cargo.toml deleted file mode 100644 index a75e4bee84a..00000000000 --- a/boards/nordic/nrf52840dk_2/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -# Licensed under the Apache License, Version 2.0 or the MIT License. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# Copyright Tock Contributors 2022. - -[package] -name = "nrf52840dk_2" -version.workspace = true -authors.workspace = true -build = "../../build.rs" -edition.workspace = true - -[dependencies] -kernel = { path = "../../../kernel" } -nrf52840dk = { path = "../nrf52840dk" } diff --git a/boards/nordic/nrf52840dk_2/Makefile b/boards/nordic/nrf52840dk_2/Makefile deleted file mode 100644 index 01a5d07ec41..00000000000 --- a/boards/nordic/nrf52840dk_2/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# Licensed under the Apache License, Version 2.0 or the MIT License. -# SPDX-License-Identifier: Apache-2.0 OR MIT -# Copyright Tock Contributors 2022. - -# Makefile for building the tock kernel for the nRF development kit - -TARGET=thumbv7em-none-eabi -PLATFORM=nrf52840dk_2 - -include ../../Makefile.common - -TOCKLOADER=tockloader - -# Where in the SAM4L flash to load the kernel with `tockloader` -KERNEL_ADDRESS=0x00000 - -# Upload programs over uart with tockloader -ifdef PORT - TOCKLOADER_GENERAL_FLAGS += --port $(PORT) -endif - -# Default target for installing the kernel. -.PHONY: install -install: flash - -# Upload the kernel over JTAG -.PHONY: flash -flash: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin - $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --jlink $< - -# Upload the kernel over JTAG using OpenOCD -.PHONY: flash-openocd -flash-openocd: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin - $(TOCKLOADER) $(TOCKLOADER_GENERAL_FLAGS) flash --address $(KERNEL_ADDRESS) --board nrf52dk --openocd $< - -# Upload the kernel over serial/bootloader -.PHONY: program -program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).hex - $(error Cannot program nRF52840DK over USB. Use \`make flash\` and JTAG) diff --git a/boards/nordic/nrf52840dk_2/src/main.rs b/boards/nordic/nrf52840dk_2/src/main.rs deleted file mode 100644 index 2d20dbc0d5e..00000000000 --- a/boards/nordic/nrf52840dk_2/src/main.rs +++ /dev/null @@ -1,85 +0,0 @@ -// Licensed under the Apache License, Version 2.0 or the MIT License. -// SPDX-License-Identifier: Apache-2.0 OR MIT -// Copyright Tock Contributors 2022. - -//! Tock kernel for the Nordic Semiconductor nRF52840 development kit (DK). - -#![no_std] -// Disable this attribute when documenting, as a workaround for -// https://github.com/rust-lang/rust/issues/62184. -#![cfg_attr(not(doc), no_main)] -#![deny(missing_docs)] - -use kernel::platform::{SyscallDriverLookup, KernelResources}; -use kernel::{capabilities, create_capability}; -use nrf52840dk_lib; - -struct Platform { - base: nrf52840dk_lib::Platform, -} - -impl SyscallDriverLookup for Platform { - fn with_driver(&self, driver_num: usize, f: F) -> R - where - F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R, - { - match driver_num { - _ => self.base.with_driver(driver_num, f), - } - } -} - -type Chip = nrf52840dk_lib::Chip; - -impl KernelResources - for Platform -{ - type SyscallDriverLookup = Self; - type SyscallFilter = >::SyscallFilter; - type ProcessFault = >::ProcessFault; - type CredentialsCheckingPolicy = >::CredentialsCheckingPolicy; - type Scheduler = >::Scheduler; - type SchedulerTimer = >::SchedulerTimer; - type WatchDog = >::WatchDog; - type ContextSwitchCallback = >::ContextSwitchCallback; - - fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup { - self - } - fn syscall_filter(&self) -> &Self::SyscallFilter { - self.base.syscall_filter() - } - fn process_fault(&self) -> &Self::ProcessFault { - self.base.process_fault() - } - fn credentials_checking_policy(&self) -> &'static Self::CredentialsCheckingPolicy { - self.base.credentials_checking_policy() - } - fn scheduler(&self) -> &Self::Scheduler { - self.base.scheduler() - } - fn scheduler_timer(&self) -> &Self::SchedulerTimer { - self.base.scheduler_timer() - } - fn watchdog(&self) -> &Self::WatchDog { - self.base.watchdog() - } - fn context_switch_callback(&self) -> &Self::ContextSwitchCallback { - self.base.context_switch_callback() - } -} - - -/// Main function called after RAM initialized. -#[no_mangle] -pub unsafe fn main() { - let main_loop_capability = create_capability!(capabilities::MainLoopCapability); - - let (board_kernel, base_platform, chip) = nrf52840dk_lib::start(); - - let platform = Platform { - base: base_platform, - }; - - board_kernel.kernel_loop(&platform, chip, Some(&platform.base.ipc), &main_loop_capability); -}