Help in programming the Atmega1284 with maniacbug-mighty-1284p.

pito:
Frankly, I am not aware of the fact Usbasp cannot flash at the top addresses. I used it with amforth for example - afaik it stores code on the top within the bootloader section - no issues ever..

And I too don't know if USBasp has such a limitation or not, just reporting that a USBtiny does and a simple work around for me was using an arduino board and Nick's program.

Lefty

I knew that USBasp didn't have the 64 kB limit.
This is from the changelog of the last version of the firmware:

usbasp.2011-05-28 (v1.4)

  • added support for controllers with flash >128kb (by Slawomir Fra?)

Ok, an interesting stuff, indeed.

  1. LED is on PB0 on my board, it flashes after reset, all programmers work fine :slight_smile:
  2. I did some editing of the avrdudeconf (added resetdelay = 15, similar to uno, and added ..tool=avrdude into boards) - that causes the avrdude resets the BT pin32 (aka dtr) now before the upload (I am using a BT module).

So the upload started, but finished with errors already published here. I did about 70 uploads of a 15kB sketch and my current findings are as follows (chip date 1027, breadboard, good decoupled, short wires (5cm long Rx, Tx to BT), no crossing with other signals or crystal):

  1. without pull up/down resistor on RX and w/ short wires the probability of a successful upload ~10%
  2. with pull-up/down 10k res on Rx - about 40%
  3. with serial 10k in RX - 100% upload, even with a 20cm long Rx wire and while the wire touched/hold during the upload (the 20cm wire at the 1284p's Rx pin side)
  4. w/o the serial 10k and with 20cm long Rx wire no luck.

That behavior might be caused, except "Rx pin signal/noise sensitivity", by a reversal of the 1284p's Rx input pin direction, even for a very short time, thus it fires against the other output (ftdi's or BT's Tx), and when the current peak is not limited (ie. by a serial resistor) it flips internally into an undefined state. Hopefully the bootloader does not change the Rx direction (or switches internal pullups on/off on that pin) somewhere in the code..

I did following experiment - 58cm long Rx wire, passed beneath the crystal, did few loops with it creating a mess :slight_smile: with 10k serial resistor wired as follows:

BTmodule_Tx --10kohm------>>---------58cm_wire------->>-----Crystal---->>----Rx pin 1284p

Uploaded an 127kB large sketch:

Binary sketch size: 127,052 bytes (of a 130,048 byte maximum)

Done 12x while touching the 58cm long wire during the upload from time to time - upload 100% ok. I did not test the code actually works, though :).

Solved?
With Low Fuse= F7 (Full Swing Oscillator 16K CK + 45ms) I cannot reproduce the upload errors anymore (the 10k serial resistor is not needed). It could be the 1284p operated @16MHz and 3V3 needs full swing (more power), otherwise the nearby RX pin may influence (modulate) the crystal oscillator frequency (especially with the DIP package with larger capacitance between the pins) and it comes to errors then..
PS: XTAL1 pin13 (RX is 14) - is the input of the crystal oscillator (high impedance, easy to modulate), would be better to have XTAL2 pin - the oscillator output - there (low impedance, harder to modulate)..

FYI - a simulation - signal from FTDI to the Rx pin, and Rx coupled via a parasitic capacitance to the XTAL1 pin of the 1284p's oscillator. For 3 parasitic capacitances - 1pF, 5pF, 10pF. You may see the effect on the frequency when the rising edge of the Rx signal comes in. May behave differently - depends on the gate (here 4011 gate model used), xtal (??), etc. parameters used.

Disclaimer: this is only a simple simulation with parts with different parameters as the 1284p probably includes. For demonstration purposes only. No warranties of any kind.

And the same for 5pF parasitic capacitance between the pins and 200ohm (no resistor), 10k, 200k serial resistor. It seems the 200k does not create a glitch in the oscillation (in this simulation).

Disclaimer: simple simulation only, with different parts as included within 1284p. For demo purposes only. No warranties of any kind.

PS: The very bottom picture is probably the most realistic simulation out of all above- with 4049 inverter simulating the 1284p oscillator with more power (full swing), and 10pF capacitance between the RX and XTAL1 pins. The oscillator period changed from 127.1ns to 135.4ns after the Rx' rising edge (thus the frequency)..

pito:
Solved?
With Low Fuse= F7 (Full Swing Oscillator 16K CK + 45ms) I cannot reproduce the upload errors anymore (the 10k serial resistor is not needed). It could be the 1284p operated @16MHz and 3V3 needs full swing (more power), otherwise the nearby RX pin may influence (modulate) the crystal oscillator frequency (especially with the DIP package with larger capacitance between the pins) and it comes to errors then..
PS: XTAL1 pin13 (RX is 14) - is the input of the crystal oscillator (high impedance, easy to modulate), would be better to have XTAL2 pin - the oscillator output - there (low impedance, harder to modulate)..

