Revamp deploy.py
Now the script supports more flashing methods: - JLink (with tockloader) - OpenOCD (with tockloader) - pyOCD - Nordic DFU - none (will produce an IntelHex file) Also merged the contributions from: - Yihui Xiong to support the Makerdiary USB dongle board - Dennis Geurts to support Nordic DFU Doc updated accordingly. Imported 2 patches for Tock kernel: - 06-add-set_vector_table_offset.patch (upstream tock/tock#1579) - 07-nrf52-bootloader.patch (upstream tock/tock#1681)
This commit is contained in:
30
boards/nrf52840_dongle_dfu/Cargo.toml
Normal file
30
boards/nrf52840_dongle_dfu/Cargo.toml
Normal file
@@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "nrf52840_dongle_dfu"
|
||||
version = "0.1.0"
|
||||
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
|
||||
build = "build.rs"
|
||||
edition = "2018"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
lto = false
|
||||
opt-level = "z"
|
||||
debug = true
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
debug = true
|
||||
|
||||
[[bin]]
|
||||
path = "../../third_party/tock/boards/nordic/nrf52840_dongle/src/main.rs"
|
||||
name = "nrf52840_dongle_dfu"
|
||||
|
||||
[dependencies]
|
||||
components = { path = "../../third_party/tock/boards/components" }
|
||||
cortexm4 = { path = "../../third_party/tock/arch/cortex-m4" }
|
||||
capsules = { path = "../../third_party/tock/capsules" }
|
||||
kernel = { path = "../../third_party/tock/kernel" }
|
||||
nrf52840 = { path = "../../third_party/tock/chips/nrf52840" }
|
||||
nrf52dk_base = { path = "../../third_party/tock/boards/nordic/nrf52dk_base" }
|
||||
4
boards/nrf52840_dongle_dfu/build.rs
Normal file
4
boards/nrf52840_dongle_dfu/build.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=layout.ld");
|
||||
println!("cargo:rerun-if-changed=../../third_party/tock/boards/kernel_layout.ld");
|
||||
}
|
||||
10
boards/nrf52840_dongle_dfu/layout.ld
Normal file
10
boards/nrf52840_dongle_dfu/layout.ld
Normal file
@@ -0,0 +1,10 @@
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00001000, LENGTH = 188K
|
||||
prog (rx) : ORIGIN = 0x00030000, LENGTH = 832K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
}
|
||||
|
||||
MPU_MIN_ALIGN = 8K;
|
||||
|
||||
INCLUDE ../../third_party/tock/boards/kernel_layout.ld
|
||||
26
boards/nrf52840_mdk_dfu/Cargo.toml
Normal file
26
boards/nrf52840_mdk_dfu/Cargo.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "nrf52840_mdk_dfu"
|
||||
version = "0.1.0"
|
||||
authors = ["Yihui Xiong <yihui.xiong@hotmail.com>"]
|
||||
build = "build.rs"
|
||||
edition = "2018"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
lto = false
|
||||
opt-level = "z"
|
||||
debug = true
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
lto = true
|
||||
opt-level = "z"
|
||||
debug = true
|
||||
|
||||
[dependencies]
|
||||
components = { path = "../../third_party/tock/boards/components" }
|
||||
cortexm4 = { path = "../../third_party/tock/arch/cortex-m4" }
|
||||
capsules = { path = "../../third_party/tock/capsules" }
|
||||
kernel = { path = "../../third_party/tock/kernel" }
|
||||
nrf52840 = { path = "../../third_party/tock/chips/nrf52840" }
|
||||
nrf52dk_base = { path = "../../third_party/tock/boards/nordic/nrf52dk_base" }
|
||||
4
boards/nrf52840_mdk_dfu/build.rs
Normal file
4
boards/nrf52840_mdk_dfu/build.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=layout.ld");
|
||||
println!("cargo:rerun-if-changed=../../third_party/tock/boards/kernel_layout.ld");
|
||||
}
|
||||
10
boards/nrf52840_mdk_dfu/layout.ld
Normal file
10
boards/nrf52840_mdk_dfu/layout.ld
Normal file
@@ -0,0 +1,10 @@
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00001000, LENGTH = 188K
|
||||
prog (rx) : ORIGIN = 0x00030000, LENGTH = 832K
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
|
||||
}
|
||||
|
||||
MPU_MIN_ALIGN = 8K;
|
||||
|
||||
INCLUDE ../../third_party/tock/boards/kernel_layout.ld
|
||||
65
boards/nrf52840_mdk_dfu/src/io.rs
Normal file
65
boards/nrf52840_mdk_dfu/src/io.rs
Normal file
@@ -0,0 +1,65 @@
|
||||
use core::fmt::Write;
|
||||
use core::panic::PanicInfo;
|
||||
use cortexm4;
|
||||
use kernel::debug;
|
||||
use kernel::debug::IoWrite;
|
||||
use kernel::hil::led;
|
||||
use kernel::hil::uart::{self, Configure};
|
||||
use nrf52840::gpio::Pin;
|
||||
|
||||
use crate::CHIP;
|
||||
use crate::PROCESSES;
|
||||
|
||||
struct Writer {
|
||||
initialized: bool,
|
||||
}
|
||||
|
||||
static mut WRITER: Writer = Writer { initialized: false };
|
||||
|
||||
impl Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> ::core::fmt::Result {
|
||||
self.write(s.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl IoWrite for Writer {
|
||||
fn write(&mut self, buf: &[u8]) {
|
||||
let uart = unsafe { &mut nrf52840::uart::UARTE0 };
|
||||
if !self.initialized {
|
||||
self.initialized = true;
|
||||
uart.configure(uart::Parameters {
|
||||
baud_rate: 115200,
|
||||
stop_bits: uart::StopBits::One,
|
||||
parity: uart::Parity::None,
|
||||
hw_flow_control: false,
|
||||
width: uart::Width::Eight,
|
||||
});
|
||||
}
|
||||
for &c in buf {
|
||||
unsafe {
|
||||
uart.send_byte(c);
|
||||
}
|
||||
while !uart.tx_ready() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[no_mangle]
|
||||
#[panic_handler]
|
||||
/// Panic handler
|
||||
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
|
||||
// The nRF52840 Dongle LEDs (see back of board)
|
||||
const LED1_PIN: Pin = Pin::P0_23;
|
||||
let led = &mut led::LedLow::new(&mut nrf52840::gpio::PORT[LED1_PIN]);
|
||||
let writer = &mut WRITER;
|
||||
debug::panic(
|
||||
&mut [led],
|
||||
writer,
|
||||
pi,
|
||||
&cortexm4::support::nop,
|
||||
&PROCESSES,
|
||||
&CHIP,
|
||||
)
|
||||
}
|
||||
123
boards/nrf52840_mdk_dfu/src/main.rs
Normal file
123
boards/nrf52840_mdk_dfu/src/main.rs
Normal file
@@ -0,0 +1,123 @@
|
||||
//! Tock kernel for the Makerdiary nRF52840 MDK USB dongle.
|
||||
//!
|
||||
//! It is based on nRF52840 SoC (Cortex M4 core with a BLE transceiver) with
|
||||
//! many exported I/O and peripherals.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use kernel::component::Component;
|
||||
#[allow(unused_imports)]
|
||||
use kernel::{debug, debug_gpio, debug_verbose, static_init};
|
||||
use nrf52840::gpio::Pin;
|
||||
use nrf52dk_base::{SpiPins, UartChannel, UartPins};
|
||||
|
||||
// The nRF52840 MDK USB Dongle LEDs
|
||||
const LED1_R_PIN: Pin = Pin::P0_23;
|
||||
const LED1_G_PIN: Pin = Pin::P0_22;
|
||||
const LED1_B_PIN: Pin = Pin::P0_24;
|
||||
|
||||
// The nRF52840 Dongle button
|
||||
const BUTTON_PIN: Pin = Pin::P0_18;
|
||||
const BUTTON_RST_PIN: Pin = Pin::P0_02;
|
||||
|
||||
const UART_RTS: Pin = Pin::P0_21;
|
||||
const UART_TXD: Pin = Pin::P0_20;
|
||||
const UART_CTS: Pin = Pin::P0_03;
|
||||
const UART_RXD: Pin = Pin::P0_19;
|
||||
|
||||
const SPI_MOSI: Pin = Pin::P0_05;
|
||||
const SPI_MISO: Pin = Pin::P0_06;
|
||||
const SPI_CLK: Pin = Pin::P0_07;
|
||||
|
||||
/// UART Writer
|
||||
pub mod io;
|
||||
|
||||
// State for loading and holding applications.
|
||||
// How should the kernel respond when a process faults.
|
||||
const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic;
|
||||
|
||||
// Number of concurrent processes this platform supports.
|
||||
const NUM_PROCS: usize = 8;
|
||||
|
||||
// RAM to be shared by all application processes.
|
||||
#[link_section = ".app_memory"]
|
||||
static mut APP_MEMORY: [u8; 0x3C000] = [0; 0x3C000];
|
||||
|
||||
static mut PROCESSES: [Option<&'static dyn kernel::procs::ProcessType>; NUM_PROCS] =
|
||||
[None, None, None, None, None, None, None, None];
|
||||
|
||||
// Static reference to chip for panic dumps
|
||||
static mut CHIP: Option<&'static nrf52840::chip::Chip> = None;
|
||||
|
||||
/// Dummy buffer that causes the linker to reserve enough space for the stack.
|
||||
#[no_mangle]
|
||||
#[link_section = ".stack_buffer"]
|
||||
pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
|
||||
|
||||
/// Entry point in the vector table called on hard reset.
|
||||
#[no_mangle]
|
||||
pub unsafe fn reset_handler() {
|
||||
// Loads relocations and clears BSS
|
||||
nrf52840::init();
|
||||
|
||||
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&PROCESSES));
|
||||
// GPIOs
|
||||
let gpio = components::gpio::GpioComponent::new(board_kernel).finalize(
|
||||
components::gpio_component_helper!(
|
||||
&nrf52840::gpio::PORT[Pin::P0_04],
|
||||
&nrf52840::gpio::PORT[Pin::P0_05],
|
||||
&nrf52840::gpio::PORT[Pin::P0_06],
|
||||
&nrf52840::gpio::PORT[Pin::P0_07],
|
||||
&nrf52840::gpio::PORT[Pin::P0_08]
|
||||
),
|
||||
);
|
||||
let button = components::button::ButtonComponent::new(board_kernel).finalize(
|
||||
components::button_component_helper!((
|
||||
&nrf52840::gpio::PORT[BUTTON_PIN],
|
||||
capsules::button::GpioMode::LowWhenPressed,
|
||||
kernel::hil::gpio::FloatingState::PullUp
|
||||
)),
|
||||
);
|
||||
|
||||
let led = components::led::LedsComponent::new().finalize(components::led_component_helper!(
|
||||
(
|
||||
&nrf52840::gpio::PORT[LED1_R_PIN],
|
||||
capsules::led::ActivationMode::ActiveLow
|
||||
),
|
||||
(
|
||||
&nrf52840::gpio::PORT[LED1_G_PIN],
|
||||
capsules::led::ActivationMode::ActiveLow
|
||||
),
|
||||
(
|
||||
&nrf52840::gpio::PORT[LED1_B_PIN],
|
||||
capsules::led::ActivationMode::ActiveLow
|
||||
)
|
||||
));
|
||||
let chip = static_init!(nrf52840::chip::Chip, nrf52840::chip::new());
|
||||
CHIP = Some(chip);
|
||||
|
||||
nrf52dk_base::setup_board(
|
||||
board_kernel,
|
||||
BUTTON_RST_PIN,
|
||||
&nrf52840::gpio::PORT,
|
||||
gpio,
|
||||
LED1_R_PIN,
|
||||
LED1_G_PIN,
|
||||
LED1_B_PIN,
|
||||
led,
|
||||
UartChannel::Pins(UartPins::new(UART_RTS, UART_TXD, UART_CTS, UART_RXD)),
|
||||
&SpiPins::new(SPI_MOSI, SPI_MISO, SPI_CLK),
|
||||
&None,
|
||||
button,
|
||||
true,
|
||||
&mut APP_MEMORY,
|
||||
&mut PROCESSES,
|
||||
FAULT_RESPONSE,
|
||||
nrf52840::uicr::Regulator0Output::V3_0,
|
||||
false,
|
||||
&Some(&nrf52840::usbd::USBD),
|
||||
chip,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user