Skip to content

Commit 78f328a

Browse files
Support RP2350 uploads automatically (#52)
The RP2350 needs special UF2 processing to support a binary flash. Adjust the command lines depending on the build revision for the Pico core to accomodate. Fixes #51
1 parent bca9cc4 commit 78f328a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/extension.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,11 @@ export function activate(context: vscode.ExtensionContext) {
337337

338338
let python3 = "python3" + ext;
339339
let python3Path = undefined;
340+
let picotool = "picotool" + ext;
341+
let picotoolPath = undefined;
340342
if (pico) {
341343
python3Path = findTool(arduinoContext, "runtime.tools.pqt-python3");
344+
picotoolPath = findTool(arduinoContext, "runtime.tools.pqt-picotool");
342345
} else if (esp8266) {
343346
python3Path = findTool(arduinoContext, "runtime.tools.python3");
344347
} else if (esp32) {
@@ -347,6 +350,9 @@ export function activate(context: vscode.ExtensionContext) {
347350
if (python3Path) {
348351
python3 = python3Path + path.sep + python3;
349352
}
353+
if (picotoolPath) {
354+
picotool = picotoolPath + path.sep + picotool;
355+
}
350356

351357
// We can't always know where the compile path is, so just use a temp name
352358
const tmp = require('tmp');
@@ -365,6 +371,25 @@ export function activate(context: vscode.ExtensionContext) {
365371
return;
366372
}
367373

374+
let conversion = false
375+
if (pico) {
376+
if (Number(arduinoContext.boardDetails?.buildProperties['version'].split('.')[0]) > 3) {
377+
// Pico 4.x needs a preparation stage for the RP2350
378+
writeEmitter.fire(bold("\r\n4.0 or above\r\n"));
379+
let picotoolOpts = ["uf2", "convert", imageFile, "-t", "bin", imageFile + ".uf2", "-o", "0x" + fsStart.toString(16), "--family", "data"];
380+
writeEmitter.fire(bold("\r\nGenerating UF2 image\r\n"));
381+
writeEmitter.fire(blue("Command Line: ") + green(picotool + " " + picotoolOpts.join(" ") + "\r\n"));
382+
exitCode = await runCommand(picotool, picotoolOpts);
383+
if (exitCode) {
384+
writeEmitter.fire(red("\r\n\r\nERROR: Generation failed, error code: " + String(exitCode) + "\r\n\r\n"));
385+
return;
386+
}
387+
conversion = true;
388+
} else {
389+
writeEmitter.fire(bold("\r\n3.x, no UF2 conversion\r\n"));
390+
}
391+
}
392+
368393
// Upload stage differs per core
369394
let uploadOpts : any[] = [];
370395
let cmdApp = python3;
@@ -374,7 +399,11 @@ export function activate(context: vscode.ExtensionContext) {
374399
if (uf2Path) {
375400
uf2conv = uf2Path + path.sep + uf2conv;
376401
}
377-
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
402+
if (conversion) {
403+
uploadOpts = [uf2conv, "--serial", serialPort, "--family", "RP2040", imageFile + ".uf2", "--deploy"];
404+
} else {
405+
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
406+
}
378407
} else if (esp32) {
379408
let flashMode = arduinoContext.boardDetails.buildProperties["build.flash_mode"];
380409
let flashFreq = arduinoContext.boardDetails.buildProperties["build.flash_freq"];

0 commit comments

Comments
 (0)