Skip to content

Commit ca2adba

Browse files
committed
Add OpenOCD as an alternative upload method for atmelsam platform // Issue #732
1 parent df0373c commit ca2adba

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

platformio/boards/arduino.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,18 @@
881881
"frameworks": ["arduino"],
882882
"name": "Arduino Zero (Programming Port)",
883883
"platform": "atmelsam",
884+
"debug": {
885+
"openocdcfg": "arduino_zero.cfg"
886+
},
884887
"upload": {
885888
"disable_flushing": true,
886889
"maximum_ram_size": 32768,
887890
"maximum_size": 262144,
888891
"protocol": "openocd",
889892
"require_upload_port" : false,
890893
"use_1200bps_touch": false,
891-
"wait_for_upload_port": false
894+
"wait_for_upload_port": false,
895+
"section_start": "0x2000"
892896
},
893897
"url": "https://www.arduino.cc/en/Main/ArduinoBoardZero",
894898
"vendor": "Arduino"
@@ -974,6 +978,9 @@
974978
"frameworks": ["arduino"],
975979
"name": "Arduino M0 Pro (Programming Port)",
976980
"platform": "atmelsam",
981+
"debug": {
982+
"openocdcfg": "arduino_zero_org.cfg"
983+
},
977984
"upload": {
978985
"disable_flushing": true,
979986
"maximum_ram_size": 32768,

platformio/boards/atmelsam.json

+12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"frameworks": ["mbed"],
99
"name": "Atmel ATSAMR21-XPRO",
1010
"platform": "atmelsam",
11+
"debug": {
12+
"openocdcfg": "atmel_samr21_xplained_pro.cfg"
13+
},
1114
"upload": {
15+
"protocol": "openocd",
1216
"maximum_ram_size": 32768,
1317
"maximum_size": 262144
1418
},
@@ -24,7 +28,11 @@
2428
"frameworks": ["mbed"],
2529
"name": "Atmel SAML21-XPRO-B",
2630
"platform": "atmelsam",
31+
"debug": {
32+
"openocdcfg": "atmel_saml21_xplained_pro.cfg"
33+
},
2734
"upload": {
35+
"protocol": "openocd",
2836
"maximum_ram_size": 32768,
2937
"maximum_size": 262144
3038
},
@@ -40,7 +48,11 @@
4048
"frameworks": ["mbed"],
4149
"name": "Atmel SAMD21-XPRO",
4250
"platform": "atmelsam",
51+
"debug": {
52+
"openocdcfg": "atmel_samd21_xplained_pro.cfg"
53+
},
4354
"upload": {
55+
"protocol": "openocd",
4456
"maximum_ram_size": 32768,
4557
"maximum_size": 262144
4658
},

platformio/builder/scripts/atmelsam.py

+22-19
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,33 @@ def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
122122
UPLOADER=join("$PIOPACKAGES_DIR", "tool-openocd", "bin", "openocd"),
123123
UPLOADERFLAGS=[
124124
"-d2",
125-
"-s", join(
126-
"$PIOPACKAGES_DIR",
127-
"tool-openocd",
128-
"share",
129-
"openocd",
130-
"scripts"
131-
),
132-
133-
"-f", join(
134-
"$PLATFORMFW_DIR",
135-
"variants",
136-
"${BOARD_OPTIONS['build']['variant']}",
137-
"openocd_scripts",
138-
"${BOARD_OPTIONS['build']['variant']}.cfg"
139-
),
125+
"-f", join(BOARD_OPTIONS.get("debug", {}).get("openocdcfg", "")),
126+
"-s", join("$PIOPACKAGES_DIR", "tool-openocd",
127+
"share", "openocd", "scripts"),
128+
"-s", join("$PIOPACKAGES_DIR", "tool-openocd",
129+
"share", "openocd", "scripts", "board")
130+
],
131+
132+
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
133+
)
134+
135+
if "zero" in env.subst("$BOARD"):
136+
env.Append(
137+
UPLOADERFLAGS=[
138+
"-s", join("$PLATFORMFW_DIR", "variants",
139+
"${BOARD_OPTIONS['build']['variant']}",
140+
"openocd_scripts")
141+
]
142+
)
140143

144+
env.Append(
145+
UPLOADERFLAGS=[
141146
"-c", "\"telnet_port", "disabled;",
142147
"program", "{{$SOURCES}}",
143148
"verify", "reset",
144-
"%s;" % user_code_section if user_code_section else "0x2000",
149+
"%s;" % user_code_section if user_code_section else "",
145150
"shutdown\""
146-
],
147-
148-
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS'
151+
]
149152
)
150153

151154
elif upload_protocol == "sam-ba":

0 commit comments

Comments
 (0)