Pages: [1]   Go Down
Author Topic: Add a new Atmega328 clone device  (Read 1268 times)
0 Members and 1 Guest are viewing this topic.
Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Happy new year folks.
I'm strugling to put a new board on boards.txt
I bought some Atmega328P on ebay and for my surprise they have a different Signature. The original one should have a device signature = 0x1e 0x95 0x0F but mine has 0x1e 0x95 0x14 so every time I want to upload a program to it I changed the avrdude.conf to the new signature. I also have a Arduino Duemilanove and when I change to this board has expected it complains about wrong signature and again i change manual the signature to the original one.
I'm tired to very time change the file, so today I try to add a new board to boards.txt
I just copy the existing entry for the original Atmega328 and edit it like this:
Code:
#atmega328.name=TempController

atmega328.upload.protocol=arduino
atmega328.upload.maximum_size=30720
atmega328.upload.speed=57600

atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=atmega
atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F

atmega328.build.mcu=ATmega328
atmega328.build.f_cpu=16000000L
atmega328.build.core=arduino
atmega328.build.variant=standard

If I save and then restart arduino IDE it wont appear on the device list, but if I remove the existing it then appears then.
Also I know this will not fix my problem about the signatures because AVRdude is still using the same cpu target atmega328.build.mcu=ATmega328

Any help how can I fix this?



Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The very first string before the . is the "internal name" of the device. It has to be different for every board. So change "atmega328.<whatever>" to "<somethingelse>.<whatever>"

eg
Code:
#tempcontroller.name=TempController

tempcontroller.upload.protocol=arduino
tempcontroller.upload.maximum_size=30720
tempcontroller.upload.speed=57600

tempcontroller.bootloader.low_fuses=0xFF
tempcontroller.bootloader.high_fuses=0xDA
tempcontroller.bootloader.extended_fuses=0x05
tempcontroller.bootloader.path=atmega
tempcontroller.bootloader.file=ATmegaBOOT_168_atmega328.hex
tempcontroller.bootloader.unlock_bits=0x3F
tempcontroller.bootloader.lock_bits=0x0F

tempcontroller.build.mcu=ATmega328
tempcontroller.build.f_cpu=16000000L
tempcontroller.build.core=arduino
tempcontroller.build.variant=standard
Logged

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK it worked.
Now is there any way to create new devices on AVRDUDE?
« Last Edit: January 02, 2013, 12:07:37 pm by HugoPT » Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What you seem to have acquired there are ATmega328, not ATmega328P - the difference is the 328P has some extra power-saving features.
Check what's printed on the package.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK it worked.
Now is there any way to create new devices on AVRDUDE?

in avrdude.conf (hardware/tools/avrdude.conf) search for "atmega328p." Copy its entire entry and change the appropriate options (probably id, desc, and signature). Then make your new boards.txt entry reference the new id.
Logged

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your help.
I made this changes, in my boards.txt file I add:
Code:
##############################################################
tempcontroller.name=TempController

tempcontroller.upload.protocol=arduino
tempcontroller.upload.maximum_size=30720
tempcontroller.upload.speed=57600

tempcontroller.bootloader.low_fuses=0xFF
tempcontroller.bootloader.high_fuses=0xDA
tempcontroller.bootloader.extended_fuses=0x05
tempcontroller.bootloader.path=atmega
tempcontroller.bootloader.file=ATmegaBOOT_168_atmega328.hex
tempcontroller.bootloader.unlock_bits=0x3F
tempcontroller.bootloader.lock_bits=0x0F
tempcontroller.build.mcu=m328pu
tempcontroller.build.f_cpu=16000000L
tempcontroller.build.core=arduino
tempcontroller.build.variant=standard
##############################################################
And as you sugest in my avrdude.conf I add:
Code:
# ATmega328-PU
#------------------------------------------------------------

