How Can Your Disable the Debug Fuse In an AVR Microcontroller After Enabling it? - Page 1
Forum section: electronics / general

author: Kalcifer
author_rank: Regular Contributor
timestamp: May 13, 2021, 02:00:46 am
content: I enabled the debugWire fuse (DWEN) in an ATtiny84A so that I could debug it using avarice and avr-gdb; however, now that I have the DWEN fuse set, I'm not sure how to then reset it. Enabling the DWEN fuse changes the RESET pin's functionality, so the ISP programming method to change the fuse initially, no longer works. Is there a way to change a fuse byte while in debug mode, or have I essentially bricked the MCU? There must be some way to change it back as Atmel Studio is able to debug the chip no problem. From what I understand, when you enter debug mode in Atmel Studio, it automatically sets the DWEN fuse, and then clears it after the debug session has completed. It could be possible that Atmel Studio is doing some proprietary trickery, but there must be some way to get around this.

author: technix
author_rank: Super Contributor
timestamp: May 13, 2021, 02:13:09 am
content: If you are using Atmel Studio, it enables and disables DWEN following the debug session starting and terminating. You need to enter and leave debug mode once, including using a dummy project if you don't mind wiping the existing program, to disable DWEN.Or if you have a high voltage programmer, that would work too.

author: Kalcifer
author_rank: Regular Contributor
timestamp: May 13, 2021, 02:15:16 am
content: Quote from: technix on May 13, 2021, 02:13:09 amIs there no way to imitate this behaviour outside of Atemel Studio?EDIT: I just now realized that terminating a debug session with avr-gdb also automatically resets the DWEN fuse. Problem solved! MCU no longer a tiny paperweight!

author: Kalcifer
author_rank: Regular Contributor
timestamp: May 13, 2021, 05:50:40 am
content: Strangely enough, however, I seem to be unable to go back into debug mode now. I can change the fuse that enables or disables DWEN in both Atmel Studio, and avrdude, but it does not enable debugWire. What should immediately happen is that when I set DWEN, I should loose all ISP functionality, but everything is working fine, and on top of that, I cannot connect to it as a debug target. Could manually programming the fuse break it in some way...? That doesn't really make any sense to me.

author: technix
author_rank: Super Contributor
timestamp: May 13, 2021, 09:07:28 am
content: Quote from: Kalcifer on May 13, 2021, 05:50:40 amI'd say you may want to perform a full erase on it, maybe using a high voltage programmer now. That would reset a lot o things to default, and if after that you are still getting problems, you would likely have used up all the write cycles.

author: Kalcifer
author_rank: Regular Contributor
timestamp: May 14, 2021, 03:02:22 am
content: Quote from: technix on May 13, 2021, 09:07:28 amhow come though?Quote from: technix on May 13, 2021, 09:07:28 amThis doesn't make a whole lot of sense to me. Changing the fuses a couple of times definitely shouldn't use up the write cycles. Plus there is other behaviour that would indicate otherwise.Generally I'm experiencing some really confusing and intermittent behaviour:1. Programmed the DWEN fuse to allow debugging which disabled ISP as expected. Debugged and closed, which after some bumpy behaviour swapped back to ISP2. Was unable to re-enter debugWire even after re programming the DWEN fuse (0x9fF --> 0xDF --> 0x9F) (Which in itself is confusing as programming the DWEN fuse should have blocked any further programming, but it didn't which is super strange.)3. After sitting for a bit, the microcontroller was all of a sudden was able to go into debugwire mode again.4. After getting into debug wire, the chip was unable to swap back to ISP even after closing the debug session.5. After sitting for a bit, the chip all of a sudden was back to being in ISP mode after trying to program the fuse to be 0xDF6. The chip is now back to step 2: it is unable to re enter debug wire mode.

author: Kalcifer
author_rank: Regular Contributor
timestamp: May 15, 2021, 05:39:16 am
content: I have found the solution, with help from this website:https://blag.pseudoberries.com/post/16374999524/avr-debugwire-on-linuxWith the Atmel-ICE connected to the target (ATtiny84A) as normally for programming:1. Program the DWEN fuse with avrdude (avrdude -c atmelice_isp -p t84 -U hfuse:w:<fusebyte for programming DWEN>:m)2. Power cycle the target3. Start the debug server with avarice (avarice -4 -w :<whatever port you want to use>)4. start debugging with avr-gdb (avr-gdb --> target remote [ localhost | 127.0.0.1 ]:<port from before>)5. When debugging is done, dont stop debugging with `detach`, or `quit` in avr-gdb, instead unprogram the DWEN fuse WHILE the debug server is running. This will put the chip into ISP mode temporarily (Intermediate state 2 from #21) so that the fuse can be successfully unprogramed. On top of this, programming the fuse will pull the target out of debug mode and return it to ISP mode so that you can power cycle as normal.