fbt_debugopts.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from re import search
  2. from SCons.Errors import UserError
  3. from fbt_options import OPENOCD_OPTS
  4. def _get_device_serials(search_str="STLink"):
  5. import serial.tools.list_ports as list_ports
  6. return set([device.serial_number for device in list_ports.grep(search_str)])
  7. def GetDevices(env):
  8. serials = _get_device_serials()
  9. if len(serials) == 0:
  10. raise UserError("No devices found")
  11. print("\n".join(serials))
  12. def generate(env, **kw):
  13. env.AddMethod(GetDevices)
  14. if (adapter_serial := env.subst("$OPENOCD_ADAPTER_SERIAL")) != "auto":
  15. env.Append(
  16. OPENOCD_OPTS=[
  17. "-c",
  18. f"adapter serial {adapter_serial}",
  19. ]
  20. )
  21. # Final command is "init", always explicitly added
  22. env.Append(
  23. OPENOCD_OPTS=["-c", "init"],
  24. )
  25. env.SetDefault(
  26. OPENOCD_GDB_PIPE=[
  27. "|openocd -c 'gdb_port pipe; log_output debug/openocd.log' ${[SINGLEQUOTEFUNC(OPENOCD_OPTS)]}"
  28. ],
  29. GDBOPTS_BASE=[
  30. "-ex",
  31. "target extended-remote ${GDBREMOTE}",
  32. "-ex",
  33. "set confirm off",
  34. "-ex",
  35. "set pagination off",
  36. ],
  37. GDBOPTS_BLACKMAGIC=[
  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 debug/FreeRTOS/FreeRTOS.py",
  50. "-ex",
  51. "source debug/flipperapps.py",
  52. "-ex",
  53. "source debug/PyCortexMDebug/PyCortexMDebug.py",
  54. "-ex",
  55. "svd_load ${SVD_FILE}",
  56. "-ex",
  57. "compare-sections",
  58. ],
  59. JFLASHPROJECT="${ROOT_DIR.abspath}/debug/fw.jflash",
  60. )
  61. def exists(env):
  62. return True