Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Nano 33 BLE Board #1909

Merged
merged 9 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"boards/opentitan",
"boards/redboard_artemis_nano",
"boards/stm32f3discovery",
"boards/nano33ble",
"capsules",
"chips/apollo3",
"chips/arty_e21_chip",
Expand Down
1 change: 1 addition & 0 deletions boards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ that Tock supports.
| [Nordic nRF52840-DK](nordic/nrf52840dk/README.md) | ARM Cortex-M4 | nRF52840 | jLink | tockloader |
| [Nordic nRF52840-Dongle](nordic/nrf52840_dongle/README.md) | ARM Cortex-M4 | nRF52840 | jLink | tockloader |
| [ACD52832](acd52832/README.md) | ARM Cortex-M4 | nRF52832 | jLink | tockloader |
| [Nano 33 BLE](nano33ble/README.md) | ARM Cortex-M4 | nRF52840 | BOSSA | bossac |
| [TI LAUNCHXL-CC26x2](launchxl/README.md) | ARM Cortex-M4 | CC2652R | openocd | tockloader |
| [ST Nucleo F446RE](nucleo_f446re/README.md) | ARM Cortex-M4 | STM32F446 | openocd | custom |
| [ST Nucleo F429ZI](nucleo_f429zi/README.md) | ARM Cortex-M4 | STM32F429 | openocd | custom |
Expand Down
15 changes: 15 additions & 0 deletions boards/nano33ble/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "nano33ble"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
build = "build.rs"
edition = "2018"

[dependencies]
cortexm4 = { path = "../../arch/cortex-m4" }
capsules = { path = "../../capsules" }
kernel = { path = "../../kernel" }
nrf52 = { path = "../../chips/nrf52" }
nrf52840 = { path = "../../chips/nrf52840" }
components = { path = "../components" }
nrf52_components = { path = "../nordic/nrf52_components" }
16 changes: 16 additions & 0 deletions boards/nano33ble/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Makefile for building the tock kernel for the Arduino Nano 33 BLE board.

TOCK_ARCH=cortex-m4
TARGET=thumbv7em-none-eabi
PLATFORM=nano33ble

include ../Makefile.common

ifdef PORT
FLAGS += --port $(PORT)
endif

# Upload the kernel using bossac
.PHONY: program
program: $(TOCK_ROOT_DIRECTORY)target/$(TARGET)/release/$(PLATFORM).bin
bossac $(FLAGS) -U -i -e -w $< -R
114 changes: 114 additions & 0 deletions boards/nano33ble/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
Arduino Nano 33 BLE
===================

<img src="https://store-cdn.arduino.cc/usa/catalog/product/cache/1/image/1040x660/604a3538c15e081937dbfbd20aa60aad/a/b/abx00031_featured.jpg" width="35%">

