fbt_debugopts.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. from SCons.Errors import UserError
  2. def _get_device_serials(search_str="STLink"):
  3. import serial.tools.list_ports as list_ports
  4. return set([device.serial_number for device in list_ports.grep(search_str)])
  5. def GetDevices(env):
  6. serials = _get_device_serials()
  7. if len(serials) == 0:
  8. raise UserError("No devices found")
  9. print("\n".join(serials))
  10. def generate(env, **kw):
  11. env.AddMethod(GetDevices)
  12. env.SetDefault(
  13. FBT_DEBUG_DIR="${ROOT_DIR}/debug",
  14. )
  15. if (adapter_serial := env.subst("$OPENOCD_ADAPTER_SERIAL")) != "auto":
  16. env.Append(
  17. OPENOCD_OPTS=[
  18. "-c",
  19. f"adapter serial {adapter_serial}",
  20. ]
  21. )
  22. # Final command is "init", always explicitly added
  23. env.Append(
  24. OPENOCD_OPTS=["-c", "init"],
  25. )
  26. env.SetDefault(
  27. OPENOCD_GDB_PIPE=[
  28. "|openocd -c 'gdb_port pipe; log_output ${FBT_DEBUG_DIR}/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}"
  29. ],
  30. GDBOPTS_BASE=[
  31. "-ex",
  32. "target extended-remote ${GDBREMOTE}",
  33. "-ex",
  34. "source ${FBT_DEBUG_DIR}/gdbinit",
  35. ],
  36. GDBOPTS_BLACKMAGIC=[
  37. "-q",
  38. "-ex",
  39. "monitor swdp_scan",
  40. "-ex",
  41. "monitor debug_bmp enable",
  42. "-ex",
  43. "attach 1",
  44. "-ex",
  45. "set mem inaccessible-by-default off",
  46. ],
  47. GDBPYOPTS=[
  48. "-ex",
  49. "source ${FBT_DEBUG_DIR}/FreeRTOS/FreeRTOS.py",
  50. "-ex",
  51. "source ${FBT_DEBUG_DIR}/flipperapps.py",
  52. "-ex",
  53. "fap-set-debug-elf-root ${FBT_FAP_DEBUG_ELF_ROOT}",
  54. "-ex",
  55. "source ${FBT_DEBUG_DIR}/PyCortexMDebug/PyCortexMDebug.py",
  56. "-ex",
  57. "svd_load ${SVD_FILE}",
  58. "-ex",
  59. "compare-sections",
  60. ],
  61. JFLASHPROJECT="${FBT_DEBUG_DIR}/fw.jflash",
  62. )
  63. def exists(env):
  64. return True