new factory atmega 328p programming over serial, take 2

thanks for all the help so far, but the story ain't over yet

have an osepp uno 3 plus hooked up to a working custom 328p chip (gnd, spi and d10 to res, sep-pwr) with working firmware in it.

examples->arduinoisp running isp sketch

reading flash with
avrdude -P /dev/ttyUSB1 -b 115200 -c arduino -p m328p -v -U flash:r:test.hex:i

result

avrdude: Version 5.10, compiled on Jun 29 2010 at 03:44:14
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/xxxx/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB1
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         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     5     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: 4.4
         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.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading flash memory:

Reading | ################################################## | 100% 4.77s

avrdude: writing output file "test.hex"

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

:200000000C9462000C948A000C948A000C948A000C948A000C948A000C948A000C948A00B8
:200020000C948A000C948A000C948A000C948A000C948A000C948A000C948A000C948A0070
......
:207E0000112484B714BE81FFF0D085E08093810082E08093C00088E18093C10086E08093FC
:207E2000C20080E18093C4008EE0C9D0259A86E020E33CEF91E0309385002093840096BBAD

now i loaded
// Atmega chip fuse detector
// Author: Nick Gammon
// Date: 22nd May 2012
// Version: 1.8

and ran the output on a terminal

Atmega chip detector.
Entered programming mode OK.
Signature = 1E 95 0F 
Processor = ATmega328P
Flash memory size = 32768
LFuse = FF 
HFuse = D6 
EFuse = FC 
Lock byte = FF 
Clock calibration = 99 
Bootloader in use: Yes
EEPROM preserved through erase: Yes
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Bootloader:

7E00: F8 94 6F EF 6D BF 68 E0 6E BF 22 24 33 24 A8 95 
7E10: 60 91 60 00 60 61 7F E0 60 93 60 00 63 FD 70 93 
7E20: 60 00 58 9A 59 9A 51 9A 21 E0 30 EA 63 E0 F1 01 
7E30: EF 01 F1 01 01 97 60 40 48 99 E1 F7 D9 F1 21 97 

First 256 bytes of program memory:

0: 0C 94 34 00 18 95 00 00 18 95 00 00 18 95 00 00 
10: 18 95 00 00 18 95 00 00 18 95 00 00 18 95 00 00 
20: 18 95 00 00 0C 94 BA 09 18 95 00 00 18 95 00 00 
30: 18 95 00 00 18 95 00 00 18 95 00 00 18 95 00 00

how comes that

:20000000 0C 94 62 00 0C 94 8A 00 0C 94 8A 00 0C 94 8A 00 avrdude, doesn't match

0: 0C 94 34 00 18 95 00 00 18 95 00 00 18 95 00 00 board-detector, which seems to be right

:10000000 0C 94 34 00 18 95 00 00 18 95 00 00 18 95 00 00 15 ... org hex file

or at the bootblock

:207E0000 11 24 84 B7 14 BE 81 FF F0 D0 85 E0 80 93 81 00 doesn't match

7E00: F8 94 6F EF 6D BF 68 E0 6E BF 22 24 33 24 A8 95 have no reference

thanks and cheers, blue2u

addendum :

i have to mention that this custom board has a 14.74 MHz ceramic resonator, where the firmware would match this freq. and operate correctly.

also i would assume that by accessing the cpu through spi, that the on board clock srce is not an issue ??? is it, if yes, please explain.

cheers, blue2u

addendum 2 :

to clearly try to define the task i'm trying to accomplish

i have 2 custom atmega328p-au based boards ... one, the org works and has firmware in it ... the 2nd one is a hw redesign with differences in the analog I/O (completely identical from a fw view)

i try to use an osepp arduino 3 plus as an isp programmer connected with mosi, miso, sck, gnd and arduino d10 connected to custom target res pin with 10 k pullup and 0u1 cap to gnd. custom target hat it's own power.

