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