Skip to content

Commit e16f80b

Browse files
authored
Merge branch 'master' into develop
2 parents b99144d + 1f0a587 commit e16f80b

File tree

214 files changed

+104554
-23154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+104554
-23154
lines changed

.github/workflows/githubci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ jobs:
5252
rm -r $HOME/$BSP_PATH/*
5353
ln -s $GITHUB_WORKSPACE $HOME/$BSP_PATH/$BSP_VERSION
5454
# Install library dependency
55-
arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit Arcada Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit nRFCrypto" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "Firmata" "MIDI Library" "SdFat - Adafruit Fork"
55+
arduino-cli lib install "Adafruit AHRS" "Adafruit APDS9960 Library" "Adafruit BMP280 Library" "Adafruit Circuit Playground" "Adafruit EPD" "Adafruit GFX Library" "Adafruit HX8357 Library" "Adafruit ILI9341" "Adafruit LIS3MDL" "Adafruit LSM6DS" "Adafruit NeoPixel" "Adafruit NeoMatrix" "Adafruit nRFCrypto" "Adafruit Sensor Calibration" "Adafruit SHT31 Library" "Adafruit SSD1306" "Adafruit ST7735 and ST7789 Library" "Firmata" "SdFat - Adafruit Fork"
56+
57+
# TODO update to support MIDI version 5 later on
58+
arduino-cli lib install "MIDI Library"@4.3.1
5659
5760
- name: Build examples
5861
run: python3 tools/build_all.py ${{ matrix.arduino-platform }}

boards.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ feather52832.build.f_cpu=64000000
4040
feather52832.build.board=NRF52832_FEATHER
4141
feather52832.build.core=nRF5
4242
feather52832.build.variant=feather_nrf52832
43-
feather52840.build.usb_manufacturer="Adafruit LLC"
44-
feather52840.build.usb_product="Feather nRF52832"
43+
feather52832.build.usb_manufacturer="Adafruit LLC"
44+
feather52832.build.usb_product="Feather nRF52832"
4545
feather52832.build.extra_flags=-DNRF52832_XXAA -DNRF52
4646
feather52832.build.ldscript=nrf52832_s132_v6.ld
4747

@@ -60,6 +60,7 @@ feather52832.menu.debug.l2=Level 2 (Full Debug)
6060
feather52832.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
6161
feather52832.menu.debug.l3=Level 3 (Segger SystemView)
6262
feather52832.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
63+
feather52832.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
6364

6465
# ----------------------------------
6566
# Bluefruit Feather nRF52840 Express
@@ -113,6 +114,7 @@ feather52840.menu.debug.l2=Level 2 (Full Debug)
113114
feather52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
114115
feather52840.menu.debug.l3=Level 3 (Segger SystemView)
115116
feather52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
117+
feather52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
116118

117119

118120
# ----------------------------------
@@ -167,6 +169,7 @@ feather52840sense.menu.debug.l2=Level 2 (Full Debug)
167169
feather52840sense.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
168170
feather52840sense.menu.debug.l3=Level 3 (Segger SystemView)
169171
feather52840sense.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
172+
feather52840sense.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
170173

171174

172175
# ---------------------------------------------
@@ -221,6 +224,7 @@ itsybitsy52840.menu.debug.l2=Level 2 (Full Debug)
221224
itsybitsy52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
222225
itsybitsy52840.menu.debug.l3=Level 3 (Segger SystemView)
223226
itsybitsy52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
227+
itsybitsy52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
224228

225229
# ---------------------------------------------
226230
# Bluefruit Circuit Playground nRF52840 Express
@@ -274,6 +278,7 @@ cplaynrf52840.menu.debug.l2=Level 2 (Full Debug)
274278
cplaynrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
275279
cplaynrf52840.menu.debug.l3=Level 3 (Segger SystemView)
276280
cplaynrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
281+
cplaynrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
277282

278283

279284
# ---------------------------------------------
@@ -298,7 +303,7 @@ cluenrf52840.upload.protocol=nrfutil
298303
cluenrf52840.upload.use_1200bps_touch=true
299304
cluenrf52840.upload.wait_for_upload_port=true
300305
cluenrf52840.upload.maximum_size=815104
301-
cluenrf52840.upload.maximum_data_size=248832
306+
cluenrf52840.upload.maximum_data_size=237568
302307

303308
# Build
304309
cluenrf52840.build.mcu=cortex-m4
@@ -328,6 +333,7 @@ cluenrf52840.menu.debug.l2=Level 2 (Full Debug)
328333
cluenrf52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
329334
cluenrf52840.menu.debug.l3=Level 3 (Segger SystemView)
330335
cluenrf52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
336+
cluenrf52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
331337

332338
# ----------------------------------
333339
# Bluefruit Metro nRF52840 Express
@@ -381,6 +387,7 @@ metro52840.menu.debug.l2=Level 2 (Full Debug)
381387
metro52840.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
382388
metro52840.menu.debug.l3=Level 3 (Segger SystemView)
383389
metro52840.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
390+
metro52840.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
384391

385392

386393

@@ -434,6 +441,7 @@ pca10056.menu.debug.l2=Level 2 (Full Debug)
434441
pca10056.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
435442
pca10056.menu.debug.l3=Level 3 (Segger SystemView)
436443
pca10056.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
444+
pca10056.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
437445

438446
# ----------------------------------
439447
# Particle Xenon
@@ -457,7 +465,7 @@ particle_xenon.upload.protocol=nrfutil
457465
particle_xenon.upload.use_1200bps_touch=true
458466
particle_xenon.upload.wait_for_upload_port=true
459467
particle_xenon.upload.maximum_size=815104
460-
particle_xenon.upload.maximum_data_size=248832
468+
particle_xenon.upload.maximum_data_size=237568
461469

462470
# Build
463471
particle_xenon.build.mcu=cortex-m4
@@ -487,6 +495,7 @@ particle_xenon.menu.debug.l2=Level 2 (Full Debug)
487495
particle_xenon.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
488496
particle_xenon.menu.debug.l3=Level 3 (Segger SystemView)
489497
particle_xenon.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
498+
particle_xenon.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1
490499

491500
# ----------------------------------
492501
# Raytac MDBT50Q - RX
@@ -510,7 +519,7 @@ mdbt50qrx.upload.protocol=nrfutil
510519
mdbt50qrx.upload.use_1200bps_touch=true
511520
mdbt50qrx.upload.wait_for_upload_port=true
512521
mdbt50qrx.upload.maximum_size=815104
513-
mdbt50qrx.upload.maximum_data_size=248832
522+
mdbt50qrx.upload.maximum_data_size=237568
514523

515524
# Build
516525
mdbt50qrx.build.mcu=cortex-m4
@@ -540,3 +549,4 @@ mdbt50qrx.menu.debug.l2=Level 2 (Full Debug)
540549
mdbt50qrx.menu.debug.l2.build.debug_flags=-DCFG_DEBUG=2
541550
mdbt50qrx.menu.debug.l3=Level 3 (Segger SystemView)
542551
mdbt50qrx.menu.debug.l3.build.debug_flags=-DCFG_DEBUG=3
552+
mdbt50qrx.menu.debug.l3.build.sysview_flags=-DCFG_SYSVIEW=1

changelog.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Adafruit nRF52 Arduino Core Changelog
22

3-
## 0.20.0
3+
## 0.21.0
44

55
This version implement comprehensive LESC and Legacy pairing using dynamic & staic Passkey.
66

@@ -50,6 +50,30 @@ A new class BLESecurity (access with Bluefruit.Security) is added to handle secu
5050
- **cental_pairing** similar to pairing_passkey but for nRF running central role
5151
- **ancs_arcada** for displaying ancs on arcada such CLUE and/or CPB.
5252

53+
## 0.20.5 - 2020.07.05
54+
55+
- Updated toolchain from gcc 7-2017q4 to 9-2019q4
56+
- Fixed GPIOTE channel conflict between libraries
57+
- Added type-safe for arrcount() macros
58+
- Added truncate() and rename() to Internal Filesystem (LittleFS).
59+
- Update CMSIS from v4 to v5 to build with TensorFlow
60+
- Update TinyUSB core to commit 0749077
61+
62+
Special thanks to @henrygab, @pyro9, @geeksville for contributing and helping with this release.
63+
64+
## 0.20.1 - 2020.04.23
65+
66+
- Update TinyUSB to commit c59fa77 due to a bug in the stack
67+
68+
## 0.20.0 - 2020.04.21
69+
70+
- Fixed Wire write ambiguous
71+
- Improved debugging with log and sysview, thanks to @henrygab
72+
- Fixed recipe to compute SRAM and ROM of sketch
73+
- Removed the force waiting Serial when debug is enabled
74+
- Updated nrfx to v2.1.0
75+
- Updated TinyUSB to commit 718db7e
76+
5377
## 0.19.0 - 2020.03.12
5478

5579
- Add BLECharacteristic::isFixedLen()

cores/nRF5/TinyUSB/Adafruit_TinyUSB_nRF.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030
#include "Arduino.h"
3131
#include "Adafruit_TinyUSB_Core.h"
3232

33+
//--------------------------------------------------------------------+
34+
// Forward USB interrupt events to TinyUSB IRQ Handler
35+
//--------------------------------------------------------------------+
36+
extern "C" void USBD_IRQHandler(void)
37+
{
38+
#if CFG_SYSVIEW
39+
SEGGER_SYSVIEW_RecordEnterISR();
40+
#endif
41+
42+
tud_int_handler(0);
43+
44+
#if CFG_SYSVIEW
45+
SEGGER_SYSVIEW_RecordExitISR();
46+
#endif
47+
}
48+
3349
//--------------------------------------------------------------------+
3450
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3551
//--------------------------------------------------------------------+
@@ -106,15 +122,6 @@ void Adafruit_TinyUSB_Core_touch1200(void)
106122
//--------------------------------------------------------------------+
107123
// Adafruit_USBD_Device platform dependent
108124
//--------------------------------------------------------------------+
109-
void Adafruit_USBD_Device::detach(void)
110-
{
111-
NRF_USBD->USBPULLUP = 0;
112-
}
113-
114-
void Adafruit_USBD_Device::attach(void)
115-
{
116-
NRF_USBD->USBPULLUP = 1;
117-
}
118125

119126
uint8_t Adafruit_USBD_Device::getSerialDescriptor(uint16_t* serial_str)
120127
{

cores/nRF5/TinyUSB/tusb_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
#define CFG_TUD_HID_BUFSIZE 64
6969

7070
// MIDI FIFO size of TX and RX
71-
#define CFG_TUD_MIDI_RX_BUFSIZE 64
72-
#define CFG_TUD_MIDI_TX_BUFSIZE 64
71+
#define CFG_TUD_MIDI_RX_BUFSIZE 128
72+
#define CFG_TUD_MIDI_TX_BUFSIZE 128
7373

7474
// Vendor FIFO size of TX and RX
7575
#define CFG_TUD_VENDOR_RX_BUFSIZE 64

cores/nRF5/WInterrupts.c

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "Arduino.h"
2323
#include "wiring_private.h"
24+
#include "nrf_gpiote.h"
2425

2526
#include <string.h>
2627

@@ -95,25 +96,59 @@ int attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
9596
return 0;
9697
}
9798

98-
for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
99-
if (channelMap[ch] == -1 || (uint32_t)channelMap[ch] == pin) {
100-
channelMap[ch] = pin;
101-
callbacksInt[ch] = callback;
102-
callbackDeferred[ch] = deferred;
103-
104-
NRF_GPIOTE->CONFIG[ch] &= ~(GPIOTE_CONFIG_PORT_PIN_Msk | GPIOTE_CONFIG_POLARITY_Msk);
105-
NRF_GPIOTE->CONFIG[ch] |= ((pin << GPIOTE_CONFIG_PSEL_Pos) & GPIOTE_CONFIG_PORT_PIN_Msk) |
106-
((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk);
99+
// All information for the configuration is known, except the prior values
100+
// of the config register. Pre-compute the mask and new bits for later use.
101+
// CONFIG[n] = (CONFIG[n] & oldRegMask) | newRegBits;
102+
//
103+
// Three fields are configured here: PORT/PIN, POLARITY, MODE
104+
const uint32_t oldRegMask = ~(GPIOTE_CONFIG_PORT_PIN_Msk | GPIOTE_CONFIG_POLARITY_Msk | GPIOTE_CONFIG_MODE_Msk);
105+
const uint32_t newRegBits =
106+
((pin << GPIOTE_CONFIG_PSEL_Pos ) & GPIOTE_CONFIG_PORT_PIN_Msk) |
107+
((polarity << GPIOTE_CONFIG_POLARITY_Pos) & GPIOTE_CONFIG_POLARITY_Msk) |
108+
((GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos ) & GPIOTE_CONFIG_MODE_Msk ) ;
109+
110+
int ch = -1;
111+
int newChannel = 0;
112+
113+
// Find channel where pin is already assigned, if any
114+
for (int i = 0; i < NUMBER_OF_GPIO_TE; i++) {
115+
if ((uint32_t)channelMap[i] != pin) continue;
116+
ch = i;
117+
break;
118+
}
119+
// else, find one not already mapped and also not in use by others
120+
if (ch == -1) {
121+
for (int i = 0; i < NUMBER_OF_GPIO_TE; i++) {
122+
if (channelMap[i] != -1) continue;
123+
if (nrf_gpiote_te_is_enabled(NRF_GPIOTE, i)) continue;
124+
125+
ch = i;
126+
newChannel = 1;
127+
break;
128+
}
129+
}
130+
// if no channel found, exit
131+
if (ch == -1) {
132+
return 0; // no channel available
133+
}
107134

108-
NRF_GPIOTE->CONFIG[ch] |= GPIOTE_CONFIG_MODE_Event;
135+
channelMap[ch] = pin; // harmless for existing channel
136+
callbacksInt[ch] = callback; // caller might be updating this for existing channel
137+
callbackDeferred[ch] = deferred; // caller might be updating this for existing channel
109138

110-
NRF_GPIOTE->INTENSET = (1 << ch);
139+
uint32_t tmp = NRF_GPIOTE->CONFIG[ch];
140+
tmp &= oldRegMask;
141+
tmp |= newRegBits; // for existing channel, effectively updates only the polarity
142+
NRF_GPIOTE->CONFIG[ch] = tmp;
111143

112-
return (1 << ch);
113-
}
144+
// For a new channel, additionally ensure no old events existed, and enable the interrupt
145+
if (newChannel) {
146+
NRF_GPIOTE->EVENTS_IN[ch] = 0;
147+
NRF_GPIOTE->INTENSET = (1 << ch);
114148
}
115149

116-
return 0;
150+
// Finally, indicate to caller the allocated / updated channel
151+
return (1 << ch);
117152
}
118153

119154
/*
@@ -129,49 +164,58 @@ void detachInterrupt(uint32_t pin)
129164

130165
for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
131166
if ((uint32_t)channelMap[ch] == pin) {
167+
NRF_GPIOTE->INTENCLR = (1 << ch);
168+
NRF_GPIOTE->CONFIG[ch] = 0;
169+
NRF_GPIOTE->EVENTS_IN[ch] = 0; // clear any final events
170+
171+
// now cleanup the rest of the use of the channel
132172
channelMap[ch] = -1;
133173
callbacksInt[ch] = NULL;
134174
callbackDeferred[ch] = false;
135-
136-
NRF_GPIOTE->CONFIG[ch] &= ~GPIOTE_CONFIG_MODE_Event;
137-
138-
NRF_GPIOTE->INTENCLR = (1 << ch);
139-
140175
break;
141176
}
142177
}
143178
}
144179

145180
void GPIOTE_IRQHandler()
146181
{
147-
#if CFG_DEBUG >= 3
182+
#if CFG_SYSVIEW
148183
SEGGER_SYSVIEW_RecordEnterISR();
149184
#endif
150185

151-
uint32_t event = offsetof(NRF_GPIOTE_Type, EVENTS_IN[0]);
152-
186+
// Read this once (not 8x), as it's a volatile read
187+
// across the AHB, which adds up to 3 cycles.
188+
uint32_t const enabledInterruptMask = NRF_GPIOTE->INTENSET;
153189
for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
154-
if ((*(uint32_t *)((uint32_t)NRF_GPIOTE + event) == 0x1UL) && (NRF_GPIOTE->INTENSET & (1 << ch))) {
155-
if (channelMap[ch] != -1 && callbacksInt[ch]) {
156-
if ( callbackDeferred[ch] ) {
157-
// Adafruit defer callback to non-isr if configured so
158-
ada_callback(NULL, 0, callbacksInt[ch]);
159-
}else{
160-
callbacksInt[ch]();
161-
}
190+
// only process where the interrupt is enabled and the event register is set
191+
// check interrupt enabled mask first, as already read that IOM value, to
192+
// reduce delays from AHB (16MHz) reads.
193+
if ( 0 == (enabledInterruptMask & (1 << ch))) continue;
194+
if ( 0 == NRF_GPIOTE->EVENTS_IN[ch]) continue;
195+
196+
// If the event was set and interrupts are enabled,
197+
// call the callback function only if it exists,
198+
// but ALWAYS clear the event to prevent an interrupt storm.
199+
if (channelMap[ch] != -1 && callbacksInt[ch]) {
200+
if ( callbackDeferred[ch] ) {
201+
// Adafruit defer callback to non-isr if configured so
202+
ada_callback(NULL, 0, callbacksInt[ch]);
203+
} else {
204+
callbacksInt[ch]();
162205
}
163-
164-
*(uint32_t *)((uint32_t)NRF_GPIOTE + event) = 0;
165-
#if __CORTEX_M == 0x04
166-
volatile uint32_t dummy = *((volatile uint32_t *)((uint32_t)NRF_GPIOTE + event));
167-
(void)dummy;
168-
#endif
169206
}
170207

171-
event = (uint32_t)((uint32_t)event + 4);
208+
// clear the event
209+
NRF_GPIOTE->EVENTS_IN[ch] = 0;
172210
}
211+
#if __CORTEX_M == 0x04
212+
// See note at nRF52840_PS_v1.1.pdf section 6.1.8 ("interrupt clearing")
213+
// See also https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html for why
214+
// using memory barrier instead of read of an unrelated volatile
215+
__DSB(); __NOP();__NOP();__NOP();__NOP();
216+
#endif
173217

174-
#if CFG_DEBUG >= 3
175-
SEGGER_SYSVIEW_RecordExitISR();
218+
#if CFG_SYSVIEW
219+
SEGGER_SYSVIEW_RecordExitISR();
176220
#endif
177221
}

cores/nRF5/WInterrupts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" {
3333

3434
#define ISR_DEFERRED 0x0100
3535

36-
#define DEFAULT 1
36+
//#define DEFAULT 1
3737
#define EXTERNAL 0
3838

3939
typedef void (*voidFuncPtr)(void);

0 commit comments

Comments
 (0)