From b57430596a06a91d2876d6e38cea3288cacabc40 Mon Sep 17 00:00:00 2001 From: Marco Maccaferri Date: Sat, 7 Dec 2024 13:12:56 +0100 Subject: [PATCH] Command line loader fixes --- .../maccasoft/propeller/Propeller1Loader.java | 6 ++--- .../propeller/Propeller1NetworkLoader.java | 8 ++++++- .../maccasoft/propeller/Propeller2Loader.java | 2 +- .../com/maccasoft/propeller/SpinCompiler.java | 24 ++++++++----------- .../propeller/devices/NetworkComPort.java | 10 ++++++-- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/modules/spin-tools/src/com/maccasoft/propeller/Propeller1Loader.java b/modules/spin-tools/src/com/maccasoft/propeller/Propeller1Loader.java index d9ce6e5c..06c447b7 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/Propeller1Loader.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/Propeller1Loader.java @@ -173,7 +173,7 @@ protected int hwfind() throws ComPortException { // Some chips may respond < 50ms, but there's no guarantee all will. // If we don't get it, we can assume the propeller is not there. if ((ii = getBit(110)) == -1) { - throw new ComPortException("Timeout waiting for first response bit"); + return 0; } //System.out.print(String.format("%02X ", ii)); @@ -201,7 +201,7 @@ protected int hwfind() throws ComPortException { } while (to++ < 100); if (to > 100) { - throw new ComPortException("Timeout waiting for response bit"); + return 0; } } //System.out.println(); @@ -257,7 +257,7 @@ public void upload(byte[] binaryImage, int type) throws ComPortException { try { hwreset(); if (hwfind() == 0) { - throw new ComPortException("Propeller 1 not found"); + throw new ComPortException("No propeller chip on port " + comPort.getPortName()); } bufferUpload(type, binaryImage, "binary image"); } finally { diff --git a/modules/spin-tools/src/com/maccasoft/propeller/Propeller1NetworkLoader.java b/modules/spin-tools/src/com/maccasoft/propeller/Propeller1NetworkLoader.java index a3c54dd9..3896b04c 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/Propeller1NetworkLoader.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/Propeller1NetworkLoader.java @@ -68,6 +68,10 @@ public Propeller1NetworkLoader(NetworkComPort serialPort, boolean shared, Propel this.shared = shared; } + public NetworkComPort getComPort() { + return comPort; + } + @Override public ComPort detect() { if (comPort != null) { @@ -200,7 +204,9 @@ protected void bufferUpload(int type, byte[] binaryImage, String text) throws Co sb.append("http://"); sb.append(comPort.getInetAddr().getHostAddress()); sb.append("/propeller/load?baud-rate=115200"); - sb.append("&reset-pin=" + comPort.getResetPin()); + if (comPort.getResetPin() != null && !comPort.getResetPin().isBlank()) { + sb.append("&reset-pin=" + comPort.getResetPin()); + } HttpRequest httpRequest = HttpRequest.newBuilder(new URI(sb.toString())) // .POST(BodyPublishers.ofByteArray(loaderImage)) // .timeout(Duration.ofMillis(NetworkComPort.RESPONSE_TIMEOUT)) // diff --git a/modules/spin-tools/src/com/maccasoft/propeller/Propeller2Loader.java b/modules/spin-tools/src/com/maccasoft/propeller/Propeller2Loader.java index 55420a83..3fc4427e 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/Propeller2Loader.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/Propeller2Loader.java @@ -200,7 +200,7 @@ public void upload(byte[] binaryImage, int type) throws ComPortException { try { hwreset(); if (hwfind() == 0) { - throw new ComPortException("Propeller 2 not found"); + throw new ComPortException("No propeller chip on port " + comPort.getPortName()); } bufferUpload(type, binaryImage, "binary image"); } finally { diff --git a/modules/spin-tools/src/com/maccasoft/propeller/SpinCompiler.java b/modules/spin-tools/src/com/maccasoft/propeller/SpinCompiler.java index 9a9a8dc8..f9f7b1ac 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/SpinCompiler.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/SpinCompiler.java @@ -101,6 +101,7 @@ public static void main(String[] args) { options.addOptionGroup(terminalOptions); options.addOption(new Option("W", false, "show all discovered wifi modules")); + options.addOption(new Option(null, "reset-pin", true, "set wifi module reset pin number")); options.addOption("q", false, "quiet mode"); @@ -322,6 +323,12 @@ else if (portName.indexOf(':') != -1) { } } } + if (serialPort != null) { + String resetPin = cmd.getOptionValue("reset-pin"); + if (resetPin != null) { + ((NetworkComPort) serialPort).setResetPin(resetPin); + } + } } catch (Exception e) { println(e.getMessage()); System.exit(1); @@ -347,15 +354,9 @@ else if (portName.indexOf(':') != -1) { @Override protected int hwfind() throws ComPortException { int version = super.hwfind(); - if (version != 0) { println(String.format("Propeller %d on port %s", version, getPortName())); } - else { - println(String.format("No propeller chip on port %s", getPortName())); - error.set(true); - } - return version; } @@ -417,22 +418,16 @@ protected void eepromVerify() throws ComPortException { }; } - else if (serialPort instanceof NetworkComPort) { + else if (compiler instanceof Spin2Compiler) { flags = cmd.hasOption("f") ? Propeller2Loader.DOWNLOAD_RUN_FLASH : Propeller2Loader.DOWNLOAD_RUN_RAM; loader = new Propeller2Loader((SerialComPort) serialPort, true) { @Override protected int hwfind() throws ComPortException { int version = super.hwfind(); - if (version != 0) { println(String.format("Propeller %d on port %s", version, getPortName())); } - else { - println(String.format("No propeller chip on port %s", getPortName())); - error.set(true); - } - return version; } @@ -473,6 +468,7 @@ protected void verifyRam() throws ComPortException { @Override protected void bufferUpload(int type, byte[] binaryImage, String text) throws ComPortException { + println(String.format("Propeller %d on %s", 1, getComPort().getInetAddr().getHostAddress())); print("Loading " + text + " to "); switch (type) { case Propeller1Loader.DOWNLOAD_EEPROM: @@ -635,7 +631,7 @@ else if (cmd == 15) { // PY: Position cursor in Y println("Done."); } - } catch (ParseException e) { + } catch (ParseException | ComPortException e) { System.out.println(e.getMessage()); } catch (CompilerException e) { println(e); diff --git a/modules/spin-tools/src/com/maccasoft/propeller/devices/NetworkComPort.java b/modules/spin-tools/src/com/maccasoft/propeller/devices/NetworkComPort.java index 468f0b33..dae923db 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/devices/NetworkComPort.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/devices/NetworkComPort.java @@ -104,7 +104,6 @@ public NetworkComPort(DeviceDescriptor descriptor) { public NetworkComPort(InetAddress inetAddr) { this.name = ""; this.inetAddr = inetAddr; - this.resetPin = "13"; } public NetworkComPort(String name, String inetAddr, String mac_address, String resetPin) { @@ -252,7 +251,14 @@ public void closePort() throws ComPortException { @Override public void hwreset() { try { - Builder builder = HttpRequest.newBuilder(new URI("http://" + inetAddr.getHostAddress() + "/propeller/reset?reset-pin=" + resetPin)); + StringBuilder sb = new StringBuilder(128); + sb.append("http://"); + sb.append(inetAddr.getHostAddress()); + sb.append("/propeller/reset"); + if (resetPin != null && !resetPin.isBlank()) { + sb.append("?reset-pin=" + resetPin); + } + Builder builder = HttpRequest.newBuilder(new URI(sb.toString())); HttpRequest httpRequest = builder.POST(BodyPublishers.noBody()).build(); client.send(httpRequest, BodyHandlers.ofString()); } catch (URISyntaxException | IOException | InterruptedException e) {