0

Disclaimer, I'm very new to all the embedded malarky.

Hi,

I have a custom made board with an ATMega328 U-TH on it.

the board came loaded with a version of optiboot and a demo sketch which was loaded using the arduino IDE and serial over usb so I know at some point what i'm trying to do was working.

i'm using avrdude and a USB UART.

what appears to happen is the sketch uploads "ok", but fails validation.

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -C"../etc/avrdude.conf" -v -patmega328p -carduino -PCOM5 -b38400 -D -Uflash:w:test.hex:i

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 "../etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 38400
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         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  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 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 : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 8.0
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading input file "test.hex"
avrdude: writing flash (4 bytes):

Writing | ################################################## | 100% 0.04s

avrdude: 4 bytes of flash written
avrdude: verifying flash memory against test.hex:
avrdude: load data flash data from input file test.hex:
avrdude: input file test.hex contains 4 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.04s

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

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

i've tried Arduino IDE and avrdude direct.

upon inspection using -

avrdude -C"../etc/avrdude.conf" -v -patmega328p -carduino -PCOM5 -b38400 -D -Uflash:r:C:\.../uploaded.ino.hex:i

I can see that the memory is full of 1414 right up to the bootloader.

:20000000141414141414141414141414141414141414141414141414141414141414141460
:20002000141414141414141414141414141414141414141414141414141414141414141440
...
:207DC000141414141414141414141414141414141414141414141414141414141414141423
:207DE000141414141414141414141414141414141414141414141414141414141414141403
:207E000001C0CEC0112484B7882361F0982F9A70923041F081FF02C097EF94BF282E80E012
:207E2000AAD0EEC082E08093C00088E18093C10086E08093C20089E18093C40088E29BD057
:207E400093E0E92EDD24D39425E0C22E31E1B32E86D0813479F483D0182F93D0123811F484
:207E600080E004C088E0113809F083E071D080E16FD0EECF823419F484E18BD0F8CF853430
:207E800011F485E0FACF853541F469D0C82F67D0D82FCC0FDD1F75D0EACF863519F484E051
:207EA00078D0DECF843609F034C059D058D0F82E56D0A82E00E011E048018FEF881A980AD7
:207EC0004ED0F80180838401F810F6CF5AD0F5E4AF1201C0FFCFFE01E7BEE89507B600FC09
:207EE000FDCFFE01A0E0B1E0CD0102962D913C910901D7BEE89511243296DC01F812F4CFF2
:207F0000FE01C7BEE89507B600FCFDCFB7BEE895AECF843771F423D022D0F82E20D031D050
:207F20008E01F80185918F0113D0FA94F110F9CF9ECF853739F425D08EE10AD085E908D0FF
:207F40008FE094CF813509F0A6CF88E014D0A3CF9091C00095FFFCCF8093C60008958091A6
:207F6000C00087FFFCCF8091C00084FD01C0A8958091C6000895E0E6F0E098E19083808307
:207F80000895EDDF803219F088E0F5DFFFCF84E1DFCFCF93C82FE3DFC150E9F7CF91F1CF74
:207FA000FC010A0167BFE895112407B600FCFDCF667029F0452B19F481E187BFE89508952E
:207FC000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC1
:207FE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000897
:00000001FF

i can confirm that the bootloader is a byte for byte match with the file which was uploaded using an ICSP by the guy that built it, except for this bit -

:0400000300007E007B

which i presume was overwritten when the previously working sketch was uploaded.

this is the supplied board config -

.upload.protocol=arduino
.upload.maximum_size=32256
.upload.speed=38400

.bootloader.low_fuses=0xE2
.bootloader.high_fuses=0xDE
.bootloader.extended_fuses=0xFF

.bootloader.file=atmega/optiboot_atmega328.hex
.bootloader.unlock_bits=0x3F
.bootloader.lock_bits=0x0F

.build.mcu=atmega328p
.build.f_cpu=8000000L
.build.core=arduino:arduino
.build.variant=arduino:standard

.bootloader.tool=arduino:avrdude
.upload.tool=arduino:avrdude

I dont have an ICSP programmer or other Arduino for reburning the bootloader.

Can anyone offer any avenues of investigation?

thanks

6
  • the bootloader came from the guy who built the board, he configured it use 38400 because - "its the fastest the uart can go, while maintaining accurate timing with a system clock of 8mhz (from memory)" – user2983931 Mar 25 at 13:45
  • 1
    I could quibble over that, but I won't. When you say "using avrdude and a USB UART", do you mean a USB to logic level serial adapter/cable? And if so is this adapter the correct logic level match for your board? – timemage Mar 25 at 13:55
  • I believe so, identical to this - makerfabs.com/usb-uart-convertor-cp2102.html , also upvoted your comment for not derailing the question with arguments over whether it could go faster :) appreciate that. – user2983931 Mar 25 at 14:51
  • Well, that's half of an answer. I can see this is going to be a long, drawn out process. So, I'll just leave you with: verify the wiring, voltage levels, lock bits, fuse values, and timing of the internal osc. (or derived serial bits). – timemage Mar 25 at 15:14
  • 1
    I've seen people get mostly good communication from serial when the GND wasn't attached, owing to capacitive coupling and a high enough baud rate. I'm not going to go through the entire diagnostic tree in comments. But yeah, there are reasons behind those suggestions. You can find me on freenode if you want to go through these in a conversational way. – timemage Mar 25 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.