Skip to content

boards/common/nrf52: allow ST-LINKV2 as programmer#13858

Closed
gschorcht wants to merge 1 commit intoRIOT-OS:masterfrom
gschorcht:boards/common/nrf52/stlinkv2
Closed

boards/common/nrf52: allow ST-LINKV2 as programmer#13858
gschorcht wants to merge 1 commit intoRIOT-OS:masterfrom
gschorcht:boards/common/nrf52/stlinkv2

Conversation

@gschorcht
Copy link
Copy Markdown
Contributor

@gschorcht gschorcht commented Apr 13, 2020

Contribution description

The PR povides a small change in the OpenOCD configuration for nRF52 boards, which allows to use the SWD interface of a ST-LINKV2 in-circuit debugger/programmer to flash nRF52 boards that do not have an on-board programmer.

Testing procedure

Use a ST-LINKV2, connect any nRF52 board and flash any program:

PROGRAMMER=openocd DEBUG_ADAPTER=stlink \
make BOARD=<nrf52 board> -C examples/hello-world flash

For example, to use the ST-LINKV2 of a STM32 nucleo-64/144 board, the nRF52 board has to be connected as follows:

nrf52 VDD     ----  nucleo-64/144 SWD (1) - Vref
nrf52 SWDCLK  ----  nucleo-64/144 SWD (2) - SWCLK
nrf52 GND     ----  nucleo-64/144 SWD (3) - GND
nrf52 SWDIO   ----  nucleo-64/144 SWD (4) - SWDIO

To use the ST-LINKV2 adapter, the nRF52 board has to be connected as follows:

nrf52 VDD     ----  ST-LINKV2 JTAG/SWD (1) - VAPP
nrf52 SWDIO   ----  ST-LINKV2 JTAG/SWD (7) - SWDIO
nrf52 SWDCLK  ----  ST-LINKV2 JTAG/SWD (9) - SWCLK
nrf52 GND     ----  ST-LINKV2 JTAG/SWD (8) - GND

Issues/PRs references

@gschorcht gschorcht added Area: boards Area: Board ports Area: toolchain Area: toolchains; everything related to compilation, libc, linking, … Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation and removed Area: toolchain Area: toolchains; everything related to compilation, libc, linking, … labels Apr 13, 2020
@aabadie aabadie self-assigned this Apr 14, 2020
@benpicco benpicco requested a review from bergzand April 14, 2020 10:05
Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

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

I think this could be done differently, more generically. What do you think ?

@@ -1,3 +1,6 @@
transport select swd
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this line could simply be moved to https://github.com/RIOT-OS/RIOT/blob/master/makefiles/tools/openocd-adapters/jlink.inc.mk

With a line like:

OPENOCD_ADAPTER_INIT ?= -c 'transport select swd'

Other boards like kw41z which can also be flashed using openocd and the jlink adapter could be simplified the same wayl.
Another benefit is that one could also use DEBUG_ADAPTER=dap and a DAPLink programmer without any change in the code to be able to flash the nrf52 boards.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Any approach that is better than mine is welcome. I'm not familiar with J-Link or any other adapters. The only adapter I have ever used is ST-LINKV2 with nucleo-64 boards. The change I suggested was simply the way I figured out how to use my ST-LINKV2 for the nRF52 board in PR #13860 because it doesn't have a J-Link adapter on the board.

OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/jlink.cfg]'

should probably be changed to

OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/jlink.cfg]' -c 'transport select swd'

Right?

I'm just wondering whether all boards that use OpenOCD and J-Link adapter also use SWD.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right ?

You got my point :)

I'm just wondering whether all boards that use OpenOCD and J-Link adapter also use SWD.

Good question. In fact, Jlink adapter supports both SWD and JTAG (see here).
But in RIOT, all boards flashed using jlink are using SWD, for the moment. We could have a new make variable for that OPENOCD_JLINK_ADAPTER_TRANSPORT or something like that set by default to swd and handle the possible values (swd/jtag) in jlink.inc.mk. What do you think ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Jlink adapter supports both SWD and JTAG

Therefore I was wondering whether all boards use SWD as transport protocol.

We could have a new make variable for that OPENOCD_JLINK_ADAPTER_TRANSPORT or something like that set by default to swd and handle the possible values (swd/jtag) in jlink.inc.mk. What do you think ?

This is the way as it is done in stlink.inc.mk. The question is how we can figure out which boards use or could use jlink and which of them set a transport protocol other than swd, which would then has to be set in the board's Makefile.include. If we suppose that a board could use openocd has to define an openocd.cfg file, the following boards select a certain transport protocol:

boards/mcb2388/dist/openocd.cfg                 jtag
boards/msba2/dist/openocd.cfg                   jtag
boards/ek-lm4f120xl/dist/openocd.cfg            hla_jtag       
boards/common/nrf52/dist/openocd.cfg            swd
boards/common/cc26x2_cc13x2/dist/openocd.cfg    jtag
boards/common/frdm/dist/openocd-klx.cfg         swd

Some of them don't use jlink but dap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Most of those don't use DEBUG_ADAPTER though, which means the Makefiles in openocd-adapters/ do no get included.

@gschorcht
Copy link
Copy Markdown
Contributor Author

Closed in favor of PR #14480.

@gschorcht gschorcht closed this Jul 10, 2020
@gschorcht gschorcht deleted the boards/common/nrf52/stlinkv2 branch August 24, 2021 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: skip compile test If set, CI server will run only non-compile jobs, but no compile jobs or their dependent jobs Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants