2022-10-25 22:15:02 +00:00
|
|
|
from re import search
|
|
|
|
|
|
|
|
from SCons.Errors import UserError
|
|
|
|
|
|
|
|
|
|
|
|
def _get_device_serials(search_str="STLink"):
|
|
|
|
import serial.tools.list_ports as list_ports
|
|
|
|
|
|
|
|
return set([device.serial_number for device in list_ports.grep(search_str)])
|
|
|
|
|
|
|
|
|
|
|
|
def GetDevices(env):
|
|
|
|
serials = _get_device_serials()
|
|
|
|
if len(serials) == 0:
|
|
|
|
raise UserError("No devices found")
|
|
|
|
|
|
|
|
print("\n".join(serials))
|
|
|
|
|
|
|
|
|
2022-10-12 16:12:05 +00:00
|
|
|
def generate(env, **kw):
|
2022-10-25 22:15:02 +00:00
|
|
|
env.AddMethod(GetDevices)
|
2022-11-05 11:47:59 +00:00
|
|
|
env.SetDefault(
|
|
|
|
FBT_DEBUG_DIR="${ROOT_DIR}/debug",
|
|
|
|
)
|
2022-10-25 22:15:02 +00:00
|
|
|
|
|
|
|
if (adapter_serial := env.subst("$OPENOCD_ADAPTER_SERIAL")) != "auto":
|
|
|
|
env.Append(
|
|
|
|
OPENOCD_OPTS=[
|
|
|
|
"-c",
|
|
|
|
f"adapter serial {adapter_serial}",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
# Final command is "init", always explicitly added
|
|
|
|
env.Append(
|
|
|
|
OPENOCD_OPTS=["-c", "init"],
|
|
|
|
)
|
|
|
|
|
2022-10-12 16:12:05 +00:00
|
|
|
env.SetDefault(
|
|
|
|
OPENOCD_GDB_PIPE=[
|
2022-11-05 11:47:59 +00:00
|
|
|
"|openocd -c 'gdb_port pipe; log_output ${FBT_DEBUG_DIR}/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}"
|
2022-10-12 16:12:05 +00:00
|
|
|
],
|
|
|
|
GDBOPTS_BASE=[
|
|
|
|
"-ex",
|
|
|
|
"target extended-remote ${GDBREMOTE}",
|
|
|
|
"-ex",
|
2022-12-26 12:13:30 +00:00
|
|
|
"source ${FBT_DEBUG_DIR}/gdbinit",
|
2022-10-12 16:12:05 +00:00
|
|
|
],
|
|
|
|
GDBOPTS_BLACKMAGIC=[
|
2023-02-09 03:40:04 +00:00
|
|
|
"-q",
|
2022-10-12 16:12:05 +00:00
|
|
|
"-ex",
|
|
|
|
"monitor swdp_scan",
|
|
|
|
"-ex",
|
|
|
|
"monitor debug_bmp enable",
|
|
|
|
"-ex",
|
|
|
|
"attach 1",
|
|
|
|
"-ex",
|
|
|
|
"set mem inaccessible-by-default off",
|
|
|
|
],
|
|
|
|
GDBPYOPTS=[
|
|
|
|
"-ex",
|
2022-11-05 11:47:59 +00:00
|
|
|
"source ${FBT_DEBUG_DIR}/FreeRTOS/FreeRTOS.py",
|
|
|
|
"-ex",
|
|
|
|
"source ${FBT_DEBUG_DIR}/flipperapps.py",
|
2022-10-12 16:12:05 +00:00
|
|
|
"-ex",
|
2022-11-05 11:47:59 +00:00
|
|
|
"fap-set-debug-elf-root ${FBT_FAP_DEBUG_ELF_ROOT}",
|
2022-10-12 16:12:05 +00:00
|
|
|
"-ex",
|
2022-11-05 11:47:59 +00:00
|
|
|
"source ${FBT_DEBUG_DIR}/PyCortexMDebug/PyCortexMDebug.py",
|
2022-10-12 16:12:05 +00:00
|
|
|
"-ex",
|
|
|
|
"svd_load ${SVD_FILE}",
|
|
|
|
"-ex",
|
|
|
|
"compare-sections",
|
|
|
|
],
|
2022-11-05 11:47:59 +00:00
|
|
|
JFLASHPROJECT="${FBT_DEBUG_DIR}/fw.jflash",
|
2022-10-12 16:12:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|