8000 Nrf52840 usbboot by hathach · Pull Request #1004 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Nrf52840 usbboot #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
50e7a4c
add bootloader hex
hathach Apr 23, 2018
ce9f05f
add missing files
hathach Apr 23, 2018
0de8697
Added note on USB CDC bootloader
microbuilder Apr 23, 2018
d0e00d7
Added built to example
microbuilder Apr 23, 2018
3d8bb96
update gitignore
hathach May 15, 2018
5365e51
Merge branch 'master' into usbboot
hathach May 15, 2018
dadf831
Merge branch 'usbboot' of github.com:microbuilder/circuitpython into …
hathach May 15, 2018
05f36eb
update the bootloader hex for feather52840
hathach May 15, 2018
53593d1
fix #809
hathach May 15, 2018
78f806c
Added board specific READMEs
May 15, 2018
52ebfd0
update nrfutil to 0.5.2d with singlebank option
hathach May 17, 2018
6d4a2f5
Merge branch 'master' into usbboot
hathach May 17, 2018
9bb4ded
Merge remote-tracking branch 'upstream/master'
hathach Jun 7, 2018
c854e2d
Merge branch 'master' into usbboot
hathach Jun 7, 2018
c10899d
allow to flash feather52 and feather52840 with jlink
hathach Jun 8, 2018
2b3436e
add feather nrf52 uart rts, cts support
hathach Jun 8, 2018
418e28c
update nrf52840 bootloader hex and target
hathach Jun 8, 2018
35d38db
update nrf52840 bootloader hex
hathach Jun 13, 2018
9fc0ec6
Merge pull request #934 from microbuilder/usbboot
ladyada Jun 15, 2018
6d2702e
Merge branch 'master' into nrf52840_usbboot
hathach Jun 19, 2018
6143710
update bootloader for feather nrf52840
hathach Jun 19, 2018
f5be5ed
Merge branch 'master' into nrf52840_usbboot
hathach Jun 25, 2018
4722371
update bootloader hex with uf2
hathach Jun 25, 2018
4d45565
update tools/uf2 to support hex input for uf2conv.py
hathach Jun 25, 2018
5454768
add uf2, bootloader target
hathach Jun 25, 2018
8d065fe
update reamde
hathach Jun 25, 2018
ecd3993
update pin map for feather52840
hathach Jun 27, 2018
bed7310
update bin files
hathach Jun 27, 2018
4920cc4
move dfu-gen dfu-flash dfu-bootloader bootloader uf2 target to common…
hathach Jun 27, 2018
8fbe1d7
clean up makefile
hathach Jun 27, 2018
c4f11df
flash target update bootloader setting to skip crc checksum
hathach Jun 27, 2018
b14b280
Merge branch 'master' into nrf52840_usbboot
hathach Jul 3, 2018
46c453c
add tinyusb as submodule
hathach Jul 3, 2018
36e2f38
update tools/uf2 to have family support
hathach Jul 3, 2018
a73effa
update tusb
hathach Jul 3, 2018
7fff7f5
add usb msc support for nrf52840
hathach Jul 4, 2018
6d0cb96
hack to call tusb_task() in the mainloop
hathach Jul 4, 2018
be2ff20
enable usb cdc interface
hathach Jul 4, 2018
1745e20
replace jlink with native usb cdc for serial REPL
hathach Jul 5, 2018
3564e98
implement msc flash, seems to work
hathach Jul 5, 2018
0365912
implement msc with internal_flash api
hathach Jul 5, 2018
4e5d9a0
clean up
hathach Jul 5, 2018
0806c0a
update fatfs cached sector when running write10
hathach Jul 5, 2018
6ef3a0b
implement filesystem_writable_by_python()
hathach Jul 6, 2018
948ddf8
make SD default to s140 and s132 for nrf52840 and nrf52832
hathach Jul 6, 2018
3e31969
mp_hal_delay_ms() to call background task
hathach Jul 6, 2018
baf68a9
remove hal_time files
hathach Jul 6, 2018
c5089d7
generate uf2 by default
hathach Jul 9, 2018
f199e87
add ARRAY_SIZE
hathach Jul 9, 2018
97a1ae9
add family option for uf2
hathach Jul 9, 2018
7715d19
update bootloader hex
hathach Jul 9, 2018
0e81959
Merge branch 'master' into nrf52840_usbboot
hathach Jul 9, 2018
69f224a
change gitmodule link from git to https
hathach Jul 9, 2018
ce01496
try to fix travis build error
hathach Jul 10, 2018
a53b1c7
code format
hathach Jul 10, 2018
10846d3
Merge branch 'master' into nrf52840_usbboot
hathach Jul 11, 2018
f98c7f7
merge review
hathach Jul 11, 2018
4b1f880
clean up
hathach Jul 11, 2018
873e202
fix travis build
hathach Jul 11, 2018
862ae2f
exclude usb from doc build
hathach Jul 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*.dxf binary
*.mpy binary
*.deb binary
*.zip binary

