Skip to content

Commit

Permalink
Command line loader fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Dec 7, 2024
1 parent efa7eab commit b574305
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 10 additions & 14 deletions modules/spin-tools/src/com/maccasoft/propeller/SpinCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b574305

Please sign in to comment.