Automatic script upload working, no buttons or fiddling

Add smarts to the UF2 uploader to potentially trigger a reboot if the
device passed in is /dev/tty* or COM*.  Will cause reboot to USB
bootloader and standard UF2 upload will happen w/o any user
intervention.
This commit is contained in:
Earle F. Philhower, III 2021-02-26 19:16:03 -08:00
parent 77d7a26428
commit 4ac271af72
6 changed files with 26 additions and 2 deletions

View file

@ -122,6 +122,10 @@ static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
void SerialUSB::begin(int baud) {
(void) baud; //ignored
if (_running) {
return;
}
tusb_init();
irq_set_exclusive_handler(PICO_STDIO_USB_LOW_PRIORITY_IRQ, low_priority_worker_irq);
@ -129,6 +133,8 @@ void SerialUSB::begin(int baud) {
mutex_init(&usb_mutex);
add_alarm_in_us(PICO_STDIO_USB_TASK_INTERVAL_US, timer_task, NULL, true);
_running = true;
}
void SerialUSB::end() {

View file

@ -19,6 +19,8 @@ public:
virtual size_t write(const uint8_t *p, size_t len) override;
using Print::write;
operator bool();
private:
bool _running = false;
};
extern SerialUSB Serial;

View file

@ -1,9 +1,12 @@
#include <Arduino.h>
extern void setup();
extern void loop();
extern "C" {
int main() {
Serial.begin();
setup();
while (1) loop();
return 0;

View file

@ -135,6 +135,6 @@ tools.uf2conv.upload.params.quiet=
# First, potentially perform an erase or nothing
# Next, do the binary upload
# Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/system/uf2conv.py" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
tools.uf2conv.upload.pattern="{cmd}" "{runtime.platform.path}/system/uf2conv.py" --serial "{serial.port}" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"
tools.uf2conv.upload.network_pattern="{cmd}" "{runtime.platform.path}/system/uf2conv.py" --family RP2040 --deploy "{build.path}/{build.project_name}.uf2"

View file

@ -32,7 +32,8 @@ import re
import os
import os.path
import argparse
import serial
import time
UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected
@ -290,6 +291,7 @@ def main():
help='specify familyID - number or name (default: 0x0)')
parser.add_argument('-C' , '--carray', action='store_true',
help='convert binary file to a C array, not UF2')
parser.add_argument('-s', '--serial', dest='serial', help='Serial port to reset before upload')
args = parser.parse_args()
appstartaddr = int(args.base, 0)
@ -301,6 +303,17 @@ def main():
except ValueError:
error("Family ID needs to be a number or one of: " + ", ".join(families.keys()))
if args.serial:
if str(args.serial).startswith("/dev/tty") or str(args.serial).startswith("COM"):
try:
ser = serial.Serial(args.serial, 1200)
ser.dtr = False
print("Resetting "+str(args.serial))
# Probably should be smart and check for device appearance or something
time.sleep(10)
except:
pass
if args.list:
list_drives()
else: