User scripts can define functions that act as hooks at specific points in the connection lifecycle. Common hooks include:
will_connect(board): Called before the connection is established. The board object is provided as an argument.did_connect(): Called after the connection is established. Note that board is not necessarily passed to this hook.
Example: Adding a ROM region (Nordic nRF52)
def will_connect(board):
# Create the new ROM region for the FICR.
ficr = RomRegion(
name="ficr",
start=0x10000000,
length=0x460
)
# Add the FICR region to the memory map.
target.memory_map.add_region(ficr)
Example: Overriding a flash algorithm (NXP i.MX RT10x0)
def will_connect():
# Look up the external flash memory region.
extFlash = target.memory_map.get_first_matching_region(name="flexspi")
# Set the path to an .FLM flash algorithm.
extFlash.flm = "MIMXRT105x_QuadSPI_4KB_SEC.FLM"
Example: Writing to a register after connection (STM32L0x1)
DBG_CR = 0x40015804
def did_connect():
# Set STANDBY, STOP, and SLEEP bits all to 1.
target.write32(DBG_CR, 0x7)
# This example applies to the Nordic nRF52 devices.
def will_connect(board):
# Create the new ROM region for the FICR.
ficr = RomRegion(
name="ficr",
start=0x10000000,
length=0x460
)
# Add the FICR region to the memory map.
target.memory_map.add_region(ficr)