Skip to content

boards/nrf52-based, dist/tools/jlink: fix and enhance JLINK_{PRE,POST}_FLASH command#21740

Merged
crasbe merged 3 commits intoRIOT-OS:masterfrom
crasbe:pr/jlink_post_flash
Oct 1, 2025
Merged

boards/nrf52-based, dist/tools/jlink: fix and enhance JLINK_{PRE,POST}_FLASH command#21740
crasbe merged 3 commits intoRIOT-OS:masterfrom
crasbe:pr/jlink_post_flash

Conversation

@crasbe
Copy link
Copy Markdown
Contributor

@crasbe crasbe commented Sep 23, 2025

Contribution description

With #20965 I added the "Pinreset Enable" functionality to RIOT for nRF52 boards by setting the right values in the UICR register after flashing.
However this had two flaws:

  1. The command for the Waveshare Board was in the wrong file (Makefile instead of Makefile.include).
  2. You can only add one additional command because the JLink commander only likes to have one command.
  3. Any command line additions or additions in application Makefiles are ignored.

The second part also involves modifying the jlink.sh script to evaluate multiple commands that are each put into "..." brackets.

Testing procedure

You can use an nRF52DK, nRF52840DK, DWM1001 or Waveshare-nRF52840 board for testing.

With current master, the two ShowConf commands are ignored and you only see the command to set the Pin Reset.

JLINK_POST_FLASH='"ShowConf" "ShowConf"' BOARD=nrf52840dk make -C examples/basic/hello-world flash
...
J-Link: Flash download: Program & Verify speed: 72 KB/s
O.K.
J-Link>Write4 0x10001200 00000012 00000012
Writing 00000012 -> 10001200
Writing 00000012 -> 10001204
J-Link>r
...

With this PR, all commands are executed.

JLINK_POST_FLASH='"ShowConf" "ShowConf"' BOARD=nrf52840dk make -C examples/basic/hello-world flash -j
...
J-Link: Flash download: Program & Verify speed: 72 KB/s
O.K.
J-Link>ShowConf
USB-Address: 0
Enum. type:  Real-SN is used
Real-SN:     1050208458
KS-Power:    Off (Default)
J-Link>ShowConf
USB-Address: 0
Enum. type:  Real-SN is used
Real-SN:     1050208458
KS-Power:    Off (Default)
J-Link>Write4 0x10001200 00000012 00000012
Writing 00000012 -> 10001200
Writing 00000012 -> 10001204
J-Link>r
...

Issues/PRs references

Fixup for #20965.

@crasbe crasbe requested a review from aabadie as a code owner September 23, 2025 13:28
@crasbe crasbe added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation 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 labels Sep 23, 2025
@github-actions github-actions bot added Area: tools Area: Supplementary tools Area: boards Area: Board ports labels Sep 23, 2025
@riot-ci
Copy link
Copy Markdown

riot-ci commented Sep 23, 2025

Murdock results

✔️ PASSED

7a789f4 boards: treat JLINK_PRE_FLASH like a list

Success Failures Total Runtime
1 0 1 01m:25s

Artifacts

@crasbe crasbe requested a review from mguetschow September 23, 2025 13:36
@crasbe
Copy link
Copy Markdown
Contributor Author

crasbe commented Sep 23, 2025

Request for Comments: Should I add the same change to the jlink.sh for JLINK_PRE_FLASH?

Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Thanks for caring and fixing!

@mguetschow
Copy link
Copy Markdown
Contributor

Request for Comments: Should I add the same change to the jlink.sh for JLINK_PRE_FLASH?

Sounds reasonable to me, or is there any disadvantage to it?

@crasbe
Copy link
Copy Markdown
Contributor Author

crasbe commented Sep 26, 2025

Request for Comments: Should I add the same change to the jlink.sh for JLINK_PRE_FLASH?

Sounds reasonable to me, or is there any disadvantage to it?

Not really, the JLINK_PRE_FLASH variable is referenced more often in the script, so it would add some lines of code, but nothing crazy.

