8000 nrf: Add support for Arduino Nano 33 BLE board. · micropython/micropython@542b992 · GitHub
[go: up one dir, main page]

Skip to content

Commit 542b992

Browse files
committed
nrf: Add support for Arduino Nano 33 BLE board.
1 parent 06ac31b commit 542b992

File tree

8 files changed

+257
-0
lines changed

8 files changed

+257
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Arduino SA
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "nrf.h"
28+
#include "nrf_gpio.h"
29+
#include "nrf_rtc.h"
30+
31+
#define PIN_ENABLE_SENSORS_3V3 (22u)
32+
#define PIN_ENABLE_I2C_PULLUP (32u)
33+
#define DFU_MAGIC_SERIAL_ONLY_RESET (0xb0)
34+
35+
void NANO33_board_early_init(void) {
36+
// Errata Nano33BLE - I2C pullup is on SWO line, need to disable TRACE
37+
// was being enabled by nrfx_clock_anomaly_132
38+
CoreDebug->DEMCR = 0;
39+
NRF_CLOCK->TRACECONFIG = 0;
40+
41+
// Bootloader enables interrupt on COMPARE[0], which we don't handle
42+
// Disable it here to avoid getting stuck when OVERFLOW irq is triggered
43+
nrf_rtc_event_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK);
44+
nrf_rtc_int_disable(NRF_RTC1, NRF_RTC_INT_COMPARE0_MASK);
45+
46+
// Always enable I2C pullup and power on startup
47+
// Change for maximum powersave
48+
nrf_gpio_cfg_output(PIN_ENABLE_SENSORS_3V3);
49+
nrf_gpio_cfg_output(PIN_ENABLE_I2C_PULLUP);
50+
51+
nrf_gpio_pin_set(PIN_ENABLE_SENSORS_3V3);
52+
nrf_gpio_pin_set(PIN_ENABLE_I2C_PULLUP);
53+
}
54+
55+
void NANO33_board_deinit(void) {
56+
nrf_gpio_cfg_output(PIN_ENABLE_SENSORS_3V3);
57+
nrf_gpio_cfg_output(PIN_ENABLE_I2C_PULLUP);
58+
59+
nrf_gpio_pin_clear(PIN_ENABLE_SENSORS_3V3);
60+
nrf_gpio_pin_clear(PIN_ENABLE_I2C_PULLUP);
61+
}
62+
63+
void NANO33_board_enter_bootloader(void) {
64+
__disable_irq();
65+
NRF_POWER->GPREGRET = DFU_MAGIC_SERIAL_ONLY_RESET;
66+
NVIC_SystemReset();
67+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"deploy": [
3+
"./deploy.md"
4+
],
5+
"docs": "",
6+
"features": [
7+
"Bluetooth 5.0",
8+
"IMU LSM9DS1",
9+
"Humidity sensor HTS221",
10+
"Pressure sensor LPS22H",
11+
"Proximity, Light, RGB sensor APDS-9960",
12+
"Microphone MPM3610",
13+
"Crypto IC ARM CC310",
14+
"USB-MICRO",
15+
"Breadboard Friendly"
16+
],
17+
"images": [
18+
"ABX00031_01.iso_998x749.jpg"
19+
],
20+
"mcu": "nRF52840",
21+
"product": "Arduino Nano 33 BLE Sense",
22+
"thumbnail": "",
23+
"url": "https://store.arduino.cc/products/arduino-nano-33-ble-sense",
24+
"vendor": "Arduino"
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### Update the bootloader
2+
3+
Before deploying any firmware, make sure you have the updated Arduino Nano 33 BLE bootloader, which relocates the bootloader so the softdevice doesn't overwrite it. Please see:
4+
5+
https://docs.arduino.cc/tutorials/nano-33-ble/getting-started-omv
6+
7+
### Via Arduino bootloader and BOSSA
8+
9+
Download BOSSA from https://github.com/shumatech/BOSSA/ and double tap reset button to enter the Arduino bootloader
10+
11+
```bash
12+
bossac -e -w --offset=0x16000 --port=ttyACM0 -i -d -U -R build-arduino_nano_33_ble_sense-s140/firmware.bin
13+
```
14+
15+
Alternatively, a Linux binary can be found here: https://github.com/openmv/openmv/blob/master/tools/bossac
16+
17+
### Via nrfprog
18+
19+
This board can also be programmed via nrfjprog (with Jlink for example), from MicroPython source repository:
20+
21+
```bash
22+
make -j8 BOARD=arduino_nano_33_ble_sense SD=s140 deploy
23+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include("$(PORT_DIR)/modules/manifest.py")
2+
freeze("$(MPY_DIR)/drivers/", "hts221.py")
3+
freeze("$(MPY_DIR)/drivers/", "lps22h.py")
4+
freeze("$(MPY_DIR)/drivers/", "lsm9ds1.py")
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
* The MIT License (MIT)
4+
* Copyright (c) 2022 Arduino SA
5+
*/
6+
7+
#define MICROPY_HW_BOARD_NAME "Arduino Nano 33 BLE Sense"
8+
#define MICROPY_HW_MCU_NAME "NRF52840"
9+
10+
#define MICROPY_MBFS (1)
11+
12+
#define MICROPY_BOARD_EARLY_INIT NANO33_board_early_init
13+
#define MICROPY_BOARD_DEINIT NANO33_board_deinit
14+
#define MICROPY_BOARD_ENTER_BOOTLOADER(nargs, args) NANO33_board_enter_bootloader()
15+
16+
#define MICROPY_PY_MACHINE_UART (1)
17+
#define MICROPY_PY_MACHINE_HW_PWM (1)
18+
#define MICROPY_PY_MACHINE_HW_SPI (1)
19+
#define MICROPY_PY_MACHINE_TIMER (1)
20+
#define MICROPY_PY_MACHINE_RTCOUNTER (1)
21+
#define MICROPY_PY_MACHINE_I2C (1)
22+
#define MICROPY_PY_MACHINE_ADC (1)
23+
#define MICROPY_PY_MACHINE_TEMP (1)
24+
25+
#define MICROPY_HW_USB_CDC (1)
26+
#define MICROPY_HW_HAS_LED (1)
27+
#define MICROPY_HW_HAS_SWITCH (0)
28+
#define MICROPY_HW_HAS_FLASH (0)
29+
#define MICROPY_HW_HAS_SDCARD (0)
30+
#define MICROPY_HW_HAS_MMA7660 (0)
31+
#define MICROPY_HW_HAS_LIS3DSH (0)
32+
#define MICROPY_HW_HAS_LCD (0)
33+
#define MICROPY_HW_ENABLE_RNG (1)
34+
#define MICROPY_HW_ENABLE_RTC (1)
35+
#define MICROPY_HW_ENABLE_TIMER (0)
36+
#define MICROPY_HW_ENABLE_SERVO (0)
37+
#define MICROPY_HW_ENABLE_DAC (0)
38+
#define MICROPY_HW_ENABLE_CAN (0)
39+
40+
// LEDs config
41+
#define MICROPY_HW_LED_COUNT (4) // 3 RGB + 1 Yellow
42+
#define MICROPY_HW_LED_PULLUP (1) // RGB LED is active low
43+
#define MICROPY_HW_LED4_PULLUP (0) // Yellow is active high
44+
#define MICROPY_HW_LED1 (24) // RED
45+
#define MICROPY_HW_LED2 (16) // GREEN
46+
#define MICROPY_HW_LED3 (6) // BLUE
47+
#define MICROPY_HW_LED4 (13) // Yellow
48+
#define HELP_TEXT_BOARD_LED "1,2,3,4"
49+
50+
// UART config
51+
#define MICROPY_HW_UART1_TX (32 + 3)
52+
#define MICROPY_HW_UART1_RX (32 + 10)
53+
// #define MICROPY_HW_UART1_CTS (7)
54+
// #define MICROPY_HW_UART1_RTS (5)
55+
// #define MICROPY_HW_UART1_HWFC (1)
56+
57+
// SPI0 config
58+
#define MICROPY_HW_SPI0_NAME "SPI0"
59+
#define MICROPY_HW_SPI0_SCK (13)
60+
#define MICROPY_HW_SPI0_MOSI (32 + 1)
61+
#define MICROPY_HW_SPI0_MISO (32 + 8)
62+
63+
// PWM config
64+
#define MICROPY_HW_PWM0_NAME "PWM0"
65+
#define MICROPY_HW_PWM1_NAME "PWM1"
66+
#define MICROPY_HW_PWM2_NAME "PWM2"
67+
#define MICROPY_HW_PWM3_NAME "PWM3"
68+
69+
#define MICROPY_HW_USB_VID (0x2341)
70+
#define MICROPY_HW_USB_PID (0x025A)
71+
#define MICROPY_HW_USB_CDC_1200BPS_TOUCH (1)
72+
73+
void NANO33_board_early_init(void);
74+
void NANO33_board_deinit(void);
75+
void NANO33_board_enter_bootloader(void);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MCU_SERIES = m4
2+
MCU_VARIANT = nrf52
3+
MCU_SUB_VARIANT = nrf52840
4+
SOFTDEV_VERSION = 6.1.1
5+
SD=s140
6+
7+
LD_FILES += boards/arduino_nano_33_ble_sense/nano_bootloader.ld boards/nrf52840_1M_256k.ld
8+
9+
NRF_DEFINES += -DNRF52840_XXAA
10+
11+
MICROPY_VFS_LFS2 = 1
12+
FROZEN_MANIFEST ?= $(BOARD_DIR)/manifest.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_flash_start = 0xe0000;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
P0,P0
2+
P1,P1
3+
P2,P2,ADC0_IN0
4+
P3,P3,ADC0_IN1
5+
P4,P4,ADC0_IN2
6+
P5,P5,ADC0_IN3
7+
P6,P6
8+
P7,P7
9+
P8,P8
10+
P9,P9
11+
P10,P10
12+
P11,P11
13+
P12,P12
14+
P13,P13
15+
P14,P14
16+
P15,P15
17+
P16,P16
18+
P17,P17
19+
P18,P18
20+
P19,P19
21+
P20,P20
22+
P21,P21
23+
P22,P22
24+
P23,P23
25+
P24,P24
26+
P25,P25
27+
P26,P26
28+
P27,P27
29+
P28,P28,ADC0_IN4
30+
P29,P29,ADC0_IN5
31+
P30,P30,ADC0_IN6
32+
P31,P31,ADC0_IN7
33+
P32,P32
34+
P33,P33
35+
P34,P34
36+
P35,P35
37+
P36,P36
38+
P37,P37
39+
P38,P38
40+
P39,P39
41+
P40,P40
42+
P41,P41
43+
P42,P42
44+
P43,P43
45+
P44,P44
46+
P45,P45
47+
P46,P46
48+
P47,P47
49+
I2C_SCL,P2
50+
I2C_SDA,P31

0 commit comments

Comments
 (0)
0