Skip to content

Commit 7df44a5

Browse files
authored
Merge pull request #47 from adafruit/develop
fix #46 issue with windows 10 build 18.09
2 parents 158c284 + 0cc0289 commit 7df44a5

File tree

10 files changed

+55
-96
lines changed

10 files changed

+55
-96
lines changed

.gitmodules

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[submodule "tinyusb"]
22
path = lib/tinyusb
33
url = https://github.com/hathach/tinyusb.git
4-
branch = develop
54
[submodule "lib/nrfx"]
65
path = lib/nrfx
76
url = https://github.com/NordicSemiconductor/nrfx.git

Makefile

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ SD_HEX = $(SD_PATH)/$(SD_FILENAME)_softdevice.hex
2828
LD_FILE = $(SRC_PATH)/linker/$(SD_NAME)_v$(SD_VER1).ld
2929

3030
MERGED_FNAME = $(OUTPUT_FILENAME)_$(SD_NAME)_$(SD_VERSION)
31-
RELEASE_DIR = bin/$(BOARD)
3231

3332

3433
MK_DIS_FIRMWARE = "$(SD_NAME) $(SD_VERSION)"
@@ -86,7 +85,7 @@ BOARD_LIST = $(sort $(subst .h,,$(subst src/boards/,,$(wildcard src/boards/*.h))
8685
NRF52832_BOARDLIST = feather_nrf52832
8786
IS_52832 = $(filter $(BOARD),$(NRF52832_BOARDLIST))
8887

89-
ifeq ($(filter $(MAKECMDGOALS),all-board all-release help),)
88+
ifeq ($(filter $(MAKECMDGOALS),all-board help),)
9089
ifeq ($(BOARD),)
9190
$(info You must provide a BOARD parameter with 'BOARD=')
9291
$(info Supported boards are: $(BOARD_LIST))
@@ -360,20 +359,11 @@ _make_all_board = $(foreach b,$(BOARD_LIST), $(call _make_board,$b,$1))
360359
all-board:
361360
$(call _make_all_board,clean all)
362361

363-
all-release:
364-
$(call _make_all_board,clean all release)
365-
366362
help:
367-
@echo To flash (with jlink) a pre-built binary with a specific version to a board
368-
@echo $$ make BOARD=feather_nrf52840_express VERSION=6.1.1r0 flash
369-
@echo
370-
@echo To flash (with dfu) a pre-built binary with a specific version to a board
371-
@echo $$ make BOARD=feather_nrf52840_express VERSION=6.1.1r0 SERIAL=/dev/ttyACM0 dfu0-flash
372-
@echo
373363
@echo To compile and build the current code for a board
374364
@echo $$ make BOARD=feather_nrf52840_express all
375365
@echo
376-
@echo To flash current code using jlink
366+
@echo To flash current code using Jlink
377367
@echo $$ make BOARD=feather_nrf52840_express flash
378368
@echo
379369
@echo To flash current code using existing bootloader dfu
@@ -388,35 +378,14 @@ __check_defined = \
388378
$(if $(value $1),, \
389379
$(error Undefined make flag: $1$(if $2, ($2))))
390380

391-
ifeq ($(VERSION),)
392-
393381
# Flash the compiled
394382
flash: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
395383
@echo Flashing: $<
396384
$(NRFJPROG) --program $< --sectoranduicrerase -f nrf52 --reset
397385

398386
dfu-flash: $(BUILD)/$(MERGED_FNAME).zip
399387
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
400-
$(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank
401-
402-
else
403-
404-
ifeq ($(VERSION),latest)
405-
VERSION_FPATH = $(RELEASE_DIR)/$(MERGED_FNAME)
406-
else
407-
VERSION_FPATH = bin/$(BOARD)/$(VERSION)/$(OUTPUT_FILENAME)_$(SD_NAME)_$(VERSION)
408-
endif
409-
410-
# Flash specific version in binary release folder
411-
flash:
412-
@echo Flashing: $(VERSION_FPATH).hex
413-
$(NRFJPROG) --program $(VERSION_FPATH).hex --chiperase -f nrf52 --reset
414-
415-
dfu-flash:
416-
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
417-
$(NRFUTIL) --verbose dfu serial --package $(VERSION_FPATH).zip -p $(SERIAL) -b 115200 --singlebank
418-
419-
endif
388+
$(NRFUTIL) --verbose dfu serial --package $< -p $(SERIAL) -b 115200 --singlebank --touch 1200
420389

421390
sd:
422391
@echo Flashing: $(SD_HEX)
@@ -457,7 +426,7 @@ size: $(BUILD)/$(OUTPUT_FILENAME)-nosd.out
457426

458427

459428
#******************* Binary generator *******************
460-
.phony: genhex genpkg release
429+
.phony: genhex genpkg
461430

462431
## Create binary .hex file from the .out file
463432
genhex: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
@@ -478,11 +447,3 @@ genpkg: $(BUILD)/$(MERGED_FNAME).zip
478447

479448
$(BUILD)/$(MERGED_FNAME).zip: $(BUILD)/$(OUTPUT_FILENAME)-nosd.hex
480449
@$(NRFUTIL) dfu genpkg --dev-type 0x0052 --dev-revision $(DFU_DEV_REV) --bootloader $< --softdevice $(SD_HEX) $@
481-
482-
# Create SD+bootloader combo with hex & dfu package at release folder
483-
release: combinehex genpkg
484-
@echo CR $(RELEASE_DIR)/$(MERGED_FNAME).hex
485-
@echo CR $(RELEASE_DIR)/$(MERGED_FNAME).zip
486-
@mkdir -p $(RELEASE_DIR)
487-
@cp $(BUILD)/$(MERGED_FNAME).hex $(RELEASE_DIR)/$(MERGED_FNAME).hex
488-
@cp $(BUILD)/$(MERGED_FNAME).zip $(RELEASE_DIR)/$(MERGED_FNAME).zip

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,18 @@ To build:
9797
make BOARD=feather_nrf52840_express all combinehex
9898
```
9999

100-
To flash the bootloader:
100+
To flash the bootloader with JLink:
101101

102102
```
103103
make BOARD=feather_nrf52840_express flash
104104
```
105105

106+
To upgrade the bootloader using DFU Serial via port /dev/ttyACM0
107+
108+
```
109+
make BOARD=feather_nrf52840_express SERIAL=/dev/ttyACM0 dfu-flash
110+
```
111+
106112
To flash SoftDevice (and chip erase):
107113

108114
```

lib/sdk11/components/libraries/bootloader_dfu/bootloader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ static void wait_for_events(void)
130130
#ifdef NRF52840_XXAA
131131
// skip if usb is not inited ( e.g OTA / finializing sd/bootloader )
132132
extern bool usb_inited(void);
133-
if ( usb_inited() )
133+
if ( tusb_inited() )
134134
{
135-
tusb_task();
135+
tud_task();
136136
tud_cdc_write_flush();
137137
}
138138
#endif

lib/tinyusb

Submodule tinyusb updated 1050 files

src/flash_nrf5x.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ void flash_nrf5x_flush (bool need_erase)
5353
{
5454
// - nRF52832 dfu via uart can miss incoming byte when erasing because cpu is blocked for > 2ms.
5555
// Since dfu_prepare_func_app_erase() already erase the page for us, we can skip it here.
56-
// - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems. Note MSC uf2
57-
// does not erase page in advance like dfu serial
56+
// - nRF52840 dfu serial/uf2 are USB-based which are DMA and should have no problems.
57+
//
58+
// Note: MSC uf2 does not erase page in advance like dfu serial
5859
if ( need_erase ) nrf_nvmc_page_erase(_fl_addr);
5960

6061
nrf_nvmc_write_words(_fl_addr, (uint32_t *) _fl_buf, FLASH_PAGE_SIZE / 4);

src/usb/msc_uf2.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@
3939

4040
#if CFG_TUD_MSC
4141

42+
#include "bootloader.h"
43+
4244
/*------------------------------------------------------------------*/
4345
/* MACRO TYPEDEF CONSTANT ENUM
4446
*------------------------------------------------------------------*/
4547

4648
/*------------------------------------------------------------------*/
4749
/* UF2
4850
*------------------------------------------------------------------*/
51+
static WriteState _wr_state = { 0 };
52+
4953
void read_block(uint32_t block_no, uint8_t *data);
50-
int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *state*/);
54+
int write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state);
5155

5256
//--------------------------------------------------------------------+
5357
// tinyusb callbacks
@@ -137,7 +141,7 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
137141
uint32_t count = 0;
138142
int wr_ret;
139143

140-
while ( (count < bufsize) && ((wr_ret = write_block(lba, buffer, false)) > 0) )
144+
while ( (count < bufsize) && ((wr_ret = write_block(lba, buffer, false, &_wr_state)) > 0) )
141145
{
142146
lba++;
143147
buffer += 512;
@@ -148,6 +152,25 @@ int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
148152
return (wr_ret < 0) ? bufsize : count;
149153
}
150154

155+
// Callback invoked when WRITE10 command is completed (status received and accepted by host).
156+
void tud_msc_write10_complete_cb(uint8_t lun)
157+
{
158+
// uf2 file writing is complete --> complete DFU process
159+
if ( _wr_state.numBlocks && (_wr_state.numWritten >= _wr_state.numBlocks) )
160+
{
161+
led_state(STATE_WRITING_FINISHED);
162+
163+
dfu_update_status_t update_status;
164+
165+
memset(&update_status, 0, sizeof(dfu_update_status_t ));
166+
update_status.status_code = DFU_UPDATE_APP_COMPLETE;
167+
update_status.app_crc = 0; // skip CRC checking with uf2 upgrade
168+
update_status.app_size = _wr_state.numBlocks*256;
169+
170+
bootloader_dfu_update_process(update_status);
171+
}
172+
}
173+
151174
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size)
152175
{
153176
(void) lun;

src/usb/uf2/ghostfat.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ static FAT_BootBlock const BootBlock = {
119119
#define NRF_LOG_DEBUG(...)
120120
#define NRF_LOG_WARNING(...)
121121

122-
static WriteState _wr_state = { 0 };
123-
124122
// get current.uf2 flash size in bytes, round up to 256 bytes
125123
static uint32_t current_flash_size(void)
126124
{
@@ -241,31 +239,15 @@ void read_block(uint32_t block_no, uint8_t *data) {
241239
/* Write UF2
242240
*------------------------------------------------------------------*/
243241

244-
/** uf2 upgrade complete -> inform bootloader to update setting and reset */
245-
static void uf2_write_complete(uint32_t numBlocks)
246-
{
247-
led_state(STATE_WRITING_FINISHED);
248-
249-
dfu_update_status_t update_status;
250-
251-
memset(&update_status, 0, sizeof(dfu_update_status_t ));
252-
update_status.status_code = DFU_UPDATE_APP_COMPLETE;
253-
update_status.app_crc = 0; // skip CRC checking with uf2 upgrade
254-
update_status.app_size = numBlocks*256;
255-
256-
bootloader_dfu_update_process(update_status);
257-
}
258-
259242
/** Write an block
260243
*
261244
* @return number of bytes processed, only 3 following values
262245
* -1 : if not an uf2 block
263246
* 512 : write is successful
264247
* 0 : is busy with flashing, tinyusb stack will call write_block again with the same parameters later on
265248
*/
266-
int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *state*/) {
249+
int write_block(uint32_t block_no, uint8_t *data, bool quiet, WriteState *state) {
267250
UF2_Block *bl = (void *)data;
268-
WriteState* state = &_wr_state;
269251

270252
NRF_LOG_DEBUG("Write magic: %x", bl->magicStart0);
271253

@@ -318,8 +300,6 @@ int write_block(uint32_t block_no, uint8_t *data, bool quiet/*, WriteState *stat
318300
if (state->numWritten >= state->numBlocks) {
319301
// flush last blocks
320302
flash_nrf5x_flush(true);
321-
322-
uf2_write_complete(state->numBlocks);
323303
}
324304
}
325305
NRF_LOG_DEBUG("wr %d=%d (of %d)", state->numWritten, bl->blockNo, bl->numBlocks);

src/usb/usb.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,9 @@ extern uint16_t usb_desc_str_serial[1+16];
6363
* We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. */
6464
extern void tusb_hal_nrf_power_event(uint32_t event);
6565

66-
6766
//------------- IMPLEMENTATION -------------//
68-
static bool _inited = false;
69-
70-
bool usb_inited(void)
71-
{
72-
return _inited;
73-
}
74-
7567
void usb_init(bool cdc_only)
7668
{
77-
// skipped if already inited
78-
if ( _inited ) return;
79-
80-
_inited = true;
81-
8269
NVIC_SetPriority(USBD_IRQn, 2);
8370

8471
// USB power may already be ready at this time -> no event generated

src/usb/usb_desc.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ enum {
5959
};
6060

6161
/*------------- Endpoint Numbering & Size -------------*/
62-
#define _EP_IN(x) (0x80 | (x))
63-
#define _EP_OUT(x) (x)
62+
#define _EP_IN(x) (0x80 | (x))
63+
#define _EP_OUT(x) (x)
6464

6565
// CDC
66-
#define EP_CDC_NOTIF _EP_IN ( ITF_NUM_CDC+1 )
67-
#define EP_CDC_NOTIF_SIZE 8
66+
#define EP_CDC_NOTIF _EP_IN ( ITF_NUM_CDC+1 )
67+
#define EP_CDC_NOTIF_SIZE 8
6868

69-
#define EP_CDC_OUT _EP_OUT( ITF_NUM_CDC+2 )
70-
#define EP_CDC_IN _EP_IN ( ITF_NUM_CDC+2 )
69+
#define EP_CDC_OUT _EP_OUT( ITF_NUM_CDC+2 )
70+
#define EP_CDC_IN _EP_IN ( ITF_NUM_CDC+2 )
7171

7272
// Mass Storage
73-
#define EP_MSC_OUT _EP_OUT( ITF_NUM_MSC+1 )
74-
#define EP_MSC_IN _EP_IN ( ITF_NUM_MSC+1 )
73+
#define EP_MSC_OUT _EP_OUT( ITF_NUM_MSC+1 )
74+
#define EP_MSC_IN _EP_IN ( ITF_NUM_MSC+1 )
75+
76+
#define EP_MSC_SIZE 64
7577

7678
//--------------------------------------------------------------------+
7779
// STRING DESCRIPTORS
@@ -280,7 +282,7 @@ usb_desc_cfg_t usb_desc_cfg =
280282
.bDescriptorType = TUSB_DESC_ENDPOINT,
281283
.bEndpointAddress = EP_MSC_OUT,
282284
.bmAttributes = { .xfer = TUSB_XFER_BULK },
283-
.wMaxPacketSize = { .size = CFG_TUD_MSC_EPSIZE},
285+
.wMaxPacketSize = { .size = EP_MSC_SIZE},
284286
.bInterval = 1
285287
},
286288

@@ -290,7 +292,7 @@ usb_desc_cfg_t usb_desc_cfg =
290292
.bDescriptorType = TUSB_DESC_ENDPOINT,
291293
.bEndpointAddress = EP_MSC_IN,
292294
.bmAttributes = { .xfer = TUSB_XFER_BULK },
293-
.wMaxPacketSize = { .size = CFG_TUD_MSC_EPSIZE},
295+
.wMaxPacketSize = { .size = EP_MSC_SIZE },
294296
.bInterval = 1
295297
}
296298
}

0 commit comments

Comments
 (0)