2022-10-25 22:15:02 +00:00
|
|
|
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(
|
2023-05-08 23:31:44 +00:00
|
|
|
FBT_DEBUG_DIR="${FBT_SCRIPT_DIR}/debug",
|
2022-11-05 11:47:59 +00:00
|
|
|
)
|
2022-10-25 22:15:02 +00:00
|
|
|
|
2023-08-22 18:33:10 +00:00
|
|
|
if (adapter_serial := env.subst("$SWD_TRANSPORT_SERIAL")) != "auto":
|
2022-10-25 22:15:02 +00:00
|
|
|
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",
|
2022-12-26 12:13:30 +00:00
|
|
|
"source ${FBT_DEBUG_DIR}/gdbinit",
|
2023-05-08 22:31:39 +00:00
|
|
|
"-ex",
|
|
|
|
"target extended-remote ${GDBREMOTE}",
|
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",
|
2023-05-08 22:31:39 +00:00
|
|
|
"source ${FBT_DEBUG_DIR}/flipperversion.py",
|
|
|
|
"-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",
|
2023-05-08 22:31:39 +00:00
|
|
|
"-ex",
|
|
|
|
"fw-version",
|
2022-10-12 16:12:05 +00:00
|
|
|
],
|
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
|