The [Arduino Nano 33 BLE](https://store.arduino.cc/usa/nano-33-ble) and [Arduino
Nano 33 BLE Sense](https://store.arduino.cc/usa/nano-33-ble-sense) are compact
boards based on the Nordic nRF52840 SoC. The "Sense" version includes the
following sensors:

- 9 axis inertial sensor
- humidity and temperature sensor
- barometric sensor
- microphone
- gesture, proximity, light color and light intensity sensor


## Getting Started

First, follow the [Tock Getting Started guide](../../../doc/Getting_Started.md)

You will need the bossac bootloader tool:

```shell
$ git clone https://github.com/arduino/BOSSA
$ cd BOSSA
$ make bossac
```
bradjc marked this conversation as resolved.
Show resolved Hide resolved

Then you will need to add `BOSSA/bin` to your `$PATH` variable so that your
system can find the `bossac` program.

## Programming the Kernel

To program the kernel we use the BOSSA tool to communicate with the bootloader
on the board which then flashes the kernel. This requires that the bootloader be
active. To force the board into bootloader mode, press the button on the board
twice in rapid succession. You should see the yellow LED pulse on and off.

At this point you should be able to simply run `make program` in this directory
to install a fresh kernel.

```
$ make program
```

You may need to specify the port like so:

```
$ make program PORT=<serial port path>
```

## Programming Applications

This is currently a weakness of the Nano 33 board as flashing applications is
not as ergonomic as Tock expects. Right now, you should be able to flash a
single application. For example, to flash the "blink" app, first compile it:

```
$ git clone https://github.com/tock/libtock-c
$ cd libtock-c/examples/blink
$ make
```

This previous step will create a TAB (`.tab` file) that normally tockloader
would use to program on the board. However, tockloader is currently not
supported. As a workaround, we can directly program a single app. To load the
blink app, first press the button on the board twice in rapid succession to
enter the bootloader, and then:

```
$ bossac -i -e -o 0x20000 -w build/cortex-m4/cortex-m4.tbf -R
```

That tells the BOSSA tool to flash the application in the Tock Binary Format to
the correct offset (the app will end up at address 0x30000). You may also need
to pass the `--port` flag.

### Userspace Resource Mapping

This table shows the mappings between resources available in userspace
and the physical elements on the Nano 33 BLE board.

| Software Resource | Physical Element |
|-------------------|---------------------|
| GPIO[2] | Pin D2 |
| GPIO[3] | Pin D3 |
| GPIO[4] | Pin D4 |
| GPIO[5] | Pin D5 |
| GPIO[6] | Pin D6 |
| GPIO[7] | Pin D7 |
| GPIO[8] | Pin D8 |
| GPIO[9] | Pin D9 |
| GPIO[10] | Pin D10 |
| LED[0] | Tri-color LED Red |
| LED[1] | Tri-color LED Green |
| LED[2] | Tri-color LED Blue |

## Debugging

The Nano 33 board uses a virtual serial console over USB to send debugging info
from the kernel and print messages from applications. You can use whatever your
favorite serial terminal program is to view the output. Tockloader also
supports reading and writing to a serial console with `tockloader listen`.

### Kernel Panics

If the kernel or an app encounter a `panic!()`, the panic handler specified in
`io.rs` is called. This causes the kernel to stop. You will notice the yellow
LED starts blinking in a repeating but slightly irregular pattern. There is also
a panic print out that provides a fair bit of debugging information. However,
currently that panic print info is transmitted over `UARTE0`, not the USB port.
So, to view the panic info, you will need to connect to the two pins on the
board labeled `TX1` and `RX0` and view the UART information there.
4 changes: 4 additions & 0 deletions boards/nano33ble/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
println!("cargo:rerun-if-changed=layout.ld");
println!("cargo:rerun-if-changed=../kernel_layout.ld");
}
10 changes: 10 additions & 0 deletions boards/nano33ble/layout.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MEMORY
{
rom (rx) : ORIGIN = 0x00010000, LENGTH = 128K
prog (rx) : ORIGIN = 0x00030000, LENGTH = 832K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}

MPU_MIN_ALIGN = 8K;

INCLUDE ../kernel_layout.ld
67 changes: 67 additions & 0 deletions boards/nano33ble/src/io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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() {}
}
}
Comment on lines +28 to +46
Copy link
Contributor

@brghena brghena Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How hard would it be to have the panic dump print out over USB instead of UART (or in addition)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really hard, maybe impossible? I don't know how to do it without interrupts.

It might be worth thinking about handling panics in apps differently so that the kernel is still running while the panic message is printed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't block this PR on it, but we're going to have to think of some way to at least be able to debug crashing apps over USB serial if we want this to be a first-class board.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

/// Default panic handler for the Nano 33 Board.
///
/// We just use the standard default provided by the debug module in the kernel.
#[cfg(not(test))]
#[no_mangle]
#[panic_handler]
pub unsafe extern "C" fn panic_fmt(pi: &PanicInfo) -> ! {
const LED_KERNEL_PIN: Pin = Pin::P0_13;
let led = &mut led::LedLow::new(&mut nrf52840::gpio::PORT[LED_KERNEL_PIN]);
let writer = &mut WRITER;
debug::panic(
&mut [led],
writer,
pi,
&cortexm4::support::nop,
&PROCESSES,
&CHIP,
)
}