Skip to content

Commit e0926a4

Browse files
Merge branch 'adafruit:master' into master
2 parents e35ebc4 + 4a2d8dd commit e0926a4

File tree

8 files changed

+84
-73
lines changed

8 files changed

+84
-73
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Bug Report
2-
description: Report a problem with TinyUSB Library
2+
description: Report a problem with the Adafruit nRF52 Arduino Core
33
labels: 'Bug'
44
body:
55
- type: markdown

.github/workflows/githubci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ jobs:
2424
- 'ledglasses_nrf52840'
2525

2626
steps:
27-
- name: Setup Python
28-
uses: actions/setup-python@v4
29-
with:
30-
python-version: '3.x'
31-
3227
- name: Checkout code
3328
uses: actions/checkout@v4
3429
with:

cores/nRF5/Print.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class Print
9898
{
9999
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
100100
}
101+
102+
virtual void flush() { /* Empty implementation for backward compatibility */ }
101103
};
102104

103105
#endif

libraries/Adafruit_TinyUSB_Arduino

libraries/Bluefruit52Lib/src/BLEAdvertising.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ BLEAdvertising::BLEAdvertising(void)
253253
_hdl = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
254254
_type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
255255
_start_if_disconnect = true;
256-
_runnning = false;
256+
_running = false;
257257

258258
_conn_mask = 0;
259259

@@ -321,7 +321,7 @@ void BLEAdvertising::setPeerAddress(const ble_gap_addr_t& peer_addr) {
321321

322322
bool BLEAdvertising::isRunning(void)
323323
{
324-
return _runnning;
324+
return _running;
325325
}
326326

327327
bool BLEAdvertising::setBeacon(BLEBeacon& beacon)
@@ -339,8 +339,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
339339
_start_if_disconnect = enable;
340340
}
341341

342-
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
343-
{
342+
bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout) {
344343
// ADV Params
345344
ble_gap_adv_params_t adv_para = {
346345
.properties = { .type = _type, .anonymous = 0 },
@@ -369,17 +368,24 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
369368
default: break;
370369
}
371370

371+
// stop first if current running since we may change advertising data/params
372+
if (_running) {
373+
sd_ble_gap_adv_stop(_hdl);
374+
}
375+
372376
// gap_adv long-live is required by SD v6
373-
static ble_gap_adv_data_t gap_adv = {
374-
.adv_data = { .p_data = _data, .len = _count },
375-
.scan_rsp_data = { .p_data = Bluefruit.ScanResponse.getData(), .len = Bluefruit.ScanResponse.count() }
376-
};
377+
static ble_gap_adv_data_t gap_adv;
378+
gap_adv.adv_data.p_data = _data;
379+
gap_adv.adv_data.len = _count;
380+
gap_adv.scan_rsp_data.p_data = Bluefruit.ScanResponse.getData();
381+
gap_adv.scan_rsp_data.len = Bluefruit.ScanResponse.count();
382+
377383
VERIFY_STATUS( sd_ble_gap_adv_set_configure(&_hdl, &gap_adv, &adv_para), false );
378384
VERIFY_STATUS( sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, _hdl, Bluefruit.getTxPower() ), false );
379385
VERIFY_STATUS( sd_ble_gap_adv_start(_hdl, CONN_CFG_PERIPHERAL), false );
380386

381387
Bluefruit._startConnLed(); // start blinking
382-
_runnning = true;
388+
_running = true;
383389
_active_interval = interval;
384390

385391
_left_timeout -= min16(_left_timeout, timeout);
@@ -403,7 +409,7 @@ bool BLEAdvertising::stop(void)
403409
{
404410
VERIFY_STATUS( sd_ble_gap_adv_stop(_hdl), false);
405411

406-
_runnning = false;
412+
_running = false;
407413
Bluefruit._stopConnLed(); // stop blinking
408414

409415
return true;
@@ -425,7 +431,7 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
425431
{
426432
bitSet(_conn_mask, conn_hdl);
427433

428-
_runnning = false;
434+
_running = false;
429435
}
430436
}
431437
break;
@@ -436,14 +442,14 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
436442
bitClear(_conn_mask, conn_hdl);
437443