Huh! It's extremely cool that you've been carrying on with this problem while the rest of us have
been sleeping!

I don't know anything about USBasp or the ATmega fuses, and can barely understand the
convoluted description of the latter in the 1284 d/s, but you may have solved the problem.
Ref Table 9-1, maniacbug's boards.txt setup uses the low-power oscillator, low fuses = 0xFF,
instead of full swing oscillator, low-fuses = 0xF7 and there lies the RX0 sensitivity problem.
Plus, possibly the XTAL1 is in the wrong place.

Sheesh, can this endless muckup on 7 continents be that simple? !!!

I am using it just now w/o the resistor on a noisy breadboard with F7 and it works fine, no issues yet.. :wink:

BTW, the 328p arduinos are lucky not to be affected by the issue as well as the Rx and Tx pins are far away off the XTAL1 pin. Moreover, XTAL1 (the critical sensitive crystal oscillator input) is flipped around against the 1284p and close to GND - GND acts as a shielding (GOOD)! See below..

IMHO the issue severity depends on the design (parasitic capacitance), crystal parameters, 2 crystal capacitors values, and how off is the actual crystal frequency from the recommended ie for 115k2:

8MHz crystal
57k   3.7% error
115k 7.8% error
16MHz crystal
57k   2.1% error
115k 3.7% error

Thus even a small additional error introduced ie. by such frequency pulling by Rx signal edges may disturb the Uart communication easily..
That is my current understanding :stuck_out_tongue: If Atmel plans a new die revision, I would recommend them to swap the oscillator pins, my invoice will follow :slight_smile:

328p vs 1284p OSC.jpg

Good analysis, I think. Funny how Atmel flipped XTAL1,2 around between the 328 and 1284.
Also, 2.1 and 3.7% errors are on the edge of reliability, AFAIAC.

BTW - hand wired constructions usually have less parasitic capacitances as the PCBs do..
BTW2 - the capacitance between two adjacent rows on a solder-less breadboard is around 3.5pF..

breadb.jpg

I've been uploading to my 1284P via ICSP due to this problem, even just a 23k sketch failed every time via the bootloader and serial.

I've just re-burnt the bootloader and tried the same sketch 3 times and it failed.

I added the 10k series resistor on RX0 and tried again and it worked!

Tried it 6 times and it uploaded 100%.

Removed the 10k resistor and it failed.

Replaced the resistor and it worked 3 times in a row again.

I'll now try re-burning the fuses with the 0xF7 low bit and report back.

EDIT: Used Nick's Bootloader Programmer (for the first time) to re-burn the bootloader and set the fuses (I changed Low Fuse from 0xFF to 0xF7 in his sketch) and retried the upload with no resistor. It worked! Now I just need a big sketch to verify it really.

The most profound thanks to you guys for working together to track down and find a solution to this problem. Ye, you can upload via ICSP, but when your board is in a device that means you have to take everything off the SPI bus. On the board I just had made I actually included a 4 pin DIP switch so I could separate everything else form the ICSP header for any code updates that needed to be programmed. I also have a serial header available as well.

Right, now it appears that the 644P family is in the sketch to be identified but there is no entry for a bootloader or fuses setup. Does anyone know how we might go about adding 644P support?

Enclosed 127kB large sketch. Not to be run, just for upload tests.
Enjoy!

EDIT: deleted - please use the BLINK sketch below..

pito:
Enclosed 127kB large sketch. Not to be run, just for upload tests.
Enjoy!

Thanks for that, but I can't compile and upload as it needs some libraries; NilTROS, NilAnaolg, NilSerial and SDFat

SDFat I can get, but I can't find the others at all so I'm guessing they are ones of your own?

http://arduino.cc/forum/index.php/topic,144715.0.html
But you may take ANY sketch you have handy - just copy and paste those LARGE

