fbt_debugopts.py 2.0 KB

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