Skip to content

Commit 8b5f3e2

Browse files
Allow OTA uploads (#66)
Fixes #17
1 parent ddceea1 commit 8b5f3e2

File tree

2 files changed

+64
-28
lines changed

2 files changed

+64
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
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.4.0",
5+
"version": "1.5.0",
66
"engines": {
77
"vscode": "^1.82.0"
88
},

src/extension.ts

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ export function activate(context: vscode.ExtensionContext) {
371371
writeEmitter.fire(red("\r\n\r\nERROR: mklittlefs not found!\r\n" + resetStyle));
372372
}
373373

374-
// TBD - add non-serial UF2 upload via OpenOCD
374+
let network = false;
375+
let networkPort = 0;
375376
let serialPort = "";
376377
if (uploadmethod === "picotool") {
377378
serialPort = "picotool";
@@ -383,10 +384,20 @@ export function activate(context: vscode.ExtensionContext) {
383384
} else {
384385
serialPort = arduinoContext.port?.address;
385386
}
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-
//}
387+
if (arduinoContext.port?.protocol === "network") {
388+
if (!arduinoContext.port?.properties.port) {
389+
writeEmitter.fire(red("\r\n\r\nERROR: Network upload but port specified, check IDE menus.\r\n"));
390+
return;
391+
}
392+
networkPort = Number(arduinoContext.port?.properties.port);
393+
network = true;
394+
writeEmitter.fire(blue("Network Info: ") + green(serialPort + ":" + String(networkPort)) + "\r\n");
395+
} else if (arduinoContext.port?.protocol === "serial") {
396+
writeEmitter.fire(blue(" Serial Port: ") + green(serialPort) + "\r\n");
397+
} else {
398+
writeEmitter.fire(red("\r\n\r\nERROR: Unknown upload method '" + String(arduinoContext.port?.properties.port) + "' specified, check IDE menus.\r\n"));
399+
return;
400+
}
390401

391402
let python3 = "python3" + ext;
392403
let python3Path = undefined;
@@ -467,33 +478,58 @@ export function activate(context: vscode.ExtensionContext) {
467478
uploadOpts = ["-f", "interface/cmsis-dap.cfg", "-f", "target/" + chip +".cfg", "-s", openocdPath + "/share/openocd/scripts",
468479
"-c", "init; adapter speed 5000; program "+ imageFile + " verify 0x" + fsStart.toString(16) + "; reset; exit"];
469480
} else {
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"];
481+
if (network) {
482+
let espota = "tools" + path.sep + "espota.py";
483+
let espotaPath = findTool(arduinoContext, "runtime.platform.path");
484+
if (espotaPath) {
485+
espota = espotaPath + path.sep + espota;
486+
}
487+
uploadOpts = ["-I", espota, "-i", serialPort, "-p", String(networkPort), "-f", imageFile, "-s"];
477488
} else {
478-
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
489+
let uf2conv = "tools" + path.sep + "uf2conv.py";
490+
let uf2Path = findTool(arduinoContext, "runtime.platform.path");
491+
if (uf2Path) {
492+
uf2conv = uf2Path + path.sep + uf2conv;
493+
}
494+
if (conversion) {
495+
uploadOpts = [uf2conv, "--serial", serialPort, "--family", "RP2040", imageFile + ".uf2", "--deploy"];
496+
} else {
497+
uploadOpts = [uf2conv, "--base", String(fsStart), "--serial", serialPort, "--family", "RP2040", imageFile];
498+
}
479499
}
480500
}
481501
} else if (esp32) {
482-
let flashMode = arduinoContext.boardDetails.buildProperties["build.flash_mode"];
483-
let flashFreq = arduinoContext.boardDetails.buildProperties["build.flash_freq"];
484-
let espTool = "esptool" + extEspTool;
485-
let espToolPath = findTool(arduinoContext, "runtime.tools.esptool_py.path");
486-
if (espToolPath) {
487-
espTool = espToolPath + path.sep + espTool;
488-
}
489-
uploadOpts = ["--chip", esp32variant, "--port", serialPort, "--baud", String(uploadSpeed),
490-
"--before", "default_reset", "--after", "hard_reset", "write_flash", "-z",
491-
"--flash_mode", flashMode, "--flash_freq", flashFreq, "--flash_size", "detect", String(fsStart), imageFile];
492-
if ((platform() === 'win32') || (platform() === 'darwin')) {
493-
cmdApp = espTool; // Have binary EXE on Mac/Windows
502+
if (network) {
503+
let espota = "tools" + path.sep + "espota.py";
504+
let espotaPath = findTool(arduinoContext, "runtime.platform.path");
505+
if (espotaPath) {
506+
espota = espotaPath + path.sep + espota;
507+
}
508+
uploadOpts = ["-r", "-i", serialPort, "-p", String(networkPort), "-f", imageFile, "-s"];
509+
510+
if ((platform() === 'win32') || (platform() === 'darwin')) {
511+
cmdApp = espota; // Have binary EXE on Mac/Windows
512+
} else {
513+
cmdApp = "python3"; // Not shipped, assumed installed on Linux
514+
uploadOpts.unshift(espota); // Need to call Python3
515+
}
494516
} else {
495-
cmdApp = "python3"; // Not shipped, assumed installed on Linux
496-
uploadOpts.unshift(espTool); // Need to call Python3
517+
let flashMode = arduinoContext.boardDetails.buildProperties["build.flash_mode"];
518+
let flashFreq = arduinoContext.boardDetails.buildProperties["build.flash_freq"];
519+
let espTool = "esptool" + extEspTool;
520+
let espToolPath = findTool(arduinoContext, "runtime.tools.esptool_py.path");
521+
if (espToolPath) {
522+
espTool = espToolPath + path.sep + espTool;
523+
}
524+
uploadOpts = ["--chip", esp32variant, "--port", serialPort, "--baud", String(uploadSpeed),
525+
"--before", "default_reset", "--after", "hard_reset", "write_flash", "-z",
526+
"--flash_mode", flashMode, "--flash_freq", flashFreq, "--flash_size", "detect", String(fsStart), imageFile];
527+
if ((platform() === 'win32') || (platform() === 'darwin')) {
528+
cmdApp = espTool; // Have binary EXE on Mac/Windows
529+
} else {
530+
cmdApp = "python3"; // Not shipped, assumed installed on Linux
531+
uploadOpts.unshift(espTool); // Need to call Python3
532+
}
497533
}
498534
} else { // esp8266
499535
let upload = "tools" + path.sep + "upload.py";

0 commit comments

Comments
 (0)