Skip to main content
Control embedded debug operations including device connection, firmware flashing, reset, and memory access using J-Link debug probes.

Import

from lager import Net, NetType

Methods

The Net-based API provides methods for embedded debugging operations.
MethodDescription
connect(speed, transport)Connect to target device
disconnect()Disconnect from target
reset(halt)Reset the device
flash(firmware_path)Flash firmware to device
erase()Perform full chip erase
read_memory(address, length)Read memory from device
status()Get connection status
rtt(channel)Create RTT session for bidirectional communication

Method Reference

Net.get(name, type=NetType.Debug)

Get a debug net by name.
from lager import Net, NetType

dbg = Net.get('DUT', type=NetType.Debug)
Parameters:
ParameterTypeDescription
namestrName of the debug net
typeNetTypeMust be NetType.Debug
Returns: Debug Net instance Note: The debug net must be configured with the target device name stored in the channel field (e.g., ‘NRF52840_XXAA’, ‘R7FA0E107’).

connect(speed=None, transport=None)

Connect to the target device.
# Connect with default settings (4000 kHz, SWD)
dbg.connect()

# Connect with custom speed
dbg.connect(speed='adaptive')

# Connect with JTAG
dbg.connect(transport='JTAG')
Parameters:
ParameterTypeDefaultDescription
speedstr'4000'Interface speed in kHz (e.g., ‘4000’) or ‘adaptive’
transportstr'SWD'Transport protocol (‘SWD’ or ‘JTAG’)
Returns: dict - Status dictionary with connection information

disconnect()

Disconnect from the target device.
dbg.disconnect()
Returns: dict - Status dictionary

reset(halt=False)

Reset the device.
# Reset and continue execution
output = dbg.reset(halt=False)
print(output)

# Reset and halt for debugging
output = dbg.reset(halt=True)
print(output)
Parameters:
ParameterTypeDefaultDescription
haltboolFalseHalt CPU after reset
Returns: str - Combined output from reset operation

flash(firmware_path)

Flash firmware to the device.
# Flash a hex file
output = dbg.flash('/path/to/firmware.hex')
print(output)

# Flash a binary file (address 0x00000000 assumed)
output = dbg.flash('/path/to/firmware.bin')
print(output)

# Flash an ELF file
output = dbg.flash('/path/to/firmware.elf')
print(output)
Parameters:
ParameterTypeDescription
firmware_pathstrPath to firmware file (.hex, .bin, or .elf)
Returns: str - Combined output from flash operation Note: For .bin files, flash address defaults to 0x00000000.

erase()

Perform full chip erase. This erases ALL flash memory including protection settings.
# Full chip erase
output = dbg.erase()
print(output)
Returns: str - Combined output from erase operation

read_memory(address, length)

Read memory from the target device.
# Read 256 bytes starting at address 0x20000000
data = dbg.read_memory(0x20000000, 256)
print(f"Read {len(data)} bytes")
print(data.hex())
Parameters:
ParameterTypeDescription
addressintStarting memory address
lengthintNumber of bytes to read
Returns: bytes - Memory data

status()

Get the current connection status.
status = dbg.status()
print(f"Connected: {status.get('connected', False)}")
Returns: dict - Status dictionary with connection information

rtt(channel=0)

Create an RTT (Real-Time Transfer) session for bidirectional communication with the target device.
# Open RTT session on default channel (0)
with dbg.rtt() as rtt:
    # Read debug output
    data = rtt.read_some(timeout=1.0)
    if data:
        print(data.decode('utf-8'))

    # Send commands to device
    rtt.write(b'test_command\n')

# Use different RTT channel
with dbg.rtt(channel=1) as rtt:
    data = rtt.read_some(timeout=2.0)
Parameters:
ParameterTypeDefaultDescription
channelint0RTT channel number (typically 0-15)
Returns: RTT context manager with methods:
  • read_some(timeout) - Read available data with timeout (returns bytes or None)
  • write(data) - Write data to target (accepts bytes or str)
