jtag2updi bricking avr64db64

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've just started playing with the AVR64DB64 chips, hoping to migrate a few things from the atmega2561 and 328.  I am using the arduino IDE, but most of my code is straight C++ and accessing registers directly to do my work.  I was able to get a simple blink program running, using the DxCore, I am using an arduino board programmed with jtag2updi to upload, so everything worked fine for a few uploads, but when I attempted to start working with TimerA0, I started getting an error uploading.  I swapped the chip to a new AVR and the original blink program uploaded, I changed a few things in the program, reuploaded and verified it still worked.  When I tried the Timer program again, I got the same error and the chip won't take any uploads anymore.  My code is below: 

volatile bool state;

void setup() {
  pinMode(0, OUTPUT);
  CPUINT_CTRLA = 0;
  TCA0_SINGLE_PER = 100;
  TCA0_SINGLE_CTRLA = 0b00000001;
  TCA0_SINGLE_CTRLB = 0b00000000;
  TCA0_SINGLE_INTCTRL = 0b00000001;
  
}

void loop() {
  digitalWrite(0, state); 
  
}

ISR(TCA0_OVF_vect){
 state = !state;
}

the error I'm receiving is below:

An error occurred while uploading the sketch
Reading | avrdude: jtagmkII_program_enable(): bad response to enter progmode command: RSP_ILLEGAL_MCU_STATE
avrdude: jtagmkII_program_enable(): bad response to enter progmode command: RSP_ILLEGAL_MCU_STATE
avrdude: jtagmkII_read_byte(): bad response to read memory command: RSP_ILLEGAL_MCU_STATE
avr_read(): error reading address 0x0000
    read operation not supported for memory "signature"
avrdude: error reading signature data for part "AVR64DB64", rc=-2
avrdude: error reading signature data, rc=-2
avrdude: jtagmkII_program_disable(): bad response to leave progmode command: RSP_ILLEGAL_MCU_STATE

avrdude done.  Thank you.

I think learning how to work with these chips would be great, but I'm in the throes of what may be a steep learning curve. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I cannot reproduce your problem on a AVR128DA28. However I did find a bug in your program in the process. The chips of the xtiny series, including AVR-Dx, do not clear interrupt flags automatically, in general (I think there are exceptions, check the datasheets).

 

So your ISR needs to be:

 

ISR(TCA0_OVF_vect){
 state = !state;
 TCA0_SINGLE_INTFLAGS = 0b00000001;
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am continuing to study the datasheet for the avr64db and saw that, I have corrected it and have gotten the timer working, I had the cpuint code there because I thought perhaps the timer wasn't running due to disabled interrupt higher up in the chain, it uploads now with no problems, but I haven't re-inserted the cpuint code, I don't see why that would cause a bricked chip, but I will do another experiment to see if adding the code back in will brick it.  I can't understand why that would be an issue since it doesn't appear to change any fuses so in my understanding, I'm not doing anything that can't be overwritten... 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually CPUINT_CTRLA is a protected register, so just writing to it has no effect. Search the datasheet and this forum for "configuration change protection" for more details.