platform.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # WizIO 2021 Georgi Angelov
  2. # http://www.wizio.eu/
  3. # https://github.com/Wiz-IO/wizio-pico
  4. from platformio.managers.platform import PlatformBase
  5. import os, platform, copy
  6. from os.path import join
  7. from platform import system, machine
  8. def get_system():
  9. sys_dir = system() +'_'+ machine()
  10. sys_dir = sys_dir.lower()
  11. if 'windows' in sys_dir:
  12. sys_dir = 'windows'
  13. return sys_dir
  14. class WiziopicoPlatform(PlatformBase):
  15. def is_embedded(self):
  16. return True
  17. def get_boards(self, id_=None):
  18. result = PlatformBase.get_boards(self, id_)
  19. if not result:
  20. return result
  21. if id_:
  22. return self._add_dynamic_options(result)
  23. else:
  24. for key, value in result.items():
  25. result[key] = self._add_dynamic_options(result[key])
  26. return result
  27. def _add_dynamic_options(self, board):
  28. # upload protocols
  29. if not board.get("upload.protocols", []):
  30. board.manifest["upload"]["protocols"] = ["uf2"]
  31. if not board.get("upload.protocol", ""):
  32. board.manifest["upload"]["protocol"] = "uf2"
  33. # debug tools
  34. debug = board.manifest.get("debug", {})
  35. non_debug_protocols = [ "uf2" ]
  36. supported_debug_tools = [ "cmsis-dap", "picoprobe", ]
  37. upload_protocol = board.manifest.get("upload", {}).get("protocol")
  38. upload_protocols = board.manifest.get("upload", {}).get("protocols", [])
  39. if debug:
  40. upload_protocols.extend(supported_debug_tools)
  41. if upload_protocol and upload_protocol not in upload_protocols:
  42. upload_protocols.append(upload_protocol)
  43. board.manifest["upload"]["protocols"] = upload_protocols
  44. if "tools" not in debug:
  45. debug["tools"] = {}
  46. for link in upload_protocols:
  47. if link in non_debug_protocols or link in debug["tools"]: continue
  48. server_args = [
  49. "-s", "$PACKAGE_DIR/share/openocd/scripts",
  50. "-f", "interface/%s.cfg" % link,
  51. "-f", "target/%s" % debug.get("openocd_target")
  52. ]
  53. if link == "picoprobe":
  54. init_cmds = [ ] # use pio default settings
  55. else:
  56. init_cmds = [
  57. "target extended-remote $DEBUG_PORT",
  58. "define pio_reset_halt_target",
  59. "end",
  60. "define pio_reset_run_target",
  61. "end"
  62. ]
  63. if link == 'picoprobe':
  64. debug["tools"][link] = {
  65. "server": {
  66. "package" : "tool-pico-openocd",
  67. "executable" : join(get_system(), "picoprobe"), # EXE
  68. "arguments" : server_args,
  69. },
  70. "init_cmds" : init_cmds,
  71. "onboard" : link in debug.get("onboard_tools", []),
  72. "default" : link == debug.get("default_tool"),
  73. }
  74. else: # CMSIS-DAP
  75. debug["tools"][link] = {
  76. "server": {
  77. "package" : "tool-pico-openocd",
  78. "executable" : join(get_system(), "openocd_rp2040"), # EXE
  79. "arguments" : server_args,
  80. },
  81. "init_cmds" : init_cmds,
  82. "onboard" : link in debug.get("onboard_tools", []),
  83. "default" : link == debug.get("default_tool"),
  84. }
  85. board.manifest["debug"] = debug
  86. return board
  87. def configure_debug_options(self, initial_debug_options, ide_data):
  88. """
  89. Deprecated. Remove method when PlatformIO Core 5.2 is released
  90. """
  91. debug_options = copy.deepcopy(initial_debug_options)
  92. if "cmsis-dap" in debug_options["tool"]:
  93. debug_options["server"]["arguments"].extend( [
  94. "-c", "adapter speed %s" % (initial_debug_options.get("speed") or "20000"),
  95. "-c", "transport select swd"
  96. ]
  97. )
  98. return debug_options