fbt_debugopts.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. "source ${FBT_DEBUG_DIR}/gdbinit",
  36. ],
  37. GDBOPTS_BLACKMAGIC=[
  38. "-q",
  39. "-ex",
  40. "monitor swdp_scan",
  41. "-ex",
  42. "monitor debug_bmp enable",
  43. "-ex",
  44. "attach 1",
  45. "-ex",
  46. "set mem inaccessible-by-default off",
  47. ],
  48. GDBPYOPTS=[
  49. "-ex",
  50. "source ${FBT_DEBUG_DIR}/FreeRTOS/FreeRTOS.py",
  51. "-ex",
  52. "source ${FBT_DEBUG_DIR}/flipperapps.py",
  53. "-ex",
  54. "fap-set-debug-elf-root ${FBT_FAP_DEBUG_ELF_ROOT}",
  55. "-ex",
  56. "source ${FBT_DEBUG_DIR}/PyCortexMDebug/PyCortexMDebug.py",
  57. "-ex",
  58. "svd_load ${SVD_FILE}",
  59. "-ex",
  60. "compare-sections",
  61. ],
  62. JFLASHPROJECT="${FBT_DEBUG_DIR}/fw.jflash",
  63. )
  64. def exists(env):
  65. return True