Skip to content

Commit

Permalink
[tools] Add JLink debug probe support
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Mar 6, 2023
1 parent f4ae65c commit dcabc64
Show file tree
Hide file tree
Showing 20 changed files with 680 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/modm/platform/uart/cortex/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,27 @@ loop 4
loop 5
```

Alternatively you can also use a JLink debug probe which auto-detects the CPU
frequency:

```
$ scons log-itm-jlink
╭────JLink────> Single Wire Viewer
╰─────SWO────── stm32l476rgt6
Target CPU (stm32l476rg) is running @ 48251 kHz.
Receiving SWO data @ 4500 kHz.
Showing data from stimulus port(s): 0
-----------------------------------------------
Hello from the SWO.
debug
info
warning
error
loop 0
loop 1
loop 2
loop 3
loop 4
loop 5
```
20 changes: 20 additions & 0 deletions src/modm/platform/uart/rtt/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,25 @@ loop 61
If you want to use this as a proper communication channel with a custom protocol
you should implement the OpenOCD config yourself (with different ports).

You can also use JLink to access the RTT data, which may be significantly faster
than OpenOCD if the debug probe has hardware support for the protocol.

```
$ scons log-rtt-jlink
╭────JLink────> Real Time Transfer
╰─────RTT────── stm32l476rgt6
SEGGER J-Link V7.84f - Real time terminal output
RTT Demo on Nucleo-64
loop: 0
loop: 1
loop: 2
loop: 3
loop: 4
loop: 5
loop: 6
loop: 7
```


[rtt]: http://openocd.org/doc/html/General-Commands.html#Real-Time-Transfer-_0028RTT_0029
40 changes: 40 additions & 0 deletions tools/build_script_generator/cmake/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ Writes the executable onto your target via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### program-jlink

Writes the executable onto your target via JLink.
(\* *only ARM Cortex-M targets*)


#### debug

- option `MODM_DBG_UI=tui` in {`tui`, `gdbgui`}.
Expand All @@ -69,6 +75,12 @@ Launches GDB via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### debug-jlink

Launches GDB via JLink.
(\* *only ARM Cortex-M targets*)


#### debug-coredump

- option `MODM_DBG_UI=tui` in {`tui`, `gdbgui`}.
Expand Down Expand Up @@ -97,6 +109,12 @@ Creates a coredump via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### coredump-jlink

Creates a coredump via JLink.
(\* *only ARM Cortex-M targets*)


#### reset

Resets the executable via OpenOCD.
Expand All @@ -109,6 +127,12 @@ Resets the executable via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### reset-jlink

Resets the executable via JLink.
(\* *only ARM Cortex-M targets*)


#### log-itm

- option `MODM_ITM_FCPU` in Hz
Expand All @@ -121,6 +145,14 @@ See the `modm:platform:itm` module for details how to use the ITM as a logging
output.


#### log-itm-jlink

- option `MODM_ITM_FCPU` in Hz

Outputs ITM channel 0 via JLinkSWOViewer.
(\* *only ARM Cortex-M targets*)


#### log-rtt

- option `MODM_RTT_CHANNEL=0` as integer.
Expand All @@ -132,5 +164,13 @@ simple telnet client. Disconnect with Ctrl+D.
See the `modm:platform:rtt` module for details how to use RTT for data transfer.


#### log-rtt-jlink

- option `MODM_RTT_CHANNEL=0` as integer.

Configures JLink in RTT mode to output the chosen channel (default 0) via a
simple telnet client. Disconnect with Ctrl+D.
(\* *only ARM Cortex-M targets*)

[cmake]: http://cmake.org
[gdbgui]: https://www.gdbgui.com
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ function(modm_targets_create project_name)
${PROJECT_BINARY_DIR}/src/${project_name}.elf
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(program-jlink DEPENDS ${project_name}.elf)
add_custom_command(TARGET program-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }}
${PROJECT_BINARY_DIR}/src/${project_name}.elf
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug
USES_TERMINAL
Expand All @@ -221,6 +228,14 @@ function(modm_targets_create project_name)
bmp -p ${MODM_BMP_PORT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug-jlink DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit -x modm/openocd_jlink
--elf ${PROJECT_BINARY_DIR}/src/${project_name}.elf --ui=${MODM_DBG_UI}
jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(debug-coredump DEPENDS ${project_name}.elf)
add_custom_command(TARGET debug-coredump
USES_TERMINAL
Expand All @@ -245,6 +260,14 @@ function(modm_targets_create project_name)
bmp -p ${MODM_BMP_PORT}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(coredump-jlink)
add_custom_command(TARGET coredump-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.gdb -x modm/gdbinit
-ex "modm_coredump" -ex "modm_build_id" -ex "quit"
jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(reset)
add_custom_command(TARGET reset
USES_TERMINAL
Expand All @@ -257,16 +280,34 @@ function(modm_targets_create project_name)
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.bmp -p ${MODM_BMP_PORT} --reset
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(reset-jlink)
add_custom_command(TARGET reset-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.jlink -device {{ jlink_partname }} --reset
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-itm)
add_custom_command(TARGET log-itm
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.itm openocd -f modm/openocd.cfg --fcpu ${MODM_ITM_FCPU}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-itm-jlink)
add_custom_command(TARGET log-itm-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.itm jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-rtt)
add_custom_command(TARGET log-rtt
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} openocd -f modm/openocd.cfg
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

add_custom_target(log-rtt-jlink)
add_custom_command(TARGET log-rtt-jlink
USES_TERMINAL
COMMAND PYTHONPATH=modm ${PYTHON3_EXECUTABLE} -m modm_tools.rtt --channel ${MODM_RTT_CHANNEL} jlink -device {{ jlink_partname }}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endfunction()

4 changes: 4 additions & 0 deletions tools/build_script_generator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ def common_target(env):
core = device.get_driver("core")["type"]
core = core.replace("fd", "").replace("f", "")
mcu = device._properties.get("mcu", "")
jlink_partname = device.partname
if device.partname.startswith("stm32"):
jlink_partname = device.partname[:11]
p = {
"core": core,
"mcu": mcu,
"platform": device.identifier["platform"],
"family": device.identifier["family"],
"partname": device.partname,
"jlink_partname": jlink_partname,
}
return p

Expand Down
106 changes: 106 additions & 0 deletions tools/build_script_generator/make/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,60 @@ make: done building targets.
```