part
    id = "m328pu";
    desc = "ATMEGA328Pu";
    has_debugwire = yes;
    flash_instr = 0xB6, 0x01, 0x11;
    eeprom_instr = 0xBD, 0xF2, 0xBD, 0xE1, 0xBB, 0xCF, 0xB4, 0x00,
  0xBE, 0x01, 0xB6, 0x01, 0xBC, 0x00, 0xBB, 0xBF,
  0x99, 0xF9, 0xBB, 0xAF;
    stk500_devcode = 0x86;
    # avr910_devcode = 0x;
    signature = 0x1e 0x95 0x14;
    pagel = 0xd7;
    bs2 = 0xc2;
    chip_erase_delay = 9000;
    pgm_enable = "1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1",
"x x x x x x x x x x x x x x x x";

    chip_erase = "1 0 1 0 1 1 0 0 1 0 0 x x x x x",
"x x x x x x x x x x x x x x x x";

    timeout = 200;
    stabdelay = 100;
    cmdexedelay = 25;
    synchloops = 32;
    bytedelay = 0;
    pollindex = 3;
    pollvalue = 0x53;
    predelay = 1;
    postdelay = 1;
    pollmethod = 1;

    pp_controlstack =
0x0E, 0x1E, 0x0F, 0x1F, 0x2E, 0x3E, 0x2F, 0x3F,
0x4E, 0x5E, 0x4F, 0x5F, 0x6E, 0x7E, 0x6F, 0x7F,
0x66, 0x76, 0x67, 0x77, 0x6A, 0x7A, 0x6B, 0x7B,
0xBE, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00;
    hventerstabdelay = 100;
    progmodedelay = 0;
    latchcycles = 5;
    togglevtg = 1;
    poweroffdelay = 15;
    resetdelayms = 1;
    resetdelayus = 0;
    hvleavestabdelay = 15;
    resetdelay = 15;
    chiperasepulsewidth = 0;
    chiperasepolltimeout = 10;
    programfusepulsewidth = 0;
    programfusepolltimeout = 5;
    programlockpulsewidth = 0;
    programlockpolltimeout = 5;

    memory "eeprom"
paged = no;
page_size = 4;
size = 1024;
min_write_delay = 3600;
max_write_delay = 3600;
readback_p1 = 0xff;
readback_p2 = 0xff;
read = " 1 0 1 0 0 0 0 0",
       " 0 0 0 x x x a9 a8",
       " a7 a6 a5 a4 a3 a2 a1 a0",
       " o o o o o o o o";

write = " 1 1 0 0 0 0 0 0",
      " 0 0 0 x x x a9 a8",
" a7 a6 a5 a4 a3 a2 a1 a0",
" i i i i i i i i";

loadpage_lo = " 1 1 0 0 0 0 0 1",
      " 0 0 0 0 0 0 0 0",
      " 0 0 0 0 0 0 a1 a0",
      " i i i i i i i i";

writepage = " 1 1 0 0 0 0 1 0",
    " 0 0 x x x x a9 a8",
    " a7 a6 a5 a4 a3 a2 0 0",
    " x x x x x x x x";

mode = 0x41;
delay = 20;
blocksize = 4;
readsize = 256;
    ;

    memory "flash"
paged = yes;
size = 32768;
page_size = 128;
num_pages = 256;
min_write_delay = 4500;
max_write_delay = 4500;
readback_p1 = 0xff;
readback_p2 = 0xff;
read_lo = " 0 0 1 0 0 0 0 0",
  " 0 0 a13 a12 a11 a10 a9 a8",
  " a7 a6 a5 a4 a3 a2 a1 a0",
  " o o o o o o o o";

read_hi = " 0 0 1 0 1 0 0 0",
  " 0 0 a13 a12 a11 a10 a9 a8",
  " a7 a6 a5 a4 a3 a2 a1 a0",
  " o o o o o o o o";