# These should also not be modified by git.
tests/basics/string_cr_conversion.py -text
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*.bin
*.map
*.hex
!ports/nrf/**/bootloader/*.hex
!ports/nrf/**/bootloader/**/*.hex
*.dis
*.exe

Expand Down
10 changes: 7 additions & 3 deletions .gitmodules
Original file line number Di A36C ff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
url = https://github.com/micropython/stm32lib
branch = work-F4-1.13.1+F7-1.5.0+L4-1.3.0
[submodule "atmel-samd/asf4"]
path = ports/atmel-samd/asf4
url = https://github.com/adafruit/asf4.git
branch = circuitpython
path = ports/atmel-samd/asf4
url = https://github.com/adafruit/asf4.git
branch = circuitpython
[submodule "tools/usb_descriptor"]
path = tools/usb_descriptor
url = https://github.com/adafruit/usb_descriptor.git
Expand Down Expand Up @@ -73,3 +73,7 @@
[submodule "ports/nrf/nrfx"]
path = ports/nrf/nrfx
url = https://github.com/NordicSemiconductor/nrfx.git
[submodule "lib/tinyusb"]
path = lib/tinyusb
url = https://github.com/hathach/tinyusb.git
branch = develop
1 change: 1 addition & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"ports/nrf/hal",
"ports/nrf/modules",
"ports/nrf/nrfx",
"ports/nrf/usb",
"ports/pic16bit",
"ports/qemu-arm",
"ports/stm32",
Expand Down
2 changes: 1 addition & 1 deletion lib/nrfutil
1 change: 1 addition & 0 deletions lib/tinyusb
Submodule tinyusb added at a0849f
96 changes: 81 additions & 15 deletions ports/nrf/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# Select the board to build for: if not given on the command line,
# then default to feather52832.
BOARD ?= feather52832
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
# Select the board to build for.
ifeq ($(BOARD),)
$(info You must provide a BOARD parameter with 'BOARD=')
$(info Possible values are:)
$(info $(sort $(subst /.,,$(subst boards/,,$(wildcard boards/*/.)))))
$(error BOARD not defined)
else
ifeq ($(wildcard boards/$(BOARD)/.),)
$(error Invalid BOARD specified)
endif
endif

# If SoftDevice is selected, try to use that one.
# Default to SD132 (exact version can be set with SOFTDEV_VERSION)
SD ?= s132
SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
include boards/$(BOARD)/mpconfigboard.mk

# TODO: Verify that it is a valid target.
SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')

# If the build directory is not given, make it reflect the board name
# Build directory with SD
BUILD ?= $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD))

include ../../py/mkenv.mk
include boards/$(BOARD)/mpconfigboard.mk
-include mpconfigport.mk

ifneq ($(SD), )
Expand Down Expand Up @@ -52,6 +53,8 @@ INC += -I./nrfx/drivers/include
INC += -I../../lib/mp-readline
INC += -I./drivers/bluetooth
INC += -I./drivers
INC += -I../../lib/tinyusb/src
INC += -I./usb

NRF_DEFINES += -DCONFIG_GPIO_AS_PINRESET

Expand Down Expand Up @@ -87,6 +90,7 @@ LIBS += -L $(dir $(LIBC_FILE_NAME)) -lc
LIBS += -L $(dir $(LIBGCC_FILE_NAME)) -lgcc

SRC_NRFX = $(addprefix nrfx/,\
drivers/src/nrfx_power.c \
drivers/src/nrfx_spim.c \
drivers/src/nrfx_twim.c \
drivers/src/nrfx_uart.c \
Expand All @@ -96,10 +100,13 @@ SRC_C += \
mphalport.c \
fatfs_port.c \
tick.c \
background.c \
internal_flash.c \
drivers/bluetooth/ble_drv.c \
drivers/bluetooth/ble_uart.c \
boards/$(BOARD)/board.c \
nrfx/mdk/system_$(MCU_SUB_VARIANT).c \
nrfx/hal/nrf_nvmc.c \
device/$(MCU_VARIANT)/startup_$(MCU_SUB_VARIANT).c \
lib/oofatfs/ff.c \
lib/oofatfs/option/ccsbcs.c \
Expand All @@ -108,10 +115,25 @@ SRC_C += \
lib/utils/context_manager_helpers.c \
lib/utils/interrupt_char.c \
lib/utils/pyexec.c \
lib/utils/stdout_helpers.c \
lib/libc/string0.c \
lib/mp-readline/readline.c \
internal_flash.c \

ifeq ($(MCU_SUB_VARIANT),nrf52840)

SRC_C += \
usb/tusb_descriptors.c \
usb/usb_msc_flash.c \
lib/tinyusb/src/portable/nordic/nrf5x/dcd_nrf5x.c \
lib/tinyusb/src/portable/nordic/nrf5x/hal_nrf5x.c \
lib/tinyusb/src/common/tusb_fifo.c \
lib/tinyusb/src/device/usbd.c \
lib/tinyusb/src/device/usbd_desc.c \
lib/tinyusb/src/class/msc/msc_device.c \
lib/tinyusb/src/class/cdc/cdc_device.c \
lib/tinyusb/src/tusb.c \

endif

DRIVERS_SRC_C += $(addprefix modules/,\
ubluepy/modubluepy.c \
Expand Down Expand Up @@ -213,9 +235,9 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os
$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os

.phony: all flash sd binary hex
.phony: all flash sd binary hex bootloader

all: binary hex
all: binary hex uf2

OUTPUT_FILENAME = firmware

Expand All @@ -231,12 +253,18 @@ hex: $(BUILD)/$(OUTPUT_FILENAME).hex
$(BUILD)/$(OUTPUT_FILENAME).hex: $(BUILD)/$(OUTPUT_FILENAME).elf
$(OBJCOPY) -O ihex $< $@

#####################
# Flash with debugger
#####################
FLASHER ?=

ifeq ($(FLASHER),)

# Also update to bootloader settting to validate application and skip checksum ( app valid = 0x0001, crc = 0x0000 )
flash: $(BUILD)/$(OUTPUT_FILENAME).hex
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
nrfjprog --erasepage $(BOOT_SETTING_ADDR) -f $(MCU_VARIANT)
nrfjprog --memwr $(BOOT_SETTING_ADDR) --val 0x00000001 -f $(MCU_VARIANT)
nrfjprog --reset -f $(MCU_VARIANT)

sd: $(BUILD)/$(OUTPUT_FILENAME).hex
Expand All @@ -245,6 +273,9 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex
nrfjprog --program $< --sectorerase -f $(MCU_VARIANT)
nrfjprog --reset -f $(MCU_VARIANT)

bootloader:
nrfjprog --program $(BOOT_FILE).hex -f nrf52 --chiperase --reset

else ifeq ($(FLASHER), pyocd)

flash: $(BUILD)/$(OUTPUT_FILENAME).hex
Expand All @@ -257,6 +288,41 @@ sd: $(BUILD)/$(OUTPUT_FILENAME).hex

endif

#####################
# Flash w F42D ith DFU
#####################
.phony: dfu-gen dfu-flash dfu-bootloader

ifeq ($(OS),Windows_NT)
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
else
NRFUTIL = nrfutil
endif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line

check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))

dfu-gen: $(BUILD)/$(OUTPUT_FILENAME).hex
$(NRFUTIL) dfu genpkg --sd-req 0xFFFE --dev-type 0x0052 --application $^ $(BUILD)/dfu-package.zip

dfu-flash: $(BUILD)/dfu-package.zip
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
$(NRFUTIL) --verbose dfu serial --package $^ -p $(SERIAL) -b 115200 --singlebank

dfu-bootloader:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyACM0)
$(NRFUTIL) --verbose dfu serial --package $(BOOT_FILE).zip -p $(SERIAL) -b 115200

uf2: $(BUILD)/$(OUTPUT_FILENAME).hex
$(ECHO) "Create $(OUTPUT_FILENAME).uf2"
$(PYTHON2) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/$(OUTPUT_FILENAME).uf2" $^

$(BUILD)/dfu-package.zip: dfu-gen

$(BUILD)/$(OUTPUT_FILENAME).elf: $(OBJ)
$(ECHO) "LINK $@"
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJ) -Wl,--start-group $(LIBS) -Wl,--end-group
Expand Down
14 changes: 14 additions & 0 deletions ports/nrf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ This is a port of CircuitPython to the Nordic Semiconductor nRF52 series of chip
* nRF52840
* [PCA10056](http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK)

## Board Specific Instructions

For board-specific instructions on building and flashing CircuitPython, see
the following links:

> **NOTE**: These board specific readmes may be more up to date than the
generic board-neutral documentation further down.

* Adafruit [Feather nRF52](boards/feather52/README.md): 512KB Flash, 64KB SRAM
* Adafruit [Feather nRF52840](boards/feather52840/README.md): 1MB Flash, 256KB SRAM
* Nordic PCA10056 see [Feather nRF52840](boards/feather52840/README.md)

For all other board targets, see the generic notes below.

## Compile and Flash

Prerequisite steps for building the nrf port:
Expand Down
34 changes: 34 additions & 0 deletions ports/nrf/background.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "tusb.h"

void run_background_tasks(void) {
#ifdef NRF52840_XXAA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if there's a better way to do this, could we only include this file if we're building for 840, then we wouldn't need the macro check

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be other background service running besides usb, e.g ble task handling.

tusb_task();
tud_cdc_flush();
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
---------- ---------- ------- -----------------------------------------
0x000FF000..0x000FFFFF ( 4KB) Bootloader Settings
0x000FE000..0x000FEFFF ( 4KB) Master Boot Record Params
0x000F4000..0x000FDFFF ( 40KB) Serial + OTA Bootloader
0x000F4000..0x000FDFFF ( 40KB) Bootloader (UF2 + CDC + OTA)

0x000F3000..0x000F3FFF ( 4KB ) Private Config Data (Bonding, Keys, etc.)
0x000F2000..0x000F2FFF ( 4KB ) User NVM data
0x000B2000..0x000F1FFF (256KB) User Filesystem
0x000ED000..0x000F3FFF (28KB ) Private Config Data (Bonding, Keys, etc.)
0x000AD000..0x000ECFFF (256KB) User Filesystem

0x00025000..0x000B1FFF (564KB) Application Code (including ISR vector)
0x00001000..0x00024FFF (144KB) SoftDevice
0x00026000..0x000ACFFF (540KB) Application Code (including ISR vector)
0x00001000..0x00025FFF (148KB) SoftDevice
0x00000000..0x00000FFF (4KB) Master Boot Record
*/

Expand All @@ -23,9 +22,9 @@ MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000

FLASH_ISR (rx) : ORIGIN = 0x00025000, LENGTH = 0x001000
FLASH_TEXT (rx) : ORIGIN = 0x00026000, LENGTH = 0x08C000
FLASH_FATFS (r) : ORIGIN = 0x000B2000, LENGTH = 0x040000
FLASH_ISR (rx) : ORIGIN = 0x00026000, LENGTH = 0x001000
FLASH_TEXT (rx) : ORIGIN = 0x00027000, LENGTH = 0x086000
FLASH_FATFS (r) : ORIGIN = 0x000AD000, LENGTH = 0x040000

/* 0x2000000 - RAM:ORIGIN is reserved for Softdevice */
RAM (xrw) : ORIGIN = 0x20004000, LENGTH = 0x20040000 - 0x20004000
Expand All @@ -42,6 +41,6 @@ _estack = ORIGIN(RAM) + LENGTH(RAM);

/* RAM extents for the garbage collector */
_ram_end = ORIGIN(RAM) + LENGTH(RAM);
_heap_end = 0x20007000; /* tunable */
_heap_end = 0x20020000; /* tunable */

INCLUDE "boards/common.ld"
32 changes: 3 additions & 29 deletions ports/nrf/boards/feather52832/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
MCU_SERIES = m4
MCU_VARIANT = nrf52
MCU_SUB_VARIANT = nrf52
SD ?= s132
SOFTDEV_VERSION ?= 2.0.1

LD_FILE = boards/feather52832/custom_nrf52832_dfu_app_$(SOFTDEV_VERSION).ld
BOOTLOADER_PKG = boards/feather52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single.zip
BOOT_FILE = boards/feather52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSION)_s132_single

BOOT_SETTING_ADDR = 0x7F000
NRF_DEFINES += -DNRF52832_XXAA

ifeq ($(OS),Windows_NT)
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
else
NRFUTIL = nrfutil
endif

CFLAGS += -DADAFRUIT_FEATHER52

check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined make flag: $1$(if $2, ($2))))

.PHONY: dfu-gen dfu-flash boot-flash

dfu-gen:
$(NRFUTIL) dfu genpkg --dev-type 0x0052 --application $(BUILD)/$(OUTPUT_FILENAME).hex $(BUILD)/dfu-package.zip

dfu-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
$(NRFUTIL) dfu serial --package $(BUILD)/dfu-package.zip -p $(SERIAL) -b 115200

boot-flash:
@:$(call check_defined, SERIAL, example: SERIAL=/dev/ttyUSB0)
$(NRFUTIL) dfu serial --package $(BOOTLOADER_PKG) -p $(SERIAL) -b 115200
Loading
0