Skip to content

Commit

Permalink
Added tasks and make targets for black-magic debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
siliconwitch committed Feb 23, 2024
1 parent a4a0039 commit bec1096
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
38 changes: 34 additions & 4 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
}
},
{
"label": "Flash",
"label": "Flash (J-Link)",
"type": "shell",
"command": "make flash",
"command": "make flash-jlink",
"problemMatcher": [
"$gcc"
],
Expand All @@ -72,9 +72,39 @@
}
},
{
"label": "Erase",
"label": "Flash (Black-Magic)",
"type": "shell",
"command": "make recover",
"command": "make flash-blackmagic",
"problemMatcher": [
"$gcc"
],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
},
{
"label": "Erase (J-Link)",
"type": "shell",
"command": "make erase-jlink",
"problemMatcher": [],
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
},
{
"label": "Erase (Black-Magic)",
"type": "shell",
"command": "make erase-blackmagic",
"problemMatcher": [],
"presentation": {
"echo": false,
Expand Down
44 changes: 40 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ GIT_COMMIT := $(shell git rev-parse --short HEAD)

BUILD := build

# Automatically assign Black Magic port depending if MacOS or Linux
ifeq ($(shell uname), Darwin)
PORT = $(shell ls /dev/cu.usbmodem*1 2> /dev/null | grep "cu.")
else
PORT = $(shell uname)
endif

application:
@make -C source/application

Expand All @@ -36,6 +43,7 @@ bootloader:
@make settings-hex-zip

settings-hex-zip:
@echo Building settings file...
@rm -f $(BUILD)/frame-firmware-*

@nrfutil settings generate \
Expand All @@ -45,7 +53,9 @@ settings-hex-zip:
--bootloader-version 0 \
--bl-settings-version 2 \
$(BUILD)/settings.hex
@echo Settings file built

@echo Building DFU package...
@mergehex \
-m $(BUILD)/settings.hex \
$(BUILD)/application.hex \
Expand All @@ -60,23 +70,49 @@ settings-hex-zip:
--sd-req 0x0123 \
--key-file source/bootloader/dfu_private_key.pem \
$(BUILD)/frame-firmware-$(BUILD_VERSION).zip
@echo DFU package built

release:
@echo Releasing...
@make clean
@make application
@make settings-hex-zip
@cp $(BUILD)/frame-firmware-$(BUILD_VERSION).hex production/
@echo Released

clean:
@rm -rf $(BUILD)
@echo Cleaned

flash:
flash-jlink:
@nrfutil device program \
--options reset=RESET_HARD \
--firmware $(BUILD)/frame-firmware-*.hex

recover:
flash-blackmagic:
@echo Flashing...
@arm-none-eabi-gdb -nx \
--batch-silent \
-ex "target extended-remote $(PORT)" \
-ex 'monitor swd_scan' \
-ex 'attach 1' \
-ex 'load' \
-ex 'compare-sections' \
-ex 'kill' \
$(BUILD)/frame-firmware-v*.hex \
2> /dev/null
@echo Flashed

erase-jlink:
@nrfutil device recover

.PHONY: all clean release flash recover
erase-blackmagic:
@arm-none-eabi-gdb -nx \
--batch-silent \
-ex "target extended-remote $(PORT)" \
-ex "monitor swd_scan" \
-ex "attach 1" \
-ex "monitor erase_mass" \
2> /dev/null
@echo Erased

.PHONY: all clean release flash-jlink flash-blackmagic erase-jlink erase-blackmagic
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ The nRF52 is designed to handle the overall system operation. It runs Lua, as we

```sh
make release
make recover # Unlocks the flash protection if needed
make flash
make erase-jlink # Unlocks the flash protection if needed
make flash-jlink
```

### Debugging
Expand Down
4 changes: 3 additions & 1 deletion source/application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ LINKED_LIBRARIES += \
-lgcc \

$(BUILD)/application.hex: $(C_FILES) ../fpga/fpga_application.h
@echo Building application...
@mkdir -p $(BUILD)
@arm-none-eabi-gcc $(FLAGS) -o $(BUILD)/application.elf $(C_FILES) $(LINKED_LIBRARIES)
@arm-none-eabi-objcopy -O ihex $(BUILD)/application.elf $(BUILD)/application.hex
@arm-none-eabi-size $(BUILD)/application.elf
@arm-none-eabi-size $(BUILD)/application.elf
@echo Application built
2 changes: 2 additions & 0 deletions source/bootloader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,14 @@ LINKED_LIBRARIES += \
$(LIBRARIES)/nrf5sdk/micro-ecc/micro_ecc_lib_nrf52hf_armgcc.a \

$(BUILD)/bootloader.hex: $(C_FILES)
@echo Building bootloader...
@mkdir -p $(BUILD)
@arm-none-eabi-gcc $(FLAGS) -o $(BUILD)/bootloader.elf $(C_FILES) $(LINKED_LIBRARIES)
@arm-none-eabi-objcopy -O ihex $(BUILD)/bootloader.elf $(BUILD)/bootloader.hex
@rm frame-bootloader-*.hex
@cp $(BUILD)/bootloader.hex frame-bootloader-$(BUILD_VERSION).hex
@arm-none-eabi-size $(BUILD)/bootloader.elf
@echo Bootloader built

regenerate_keys:
@nrfutil keys generate dfu_private_key.pem
Expand Down

0 comments on commit bec1096

Please sign in to comment.