loadpage_lo = " 0 1 0 0 0 0 0 0",
      " 0 0 0 x x x x x",
      " x x a5 a4 a3 a2 a1 a0",
      " i i i i i i i i";

loadpage_hi = " 0 1 0 0 1 0 0 0",
      " 0 0 0 x x x x x",
      " x x a5 a4 a3 a2 a1 a0",
      " i i i i i i i i";

writepage = " 0 1 0 0 1 1 0 0",
    " 0 0 a13 a12 a11 a10 a9 a8",
    " a7 a6 x x x x x x",
    " x x x x x x x x";

mode = 0x41;
delay = 6;
blocksize = 128;
readsize = 256;

    ;

    memory "lfuse"
size = 1;
min_write_delay = 4500;
max_write_delay = 4500;
read = "0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0",
       "x x x x x x x x o o o o o o o o";

write = "1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0",
      "x x x x x x x x i i i i i i i i";
    ;

    memory "hfuse"
size = 1;
min_write_delay = 4500;
max_write_delay = 4500;
read = "0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0",
       "x x x x x x x x o o o o o o o o";

write = "1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0",
      "x x x x x x x x i i i i i i i i";
    ;

    memory "efuse"
size = 1;
min_write_delay = 4500;
max_write_delay = 4500;
read = "0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0",
       "x x x x x x x x x x x x x o o o";

write = "1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0",
      "x x x x x x x x x x x x x i i i";
    ;

    memory "lock"
size = 1;
min_write_delay = 4500;
max_write_delay = 4500;
read = "0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0",
       "x x x x x x x x x x o o o o o o";

write = "1 0 1 0 1 1 0 0 1 1 1 x x x x x",
      "x x x x x x x x 1 1 i i i i i i";
    ;

    memory "calibration"
size = 1;
read = "0 0 1 1 1 0 0 0 0 0 0 x x x x x",
       "0 0 0 0 0 0 0 0 o o o o o o o o";
    ;

    memory "signature"
size = 3;
read = "0 0 1 1 0 0 0 0 0 0 0 x x x x x",
       "x x x x x x a1 a0 o o o o o o o o";
    ;
;

When I try to compile I get this error:
avr-g++: error: unrecognized argument in option ‘-mmcu=m328pu’

There must be in some part where the arduino IDE must match with a expected cpu type.
If I use the console to see if the avrdude is talking with cpu using the new settings it works as expected, so the problem remains somewhere in arduino core.
Quote
$ sudo /usr/bin/avrdude -c usbtiny -p m328pu

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9514

avrdude: safemode: Fuses OK