the custom boards run off a ceramic resonator at 14.74 MHz ... can't change cause of lack of srce for fw.

i can only afford to at best read the org board info out ... writes or other changes are too risky ... it's the only reference.

the initial post "take2" shows the differences reading the fw of the "org" board out, but shows differences in data read with avrdude vs Atmega chip fuse detector from Nick Gammon.

the data from the Nick read seems to be the correct one, since the 1st 50 bytes or so are a match to a newer fw hex file (only have the hex file, no srce, does not contain the boot sect).

how the .... can i get this hex file into this custom target.

i retrieved the boot img with Nicks sketch and created a boot_img.hex out of it which i could load into the custom hw, which i did by changing Nicks Atmega chip programmer. got the bootloader into, but the win based fw download pgm dedicated to this board times out ... verified the RxD all the way to the cpu.

that's it for now ... any clue ... i'm out of thought's for now.

by the way ... after loading the bootloader img including fuses into the new boards, the osc pins show about 1 V pp oscillation similar to the working org board, same freq and amplitude, so i assume the fuse change took and the osc is working.

i still don't know how to "reliably" retrieve a fw image from the org and get it reliably to the new boards ... in my 30 years of hw / fw design i never had such tools problems. maybe i should have started with the dragon board and not the arduino ... don't know

sorry, didn't want to say anything bad about the arduino.

any help is appreciated, cheers, blue2u.

blue2u:
i would assume that by accessing the cpu through spi, that the on board clock srce is not an issue ??? is it, if yes, please explain.

That would be a wrong assumption. If you set the fuses to use an external oscillator you will need the resonator attached or the system clock will stop running and SPI programming will not be possible. The system clock has to be running at least four times as fast as the SPI data clock.

thanks John for the info ... as i mentioned earlier, i'm not an avr insider

i have more puzzling info ... i feel like on a slot machine in vegas :slight_smile:

same electrical setup ... spi ... board powered by arduino.
arduino loaded with arduinoisp
i took one of the new custom atmega328p-au boards and loaded the hex-file (no srce avail) with avrdude write and then an avrdude verify ... also copied part of this verify into the data below

---------------- 1st the write operation ----------------

avrdude -P /dev/ttyUSB1 -b 115200 -c arduino -p m328p -v -U flash:w:test_src.hex:i

avrdude: Version 5.10, compiled on Jun 29 2010 at 03:44:14
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/xxxxx/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB1
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         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     5     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: 4.4
         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.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "test_src.hex"
avrdude: writing flash (31602 bytes):

Writing | ################################################## | 100% 6.01s

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

Reading | ################################################## | 100% 4.55s

avrdude: verifying ...
avrdude: 31602 bytes of flash verified

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

---------------- now the verify operation ----------------

avrdude -P /dev/ttyUSB1 -b 115200 -c arduino -p m328p -v -U flash:r:test_src_rd.hex:i 

avrdude: Version 5.10, compiled on Jun 29 2010 at 03:44:14
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/xxxxx/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

.....................

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         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.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading flash memory:

Reading | ################################################## | 100% 4.77s

avrdude: writing output file "V0.06b_12v_rd.hex"

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

---------------- here parts of the read operation ----------------

:200000000C9434001895000018950000189500001895000018950000189500001895000051
:20002000189500000C94A50A189500001895000018950000189500001895000018950000B6
.......
:2000E00088608093600040E453E360E570E0E0E1F0E0A0E1B0E094E00E94333D0417150757

:207B40005300460054004500480044003200390033003400350036004900536F667477616D
:207B600072652056302E3036620055005600570058002D312E3300004C616D6264612031E7
:207B8000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF05

:207DE000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA3
:207E0000112484B714BE81FFF0D085E08093810082E08093C00088E18093C10086E08093FC
:207E2000C20080E18093C4008EE0C9D0259A86E020E33CEF91E0309385002093840096BBAD
..........
:207FE0001150E9F7F2DF1F91089580E0E8DFEE27FF270994FFFFFFFFFFFFFFFFFFFF040425
:00000001FF