byte PROGMEM atmega2560_v2 [] = {
0x0D, 0x94, 0x89, 0xF1, 0x0D, 0x94,

bla-bla stuff from the sketch I posted in it.. You can easily make 512kB sketch from it if you like :slight_smile:

This BLINK compiles 129,948 bytes. You have to have SdFat lib there.
Not for running, just for compile and 1284p upload test..
Remove your SDCARD when playing with it..
No warranties of any kind. Use at your own risk.. :stuck_out_tongue:

Binary sketch size: 129,948 bytes (of a 130,048 byte maximum)

Blink_129048bytes.zip (107 KB)

I managed to find the libraries to use your sketch.

O...M...G...It works!! 127k Sketch uploaded several times.

Fantastic work.

tack:
Right, now it appears that the 644P family is in the sketch to be identified but there is no entry for a bootloader or fuses setup. Does anyone know how we might go about adding 644P support?

I have a optiboot version working on a 644P Bobuino board. I just used my USBtiny to burn the bootload, but the arduinoISP sketch should work also from the IDE once you have the bootloader saved in the correct folder and make the boards.txt entry.

:020000000504F5
:10FC0000112484B714BE81FFF2D085E08093810077
:10FC100082E08093C00088E18093C10086E08093F9
:10FC2000C20080E18093C4008EE0CBD0209A86E0B1
:10FC300020E33CEF91E0309385002093840096BB55
:10FC4000B09BFECF189AA8958150A9F7CC24DD244B
:10FC500088248394B5E0AB2EA1E19A2EF3E0BF2E69
:10FC6000A4D0813471F4A1D0082FB1D0023811F49E
:10FC700085E005C0013811F484E001C083E08DD037
:10FC800089C0823411F484E103C0853419F485E01D
:10FC9000A6D080C0853579F488D0E82EFF2485D0A1
:10FCA000082F10E0102F00270E291F29000F111F09
:10FCB0008ED068016FC0863521F484E090D080E05A
:10FCC000DECF843609F040C070D06FD0082F6DD0E1
:10FCD00080E0C81680EED80618F4F601B7BEE895A5
:10FCE000C0E0D1E062D089930C17E1F7F0E0CF16C5
:10FCF000F0EEDF0618F0F601B7BEE89568D007B65B
:10FD000000FCFDCFA601A0E0B1E02C9130E01196FF
:10FD10008C91119790E0982F8827822B932B129625
:10FD2000FA010C0187BEE89511244E5F5F4FF2E0A7
:10FD3000A030BF0751F7F601A7BEE89507B600FC53
:10FD4000FDCF97BEE89526C08437B1F42ED02DD0D4
:10FD5000F82E2BD03CD0F601EF2C8F010F5F1F4FF8
:10FD600084911BD0EA94F801C1F70894C11CD11CFE
:10FD7000FA94CF0CD11C0EC0853739F428D08EE10F
:10FD80000CD086E90AD08AE07ACF813511F488E078
:10FD900018D01DD080E101D063CF982F8091C00092
:10FDA00085FFFCCF9093C60008958091C00087FF27
:10FDB000FCCF8091C00084FD01C0A8958091C60051
:10FDC0000895E0E6F0E098E1908380830895EDDF08
:10FDD000803219F088E0F5DFFFCF84E1DECF1F939A
:10FDE000182FE3DF1150E9F7F2DF1F91089580E04B
:08FDF000E8DFEE27FF2709946C
:040000030000FC00FD
:00000001FF

And here is the boards.txt entry for the 644P

##############################################################

bobuino644.name=Bobuino 644P optiboot
bobuino644.upload.protocol=arduino
bobuino644.upload.maximum_size=63488
bobuino644.upload.speed=115200
bobuino644.bootloader.low_fuses=0xff
bobuino644.bootloader.high_fuses=0xdc
bobuino644.bootloader.extended_fuses=0xfd
bobuino644.bootloader.path=optiboot
bobuino644.bootloader.file=optiboot_atmega644p-4-5.hex
bobuino644.bootloader.unlock_bits=0x3F
bobuino644.bootloader.lock_bits=0x0F
bobuino644.build.mcu=atmega644p
bobuino644.build.f_cpu=16000000L
#bobuino644.build.core=arduino:arduino
bobuino644.build.core=standard
bobuino644.build.variant=bobuino

##############################################################

Lefty

oric_dan:
..and there lies the RX0 sensitivity problem.

To clarify a little bit - No, it is not the "RX0 sensitivity" problem. That is an urban myth..

RX0 is perfectly fine.

It is definitely the XTAL1-pin placement problem (crystal oscillator input) - and most notably a not good decision at Atmel not to follow ie. the 328p as far as the crystal oscillator pins layout is concerned..

oric_dan:
lefty, where did you get this file? --> optiboot_atmega644p-4-5.hex

I think here:

http://code.google.com/p/optiboot/downloads/list

from here:

http://code.google.com/p/optiboot/

The only bootloader I can't remember a source site from is the optiboot compiled for the mega1280 chip which I found only after several days of searching. But I finely did locate a copy somewhere and now all my mega1280 boards (both of them LOL) are working well with optiboot.

Lefty