Note: Debug connection must be active before using RTT. Call connect() first.

Examples

Flash Firmware and Reset

from lager import Net, NetType

# Get debug net
dbg = Net.get('DUT', type=NetType.Debug)

# Connect to target
status = dbg.connect()
print(f"Connected: {status}")

# Flash firmware
output = dbg.flash('/etc/lager/firmware/app.hex')
print(output)

# Reset and run
output = dbg.reset(halt=False)
print(output)

# Disconnect
dbg.disconnect()

Chip Erase Before Programming

from lager import Net, NetType

# Get debug net
dbg = Net.get('DUT', type=NetType.Debug)

# Erase entire chip first (ensures clean state)
print("Erasing chip...")
output = dbg.erase()
print(output)

# Connect after erase
status = dbg.connect()
print(f"Connected: {status}")

# Flash new firmware
output = dbg.flash('/etc/lager/firmware/app.hex')
print(output)

# Disconnect
dbg.disconnect()

Read Memory

from lager import Net, NetType

dbg = Net.get('DUT', type=NetType.Debug)

# Connect to target
dbg.connect()

# Read 256 bytes from RAM
data = dbg.read_memory(0x20000000, 256)
print(f"Read {len(data)} bytes")
print(data.hex())

# Disconnect
dbg.disconnect()
For most use cases, the CLI provides a simpler interface:
# Start GDB server (connect to target)
lager debug <net> gdbserver --box <gateway>

# Flash firmware
lager debug <net> flash --hex firmware.hex --box <gateway>

# Reset device
lager debug <net> reset --box <gateway>

# Erase flash
lager debug <net> erase --box <gateway>

# Read memory
lager debug <net> memrd 0x20000000 256 --box <gateway>

# Disconnect
lager debug <net> disconnect --box <gateway>

# Check status
lager debug <net> status --box <gateway>
See the CLI Debug Reference for full CLI documentation.

RTT Streaming

SEGGER Real-Time Transfer (RTT) enables high-speed bidirectional communication with embedded devices during debugging (faster than UART, no timing impact).
from lager import Net, NetType

# Connect debug probe first
debug = Net.get('debug1', type=NetType.Debug)
debug.connect()

# Open RTT session for reading debug output
with debug.rtt() as rtt:
    # Read debug output from MCU
    data = rtt.read_some(timeout=1.0)
    if data:
        print(data.decode('utf-8'))

    # Can also write commands to MCU
    rtt.write(b'start_test\n')
RTT Methods:
MethodDescription
read_some(timeout)Read available data with timeout (returns bytes or None)
write(data)Write data to RTT (accepts bytes or str)
CLI Alternative: Use lager debug <net> gdbserver --rtt-reset to stream RTT logs directly.

Supported Devices

J-Link supports a wide range of ARM Cortex-M and other microcontrollers. Common device names:
ManufacturerDevice NameDescription
NordicNRF52840_XXAAnRF52840
NordicNRF52833_XXAAnRF52833
NordicNRF5340_XXAA_APPnRF5340 Application Core
RenesasR7FA0E107RA0E1 Series
RenesasR7FA2L1RA2L1 Series
STMicroSTM32F103C8STM32F1 Series
STMicroSTM32F407VGSTM32F4 Series
STMicroSTM32L476RGSTM32L4 Series
For a complete list, see SEGGER’s supported devices.

Supported Hardware

Debug ProbeFeatures
J-LinkJTAG/SWD debugging, flash programming
CMSIS-DAPSWD debugging (via pyOCD backend)
ST-LinkSWD debugging (via pyOCD backend)

Notes

  • Debug nets must be configured with the target device name in the channel field
  • The CLI (lager debug) is recommended for most use cases
  • Python Net API is intended for advanced automation scripts running on the Lager Box
  • Always call disconnect() when finished to release the debug probe
  • Use erase() to perform a full chip erase and clear protection settings
  • RTT requires an active debug connection (see RTT Streaming section above)