Author Topic: How Can Your Disable the Debug Fuse In an AVR Microcontroller After Enabling it?  (Read 591 times)

0 Members and 1 Guest are viewing this topic.

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
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.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3503
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
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.
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
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.
Is 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!
« Last Edit: May 13, 2021, 02:38:34 am by Kalcifer »
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
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.
 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3503
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
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.
I'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.
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
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.
I'd say you may want to perform a full erase on it, maybe using a high voltage programmer now.

how come though?

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.
you would likely have used up all the write cycles.

This 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 ISP

2. 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 0xDF

6. The chip is now back to step 2: it is unable to re enter debug wire mode.
 

Offline Kalcifer

  • Regular Contributor
  • *
  • Posts: 69
  • Country: ca
I have found the solution, with help from this website: https://blag.pseudoberries.com/post/16374999524/avr-debugwire-on-linux


With 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 target

3. 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf