boards: Add the Arduino Nano BLE 33

This commit adds the board definition files
needed to support the Arduino Nano BLE 33.
Tested: the following have been verified with
my logic analyzer.
* Serial peripherals (UART, I2C, SPI)
* USB
* RTC

Untested:
* PWM. In theory it should work but I don't
have a good enough logic analyzer to test this

* RTC's. The board doesn't have a backup battery.
The peripherals are enabled for modding another
battery in the device tree.

Signed-off-by: Jefferson Lee <jeffersonlee2000@gmail.com>
This commit is contained in:
Jefferson Lee 2020-10-10 19:10:16 -07:00 committed by Maureen Helm
parent f4a26837c8
commit 35c5fbe554
13 changed files with 534 additions and 1 deletions

View File

@ -0,0 +1,13 @@
# Copyright (c) 2020 Jefferson Lee.
# SPDX-License-Identifier: Apache-2.0
add_library(arduino_nano_33_ble_pins INTERFACE)
target_include_directories(arduino_nano_33_ble_pins
INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/inc/")
if(CONFIG_BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS)
zephyr_library()
zephyr_library_sources("${CMAKE_CURRENT_SOURCE_DIR}/src/init_sensors.c")
target_link_libraries(${ZEPHYR_CURRENT_LIBRARY} PRIVATE arduino_nano_33_ble_pins)
endif()

View File

@ -0,0 +1,20 @@
# Copyright (c) 2020 Jefferson Lee.
# SPDX-License-Identifier: Apache-2.0
config BOARD_ARDUINO_NANO_33_BLE
bool "Arduino Nano 33 BLE board"
depends on SOC_NRF52840_QIAA
config BOARD_ARDUINO_NANO_33_BLE_EN_USB_CONSOLE
bool "Sends the console output over the USB port"
depends on BOARD_ARDUINO_NANO_33_BLE
select SERIAL
select USB
select CONSOLE
select PRINTK
select UART_INTERRUPT_DRIVEN
select USB_UART_CONSOLE
config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS
bool "Initializes the internal I2C sensors on the board"
depends on BOARD_ARDUINO_NANO_33_BLE

View File

@ -0,0 +1,42 @@
# Copyright (c) 2020 Jefferson Lee.
# SPDX-License-Identifier: Apache-2.0
if BOARD_ARDUINO_NANO_33_BLE
config BOARD
default "arduino_nano_33_ble"
if USB
config USB_NRFX
default y
config USB_DEVICE_STACK
default y
endif # USB
config BT_CTLR
default BT
if I2C
config I2C_NRFX
default y
config NRFX_TWIM
default y
config I2C_0
default y
config I2C_1
default y
config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS
default y
endif #I2C
if SPI
config SPI_NRFX
default y
config NRFX_SPIM
default y
config SPI_2
default y
config SPI_2_NRF_SPIM
default y
endif #SPI
endif #board

View File

@ -0,0 +1,125 @@
/*
* Copyright (c) 2020 Jefferson Lee
*
* SPDX-License-Identifier: Apache-2.0
*/
/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
/ {
model = "Arduino Nano 33 BLE (Sense)";
compatible = "arduino,arduino_nano_33_ble";
chosen {
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
zephyr,uart-mcumgr = &uart0;
zephyr,bt-mon-uart = &uart0;
zephyr,bt-c2h-uart = &uart0;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &code_partition;
};
leds {
compatible = "gpio-leds";
led0: led_0 {
gpios = <&gpio0 24 0>;
label = "Red LED";
};
};
/* These aliases are provided for compatibility with samples */
aliases {
led0 = &led0;
spi = &spi2;
};
};
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
code_partition: partition@10000 {
label = "code";
reg = <0x10000 0xf0000>;
read-only;
};
};
};
/*
* guide specifying pin numbers: https://docs.zephyrproject.org/latest/boards/arm/nrf52840dk_nrf52840/doc/index.html
* Given Pin PB.A:
* pin_no = B*32 + A
* ex. P1.0 => 32
*/
&adc {
status = "okay";
};
&uart0 {
compatible = "nordic,nrf-uart";
current-speed = <115200>;
status = "okay";
tx-pin = <35>; //P1.03
rx-pin = <42>; //P1.10
};
&i2c0 {
compatible = "nordic,nrf-twim";
status = "okay";
sda-pin = <31>; //P0.31
scl-pin = <2>; //P0.02
};
&i2c1 {
compatible = "nordic,nrf-twim";
status = "okay";
sda-pin = <14>; //P0.14
scl-pin = <15>; //P0.15
};
// we use SPI2 because SPI1/0 shares conflicts with I2C1/0
&spi2 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <13>; //P0.13
mosi-pin = <33>; //P1.01
miso-pin = <40>; //P1.08
};
&gpio0 {
status = "okay";
};
&gpio1 {
status = "okay";
};
&usbd {
compatible = "nordic,nrf-usbd";
status = "okay";
};
// All PWM's should be enaled
&pwm0 {
status = "okay";
};
&pwm1 {
status = "okay";
};
&pwm2 {
status = "okay";
};
&pwm3 {
status = "okay";
};
/*
* NOTE: curiously, there is no PDM (microphone) interface in the
* nordic DTSI file.
* You'll need to use the nordic-specific PDM libraries.
*/
/*
* the following sets up the peripherals according to this file:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/19ddd214d255ca20b233eefa76662b360595c146/variants/ARDUINO_NANO33BLE/variant.cpp#L136
* The bootloader will conflict with RTC1
*/
&rtc1 {
status = "disabled";
};