and now arduino loaded with Atmega chip fuse detector
below the terminal printout

Atmega chip detector.
Entered programming mode OK.
Signature = 1E 95 0F 
Processor = ATmega328P
Flash memory size = 32768
LFuse = FF 
HFuse = D6 
EFuse = FC 
Lock byte = FF 
Clock calibration = B8 
Bootloader in use: Yes
EEPROM preserved through erase: Yes
Watchdog timer always on: No
Bootloader is 512 bytes starting at 7E00

Bootloader:

7E00: F8 94 6F EF 6D BF 68 E0 6E BF 22 24 33 24 A8 95 
7E10: 60 91 60 00 60 61 7F E0 60 93 60 00 63 FD 70 93
...... 
7FE0: 60 EF 21 F4 A1 DF 60 E8 08 F0 61 EF 7F BF 08 95 
7FF0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF ED CF 

MD5 sum of bootloader = 93 0B E7 E1 60 E9 E1 CF AC 70 FD 4A 20 22 12 C7 

First 256 bytes of program memory:

0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 
..........
F0: FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF

how is it ever possible that avrdude shows that it read the hex-file it wrote and verified
is now a blank section starting at 0x0000 - 0x0100 according to the
Atmega chip fuse detector from Nick

i did not disconnect anything between the avrdude write, verify and chip fuse detector sketch.

this result is repeatable not a one time fly by night data fetch.

any ideas guys ???

i'm expecting
2x USBASP USB AVR Programmer for Atmel;USB ASP USBISP ISP Arduino Bootloader USA
in the mail ... and am wondering how long this stuff is gonna take from supposedly illinois ???

this will be the next try.

the 5V seem stable ... pin aref with a 0u1 shows 0 V. ceramic resonator amplitude about 1 V (i don't have the scope out right now, but the looked like the one on the good org board

tx and hopefully this mess will find some explanations

cheers, blue2u.

hi guys :

in my despair i changed Blinky code so that an on-board led blinks ... compiled and downloaded with shift upload "upload using programmer" ... and it blinks ... so the hw is not dead and the fuses can't be that far off ... at least some debug environment opened up now ... what an incredible drag ... but with a smile right now ... light at the end of the tunnel ... no can't be a train :slight_smile:

now is there a way to upload a generic hex file not created within arduino and upload it with arduino ...

worst case i go into the /tmp/ folder and swap the hex file against mine ... any ideas ???

please there are still tons of my other more professional questions, if u could pls help

cheers, Klaus

blue2u:
now is there a way to upload a generic hex file not created within arduino and upload it with arduino ...

No.

What you can do is turn on verbose upload logging and that will show you the exact avrdude command that Arduino uses to upload your sketch to the ATmega. Do the same command but with your .hex instead of the one generated by the compile and link process.

thanks john :

this helped me to identify the following

  1. my choice, the isp type arduino, even it seemed to work at 115200, but not at slower rates, was not working right.

  2. the, in the arduino verbose used, programmer type of " -c stk500v1 " also accepted the " -b 19200 "

this was part of the the new command line

avrdude -p atmega328p -c stk500v1 -P /dev/ttyUSB1 -b 19200 -U file.hex

worked on the 1st board since i had the fuses right with all my previous trys

on the 2nd with the org fuses from a blank cpu i had to set the fuses

had a typo in the fuse settings 1st and needed to change the cpu

on the 2nd go i thought i had things right, but also some failure

avrdude said that the chip signature was 0x000000 ... but i didn't have another cpu

also since i didn't have hot air to unsolder the cpu and my buddies assembly shop was closed, i cut (ground) very carefully the pins along the chip including the plastic housing of the cpu and didn't touch the pc. i used a dremel with the thin rotating grinding disc ... the pin remainders where easily whisked up with the solder iron.

again thanks to all :slight_smile:

cheers, blue2u