From 06491d5641788c35e1f4a574989e5dc34a01cbdd Mon Sep 17 00:00:00 2001 From: Bernhard Nebel Date: Wed, 1 Jan 2025 22:57:42 +0100 Subject: [PATCH] V4.0.1 --- .../Add_dw-link-tools-release.sh | 7 ++- .../ATTinyCore-mods/Boards_manager_release.sh | 7 ++- .../MicroCore-mods/Boards_manager_release.sh | 7 ++- .../Add_dw-link-tools-release.sh | 7 ++- .../MiniCore-mods/Boards_manager_release.sh | 13 +++-- docs/changelog.md | 11 ++++ docs/manual.md | 12 ++-- docs/quickstart-AVR-GDB.md | 6 +- docs/quickstart-Arduino-IDE2.md | 6 +- docs/wishlist.md | 25 +++++---- dw-link/dw-link.h | 13 ++--- dw-link/dw-link.ino | 56 +++++++++++-------- 12 files changed, 98 insertions(+), 72 deletions(-) diff --git a/core-mods/ATTinyCore-mods/Add_dw-link-tools-release.sh b/core-mods/ATTinyCore-mods/Add_dw-link-tools-release.sh index a92187d..b2ff394 100644 --- a/core-mods/ATTinyCore-mods/Add_dw-link-tools-release.sh +++ b/core-mods/ATTinyCore-mods/Add_dw-link-tools-release.sh @@ -3,6 +3,7 @@ AUTHOR=felias-fogg # Github username REALAUTHOR=drazzy.com # Real author name REPOSITORY=ATTinyCore # Github repo name +SUFFIX=_plus_Debug # suffix for index file DWTOOLS_VERSION="1.3.0" @@ -63,7 +64,7 @@ printf "File4: ${FILE4}, Size: ${SIZE4}, SHA256: ${SHASUM4}, URL4: ${URL4}\n" #printf "File5: ${FILE5}, Size: ${SIZE5}, SHA256: ${SHASUM5}, URL5: ${URL5}\n" printf "File6: ${FILE6}, Size: ${SIZE6}, SHA256: ${SHASUM6}, URL6: ${URL6}\n" -cp "package_${REALAUTHOR}_${REPOSITORY}_index.json" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +cp "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" ### NOTE: OS platform 5 needs to be added! @@ -140,7 +141,7 @@ jq -r \ "url": $url6 } ] -}' "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}_index.json" +}' "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" rm $FILE1 rm $FILE2 @@ -148,4 +149,4 @@ rm $FILE3 rm $FILE4 #rm $FILE5 rm $FILE6 -rm "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +rm "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" diff --git a/core-mods/ATTinyCore-mods/Boards_manager_release.sh b/core-mods/ATTinyCore-mods/Boards_manager_release.sh index de0a910..f2478a2 100755 --- a/core-mods/ATTinyCore-mods/Boards_manager_release.sh +++ b/core-mods/ATTinyCore-mods/Boards_manager_release.sh @@ -12,6 +12,7 @@ AUTHOR=felias-fogg # Github username REALAUTHOR=drazzy.com # real author REPOSITORY=ATTinyCore # Github repo name +SUFFIX=_plus_Debug # Get the download URL for the latest release from Github DOWNLOAD_URL=$(curl -s https://api.github.com/repos/$AUTHOR/$REPOSITORY/releases/latest | grep "tarball_url" | awk -F\" '{print $4}') @@ -50,7 +51,7 @@ SHA256="SHA-256:$(shasum -a 256 "$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" | a # Create Github download URL URL="https://${AUTHOR}.github.io/${REPOSITORY}/$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" -cp "package_${REALAUTHOR}_${REPOSITORY}_index.json" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +cp "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" # Add new boards release entry jq -r \ @@ -103,7 +104,7 @@ jq -r \ "version": "1.3.0" } ] -}' "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}_index.json" +}' "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" # Remove files that's no longer needed -rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" diff --git a/core-mods/MicroCore-mods/Boards_manager_release.sh b/core-mods/MicroCore-mods/Boards_manager_release.sh index 0695dcf..e58513a 100755 --- a/core-mods/MicroCore-mods/Boards_manager_release.sh +++ b/core-mods/MicroCore-mods/Boards_manager_release.sh @@ -12,6 +12,7 @@ AUTHOR=felias-fogg REALAUTHOR=MCUdude # Github username REPOSITORY=MicroCore # Github repo name +SUFFIX=_plus_Debug # Get the download URL for the latest release from Github DOWNLOAD_URL=$(curl -s https://api.github.com/repos/$AUTHOR/$REPOSITORY/releases/latest | grep "tarball_url" | awk -F\" '{print $4}') @@ -50,7 +51,7 @@ SHA256="SHA-256:$(shasum -a 256 "$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" | a # Create Github download URL URL="https://${AUTHOR}.github.io/${REPOSITORY}/$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" -cp "package_${REALAUTHOR}_${REPOSITORY}_index.json" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +cp "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" # Add new boards release entry jq -r \ @@ -90,7 +91,7 @@ jq -r \ "version": "1.3.0" } ] -}' "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}_index.json" +}' "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" # Remove files that's no longer needed -rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" diff --git a/core-mods/MiniCore-mods/Add_dw-link-tools-release.sh b/core-mods/MiniCore-mods/Add_dw-link-tools-release.sh index 4418990..e69ef49 100755 --- a/core-mods/MiniCore-mods/Add_dw-link-tools-release.sh +++ b/core-mods/MiniCore-mods/Add_dw-link-tools-release.sh @@ -3,6 +3,7 @@ AUTHOR=felias-fogg # Github username REALAUTHOR=MCUDude # Real author name REPOSITORY=MiniCore # Github repo name +SUFFIX=_plus_Debug DWTOOLS_VERSION="1.3.0" @@ -63,7 +64,7 @@ printf "File4: ${FILE4}, Size: ${SIZE4}, SHA256: ${SHASUM4}, URL4: ${URL4}\n" #printf "File5: ${FILE5}, Size: ${SIZE5}, SHA256: ${SHASUM5}, URL5: ${URL5}\n" printf "File6: ${FILE6}, Size: ${SIZE6}, SHA256: ${SHASUM6}, URL6: ${URL6}\n" -cp "package_${REALAUTHOR}_${REPOSITORY}_index.json" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +cp "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" ### NOTE: OS platform 5 needs to be added! @@ -140,7 +141,7 @@ jq -r \ "url": $url6 } ] -}' "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}_index.json" +}' "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" rm $FILE1 rm $FILE2 @@ -148,4 +149,4 @@ rm $FILE3 rm $FILE4 #rm $FILE5 rm $FILE6 -rm "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +rm "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" diff --git a/core-mods/MiniCore-mods/Boards_manager_release.sh b/core-mods/MiniCore-mods/Boards_manager_release.sh index 559e21c..ad70823 100755 --- a/core-mods/MiniCore-mods/Boards_manager_release.sh +++ b/core-mods/MiniCore-mods/Boards_manager_release.sh @@ -9,9 +9,10 @@ ########################################################## # Change these to match your repo -AUTHOR=felias-fogg -REALAUTHOR=MCUdude # Github username -REPOSITORY=MiniCore # Github repo name +AUTHOR=felias-fogg # Github username +REALAUTHOR=MCUdude # real author! +REPOSITORY=MiniCore # Github repo +SUFFIX=_plus_Debug # suffix to distinguish it # Get the download URL for the latest release from Github DOWNLOAD_URL=$(curl -s https://api.github.com/repos/$AUTHOR/$REPOSITORY/releases/latest | grep "tarball_url" | awk -F\" '{print $4}') @@ -50,7 +51,7 @@ SHA256="SHA-256:$(shasum -a 256 "$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" | a # Create Github download URL URL="https://${AUTHOR}.github.io/${REPOSITORY}/$REPOSITORY-${DOWNLOADED_FILE#"v"}.tar.bz2" -cp "package_${REALAUTHOR}_${REPOSITORY}_index.json" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +cp "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" # Add new boards release entry jq -r \ @@ -99,7 +100,7 @@ jq -r \ "version": "1.3.0" } ] -}' "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}_index.json" +}' "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" > "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json" # Remove files that's no longer needed -rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}_index.json.tmp" +rm -rf "$REPOSITORY-${DOWNLOADED_FILE#"v"}" "package_${REALAUTHOR}_${REPOSITORY}${SUFFIX}_index.json.tmp" diff --git a/docs/changelog.md b/docs/changelog.md index 8073299..ef9010b 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,16 @@ # Changelog for dw-link +## Version 4.0.1 +- Fixed: missing declarations in dw-link.h +- Added: new enum type FuseByte +- Changed: first parameter in ispProgramFuse is now of type FuseByte + instead a boolean +- Changed: code in ispProgramFuse, which now more straightforward and + allows to change the extended fuse as well +- Added: bootloader reset vector is disabled when chip is erased for + M328/168/88 in targetISPConnect +- The naming scheme for boards manager URLs was changed by suffixing the core name with "\_plus\_Debug". Having names different from the original ones guarantees that the modified revisions will be shown when installing the package. This needs to be reflected in the documentation. + ## Version 4.0.0 - Added: Debugging in Arduino IDE 2 is now supported. This affects diff --git a/docs/manual.md b/docs/manual.md index 1f9475f..e725b9d 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -285,11 +285,11 @@ We need to install two new cores, which are forks of [MiniCore](https://github.c Open the `Preference` dialog of the Arduino IDE and paste the following two URLs into the list of `Additional boards manager URLs`: ``` -https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_index.json +https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_plus_Debug_index.json ``` ``` -https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_index.json +https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_plus_Debug_index.json ``` Then, you need to start the `Boards Manager`, which you find under `Tools`-->`Board`. Install MiniCore and ATTinyCore, choosing the most recent version with a `+debug` postfix. Note that the packages include tools that are incompatible with older OS versions. In particular, 32-bit host systems are not supported. If you have such a system, you only can use the approach described in Sections 6 and 7. @@ -345,11 +345,11 @@ A more minimalistic approach might be better if you are uncomfortable using Ardu In order to be able to debug the MCUs mentioned in the Introduction, you need to install 3rd party cores. For the classic ATtiny family, this is [ATTinyCore](https://github.com/SpenceKonde/ATTinyCore/blob/master/Installation.md) and for the ATmegaX8 family (including the Arduino UNO), it is [MiniCore](https://github.com/MCUdude/MiniCore). To be able to generate object files that are debug-friendly, you need to install my fork of the board manager files. You first have to add URLs under the `Additional Boards Manager URLs` in the `Preference` menu: - ``` - https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_index.json + https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_plus_Debug_index.json ``` - ``` - https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_index.json + https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_plus_Debug_index.json ``` After that, you can download and install the board using the `Boards Manager`, which you find in the Arduino IDE menu under `Tools`-->`Board`. Currently, choose the versions that have a `+debug` suffix in their version number! I hope the capability of generating debug-friendly binaries will be incorporated in future versions of these board manager files, in which case you can rely on the regular board manager files by MCUdude and SpenceKonde. @@ -1033,7 +1033,7 @@ Error # | Meaning --:|--- 1 | Connection error: No response to ISP and debugWIRE communication; check wiring 2 | Connection error: MCU type is not supported -3 | Connection error: Lock bits are set +3 | Connection error: Lock bits or BOOTRST could not be cleared 4 | Connection error: MCU has PC with stuck-at-one bits 5 | MCU type does not match 6 | Unknown connection error @@ -1162,3 +1162,5 @@ Initial version * Integration of Arduino IDE 2 * New fatal error: Wrong MCU type (caused by monitor mcu command) +* Renamed fatal error 3 +* The *boards manager URLs* have changed: a suffix `_plus_Debug` has been added to the core name. diff --git a/docs/quickstart-AVR-GDB.md b/docs/quickstart-AVR-GDB.md index b64a115..893275c 100644 --- a/docs/quickstart-AVR-GDB.md +++ b/docs/quickstart-AVR-GDB.md @@ -30,13 +30,11 @@ You probably already have installed the Arduino IDE. If not, download and instal Open the `Preference` dialog of the Arduino IDE and paste the following two URLs into the list of `Additional boards manager URLs`: - https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_index.json + https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_plus_Debug_index.json ``` -https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_index.json +https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_plus_Debug_index.json ``` -And you need to delete the MiniCore-URL hosted by MCUDude if you already have that in your URL list. - Close the `Preference` dialog with `OK`. Now we want to install the two cores `ATTinyCore` and `MiniCore`. * Select `Tools` -> `Board` -> `Board Managers` ... . This will open the Boards Manager dialog. diff --git a/docs/quickstart-Arduino-IDE2.md b/docs/quickstart-Arduino-IDE2.md index c96443c..e99973b 100644 --- a/docs/quickstart-Arduino-IDE2.md +++ b/docs/quickstart-Arduino-IDE2.md @@ -31,13 +31,11 @@ You probably already have installed the Arduino IDE 2. If not, download and inst Open the `Preference` dialog of the Arduino IDE and paste the following two `Board Manager URLs` into the list: - https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_index.json + https://felias-fogg.github.io/ATTinyCore/package_drazzy.com_ATTinyCore_plus_Debug_index.json ``` -https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_index.json +https://felias-fogg.github.io/MiniCore/package_MCUdude_MiniCore_plus_Debug_index.json ``` -And you need to delete the MiniCore-URL hosted by MCUDude if you already have that in your URL list. - Close the `Preference` dialog with `OK`. Now, we want to install the two cores, `ATTinyCore` and `MiniCore`. * Select `Tools` -> `Board` -> `Board Managers` ... . This will open the Boards Manager dialog. diff --git a/docs/wishlist.md b/docs/wishlist.md index 8033491..87f19ce 100644 --- a/docs/wishlist.md +++ b/docs/wishlist.md @@ -22,18 +22,12 @@ ##### List of tasks to work on: -* write a short debug description for PIO - * produce short youtube video to promote dw-link probe * use "blinkmodes.ino" in order to highlight embedded programming, perhaps in a video? -* try to use seer GUI again - * Implement STK500v2 protocol -* try integration of tool into IDE 2.0 again - * debug tiny13 problem, perhaps by reverting back to the version in 2022, when it seemed to work @@ -43,8 +37,6 @@ * implement semi-hosting -* integrate into the Arduino VSC plugin - * design case for debugger and print it * a mode where reads & writes are double-checked: "monitor @@ -56,11 +48,15 @@ ##### List of tasks done: -* clean up Gede interface +- try integration of tool into IDE 2.0 again + +- clean up Gede interface - * no multiple main breaks oints +* no multiple main breaks oints - * reloading files in GUI when reloading files +* reloading files in GUI when reloading files + +- write a short debug description for PIO * write/design setup for UNO debugging with connected USB cable @@ -96,3 +92,10 @@ +**List of tasks abandoned**: + +- try to use seer GUI again +- integrate into the Arduino VSC plugin + + + diff --git a/dw-link/dw-link.h b/dw-link/dw-link.h index 0ee19b0..c748883 100644 --- a/dw-link/dw-link.h +++ b/dw-link/dw-link.h @@ -1,8 +1,8 @@ void blockIRQ(); void unblockIRQ(); +void setupio(); void monitorSystemLoadState(); void initSession(); -void setupio(); void reportFatalError(byte, boolean); void setSysState(statetype); void gdbHandleCmd(); @@ -10,22 +10,21 @@ void gdbParsePacket(const byte *); void gdbParseMonitorPacket(byte *); int gdbDetermineMonitorCommand(char *, char &); void gdbHelp(); +void gdbCheckMcu(const char *); +boolean gdbConnect(boolean); +boolean gdbStop(boolean); +void gdbReportConnected(); void gdbReportLastError(); void gdbTimeoutCounter(); void gdbSteppingMode(char); void gdbVersion(); void gdbSpeed(char); -byte findArg(const byte []); - void gdbSetMaxBPs(byte); void gdbGetMaxBPs(); void gdbReportFlashCount(); void gdbReportRamUsage(); -boolean gdbConnect(boolean); boolean powerCycle(boolean); void power(boolean); -boolean gdbStop(boolean); -void gdbReportConnected(); boolean gdbReset(); void gdbSetFuses(Fuses); void gdbGetFuses(boolean, boolean); @@ -128,7 +127,7 @@ boolean enterProgramMode(); void leaveProgramMode(); unsigned int ispGetChipId(); byte ispReadFuse(boolean); -boolean ispProgramFuse(boolean, byte, byte); +boolean ispProgramFuse(FuseByte, byte, byte); boolean ispEraseFlash(); boolean ispLocked(); boolean setMcuAttr(unsigned int); diff --git a/dw-link/dw-link.ino b/dw-link/dw-link.ino index 4d1f458..5afbf48 100644 --- a/dw-link/dw-link.ino +++ b/dw-link/dw-link.ino @@ -414,6 +414,8 @@ unsigned long speedlimit = SPEEDLIMIT; enum Fuses { CkDiv8, CkDiv1, CkRc, CkARc, CkXtal, CkExt, CkSlow, Erase, DWEN, UnknownFuse }; +enum FuseByte { LowFuse, HighFuse, ExtendedFuse }; + // monitor command names const char mohelp[] PROGMEM = "help"; const char moversion[] PROGMEM = "version"; @@ -629,7 +631,7 @@ void monitorSystemLoadState(void) { // init all global vars when the debugger connects void initSession(void) { - //DEBLN(F("initSession")); + DEBLN(F("initSession")); flashidle = true; ctx.safestep = true; bpcnt = 0; @@ -2326,6 +2328,7 @@ int targetISPConnect(void) { unsigned int sig; int result = 0; + boolean succ; if (!enterProgramMode()) return -1; sig = ispGetChipId(); @@ -2340,11 +2343,23 @@ int targetISPConnect(void) enterProgramMode(); if (ispLocked()) result = -3; - else - result = 0; + else { // here we disable the bootloader-vector fuse BOOTRST if set + // ATmega88/168: Ext. Fuse, Bit 0 + // ATmega328: High Fuse, Bit 0 + succ = true; + if (sig == 0x930A || sig == 0x930F || sig == 0x9316 || sig == 0x9406 || sig == 0x940B || sig == 0x9415) { + // ATmega88 or 168: BOOTRST is in bit 0 of the extended fuse byte + succ = ispProgramFuse(ExtendedFuse, 1, 1); + } else if (sig == 0x9514 || sig == 0x950F || sig == 0x9516) { + // ATmega328: BOOTRST is bit 0 of high fuse byte + succ = ispProgramFuse(HighFuse, 1, 1); + } + if (succ) result = 0; + else result = -3; + } } if (result == 0) { - if (ispProgramFuse(true, mcu.dwenfuse, 0)) { // set DWEN fuse and powercycle later + if (ispProgramFuse(HighFuse, mcu.dwenfuse, 0)) { // set DWEN fuse and powercycle later result = 0; } else { result = -1; @@ -2404,15 +2419,15 @@ int targetSetFuses(Fuses fuse) } // now we are in ISP mode and know what processor we are dealing with switch (fuse) { - case CkDiv1: succ = ispProgramFuse(false, mcu.ckdiv8, mcu.ckdiv8); break; - case CkDiv8: succ = ispProgramFuse(false, mcu.ckdiv8, 0); break; - case CkRc: succ = ispProgramFuse(false, (mcu.ckmsk|mcu.sutmsk), mcu.rcosc); break; - case CkARc: succ = ispProgramFuse(false, (mcu.ckmsk|mcu.sutmsk), mcu.arosc); break; - case CkExt: succ = ispProgramFuse(false, (mcu.ckmsk|mcu.sutmsk), mcu.extosc); break; - case CkXtal: succ = ispProgramFuse(false, (mcu.ckmsk|mcu.sutmsk), mcu.xtalosc); break; - case CkSlow: succ = ispProgramFuse(false, (mcu.ckmsk|mcu.sutmsk), mcu.slowosc); break; + case CkDiv1: succ = ispProgramFuse(LowFuse, mcu.ckdiv8, mcu.ckdiv8); break; + case CkDiv8: succ = ispProgramFuse(LowFuse, mcu.ckdiv8, 0); break; + case CkRc: succ = ispProgramFuse(LowFuse, (mcu.ckmsk|mcu.sutmsk), mcu.rcosc); break; + case CkARc: succ = ispProgramFuse(LowFuse, (mcu.ckmsk|mcu.sutmsk), mcu.arosc); break; + case CkExt: succ = ispProgramFuse(LowFuse, (mcu.ckmsk|mcu.sutmsk), mcu.extosc); break; + case CkXtal: succ = ispProgramFuse(LowFuse, (mcu.ckmsk|mcu.sutmsk), mcu.xtalosc); break; + case CkSlow: succ = ispProgramFuse(LowFuse, (mcu.ckmsk|mcu.sutmsk), mcu.slowosc); break; case Erase: succ = ispEraseFlash(); break; - case DWEN: succ = ispProgramFuse(true, mcu.dwenfuse, mcu.dwenfuse); break; + case DWEN: succ = ispProgramFuse(HighFuse, mcu.dwenfuse, mcu.dwenfuse); break; default: succ = false; } return (succ ? 1 : -3); @@ -3573,9 +3588,8 @@ byte ispReadFuse(boolean high) } // program fuse and/or high fuse -boolean ispProgramFuse(boolean high, byte fusemsk, byte fuseval) +boolean ispProgramFuse(FuseByte fuse, byte fusemsk, byte fuseval) { - byte newfuse; byte lowfuse, highfuse, extfuse; boolean succ = true; @@ -3583,15 +3597,11 @@ boolean ispProgramFuse(boolean high, byte fusemsk, byte fuseval) highfuse = ispSend(0x58, 0x08, 0x00, 0x00, true); extfuse = ispSend(0x50, 0x08, 0x00, 0x00, true); - if (high) newfuse = highfuse; - else newfuse = lowfuse; - - //DEBPR(F("Old ")); if (high) DEBPR(F("high ")); DEBPR(F("fuse: ")); DEBLNF(newfuse,HEX); - newfuse = (newfuse & ~fusemsk) | (fuseval & fusemsk); - //DEBPR(F("New ")); if (high) DEBPR(F("high ")); DEBPR(F("fuse: ")); DEBLNF(newfuse,HEX); - - if (high) highfuse = newfuse; - else lowfuse = newfuse; + switch (fuse) { + case LowFuse: lowfuse = (lowfuse & ~fusemsk) | (fuseval & fusemsk); break; + case HighFuse: highfuse = (highfuse & ~fusemsk) | (fuseval & fusemsk); break; + case ExtendedFuse: extfuse = (extfuse & ~fusemsk) | (fuseval & fusemsk); break; + } ispSend(0xAC, 0xA0, 0x00, lowfuse, true); _delay_ms(15);