Go Down

Topic: Lock bit mismatch error while burning Micro bootloader to custom board (Read 324 times) previous topic - next topic

ckambiselis

Hi,
I made a custom board using 32u4 chips bought from a distributor and wanted to burn the bootloader since there wasn't one in the chip and it wasn't recognized as a USB device so I could upload my code, I have an original Atmel ICE that I'm using to burn the bootloader through Arduino IDE (I also checked if there are updates on the Board Manager), after selecting the board type as "Arduino/Genuino Micro" and the programmer as "Atmel-ICE", I press "Burn bootloader" and after a second I get the following error.

Code: [Select]
Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Micro"

C:\Users\Oscar\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Oscar\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega32u4 -catmelice_isp -Pusb -e -Ulock:w:0x3F:m -Uefuse:w:0xcb:m -Uhfuse:w:0xd8:m -Ulfuse:w:0xff:m

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Oscar\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : atmelice_isp
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : JTAG3_ISP
         Description     : Atmel-ICE (ARM/AVR) in ISP mode
         Vtarget         : 5.0 V
         SCK period      : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: erasing chip
avrdude: reading input file "0x3F"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3F:
avrdude: load data lock data from input file 0x3F:
avrdude: input file 0x3F contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "lock", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xff instead of 0x3f (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xcb"
avrdude: writing efuse (1 bytes):

Error while burning bootloader.
Writing | ################################################## | 100% 0.09s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xcb:
avrdude: load data efuse data from input file 0xcb:
avrdude: input file 0xcb contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xf3 != 0xcb
avrdude: verification error; content mismatch

avrdude done.  Thank you.

Willem43

I just recently built a small programmer using the Atmega32u4 chip.  It is a very bare bones layout with 16Mhz external crystal.

I however, used an UNO as ISP and selected Leonardo as the board.  Had no problems uploading sketches or burning the bootloader.  All works as expected.

I had a quick look and all the fuses seem to be the same for the Micro and the Leonardo.  I do not really know what differs.

I am sure someone more knowledgeable with AVRdude will turn up to help.

Willem.

ckambiselis

Thanks for the suggestion, I just tried with Leonardo selected as the Board but seems like the same problem.

ckambiselis

Found a tutorial at RobotShop on how to set the fuses and burn the bootloader using Atmel Studio and seems that all are verified OK, used the Caterina-Micro bootloader, but when I connect the board to USB nothing is found not even an "unknown device".

Here is the boardview and schematic section of the MCU and USB part, please excuse the cruelty of the schematic as I just copied most of it from the original Arduino Eagle sch file but had to change the footprint of the 32u4 and the components to the ones I could find from the distributor I use.

Oscar

Willem43

You actually did not include the attachments.

I really do not know why you have problems.  I simply used the fuses as set in the Arduino Board file (no changes) and burned the bootloader.  No problems or error messages.  That was my second board using the 23u4, the first was for a timer board and I had no problems there either.

The default avr Board.txt file set the fuses as follows:
low_fuses=0xff
high_fuses=0xd8
extended_fuses=0xcb
unlock_bits=0x3F
lock_bits=0x2F
bootloader.file=caterina/Caterina-Leonardo.hex

Provide the schematics and will have a look at them.

Willem.

ckambiselis

Oops  :D , edited the post to include the files. And the tutorial used https://www.robotshop.com/community/forum/t/setting-arduino-fuses-manually-in-avr-studio/13065

ckambiselis

Update:
Found the USB problem, had the D+ and D- varistors mixed with the resistors, switched them and know I get "Unknown Device" and the status details say "A request for the USB device descriptor failed."

Oscar

Willem43

Firstly, I do not see any obvious problem with your board's connections.  I do have problems reading the schematic - the connections on the left have no labels to tell me where they go on the 32u4.  I can however get a good idea from the board layout.

Mine is pretty much the same as yours except I use the Little Fuse SPO503BAHTG TVS instead of the singles (there is a third unit in my package which is connected to USBVCC).  This is the unit recommended by Silicon Labs when using the CP2104 USB to Serial bridge - so I have some in stock and just used that.

What I do not quite understand about the "Unknown Device" message is: Have you been successful in burning a boot loader?  If not, you will not get any USB connection (I could be wrong on this since I have not checked that before burning the bootloader).

Willem

ckambiselis

Well when I tried burning the bootloader using the IDE and got the error, I tried the USB connection and didn't get anything, but that was also when I had the parts mixed, then I did it manually through Atmel Studio 7 and the verifications where OK, after that I found that I had the components mixed and fixed that and got the Unknown Device.

Haven't tested through the IDE again though, but it shouldn't make a difference on the IDE error message, since it shouldn't use the USB port. The TVS I have used are specifically meant for USB protection.

From the error message it seems like the bootloader version is old or something, but I am using the latest version of the IDE and have checked and updated the Boards libraries.

Code: [Select]
avrdude: WARNING: invalid value for unused bits in fuse "lock", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xff instead of 0x3f (double check with your datasheet first).


Oscar

Willem43

That message is not an error, it is a warning.  You can safely ignore it.  There is quite a history behind it going back quite a few years.

I have never used Atmel Studio so I cannot comment on its operation etc.  I go for convenience and the IDE does everything I require.

The IDE and avrdude versions shown in the OP is exactly what I am using and I think is the latest.

I looked at the data sheet for the TVS you are using and it has very little in the line of specification (does not mention USB anywhere - neither does mine actually).  I am sure it is fine for this purpose. The one I use is merely for convenience (again) with three units in a single package (4 pin SMD) - it is recommended for exactly this purpose.  Whichever is used will make no difference to your problem (unless it is faulty or connected wrongly off course  ;) ).

