-
Notifications
You must be signed in to change notification settings - Fork 2.1k
boards/nrf52840dongle: Support a FLOSS programmer #21466
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
base: master
Are you sure you want to change the base?
Changes from all commits
7cefa6d
ad61b52
972e25a
11e54b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,26 @@ | ||||||
| # This board uses the vendor's serial bootloader | ||||||
|
|
||||||
| PROGRAMMER ?= nrfutil | ||||||
| PROGRAMMER ?= nrfdfu | ||||||
|
|
||||||
| ifeq (nrfutil,$(PROGRAMMER)) | ||||||
| USING_NRF_BOOTLOADER = 1 | ||||||
|
|
||||||
| # Using nrfutil implies using the Nordic bootloader described at | ||||||
| FLASHFILE = $(HEXFILE) | ||||||
| FLASHDEPS += $(HEXFILE).zip | ||||||
| FLASHER = nrfutil | ||||||
| FFLAGS = dfu usb-serial --port=${PORT} --package=$(HEXFILE).zip | ||||||
| endif | ||||||
|
|
||||||
| ifeq (nrfdfu,$(PROGRAMMER)) | ||||||
| USING_NRF_BOOTLOADER = 1 | ||||||
|
|
||||||
| FLASHFILE = $(ELFFILE) | ||||||
| FLASHER = nrfdfu | ||||||
| FFLAGS = $(FLASHFILE) | ||||||
| endif | ||||||
|
|
||||||
| ifeq (1,$(USING_NRF_BOOTLOADER)) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Since the number of programmer variants is very limited (two), we could omit the extra variable here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is value to having this independent, because it could also be used with an external programmer but leaving the bootloader in place. Even if you accept that rationale, let's leave this open for the naming issue. I think that the adafruit bootloader is similar enough, but I'll want to check that anyway while looking at knurling-rs/nrfdfu-rs#16, and then I'll see if there is a better name to use here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a valid point, but then the parameter must be documented somewhere. There is a similar parameter for the Adafruit nRF52 Bootloader called |
||||||
| # Using an nrfutil style flasher implies using the Nordic bootloader described at | ||||||
| # <https://devzone.nordicsemi.com/nordic/short-range-guides/b/getting-started/posts/nrf52840-dongle-programming-tutorial>. | ||||||
| # | ||||||
| # It has a static MBR at the first 4k, and an ample 128k Open USB Bootloader at | ||||||
|
|
@@ -14,15 +30,10 @@ ifeq (nrfutil,$(PROGRAMMER)) | |||||
| ROM_OFFSET = 0x1000 | ||||||
| ROM_LEN = 0xdf000 | ||||||
|
|
||||||
| FLASHFILE = $(HEXFILE) | ||||||
| FLASHDEPS += $(HEXFILE).zip | ||||||
| FLASHER = nrfutil | ||||||
| FFLAGS = dfu usb-serial --port=${PORT} --package=$(HEXFILE).zip | ||||||
|
|
||||||
| include $(RIOTMAKE)/tools/usb_board_reset.mk | ||||||
| endif | ||||||
|
|
||||||
| PROGRAMMERS_SUPPORTED += nrfutil | ||||||
| PROGRAMMERS_SUPPORTED += nrfutil nrfdfu | ||||||
|
|
||||||
| %.hex.zip: %.hex | ||||||
| $(call check_cmd,$(FLASHER),Flash program and preparation tool) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,22 +48,41 @@ reset button as well as 15 configurable external pins. | |
|
|
||
| ### Flash the board {#nrf52840dongle_flash} | ||
|
|
||
| The board is flashed using its on-board boot loader; the proprietary | ||
| The board is flashed using its on-board boot loader | ||
| called [Open USB bootloader](https://devzone.nordicsemi.com/nordic/short-range-guides/b/getting-started/posts/nrf52840-dongle-programming-tutorial) | ||
| using either of two tools described below. | ||
|
|
||
| If RIOT is already running on the board, flashing the device will automatically reset the CPU and enter | ||
| the bootloader. | ||
| If some other firmware is running or RIOT crashed, you need to enter the bootloader | ||
| manually by pressing the board's reset button. | ||
|
|
||
| Readiness of the bootloader is indicated by LD2 pulsing in red. | ||
|
|
||
| #### nrfdfu | ||
|
|
||
| The tool [nrfdfu](https://github.com/knurling-rs/nrfdfu-rs/) | ||
| is RIOT's default way of flashing a program by sending it to the bootloader. | ||
|
|
||
| It needs to be installed locally using `cargo install nrfdfu`. | ||
|
|
||
| #### nrfutil | ||
|
|
||
| The proprietary | ||
| [nrfutil](https://www.nordicsemi.com/Products/Development-tools/nRF-Util) program needs to | ||
| be installed, and `nrfutil install nrf5sdk-tools` needs to be executed. Note | ||
| that nrfutil, even when not running the "install" command, will install itself | ||
| into `~/.nrfutil`. The older Python based version of nrfutil is no longer | ||
| maintained by Nordic, and has become dysfunctional on Python 3.11. | ||
|
|
||
| The nrfutil can turn the binary into a suitable zip file and send it to the | ||
| The nrfutil works in two steps by turning the binary into a zip file and then sending the content of that zip file to the | ||
| bootloader. The process is automated in the usual `make flash` target. | ||
|
|
||
| If RIOT is already running on the board, it will automatically reset the CPU and enter | ||
| the bootloader. | ||
| If some other firmware is running or RIOT crashed, you need to enter the bootloader | ||
| manually by pressing the board's reset button. | ||
| #### Other programming methods | ||
|
|
||
| Readiness of the bootloader is indicated by LD2 pulsing in red. | ||
| When building a program for this board to be flashed using other methods | ||
| (e.g. using the board's Tag-Connect footprint), | ||
| setting `USING_NRF_BOOTLOADER=1` in the makefiles aligns the program suitable to be flashed after the bootloader. | ||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it make sense to set
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One has to use an external programmer to lock oneself out, but then I think that working on the full device unless something else is specified is at least consistent with what we had and have in other places. There are multiple bootloaders, and people do flash other bootloaders in, so I'd say that once a debugger is connected, it's a stretch to assume that the bootloader is still there. What I would appreciate if we had was a way to say "hey I have this board and a debugger attached, RIOT please undo what you did and do a factory reset", and I'm starting to gather the metadata for that, but that's something bigger.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One should assume that when someone gathers a J-Link and a Tag Connect, that they know what they are doing, indeed. For reference: Mikolai started working on such an "undo RIOT changes" in #21330 by reflashing the Adafruit Bootloader, but that is riddled by oddities in the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, "explicit" would be better, but for now I think we should prioritize "consistent". (On the long run I'd like to have something like BOOTLOADER along with BOARD, where the former has a default depending on the latter; not sure how to do that switch in a way that it's apparent to all users what is happening). |
||
|
|
||
| ### Accessing STDIO | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather leave it as is in this commit so that it is visible in the commit that this line was not modified. (The GitHub diff settings choice mark it as a new line, but eg. a
git diff color-moveddoes show those as unmodified).