#### make program-jlink

```
make program-jlink profile={debug|release}
```

Writes the executable onto your target via JLink.
This is a convenience wrapper around the programming options and methods
defined in the `modm:build` module.
(\* *only ARM Cortex-M targets*)

```
$ make program-jlink
SEGGER J-Link GDB Server V7.84f Command Line Version
JLinkARM.dll V7.84f (DLL compiled Feb 7 2023 16:45:51)
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: yes
Generate logfile: off
Verify download: off
Init regs on start: off
Silent mode: on
Single run mode: off
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: stm32l476rg
Target device parameters: none
Target interface: SWD
Target interface speed: 4000kHz
Target endian: little
modm::delay_us (us=<optimized out>) at modm/src/modm/platform/core/delay.cpp:33
33 if (now - start >= cycles) break;
Loading section .text, size 0x188 lma 0x8000000
Loading section .build_id, size 0x24 lma 0x8000188
Loading section .text, size 0xe7c lma 0x80001b0
Loading section .rodata, size 0x6c lma 0x800102c
Loading section .data, size 0x4 lma 0x8001098
Loading section .fastdata, size 0x8 lma 0x800109c
Loading section .rodata, size 0x70 lma 0x80010a4
Start address 0x08000a50, load size 4368
Transfer rate: 4265 KB/sec, 624 bytes/write.
Resetting target
```

#### make debug

```
Expand Down Expand Up @@ -295,6 +349,16 @@ Launches GDB to debug via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### make debug-jlink

```
make debug-jlink profile={debug|release} ui={tui|gdbgui}
```

Launches GDB to debug via JLink.
(\* *only ARM Cortex-M targets*)


#### make debug-coredump

```
Expand Down Expand Up @@ -332,6 +396,16 @@ Creates a coredump via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### make coredump-jlink

```
make coredump-jlink
```

Creates a coredump via JLink.
(\* *only ARM Cortex-M targets*)


#### make reset

```
Expand All @@ -352,6 +426,16 @@ Resets the executable via Black Magic Probe.
(\* *only ARM Cortex-M targets*)


#### make reset-jlink

```
make reset-jlink
```

Resets the executable via JLink.
(\* *only ARM Cortex-M targets*)


#### make log-itm

```
Expand All @@ -378,6 +462,17 @@ See the `modm:platform:itm` module for details how to use the ITM as a logging
output.


#### make log-itm-jlink

```
make log-itm-jlink [channel={int}]
```

Outputs the ITM channel via JLinkSWOViewer. Note that JLink auto-detects the
CPU frequency.
(\* *only ARM Cortex-M targets*)


#### make log-rtt

```
Expand All @@ -402,6 +497,17 @@ loop: 61
See the `modm:platform:rtt` module for details how to use RTT for data transfer.


#### make log-rtt-jlink

```
make log-rtt-jlink [channel={int}]
```

Configures JLink in RTT mode to output the chosen channel (default 0) via a
simple telnet client. Disconnect with Ctrl+D.
(\* *only ARM Cortex-M targets*)


#### make library

```
Expand Down
Loading

0 comments on commit dcabc64

Please sign in to comment.