Willem.

ckambiselis

Something really weird is going on with the board. Today I connected the USB again and it recognized it as an Arduino Micro on port 7 but when I went to upload a blank sketch and the upload reset the board, the board appeared as Unknown Device again and the upload failed.

I uploaded the ArduinoISP sketch to an Arduino Nano and was able to burn the bootloader through the IDE using it, my custom board appeared as an Arduino Micro on port 7 but when I went to upload a blank sketch on the reset the board appeared as Unknown Device again and the upload failed, I then disconnected it from the USB and reconnected it and it appeared as an Arduino Micro again, I disconnected and reconnected it a couple of times and every now and then it appears as Unknown.

I'm unable to upload a sketch through USB, but I am able to upload sketches through the ICSP, so I uploaded a USB serial port test sketch and I was able to connect through the serial monitor using the USB cable and it respondent normally, had it connected for a couple of minutes and it was running fine.

Code: [Select]
byte leds = 0;

void setup()
{
  Serial.begin(9600);
  while (! Serial);
  Serial.println("Enter LED Number 0 to 7 or 'x' to clear");
}

void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch >= '0' && ch <= '7')
    {
      int led = ch - '0';
      bitSet(leds, led);
      Serial.print("Turned on LED ");
      Serial.println(led);
    }
    if (ch == 'x')
    {
      leds = 0;
      Serial.println("Cleared");
    }
  }
}


Oscar

BJHenry

OP's schematic:

There is something really screwy with that schematic. Have you manually edited it or something? It doesn't show where any of the nets connect to the actual microcontroller.
It also appears that you're missing the 100nF decoupling capacitors for the microcontroller.

Willem43

@BJHenry

I already asked about that in post #7.  Looks like parts were cut between the left and the processor.  It is possible to get some idea from the picture of the board - but not a complete one.

Willem

ckambiselis

The original MCU part is taken from the original Arduino Micro schematic, but after having routed the whole thing had to change the footprint to something more manageable and of course doing a part "Replace" didn't work since the pin naming was different, so I draw new lines to the new footprint and renamed them to match the old footprint before deleting the original so I don't have to route everything again.

There is a 100nF on AREF, 1uF on UCAP and 1uF on the VCC/AVCC. I'm pretty sure i didn't change and any of the MCU passives except of the crystal to one that I could actually find from the distributor I ordered all the parts.

Here is the schematic made less of an eyesore, nothing changed just removed the extra lines and connected what is already connected.

It feels like there is some kind of timing issue that makes the board Unknown every now and then, in Atmel Studio there is a tab in the Programming window to calibrate the oscillator but it only went to 8MHz so I didn't touch it.

Oscar

Willem43

Your board is pretty much the same as mine.  I do have an extra 47uF cap on the power supply and used 100nF for VCC and  AVCC.

I have no problems programming initiallly with ICSP and afterwards with USB.

My circuit diagram for comparison:


I really do not know why you have problems.  I use the same version IDE and avrdude as you (on Windows 10) with the default Leonardo board settings and bootloader, ie Caterina.

Willem

Go Up