Skip to content

Commit

Permalink
Rename nrf52840dk_2 to thread tutorial configuration board
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann committed May 5, 2024
1 parent 8589674 commit 2336b57
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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" }
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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<nrf52840::i2c::TWI<'static>>;
// type ScreenDriver = components::screen::ScreenSharedComponentType<Screen>;
type ScreenDriver = components::screen::ScreenComponentType;

struct Platform {
base: nrf52840dk_lib::Platform,
screen: &'static ScreenDriver,
}

impl SyscallDriverLookup for Platform {
fn with_driver<F, R>(&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<Chip>
for Platform
{
type SyscallDriverLookup = Self;
type SyscallFilter = <nrf52840dk_lib::Platform as KernelResources<Chip>>::SyscallFilter;
type ProcessFault = <nrf52840dk_lib::Platform as KernelResources<Chip>>::ProcessFault;
type Scheduler = <nrf52840dk_lib::Platform as KernelResources<Chip>>::Scheduler;
type SchedulerTimer = <nrf52840dk_lib::Platform as KernelResources<Chip>>::SchedulerTimer;
type WatchDog = <nrf52840dk_lib::Platform as KernelResources<Chip>>::WatchDog;
type ContextSwitchCallback = <nrf52840dk_lib::Platform as KernelResources<Chip>>::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);
}
19 changes: 12 additions & 7 deletions boards/nordic/nrf52840dk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Nrf52840DefaultPeripherals>> = 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.
Expand Down Expand Up @@ -282,7 +286,7 @@ impl SyscallDriverLookup for Platform {
}
}

impl KernelResources<nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>>
impl KernelResources<Chip>
for Platform
{
type SyscallDriverLookup = Self;
Expand Down Expand Up @@ -323,7 +327,8 @@ impl KernelResources<nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'
pub unsafe fn start() -> (
&'static kernel::Kernel,
Platform,
&'static nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>,
&'static Chip,
&'static Nrf52DefaultPeripherals<'static>,
) {
//--------------------------------------------------------------------------
// INITIAL SETUP
Expand Down Expand Up @@ -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<Nrf52840DefaultPeripherals>,
Chip,
nrf52840::chip::NRF52::new(nrf52840_peripherals)
);
CHIP = Some(chip);
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -964,5 +969,5 @@ pub unsafe fn start() -> (
debug!("{:?}", err);
});

(board_kernel, platform, chip)
(board_kernel, platform, chip, base_peripherals)
}
14 changes: 0 additions & 14 deletions boards/nordic/nrf52840dk_2/Cargo.toml

This file was deleted.

39 changes: 0 additions & 39 deletions boards/nordic/nrf52840dk_2/Makefile

This file was deleted.

Loading

0 comments on commit 2336b57

Please sign in to comment.