@crasbe crasbe requested a review from basilfx as a code owner September 30, 2025 12:56
@crasbe crasbe changed the title boards/nrf52-based, dist/tools/jlink: fix and enhance JLINK_POST_FLASH command boards/nrf52-based, dist/tools/jlink: fix and enhance JLINK_{PRE,POST}_FLASH command Sep 30, 2025
@crasbe
Copy link
Copy Markdown
Contributor Author

crasbe commented Sep 30, 2025

I added the same functionality to the JLINK_PRE_FLASH variable as with the JLINK_POST_FLASH variable and migrated the boards that use it to treat it as a list.

As a testing procedure, you don't have to have one of the affected boards, you can just check the burn.seg file that is generated by the dist/tools/jlink/jlink.sh script.

First: Check that the changes didn't break anything:

cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ BOARD=stk3200 make -C examples/basic/hello-world flash
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world'
Building application "hello-world" for "stk3200" with CPU "efm32".

"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
...
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/cortexm_common/periph
   text    data     bss     dec     hex filename
   9364      20    1772   11156    2b94 /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
/home/cbuec/RIOTstuff/riot-vanilla/RIOT/dist/tools/jlink/jlink.sh flash /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
### Flashing Target ###
### Flashing elf file ###
SEGGER J-Link Commander V8.10a (Compiled Oct  2 2024 14:18:35)
DLL version V8.10a, compiled Oct  2 2024 14:18:10

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...
J-Link>r
J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link.

Script processing completed.

make: *** [/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/../../../Makefile.include:863: flash] Error 1
make: Leaving directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world'



cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ cat examples/basic/hello-world/bin/stk3200/burn.seg
r
loadfile /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
r
g
exit

Second: Check that the new behavior works as intended:

cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ JLINK_PRE_FLASH='"ShowConf" "ShowConf"' BOARD=stk3200 make -C
examples/basic/hello-world flash -j
make: Entering directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world'
Building application "hello-world" for "stk3200" with CPU "efm32".

"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/pkg/cmsis/
...
"make" -C /home/cbuec/RIOTstuff/riot-vanilla/RIOT/cpu/cortexm_common/periph
   text    data     bss     dec     hex filename
   9364      20    1772   11156    2b94 /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
/home/cbuec/RIOTstuff/riot-vanilla/RIOT/dist/tools/jlink/jlink.sh flash /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
### Flashing Target ###
### Flashing elf file ###
SEGGER J-Link Commander V8.10a (Compiled Oct  2 2024 14:18:35)
DLL version V8.10a, compiled Oct  2 2024 14:18:10

J-Link Commander will now exit on Error

J-Link Command File read successfully.
Processing script file...
J-Link>ShowConf
J-Link connection not established yet but required for command.
Connecting to J-Link via USB...FAILED: Cannot connect to J-Link.

Script processing completed.

make: *** [/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/../../../Makefile.include:863: flash] Error 1
make: Leaving directory '/home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world'



cbuec@W11nMate:~/RIOTstuff/riot-vanilla/RIOT$ cat examples/basic/hello-world/bin/stk3200/burn.seg
ShowConf
ShowConf
r
loadfile /home/cbuec/RIOTstuff/riot-vanilla/RIOT/examples/basic/hello-world/bin/stk3200/hello-world.elf
r
g
exit

@crasbe crasbe requested a review from mguetschow September 30, 2025 13:01
Copy link
Copy Markdown
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Thanks for fixing! Please squash :)

@crasbe crasbe force-pushed the pr/jlink_post_flash branch from 838e493 to 9bc3dd1 Compare September 30, 2025 17:19
@crasbe crasbe force-pushed the pr/jlink_post_flash branch from 9bc3dd1 to 7a789f4 Compare September 30, 2025 17:19
@crasbe crasbe enabled auto-merge September 30, 2025 17:20
@crasbe crasbe added this pull request to the merge queue Sep 30, 2025
Merged via the queue into RIOT-OS:master with commit 20f2e09 Oct 1, 2025
25 checks passed
@crasbe crasbe deleted the pr/jlink_post_flash branch October 7, 2025 14:56
@benpicco benpicco added this to the Release 2025.10 milestone Dec 3, 2025
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: bug The issue reports a bug / The PR fixes a bug (including spelling errors) 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.

4 participants