View File

@ -0,0 +1,20 @@
identifier: arduino_nano_33_ble
name: Arduino Nano 33 BLE (Sense)
type: mcu
arch: arm
toolchain:
- zephyr
- gnuarmemb
- xtools
supported:
- adc
- ble
- i2c
- ieee802154
- pwm
- serial
- spi
- uart
- usb_cdc
- usb_device
- watchdog

View File

@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
CONFIG_SOC_SERIES_NRF52X=y
CONFIG_SOC_NRF52840_QIAA=y
CONFIG_BOARD_ARDUINO_NANO_33_BLE=y
# Enable MPU
CONFIG_ARM_MPU=y
CONFIG_HW_STACK_PROTECTION=y
# enable peripherals
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
# enable flashing and linker options
CONFIG_USE_DT_CODE_PARTITION=y
# additional board options
CONFIG_GPIO_AS_PINRESET=y

View File

@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0
include(${ZEPHYR_BASE}/boards/common/bossac.board.cmake)

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

View File

@ -0,0 +1,141 @@
.. _arduino_nano_33_ble:
Arduino Nano 33 BLE (Sense)
#################################
Overview
********
The Arduino Nano 33 BLE is designed around Nordic Semiconductor's
nRF52840 ARM Cortex-M4F CPU. Arduino sells 2 variants of the board, the
plain `BLE`_ type and the `BLE Sense`_ type. The "Sense" variant is distinguished by
the inclusion of more sensors, but otherwise both variants are the same.
.. image:: img/arduino_nano_33_ble_sense.png
:width: 500px
:align: center
:alt: Arduino Nano 33 BLE (Sense variant)
The Sense variant of the board
Hardware
********
Supported Features
==================
The package is configured to support the following hardware:
+-----------+------------+----------------------+
| Interface | Controller | Driver/Component |
+===========+============+======================+
| ADC | on-chip | adc |
+-----------+------------+----------------------+
| CLOCK | on-chip | clock_control |
+-----------+------------+----------------------+
| FLASH | on-chip | flash |
+-----------+------------+----------------------+
| GPIO | on-chip | gpio |
+-----------+------------+----------------------+
| I2C0 | on-chip | i2c |
+-----------+------------+----------------------+
| I2C1 | on-chip | i2c |
+-----------+------------+----------------------+
| MPU | on-chip | arch/arm |
+-----------+------------+----------------------+
| NVIC | on-chip | arch/arm |
+-----------+------------+----------------------+
| PWM | on-chip | pwm |
+-----------+------------+----------------------+
| RADIO | on-chip | Bluetooth, |
| | | ieee802154 |
+-----------+------------+----------------------+
| RTC | on-chip | system clock |
+-----------+------------+----------------------+
| SPI | on-chip | spi |
+-----------+------------+----------------------+
| UART | on-chip | serial |
+-----------+------------+----------------------+
| USB | on-chip | usb |
+-----------+------------+----------------------+
| WDT | on-chip | watchdog |
+-----------+------------+----------------------+
Other hardware features are not supported by the Zephyr kernel.
Notably, this includes the PDM (microphone) interface.
Connections and IOs
===================
The `schematic`_ will tell you everything
you need to know about the pins.
A convinience header mapping the Arduino pin names to their
Zephyr pin numbers can be found in :code:`arduino_nano_33_ble_pins.h`,
if you link against the :code:`arduino_nano_33_ble_pins` CMake library.
For your convience, two Kconfig options are added:
#. :code:`BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS`:
This configuration option enables the internal I2C sensors.
#. :code:`BOARD_ARDUINO_NANO_33_BLE_EN_USB_CONSOLE`:
This configuration option enables the USB CDC subsystem and
the console, so that printk works.
Programming and Debugging
*************************
This board requires the Arduino variant of bossac. You will not
be able to flash with the bossac included with the zephyr-sdk, or
using shumatech's mainline build.
You can get this variant of bossac with one of two ways:
#. Building the binary from the `Arduino source tree <https://github.com/arduino/BOSSA/tree/nrf>`_
#. Downloading the Arduino IDE
#. Install the board support package within the IDE
#. Change your IDE preferences to provide verbose logging
#. Build and flash a sample application, and read the logs to figure out where Arduino stored bossac.
Once you have a path to bossac, you can pass it as an argument to west:
.. code-block:: bash
west flash --bossac="<path to the arduino version of bossac>"
Flashing
========
Attach the board to your computer using the USB cable, and then
.. zephyr-app-commands::
:zephyr-app: samples/blinky
:board: arduino_nano_33_ble
:goals: build
:compact:
Double-tap the RESET button on your board. Your board should disconnect, reconnect,
and there should be a pulsing orange LED near the USB port.
Then, you can flash the image using the above script.
You should see the the red LED blink.
References
**********
.. target-notes::
.. _BLE:
https://store.arduino.cc/usa/nano-33-ble/
.. _BLE SENSE:
https://store.arduino.cc/usa/nano-33-ble-sense/
.. _pinouts:
https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather/pinouts
.. _schematic:
https://content.arduino.cc/assets/NANO33BLE_V2.0_sch.pdf

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "arduino_nano_33_ble_pins.h"
/* this header-only library makes GPIO access a little more arduino-y. */
#include <device.h>
#include <drivers/gpio.h>
struct arduino_gpio_t {
const struct device *gpios[2];
};
static inline void arduino_gpio_init(struct arduino_gpio_t *gpios)
{
gpios->gpios[0] = device_get_binding("GPIO_0");
gpios->gpios[1] = device_get_binding("GPIO_1");
}
static inline int arduino_gpio_pinMode(struct arduino_gpio_t *gpios,
int pin, int mode)
{
return gpio_pin_configure(gpios->gpios[pin / 32], pin % 32, mode);
}
static inline int arduino_gpio_digitalWrite(struct arduino_gpio_t *gpios,
int pin, int value)
{
return gpio_pin_set(gpios->gpios[pin / 32], pin % 32, value);
}
static inline int arduino_gpio_digitalRead(struct arduino_gpio_t *gpios,
int pin)
{
return gpio_pin_get(gpios->gpios[pin / 32], pin % 32);
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
/*
* This file will map the arduino pin names to their pin number
* Definitions are copied from here:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/6216632cc70271619ad43547c804dabb4afa4a00/variants/ARDUINO_NANO33BLE/variant.cpp#L77
* (in the array g_APinDescription)
* The pin number is derived using the formula:
* Given GPIO pin PB.A
* Pin Number = B*32 + A
* ex. P1.3 => 35
*/
#define ARDUINO_D0_TX (32 * 1 + 3) /* P1.3 */
#define ARDUINO_D1_RX (32 * 1 + 10) /* P1.10 */
#define ARDUINO_D2 (32 * 1 + 11) /* P1.11 */
#define ARDUINO_D3 (32 * 1 + 12) /* P1.12 */
#define ARDUINO_D4 (32 * 1 + 15) /* P1.15 */
#define ARDUINO_D5 (32 * 1 + 13) /* P1.13 */
#define ARDUINO_D6 (32 * 1 + 14) /* P1.14 */
#define ARDUINO_D7 (32 * 0 + 23) /* P0.23 */
#define ARDUINO_D8 (32 * 0 + 21) /* P0.21 */
#define ARDUINO_D9 (32 * 0 + 27) /* P0.27 */
#define ARDUINO_D10 (32 * 1 + 2) /* P1.2 */
#define ARDUINO_D11_MOSI (32 * 1 + 1) /* P1.1 */
#define ARDUINO_D12_MISO (32 * 1 + 8) /* P1.8 */
#define ARDUINO_D13_SCK (32 * 0 + 13) /* P0.13 */
#define ARDUINO_A0 (32 * 0 + 24) /* P0.24 */
#define ARDUINO_A1 (32 * 0 + 5) /* P0.5 */
#define ARDUINO_A2 (32 * 0 + 30) /* P0.30 */
#define ARDUINO_A3 (32 * 0 + 29) /* P0.29 */
#define ARDUINO_A4_SDA (32 * 0 + 31) /* P0.31 */
#define ARDUINO_A5_SCL (32 * 0 + 2) /* P0.2 */
#define ARDUINO_A6 (32 * 0 + 28) /* P0.28 */
#define ARDUINO_A7 (32 * 0 + 3) /* P0.3 */
#define ARDUINO_LEDR (32 * 0 + 24) /* P0.24 */
#define ARDUINO_LEDG (32 * 0 + 16) /* P0.16 */
#define ARDUINO_LEDB (32 * 0 + 6) /* P0.6 */
#define ARDUINO_LEDPWR (32 * 1 + 9) /* P1.9 */
#define ARDUINO_INT_APDS (32 * 0 + 19) /* P0.19 */
#define ARDUINO_PDM_PWR (32 * 0 + 17) /* P0.17 */
#define ARDUINO_PDM_CLK (32 * 0 + 26) /* P0.26 */
#define ARDUINO_PDM_DIN (32 * 0 + 25) /* P0.25 */
#define ARDUINO_SDA1 (32 * 0 + 14) /* P0.14 */
#define ARDUINO_SCL1 (32 * 0 + 15) /* P0.15 */
#define ARDUINO_INTERNAL_I2C_PULLUP (32 * 1 + 0) /* P1.0 */
#define ARDUINO_INTERNAL_VDD_ENV_ENABLE (32 * 0 + 22) /* P0.22 */

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) 2020 Jefferson Lee.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <init.h>
#include <arduino_nano_33_ble.h>
/*
* this method roughly follows the steps here:
* https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/6216632cc70271619ad43547c804dabb4afa4a00/variants/ARDUINO_NANO33BLE/variant.cpp#L136
*/
static int board_internal_sensors_init(const struct device *dev)
{
ARG_UNUSED(dev);
struct arduino_gpio_t gpios;
arduino_gpio_init(&gpios);
arduino_gpio_pinMode(&gpios, ARDUINO_LEDPWR, GPIO_OUTPUT);
arduino_gpio_digitalWrite(&gpios, ARDUINO_LEDPWR, 1);
CoreDebug->DEMCR = 0;
NRF_CLOCK->TRACECONFIG = 0;
/*
* Arduino uses software to disable RTC1,
* but I disabled it using DeviceTree
*/
/* nrf_rtc_event_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); */
/* nrf_rtc_int_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK); */
NRF_PWM_Type * PWM[] = {
NRF_PWM0, NRF_PWM1, NRF_PWM2, NRF_PWM3
};
for (unsigned int i = 0; i < (ARRAY_SIZE(PWM)); i++) {
PWM[i]->ENABLE = 0;
PWM[i]->PSEL.OUT[0] = 0xFFFFFFFFUL;
}
/*
* the PCB designers decided to use GPIO's
* as power pins for the internal sensors
*/
arduino_gpio_pinMode(&gpios, ARDUINO_INTERNAL_VDD_ENV_ENABLE, GPIO_OUTPUT);
arduino_gpio_pinMode(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, GPIO_OUTPUT);
arduino_gpio_digitalWrite(&gpios, ARDUINO_INTERNAL_VDD_ENV_ENABLE, 1);
arduino_gpio_digitalWrite(&gpios, ARDUINO_INTERNAL_I2C_PULLUP, 1);
return 0;
}
SYS_INIT(board_internal_sensors_init, PRE_KERNEL_1, 32);

View File

@ -47,7 +47,8 @@
defined(CONFIG_BOARD_ADAFRUIT_FEATHER_NRF52840) || \
defined(CONFIG_BOARD_RUUVI_RUUVITAG) || \
defined(CONFIG_BOARD_BT510) || \
defined(CONFIG_BOARD_PINNACLE_100_DVK)
defined(CONFIG_BOARD_PINNACLE_100_DVK) || \
defined(CONFIG_BOARD_ARDUINO_NANO_33_BLE)
#include <hal/nrf_saadc.h>
#define ADC_DEVICE_NAME DT_LABEL(DT_INST(0, nordic_nrf_saadc))