@ -1,22 +1,23 @@
# Select the board to build for: if not given on the command line,
# then default to feather52832.
BOARD ?= feather52832
i f e q ( $( wildcard boards /$ ( BOARD ) /.) , )
$( error Invalid BOARD specified )
# Select the board to build for.
i f e q ( $( 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)
e l s e
ifeq ( $( wildcard boards/$( BOARD) /.) ,)
$( error Invalid BOARD specified)
endif
e n d i f
# 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:]' )
i n c l u d e b o a r d s / $( BOARD ) / m p c o n f i g b o a r d . m k
# 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) )
i n c l u d e . . / . . / p y / m k e n v . m k
i n c l u d e b o a r d s / $( BOARD ) / m p c o n f i g b o a r d . m k
- i n c l u d e m p c o n f i g p o r t . m k
i f n e q ( $( SD ) , )
@ -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
@ -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 \
@ -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 \
@ -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 \
i f e q ( $( MCU_SUB_VARIANT ) , n r f 5 2 8 4 0 )
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 \
e n d i f
DRIVERS_SRC_C += $( addprefix modules/,\
ubluepy/modubluepy.c \
@ -124,7 +146,6 @@ DRIVERS_SRC_C += $(addprefix modules/,\
ubluepy/ubluepy_descriptor.c \
ubluepy/ubluepy_scanner.c \
ubluepy/ubluepy_scan_entry.c \
ble/modble.c \
)
SRC_COMMON_HAL += \
@ -151,6 +172,12 @@ SRC_COMMON_HAL += \
supervisor/__init__.c \
supervisor/Runtime.c \
i f n e q ( $( SD ) , )
SRC_COMMON_HAL += \
bleio/__init__.c \
bleio/Adapter.c
e n d i f
# These don't have corresponding files in each port but are still located in
# shared-bindings to make it clear what the contents of the modules are.
SRC_BINDINGS_ENUMS = \
@ -213,9 +240,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 uf 2
OUTPUT_FILENAME = firmware
@ -231,12 +258,18 @@ hex: $(BUILD)/$(OUTPUT_FILENAME).hex
$(BUILD)/$(OUTPUT_FILENAME).hex : $( BUILD ) /$( OUTPUT_FILENAME ) .elf
$( OBJCOPY) -O ihex $< $@
#####################
# Flash with debugger
#####################
FLASHER ?=
i f e q ( $( 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
@ -245,18 +278,64 @@ 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
e l s e i f e q ( $( FLASHER ) , p y o c d )
flash : $( BUILD ) /$( OUTPUT_FILENAME ) .hex
pyocd-flashtool -t $( MCU_VARIANT) $<
pyocd-flashtool -t $( MCU_SUB_VARIANT) $< --sector_erase
pyocd-tool -t $( MCU_SUB_VARIANT) erase $( BOOT_SETTING_ADDR)
pyocd-tool -t $( MCU_SUB_VARIANT) write32 $( BOOT_SETTING_ADDR) 0x00000001
pyocd-tool -t $( MCU_SUB_VARIANT) reset
sd : $( BUILD ) /$( OUTPUT_FILENAME ) .hex
pyocd-flashtool -t $( MCU_VARIANT) --chip_erase
pyocd-flashtool -t $( MCU_VARIANT) $( SOFTDEV_HEX)
pyocd-flashtool -t $( MCU_VARIANT) $<
pyocd-flashtool -t $( MCU_SUB_VARIANT) --chip_erase
pyocd-flashtool -t $( MCU_SUB_VARIANT) $( SOFTDEV_HEX)
pyocd-flashtool -t $( MCU_SUB_VARIANT) $< --sector_erase
pyocd-tool -t $( MCU_SUB_VARIANT) reset $( BOOT_SETTING_ADDR)
bootloader :
pyocd-flashtool -t $( MCU_SUB_VARIANT) $( BOOT_FILE) .hex --chip_erase
pyocd-tool -t $( MCU_SUB_VARIANT) reset
e n d i f
#####################
# Flash with DFU
#####################
.phony : dfu -gen dfu -flash dfu -bootloader
i f e q ( $( OS ) , W i n d o w s _ N T )
NRFUTIL = ../../lib/nrfutil/binaries/win32/nrfutil.exe
e l s e
NRFUTIL = nrfutil
e n d i f
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