avrdude done.  Thank you.
Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Last time I saw someone have this problem, he resolved the problem by pretending the device was an atmega328p and editing the device signature in the atmega328p entry in avrdude.conf. Not ideal, but it worked for him. We never did get to the bottom of why adding a new entry to avrdude.conf didn't work.
« Last Edit: January 04, 2013, 06:05:03 pm by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
pretending the device was an atmega328p and editing the device signature in the atmega328p entry in avrdude.conf
Well that's what I had done until now, that's because I'm looking for the answer since when I get the duemilanove attached I must go to the avrdude and change the signature again and again.Boring  smiley-evil
I understand the compiler, the new entry for it is new, it must know how many pins, register and so on about this new device apart of being the same as the atmega328p his name must be diferent because of the signature differences.
I will still look for my answer smiley-mr-green
Thanks anyway
Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6593
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It might be worth searching for avrdude.conf on your computer, in case there is more than one.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I activate the debug option on arduino IDE and I found the problem is on avr gcc
Avr-gcc have an internal list of devices:
Code:
Known MCU names:
  avr1 avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega1
  avrxmega2 avrxmega3 avrxmega4 avrxmega5 avrxmega6 avrxmega7 at90s1200
  attiny11 attiny12 attiny15 attiny28 at90s2313 at90s2323 at90s2333
  at90s2343 attiny22 attiny26 at90s4414 at90s4433 at90s4434 at90s8515
  at90c8534 at90s8535 attiny13 attiny13a attiny2313 attiny2313a attiny24
  attiny24a attiny4313 attiny44 attiny44a attiny84 attiny84a attiny25
  attiny45 attiny85 attiny261 attiny261a attiny461 attiny461a attiny861
  attiny861a attiny87 attiny43u attiny48 attiny88 at86rf401 ata6289
  at43usb355 at76c711 atmega103 at43usb320 attiny167 at90usb82 at90usb162
  atmega8u2 atmega16u2 atmega32u2 atmega8 atmega48 atmega48a atmega48p
  atmega88 atmega88a atmega88p atmega88pa atmega8515 atmega8535 atmega8hva
  at90pwm1 at90pwm2 at90pwm2b at90pwm3 at90pwm3b at90pwm81 atmega16
  atmega16a atmega161 atmega162 atmega163 atmega164a atmega164p atmega165
  atmega165a atmega165p atmega168 atmega168a atmega168p atmega169
  atmega169a atmega169p atmega169pa atmega32 atmega323 atmega324a
  atmega324p atmega324pa atmega325 atmega325a atmega325p atmega325pa
  atmega3250 atmega3250a atmega3250p atmega3250pa atmega328 atmega328p
  atmega329 atmega329a atmega329p atmega329pa atmega3290 atmega3290a
  atmega3290p atmega3290pa atmega406 atmega64 atmega640 atmega644
  atmega644a atmega644p atmega644pa atmega645 atmega645a atmega645p
  atmega649 atmega649a atmega649p atmega6450 atmega6450a atmega6450p
  atmega6490 atmega6490a atmega6490p atmega16hva atmega16hva2 atmega16hvb
  atmega16hvbrevb atmega32hvb atmega32hvbrevb atmega64hve at90can32
  at90can64 at90pwm161 at90pwm216 at90pwm316 atmega32c1 atmega64c1
  atmega16m1 atmega32m1 atmega64m1 atmega16u4 atmega32u4 atmega32u6
  at90usb646 at90usb647 at90scr100 at94k m3000 atmega128 atmega1280
  atmega1281 atmega1284p atmega128rfa1 at90can128 at90usb1286 at90usb1287
  atmega2560 atmega2561 atxmega16a4 atxmega16d4 atxmega16x1 atxmega32a4
  atxmega32d4 atxmega32x1 atxmega64a3 atxmega64d3 atxmega64a1 atxmega64a1u
  atxmega128a3 atxmega128b1 atxmega128d3 atxmega192a3 atxmega192d3
  atxmega256a3 atxmega256a3b atxmega256a3bu atxmega256d3 atxmega128a1
  atxmega128a1u

Now I have no clue how can I add a new device but I notice that there is a device called atmega328
I used that (I still don't know the diferences) atmega328 on my boards.txt and in avrdude.conf and now it compiles ok.
« Last Edit: January 04, 2013, 06:27:02 pm by HugoPT » Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1544
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also found this
Quote
gregsmithcts - Oct 18, 2011 - 08:21 PM
Post subject: RE: Difference between ATmega328, 328P and 328PU I think you'll find the differences are just in the silicon and affect the power consumption. In terms for functionality and pin compatibility (and programming) there is no difference.

So my problem is solved.In duemilanove I use the atmega328P and in my custom board I use atmega328  smiley-lol
Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17262
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Didn't user westfw come up with a bootloader 'fix' for this problem where it would report back to AVRDUDE the signature of a 328p chip even though it was installed into a 328 non p chip. Simply lying to AVRDUDE seemed to be the simplest method. I guess the trick is how to get such a 'modified' bootloader installed into a 328 non p chip in the first place, chick and egg problem? Anyway maybe contacting westfw would give you a direct path to success as I'm pretty sure he dealt with this issue in the past.

Lefty
Logged

Pages: [1]   Go Up
Jump to: