Skip to content

Commit ddceea1

Browse files
Support Picotool and OpenOCD uploads on the Picos (#65)
1 parent 5edc749 commit ddceea1

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "arduino-littlefs-upload",
33
"displayName": "arduino-littlefs-upload",
44
"description": "Build and uploads LittleFS filesystems for the Arduino-Pico RP2040 core, ESP8266 core, or ESP32 core under Arduino IDE 2.2.1 or higher",
5-
"version": "1.3.0",
5+
"version": "1.4.0",
66
"engines": {
77
"vscode": "^1.82.0"
88
},

src/extension.ts

+56-14
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ async function runCommand(exe : string, opts : any[]) {
125125
return exitCode;
126126
}
127127

128+
function getSelectedUploadMethod(boardDetails : BoardDetails) : string {
129+
const uploadOptions = boardDetails.configOptions.find(option => option.option === "uploadmethod");
130+
if (uploadOptions === undefined) {
131+
return "default";
132+
}
133+
134+
const selectedOption = uploadOptions.values.find(value => value.selected === true);
135+
if (selectedOption === undefined) {
136+
return "default";
137+
}
138+
139+
return selectedOption.value;
140+
}
141+
128142
function getSelectedPartitionScheme(boardDetails : BoardDetails) : string | undefined {
129143
const partitionSchemeOptions = boardDetails.configOptions.find(option => option.option === "PartitionScheme");
130144
if (partitionSchemeOptions === undefined) {
@@ -222,13 +236,18 @@ export function activate(context: vscode.ExtensionContext) {
222236

223237
// Figure out what we're running on
224238
let pico = false;
239+
let rp2350 = false;
240+
let uploadmethod = "default";
225241
let esp8266 = false;
226242
let esp32 = false;
227243
let esp32variant = "";
228244
switch (arduinoContext.fqbn.split(':')[1]) {
229245
case "rp2040": {
230246
writeEmitter.fire(blue(" Device: ") + green("RP2040 series") + "\r\n");
231247
pico = true;
248+
rp2350 = arduinoContext.boardDetails.buildProperties['build.chip'].startsWith("rp2350");
249+
uploadmethod = getSelectedUploadMethod(arduinoContext.boardDetails);
250+
writeEmitter.fire(blue("Upload Using: ") + green(uploadmethod) + "\r\n");
232251
break;
233252
}
234253
case "esp8266": {
@@ -354,24 +373,31 @@ export function activate(context: vscode.ExtensionContext) {
354373

355374
// TBD - add non-serial UF2 upload via OpenOCD
356375
let serialPort = "";
357-
if (arduinoContext.port?.address === undefined) {
376+
if (uploadmethod === "picotool") {
377+
serialPort = "picotool";
378+
} else if (uploadmethod === "picoprobe_cmsis_dap") {
379+
serialPort = "openocd";
380+
} else if (arduinoContext.port?.address === undefined) {
358381
writeEmitter.fire(red("\r\n\r\nERROR: No port specified, check IDE menus.\r\n"));
359382
return;
360383
} else {
361384
serialPort = arduinoContext.port?.address;
362385
}
363-
if (arduinoContext.port?.protocol !== "serial") {
364-
writeEmitter.fire(red("\r\n\r\nERROR: Only serial port upload supported at this time.\r\n"));
365-
return;
366-
}
386+
//if (arduinoContext.port?.protocol !== "serial") {
387+
// writeEmitter.fire(red("\r\n\r\nERROR: Only serial port upload supported at this time.\r\n"));
388+
// return;
389+
//}
367390

368391
let python3 = "python3" + ext;
369392
let python3Path = undefined;
370393
let picotool = "picotool" + ext;
371394
let picotoolPath = undefined;
395+
let openocd = "openocd" + ext;
396+
let openocdPath = undefined;
372397
if (pico) {
373398
python3Path = findTool(arduinoContext, "runtime.tools.pqt-python3");
374399
picotoolPath = findTool(arduinoContext, "runtime.tools.pqt-picotool");
400+
openocdPath = findTool(arduinoContext, "runtime.tools.pqt-openocd");
375401
} else if (esp8266) {
376402
python3Path = findTool(arduinoContext, "runtime.tools.python3");
377403
} else if (esp32) {
@@ -383,6 +409,9 @@ export function activate(context: vscode.ExtensionContext) {
383409
if (picotoolPath) {
384410
picotool = picotoolPath + path.sep + picotool;
385411
}
412+
if (openocdPath) {
413+
openocd = openocdPath + path.sep + "bin" + path.sep + openocd;
414+
}
386415

387416
// We can't always know where the compile path is, so just use a temp name
388417
const tmp = require('tmp');
@@ -404,7 +433,7 @@ export function activate(context: vscode.ExtensionContext) {
404433
let conversion = false
405434
if (pico) {
406435
if (Number(arduinoContext.boardDetails?.buildProperties['version'].split('.')[0]) > 3) {
407-
if (arduinoContext.boardDetails.buildProperties['build.chip'] == "rp2350") {
436+
if (rp2350) {
408437
// Pico 4.x needs a preparation stage for the RP2350
409438
writeEmitter.fire(bold("\r\n4.0 or above\r\n"));
410439
let picotoolOpts = ["uf2", "convert", imageFile, "-t", "bin", imageFile + ".uf2", "-o", "0x" + fsStart.toString(16), "--family", "data"];
@@ -426,15 +455,28 @@ export function activate(context: vscode.ExtensionContext) {
426455
let uploadOpts : any[] = [];
427456
let cmdApp = python3;
428457
if (pico) {
429-
let uf2conv = "tools" + path.sep + "uf2conv.py";
430-
let uf2Path = findTool(arduinoContext, "runtime.platform.path");
431-
if (uf2Path) {
432-
uf2conv = uf2Path + path.sep + uf2conv;
433-
}
434-
if (conversion) {
435-
uploadOpts = [uf2conv, "--serial", serialPort, "--family", "RP2040", imageFile + ".uf2", "--deploy"];
458+
if (uploadmethod === "picotool") {
459+
cmdApp = picotool;
460+
uploadOpts = ["load", imageFile, "-o", "0x" + fsStart.toString(16), "-f", "-x"];
461+
} else if (uploadmethod === "picoprobe_cmsis_dap") {
462+
cmdApp = openocd;
463+
let chip = "rp2040";
464+
if (arduinoContext.boardDetails.buildProperties['build.chip']) {
465+
chip = arduinoContext.boardDetails.buildProperties['build.chip'];
466+
}
467+
uploadOpts = ["-f", "interface/cmsis-dap.cfg", "-f", "target/" + chip +".cfg", "-s", openocdPath + "/share/openocd/scripts",
468+
"-c", "init; adapter speed 5000; program "+ imageFile + " verify 0x" + fsStart.toString(16) + "; reset; exit"];
436469
} else {
437-
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
470+
let uf2conv = "tools" + path.sep + "uf2conv.py";
471+
let uf2Path = findTool(arduinoContext, "runtime.platform.path");
472+
if (uf2Path) {
473+
uf2conv = uf2Path + path.sep + uf2conv;
474+
}
475+
if (conversion) {
476+
uploadOpts = [uf2conv, "--serial", serialPort, "--family", "RP2040", imageFile + ".uf2", "--deploy"];
477+
} else {
478+
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
479+
}
438480
}
439481
} else if (esp32) {
440482
let flashMode = arduinoContext.boardDetails.buildProperties["build.flash_mode"];

0 commit comments

Comments
 (0)