438444
// Auto start if enabled and not connected to any central
439-
if ( !_runnning && _start_if_disconnect ) start(_stop_timeout);
445+
if ( !_running && _start_if_disconnect ) start(_stop_timeout);
440446
}
441447
break;
442448

443449
case BLE_GAP_EVT_ADV_SET_TERMINATED:
444450
if (evt->evt.gap_evt.params.adv_set_terminated.reason == BLE_GAP_EVT_ADV_SET_TERMINATED_REASON_TIMEOUT)
445451
{
446-
_runnning = false;
452+
_running = false;
447453

448454
// If still advertising, it is only in slow mode --> blink normal
449455
Bluefruit.setConnLedInterval(CFG_ADV_BLINKY_INTERVAL);

libraries/Bluefruit52Lib/src/BLEAdvertising.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class BLEAdvertising : public BLEAdvertisingData
154154
uint8_t _hdl;
155155
uint8_t _type;
156156
bool _start_if_disconnect;
157-
bool _runnning;
157+
bool _running;
158158
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
159159

160160
uint32_t _conn_mask;

libraries/InternalFileSytem/src/flash/flash_nrf5x.c

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
#include "delay.h"
3030
#include "rtos.h"
3131

32-
3332
#ifdef NRF52840_XXAA
3433
#define BOOTLOADER_ADDR 0xF4000
3534
#else
3635
#define BOOTLOADER_ADDR 0x74000
3736
#endif
3837

38+
// How many retry attempts when performing flash operations
39+
#define MAX_RETRY 20
40+
3941
// defined in linker script
4042
extern uint32_t __flash_arduino_start[];
4143
//extern uint32_t __flash_arduino_end[];
@@ -44,12 +46,7 @@ extern uint32_t __flash_arduino_start[];
4446
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
4547
//--------------------------------------------------------------------+
4648
static SemaphoreHandle_t _sem = NULL;
47-
48-
void flash_nrf5x_event_cb (uint32_t event)
49-
{
50-
// if (event != NRF_EVT_FLASH_OPERATION_SUCCESS) LOG_LV1("IFLASH", "Flash op Failed");
51-
if ( _sem ) xSemaphoreGive(_sem);
52-
}
49+
static uint32_t _flash_op_result = NRF_EVT_FLASH_OPERATION_SUCCESS;
5350

5451
// Flash Abstraction Layer
5552
static bool fal_erase (uint32_t addr);
@@ -70,6 +67,31 @@ static flash_cache_t _cache =
7067
.cache_buf = _cache_buffer
7168
};
7269

