Skip to content

Commit

Permalink
V3.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
felias-fogg committed Sep 23, 2023
1 parent 914b9fc commit ba9eee4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
Binary file removed docs/SMD-soldering.png
Binary file not shown.
11 changes: 11 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog for dw-link

## Version 3.5.3

* ISP programmer: disabling debugWIRE mode when switching into programming mode after 'P' record.
* The above change did not work initially because the IC interrupt was still active and blocked apparently everything else. For this reason:
* all dw.enable(true) and dw.enable(false) statements were deleted
* in dwSerial, the enable(true) statements were deleted.

* Now the only place, where the IC interrupt is enabled is the begin method in SingleWireSerial and it is disabled in the end method in SingleWireSerial as well as in the sendBreak and calibrate methods in dwSerial. This appears to be the right way of dealing with this interrupt.
* When autodw is off, everything is done the same way when gdbStop is called, but inside targetStop, the DW stop command is not sent and the DWEN fuse is not cleared.
* Fixed: in gdbG/SetFuses, we now immediately return after an error message caused by autodw-off. Before that, accidentally DW mode was switched off. Interestingly, this led only sometimes to a problem.

## Version 3.5.2 (15-Sep-2023)

* Only cosmetic changes:
Expand Down
4 changes: 0 additions & 4 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,6 @@ I have encountered situations [when it was impossible to get the right informati

## 9 Trouble shooting

#### Problem: When using dw-link as an ISP programmer it seems to be unresponsive.

It could be that the target is still in debugWIRE mode. Start a debugging session and end it regularly, then it is guaranteed that the MCU is back to normal and programming should be possible, provided you have chosen the right programmer STK500v1 (in Arduino speak `Arduino as ISP` or `AVR ISP`). This problem will vanish in future versions of dw-link.

#### Problem: It is impossible to upload the dw-link firmware to the UNO board

Maybe, the dw-link probe shield or the auto-reset disabling capacitor is still plugged into the UNO board? Remove, and try gain.
Expand Down
Binary file modified docs/manual.pdf
Binary file not shown.
57 changes: 32 additions & 25 deletions dw-link/dw-link.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// because relevant input ports are not in the I/O range and therefore the tight timing
// constraints are not satisfied.

#define VERSION "3.5.2"
#define VERSION "3.5.3"

// some constants, you may want to change
#ifndef PROGBPS
Expand All @@ -46,7 +46,6 @@
//#define HOSTBPS 230400UL // works with UNOs, but not with Nanos
#endif
// #define STUCKAT1PC 1 // allow also MCUs that have PCs with stuck-at-1 bits
// #define NOAUTODWOFF 1 // do not automatically leave debugWIRE mode
// #define HIGHSPEEDDW 1 // allow for DW speed up to 250 kbps

// these should stay undefined for the ordinary user
Expand Down Expand Up @@ -796,7 +795,7 @@ void gdbParsePacket(const byte *buff)
gdbUpdateBreakpoints(true); /* remove BREAKS in memory before exit */
validpg = false;
fatalerror = NO_FATAL;
if (!ctx.autodw || gdbStop(false)) /* disable DW mode */
if (gdbStop(false)) /* disable DW mode */
gdbSendReply("OK"); /* and signal that everything is OK */
break;
case 'c': /* continue */
Expand All @@ -807,7 +806,7 @@ void gdbParsePacket(const byte *buff)
break;
case 'k':
gdbUpdateBreakpoints(true); /* remove BREAKS in memory before exit */
if (ctx.autodw) gdbStop(false); /* stop DW mode */
gdbStop(false); /* stop DW mode */
break;
case 's': /* single step */
case 'S': /* step with signal - just ignore signal */
Expand All @@ -819,9 +818,7 @@ void gdbParsePacket(const byte *buff)
break;
case 'v':
if (memcmp_P(buf, (void *)PSTR("vRun"), 4) == 0) {/* Run command */
if (targetOffline() && !ctx.autodw) {
gdbSendReply("E01");
} else if (gdbConnect(false)) { /* re-enable DW mode, reset MCU, and clear PC */
if (gdbConnect(false)) { /* re-enable DW mode, reset MCU, and clear PC */
setSysState(CONN_STATE);
gdbSendState(SIGTRAP); /* trap signal */
} else {
Expand All @@ -830,7 +827,7 @@ void gdbParsePacket(const byte *buff)
} else
if (memcmp_P(buf, (void *)PSTR("vKill"), 5) == 0) {
gdbUpdateBreakpoints(true); /* remove BREAKS in memory before exit */
if (!ctx.autodw || gdbStop(false)) /* stop DW mode (if autodw) */
if (gdbStop(false)) /* stop DW mode (if autodw) */
gdbSendReply("OK"); /* and signal that everything is OK */
} else {
gdbSendReply(""); /* not supported */
Expand All @@ -842,8 +839,8 @@ void gdbParsePacket(const byte *buff)
else if (memcmp_P(buff, (void *)PSTR("qSupported"), 10) == 0) {
//DEBLN(F("qSupported"));
initSession(); /* always init all vars when gdb connects */
if (!ctx.autodw || gdbConnect(false)) /* and try to connect (if autodw) */
gdbSendPSTR((const char *)PSTR("PacketSize=90"));
if (!ctx.autodw || gdbConnect(false)) /* and try to connect (if autodw) */
gdbSendPSTR((const char *)PSTR("PacketSize=90"));
} else if (memcmp_P(buf, (void *)PSTR("qC"), 2) == 0)
gdbSendReply("QC01"); /* current thread is always 1 */
else if (memcmp_P(buf, (void *)PSTR("qfThreadInfo"), 12) == 0)
Expand Down Expand Up @@ -900,7 +897,7 @@ void gdbParseMonitorPacket(byte *buf)
}
break;
case MORESET:
if (gdbReset()) gdbSendReply("OK");
if (gdbReset()) gdbReplyMessagePSTR(PSTR("MCU has been reset"), -1);
else gdbSendReply("E05");
break;
case MOCKDIV:
Expand Down Expand Up @@ -1060,6 +1057,7 @@ boolean gdbConnect(boolean verbose)
gdbReportConnected();
}
gdbCleanupBreakpointTable();
targetReset();
targetInitRegisters();
return true;
}
Expand All @@ -1079,7 +1077,6 @@ boolean gdbConnect(boolean verbose)
DEBLN(conncode);
if (fatalerror == NO_FATAL) fatalerror = -conncode;
setSysState(ERROR_STATE);
if (conncode < 0) dw.enable(false); // otherwise if DWLINE has no pullup, the program goes astray!
flushInput();
targetInitRegisters();
return false;
Expand All @@ -1089,10 +1086,7 @@ boolean gdbConnect(boolean verbose)
// try to disable the debugWIRE interface on the target system
boolean gdbStop(boolean verbose)
{
#if NOAUTODWOFF
if (!verbose) return true; // no silent exits from DW mode
#endif
if (targetStop()) {
if (targetStop(verbose)) {
setSysState(NOTCONN_STATE);
if (verbose) {
gdbReportConnected();
Expand Down Expand Up @@ -1210,7 +1204,6 @@ boolean powerCycle(boolean verbose)
int retry = 0;
byte b;

dw.enable(false);
setSysState(PWRCYC_STATE);
while (retry < 20) {
//DEBPR(F("retry=")); DEBLN(retry);
Expand All @@ -1234,7 +1227,6 @@ boolean powerCycle(boolean verbose)
}
//_delay_ms(1000);
_delay_ms(200);
dw.enable(true);
if (targetDWConnect()) {
setSysState(CONN_STATE);
return true;
Expand Down Expand Up @@ -1280,6 +1272,7 @@ void gdbSetFuses(Fuses fuse)
if (!ctx.autodw && !offline) {
gdbDebugMessagePSTR(PSTR("Disable debugWIRE first!"),-1);
gdbSendReply("E01");
return;
}
setSysState(NOTCONN_STATE);
res = targetSetFuses(fuse);
Expand Down Expand Up @@ -1327,6 +1320,7 @@ void gdbGetFuses(boolean ckdiv, boolean noreply)
if (!ctx.autodw && !offline) {
gdbDebugMessagePSTR(PSTR("Disable debugWIRE first!"),-1);
gdbSendReply("E01");
return;
}

setSysState(NOTCONN_STATE);
Expand Down Expand Up @@ -2323,10 +2317,13 @@ int targetISPConnect(void)


// disable debugWIRE mode
boolean targetStop(void)
boolean targetStop(boolean always)
{
int ret = targetSetFuses(DWEN);
leaveProgramMode();
int ret = 1;
if (always || ctx.autodw) {
ret = targetSetFuses(DWEN);
leaveProgramMode();
}
dw.end();
return (ret == 1);
}
Expand Down Expand Up @@ -2690,7 +2687,7 @@ void targetStep(void)
// reset the MCU
boolean targetReset(void)
{
dw.sendCmd((const byte[]) {0x07}, 1, true); // eturn before last bit is sent so that we catch the break
dw.sendCmd((const byte[]) {0x07}, 1, true); // return before last bit is sent so that we catch the break

if (expectBreakAndU()) {
DEBLN(F("RESET successful"));
Expand Down Expand Up @@ -3479,7 +3476,6 @@ boolean enterProgramMode (void)
byte timeout = 6;

//DEBLN(F("Entering progmode"));
dw.enable(false);
ctx.ispspeed = NORMAL_ISP;
do {
if (timeout < 5) ctx.ispspeed = SLOW_ISP;
Expand Down Expand Up @@ -3510,7 +3506,6 @@ void leaveProgramMode(void)
disableSpiPins();
_delay_ms(10);
pinMode(DWLINE, INPUT); // allow MCU to run or to communicate via debugWIRE
dw.enable(true);
}


Expand Down Expand Up @@ -4737,8 +4732,20 @@ void avrisp (void) {

case 0x50: // 'P' - 0x50 Enter Program Mode
if (!pmode) {
if (enterProgramMode())
DEBLN(F("enter PM"));
if (enterProgramMode()) {
DEBLN(F("SUCCESS!"));
pmode = 1;
} else {
DEBLN(F("No prog state"));
if (targetSetFuses(DWEN) == 1) {
DEBLN(F("DW off"));
pmode = 1;
} else {
DEBLN(F("DW still on"));
leaveProgramMode();
}
}
}
if (pmode) {
empty_reply();
Expand Down
2 changes: 0 additions & 2 deletions dw-link/src/dwSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void dwSerial::sendBreak(void)
ICDDR |= _BV(ICBIT); // switch pin to output (which is always low)
_delay_ms(400); // enough for 30 bps
ICDDR &= ~_BV(ICBIT); // and switch it back to being an input
enable(true);
}


Expand Down Expand Up @@ -109,7 +108,6 @@ unsigned long dwSerial::calibrate()
eightbits = eightbits + ICR + 12; // 12 because of the late state of the counter
SREG = saveSREG;
bps = (F_CPU*8/eightbits);
enable(true);
return bps;
}

0 comments on commit ba9eee4

Please sign in to comment.