Skip to content

Commit 1103490

Browse files
authored
Merge pull request #2244 from dhalbert/itsybitsy_nrf52840_express
Initial Itsy nRF52840 defn
2 parents 2b02750 + d0044c7 commit 1103490

File tree

8 files changed

+206
-12
lines changed

8 files changed

+206
-12
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
- "hallowing_m4_express"
111111
- "itsybitsy_m0_express"
112112
- "itsybitsy_m4_express"
113+
- "itsybitsy_nrf52840_express"
113114
- "kicksat-sprite"
114115
- "makerdiary_nrf52840_mdk"
115116
- "makerdiary_nrf52840_mdk_usb_dongle"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
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 "boards/board.h"
28+
29+
void board_init(void) {
30+
}
31+
32+
bool board_requests_safe_mode(void) {
33+
return false;
34+
}
35+
36+
void reset_board(void) {
37+
38+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "nrfx/hal/nrf_gpio.h"
2+
3+
#define MICROPY_HW_BOARD_NAME "Adafruit ItsyBitsy nRF52840 Express"
4+
#define MICROPY_HW_MCU_NAME "nRF52840"
5+
#define MICROPY_PY_SYS_PLATFORM "ItsyBitsy52840Express"
6+
7+
#define FLASH_SIZE (0x100000)
8+
#define FLASH_PAGE_SIZE (4096)
9+
10+
#define MICROPY_HW_LED_STATUS (&pin_P0_06)
11+
12+
#define MICROPY_HW_APA102_MOSI (&pin_P0_08)
13+
#define MICROPY_HW_APA102_SCK (&pin_P1_09)
14+
15+
#if QSPI_FLASH_FILESYSTEM
16+
#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 21)
17+
#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 22)
18+
#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(1, 00)
19+
#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(0, 17)
20+
#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(0, 19)
21+
#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(0, 23)
22+
#endif
23+
24+
#if SPI_FLASH_FILESYSTEM
25+
#define SPI_FLASH_MOSI_PIN &pin_P0_21
26+
#define SPI_FLASH_MISO_PIN &pin_P0_22
27+
#define SPI_FLASH_SCK_PIN &pin_P0_19
28+
#define SPI_FLASH_CS_PIN &pin_P0_23
29+
#endif
30+
31+
#define CIRCUITPY_AUTORELOAD_DELAY_MS 500
32+
33+
#define CIRCUITPY_INTERNAL_NVM_SIZE (4096)
34+
35+
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE)
36+
37+
#define BOARD_HAS_CRYSTAL 1
38+
39+
#define DEFAULT_I2C_BUS_SCL (&pin_P0_14)
40+
#define DEFAULT_I2C_BUS_SDA (&pin_P0_16)
41+
42+
#define DEFAULT_SPI_BUS_SCK (&pin_P0_13)
43+
#define DEFAULT_SPI_BUS_MOSI (&pin_P0_15)
44+
#define DEFAULT_SPI_BUS_MISO (&pin_P0_20)
45+
46+
#define DEFAULT_UART_BUS_RX (&pin_P0_25)
47+
#define DEFAULT_UART_BUS_TX (&pin_P0_24)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x8052
3+
USB_PRODUCT = "ItsyBitsy nRF52840 Express"
4+
USB_MANUFACTURER = "Adafruit Industries LLC"
5+
6+
MCU_SERIES = m4
7+
MCU_VARIANT = nrf52
8+
MCU_SUB_VARIANT = nrf52840
9+
MCU_CHIP = nrf52840
10+
SD ?= s140
11+
SOFTDEV_VERSION ?= 6.1.0
12+
13+
BOOT_SETTING_ADDR = 0xFF000
14+
15+
ifeq ($(SD),)
16+
LD_FILE = boards/nrf52840_1M_256k.ld
17+
else
18+
LD_FILE = boards/adafruit_$(MCU_SUB_VARIANT)_$(SD_LOWER)_v$(firstword $(subst ., ,$(SOFTDEV_VERSION))).ld
19+
CIRCUITPY_BLEIO = 1
20+
endif
21+
22+
NRF_DEFINES += -DNRF52840_XXAA -DNRF52840
23+
24+
# Don't use up a hardware SPI peripheral for the status DotStar: we only have one or two.
25+
CIRCUITPY_BITBANG_APA102 = 1
26+
27+
QSPI_FLASH_FILESYSTEM = 1
28+
EXTERNAL_FLASH_DEVICE_COUNT = 1
29+
EXTERNAL_FLASH_DEVICES = "GD25Q16C"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
4+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_P0_04) },
5+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_P0_30) },
6+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_P0_28) },
7+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_P0_31) },
8+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_P0_02) },
9+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_P0_03) },
10+
11+
{ MP_ROM_QSTR(MP_QSTR_SWITCH), MP_ROM_PTR(&pin_P0_29) },
12+
13+
{ MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_P0_25) },
14+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_P0_25) },
15+
16+
{ MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P0_24) },
17+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_P0_24) },
18+
19+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P1_02) },
20+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_P0_27) },
21+
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_P1_08) },
22+
{ MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_P0_07) },
23+
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_P0_05) },
24+
{ MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_P0_26) },
25+
{ MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_P0_11) },
26+
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_P0_12) },
27+
28+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_14) },
29+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_16) },
30+
31+
{ MP_ROM_QSTR(MP_QSTR_APA102_MOSI), MP_ROM_PTR(&pin_P0_08) },
32+
{ MP_ROM_QSTR(MP_QSTR_APA102_SCK), MP_ROM_PTR(&pin_P1_09) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_13) },
35+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P0_15) },
36+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P0_20) },
37+
38+
{ MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_P0_06) },
39+
{ MP_ROM_QSTR(MP_QSTR_BLUE_LED), MP_ROM_PTR(&pin_P0_06) },
40+
41+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
42+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
43+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
44+
};
45+
46+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/nrf/common-hal/microcontroller/Pin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ void reset_pin_number(uint8_t pin_number) {
9191
}
9292
#endif
9393
#ifdef MICROPY_HW_APA102_MOSI
94-
if (pin == MICROPY_HW_APA102_MOSI->number ||
95-
pin == MICROPY_HW_APA102_SCK->number) {
94+
if (pin_number == MICROPY_HW_APA102_MOSI->number ||
95+
pin_number == MICROPY_HW_APA102_SCK->number) {
9696
apa102_mosi_in_use = apa102_mosi_in_use && pin_number != MICROPY_HW_APA102_MOSI->number;
9797
apa102_sck_in_use = apa102_sck_in_use && pin_number != MICROPY_HW_APA102_SCK->number;
9898
if (!apa102_sck_in_use && !apa102_mosi_in_use) {

shared-module/bitbangio/SPI.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,20 @@ void shared_module_bitbangio_spi_construct(bitbangio_spi_obj_t *self,
4343
if (result != DIGITALINOUT_OK) {
4444
mp_raise_ValueError(translate("Clock pin init failed."));
4545
}
46+
common_hal_digitalio_digitalinout_switch_to_output(&self->clock, self->polarity == 1, DRIVE_MODE_PUSH_PULL);
47+
4648
if (mosi != mp_const_none) {
4749
result = common_hal_digitalio_digitalinout_construct(&self->mosi, mosi);
4850
if (result != DIGITALINOUT_OK) {
4951
common_hal_digitalio_digitalinout_deinit(&self->clock);
5052
mp_raise_ValueError(translate("MOSI pin init failed."));
5153
}
5254
self->has_mosi = true;
55+
common_hal_digitalio_digitalinout_switch_to_output(&self->mosi, false, DRIVE_MODE_PUSH_PULL);
5356
}
57+
5458
if (miso != mp_const_none) {
59+
// Starts out as input by default, no need to change.
5560
result = common_hal_digitalio_digitalinout_construct(&self->miso, miso);
5661
if (result != DIGITALINOUT_OK) {
5762
common_hal_digitalio_digitalinout_deinit(&self->clock);

supervisor/shared/rgb_led_status.c

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,18 @@ static uint8_t status_apa102_color[APA102_BUFFER_LENGTH] = {0, 0, 0, 0, 0xff, 0,
4646
#if CIRCUITPY_BITBANG_APA102
4747
#include "shared-bindings/bitbangio/SPI.h"
4848
#include "shared-module/bitbangio/types.h"
49-
static bitbangio_spi_obj_t status_apa102;
49+
static bitbangio_spi_obj_t status_apa102 = {
50+
.base = {
51+
.type = &bitbangio_spi_type,
52+
},
53+
};
5054
#else
5155
#include "shared-bindings/busio/SPI.h"
52-
busio_spi_obj_t status_apa102;
56+
busio_spi_obj_t status_apa102 = {
57+
.base = {
58+
.type = &busio_spi_type,
59+
},
60+
};
5361
#endif
5462
#endif
5563

@@ -59,9 +67,21 @@ busio_spi_obj_t status_apa102;
5967
#include "shared-bindings/pulseio/PWMOut.h"
6068
#include "shared-bindings/microcontroller/Pin.h"
6169

62-
pulseio_pwmout_obj_t rgb_status_r;
63-
pulseio_pwmout_obj_t rgb_status_g;
64-
pulseio_pwmout_obj_t rgb_status_b;
70+
pulseio_pwmout_obj_t rgb_status_r = {
71+
.base = {
72+
.type = &pulseio_pwmout_type,
73+
},
74+
};
75+
pulseio_pwmout_obj_t rgb_status_g = {
76+
.base = {
77+
.type = &pulseio_pwmout_type,
78+
},
79+
};
80+
pulseio_pwmout_obj_t rgb_status_b = {
81+
.base = {
82+
.type = &pulseio_pwmout_type,
83+
},
84+
};
6585

6686
uint8_t rgb_status_brightness = 0xFF;
6787

@@ -74,8 +94,14 @@ uint16_t status_rgb_color[3] = {
7494
static uint32_t current_status_color = 0;
7595
#endif
7696

77-
97+
static bool rgb_led_status_init_in_progress = false;
7898
void rgb_led_status_init() {
99+
if (rgb_led_status_init_in_progress) {
100+
// Avoid recursion.
101+
return;
102+
}
103+
rgb_led_status_init_in_progress = true;
104+
79105
#ifdef MICROPY_HW_NEOPIXEL
80106
common_hal_digitalio_digitalinout_construct(&status_neopixel, MICROPY_HW_NEOPIXEL);
81107
// Pretend we aren't using the pins. digitalio.DigitalInOut
@@ -91,15 +117,15 @@ void rgb_led_status_init() {
91117
mp_const_none);
92118
#else
93119
if (!common_hal_busio_spi_deinited(&status_apa102)) {
94-
// Don't use spi_deinit because that leads to infinite
95-
// recursion because reset_pin_number may call
96-
// rgb_led_status_init.
97-
spi_m_sync_disable(&status_apa102.spi_desc);
120+
// This may call us recursively if reset_pin_number() is called,
121+
// The rgb_led_status_init_in_progress guard will prevent further recursion.
122+
common_hal_busio_spi_deinit(&status_apa102);
98123
}
99124
common_hal_busio_spi_construct(&status_apa102,
100125
MICROPY_HW_APA102_SCK,
101126
MICROPY_HW_APA102_MOSI,
102127
mp_const_none);
128+
common_hal_busio_spi_never_reset(&status_apa102);
103129
#endif
104130
// Pretend we aren't using the pins. bitbangio.SPI will
105131
// mark them as used.
@@ -149,6 +175,8 @@ void rgb_led_status_init() {
149175
current_status_color = 0x1000000; // Not a valid color
150176
new_status_color(rgb);
151177
#endif
178+
179+
rgb_led_status_init_in_progress = false;
152180
}
153181

154182
void reset_status_led() {

0 commit comments

Comments
 (0)