70+
void flash_nrf5x_event_cb (uint32_t event) {
71+
if ( _sem ) {
72+
// Record the result, for consumption by fal_erase or fal_program
73+
// Used to reattempt failed operations
74+
_flash_op_result = event;
75+
76+
// Signal to fal_erase or fal_program that our async flash op is now complete
77+
xSemaphoreGive(_sem);
78+
}
79+
}
80+
81+
// When soft device is enabled, flash ops are async
82+
// Eventual success is reported via callback, which we await
83+
static uint32_t wait_for_async_flash_op_completion(void) {
84+
uint8_t sd_en = 0;
85+
(void) sd_softdevice_is_enabled(&sd_en);
86+
87+
if (sd_en) {
88+
xSemaphoreTake(_sem, portMAX_DELAY);
89+
return (_flash_op_result == NRF_EVT_FLASH_OPERATION_SUCCESS) ? NRF_SUCCESS : NRF_ERROR_TIMEOUT;
90+
} else {
91+
return NRF_SUCCESS;
92+
}
93+
}
94+
7395
//--------------------------------------------------------------------+
7496
// Application API
7597
//--------------------------------------------------------------------+
@@ -105,62 +127,48 @@ bool flash_nrf5x_erase(uint32_t addr)
105127
static bool fal_erase (uint32_t addr)
106128
{
107129
// Init semaphore for first call
108-
if ( _sem == NULL )
109-
{
110-
_sem = xSemaphoreCreateCounting(10, 0);
130+
if ( _sem == NULL ) {
131+
_sem = xSemaphoreCreateBinary();
111132
VERIFY(_sem);
112133
}
113134

114-
// retry if busy
115-
uint32_t err;
116-
while ( NRF_ERROR_BUSY == (err = sd_flash_page_erase(addr / FLASH_NRF52_PAGE_SIZE)) )
117-
{
135+
// Erase the page: Multiple attempts if needed
136+
for (uint8_t attempt = 0; attempt < MAX_RETRY; ++attempt) {
137+
if (NRF_SUCCESS == sd_flash_page_erase(addr / FLASH_NRF52_PAGE_SIZE)) {
138+
if (NRF_SUCCESS == wait_for_async_flash_op_completion()) {
139+
return true;
140+
}
141+
}
118142
delay(1);
119143
}
120-
VERIFY_STATUS(err, false);
121-
122-
// wait for async event if SD is enabled
123-
uint8_t sd_en = 0;
124-
(void) sd_softdevice_is_enabled(&sd_en);
125-
126-
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
127-
128-
return true;
144+
return false;
129145
}
130146

131-
static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len)
132-
{
133-
// wait for async event if SD is enabled
134-
uint8_t sd_en = 0;
135-
(void) sd_softdevice_is_enabled(&sd_en);
136-
137-
uint32_t err;
138-
139-
// Somehow S140 v6.1.1 assert an error when writing a whole page
140-
// https://devzone.nordicsemi.com/f/nordic-q-a/40088/sd_flash_write-cause-nrf_fault_id_sd_assert
141-
// Workaround: write half page at a time.
142-
#if NRF52832_XXAA
143-
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len/4)) )
144-
{
147+
// helper for fal_program()
148+
static bool fal_sub_program(uint32_t dst, void const * src, uint32_t len) {
149+
for (uint8_t attempt = 0; attempt < MAX_RETRY; ++attempt) {
150+
if (NRF_SUCCESS == sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len/4)) {
151+
if (NRF_SUCCESS == wait_for_async_flash_op_completion()) {
152+
return true;
153+
}
154+
}
145155
delay(1);
146156
}
147-
VERIFY_STATUS(err, 0);
157+
return false;
158+
}
148159

149-
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
160+
static uint32_t fal_program (uint32_t dst, void const * src, uint32_t len) {
161+
#if NRF52832_XXAA
162+
VERIFY(fal_sub_program(dst, src, len), 0);
150163
#else
151-
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) dst, (uint32_t const *) src, len/8)) )
152-
{
153-
delay(1);
154-
}
155-
VERIFY_STATUS(err, 0);
156-
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
164+
// Somehow S140 v6.1.1 assert an error when writing a whole page
165+
// https://devzone.nordicsemi.com/f/nordic-q-a/40088/sd_flash_write-cause-nrf_fault_id_sd_assert
166+
// Workaround: write half page at a time.
167+
VERIFY(fal_sub_program(dst, src, len/2), 0); // 1st half
157168

158-
while ( NRF_ERROR_BUSY == (err = sd_flash_write((uint32_t*) (dst+ len/2), (uint32_t const *) (src + len/2), len/8)) )
159-
{
160-
delay(1);
161-
}
162-
VERIFY_STATUS(err, 0);
163-
if ( sd_en ) xSemaphoreTake(_sem, portMAX_DELAY);
169+
dst += len/2;
170+
src += len/2;
171+
VERIFY(fal_sub_program(dst, src, len/2), 0); // 2nd half
164172
#endif
165173

166174
return len;

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818

1919
name=Adafruit nRF52 Boards
20-
version=1.6.1
20+
version=1.7.0
2121

2222
# Compile variables
2323
# -----------------

0 commit comments

Comments
 (0)