Offline
Full Member
Karma: 1
Posts: 167
|
 |
« on: April 24, 2012, 10:26:28 am » |
Hi,
I´am digging though the Optiloader code so i can adapt it to program ATmega2560 to.
Does anyone with experience think the task will be to hard? What are the main problems or alterations that i should be expecting to do?
regards
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #1 on: April 24, 2012, 07:56:06 pm » |
Yeah, it will be hard. optiLoader is based on ArduinoISP, which uses the STK500v1 protocol, which doesn't specifically handle targets with more than 128kbytes of memory...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 167
|
 |
« Reply #2 on: April 26, 2012, 09:19:03 am » |
At the moment i´m trying to test the optiloader in an Atmel328 that i have in a custom board, using an arduino UNO. And i´m receiving this answer: OptiLoader Bootstrap programmer. 2011 by Bill Westfield (WestfW)
Target power on! ... Starting Program Mode - Failed, result = 0x0
Target power OFF!
Type 'G' or hit RESET for next chip
OptiLoader Bootstrap programmer. 2011 by Bill Westfield (WestfW)
Target power on! ... Starting Program Mode - Failed, result = 0x0
Target power OFF!
Type 'G' or hit RESET for next chip Do you have any idea of what i might be doing wrong. When i use my AVRisp to program a normal arduino bootloader, i have no problem. Best regards
|
|
|
|
« Last Edit: April 26, 2012, 10:18:02 am by LuisSoares »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 167
|
 |
« Reply #3 on: April 26, 2012, 09:22:59 am » |
Relatively to your previous answer of difficulty of modification...
Is it that hard, isn´t it basically allowing it to write a bigger memory. Repeating the process but for a bigger address range.
To explain a little bit more the objective... My basic idea is to use the optiloader as inspiration to write a program that goes to an SDCARD to get a sketch (Intel.hex file) and writes it the flash memory of a ATmega2560.
Best regards
|
|
|
|
« Last Edit: April 26, 2012, 10:47:05 am by LuisSoares »
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #4 on: April 26, 2012, 12:11:26 pm » |
I guess since it doesn't actually implement the stk protocol, it wouldn't be THAT awful. There are a lot of things passed around in 16bit pointers that would have to be changed to use longs. Have you seen Adafruit's modification? I think they fixed the size restrictions, for example. https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #5 on: April 26, 2012, 12:15:12 pm » |
Starting Program Mode - Failed, result = 0x0 This would tend to mean that there was no response to the initial SPI "start programming" command, which is usually caused by a wiring error (MOSI and MISO swapped, SCK not in the right place, etc.)
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 129
Posts: 10388
|
 |
« Reply #6 on: April 26, 2012, 04:49:57 pm » |
Have you seen Adafruit's modification? I think they fixed the size restrictions, for example. Naw. Looks like it uses 16 bit addresses as well... uint16_t pageaddr
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 167
|
 |
« Reply #7 on: April 27, 2012, 04:46:57 am » |
Hei, There was an error on the pins placement, right now it seems to be programming. I haven´t yet run trough the code, but i read the page http://ladyada.net/library/tools/standaloneisp.html. There i found this comment: Unlike the specialized Optiloader, this program can be adapted to any AVR and any size HEX file as long as you can fit the HEX into the flash of the microcontroller. Since HEX files are ascii, they basically 2x the size of the code itself. So if you have a 500 byte program, the HEX will be 1K. The sketch itself takes about 10KB so you have approximately 20KB left for the HEX which is good for about 10KB of flash to burn. This isn't tons but I suppose if you wanted to port the program to the Mega then you could fit up to 128KB of flash for massive chips.
You can paste your new HEX into images.cpp . You'll need also to set the bottom two bytes of the signature (third entry), and the fuses you want to set before you start programming, and the fuses you want to set after programming (in case the lock bits have changed). The fuse mask is used because not all fuse bits are used so if you write a zero to an unused bit (as avrdude prefers to do) it may be read back as a 1 which can cause verification errors. Next is the size of the chip flash in bytes and the size of a flash page for the chip (you may need to research the datasheet for this number). The first two arguments (name of flash and name of chip) are for your records, they arent really used by the program itself.
After you've adjusted those, go back to the main pde sketch and update
byte pageBuffer[128]; /* One page of flash */ so that the size of the flash page buffer is larger if necessary ...... Do you think that the adaloader might be a better starting point to attain my objective?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 167
|
 |
« Reply #8 on: April 27, 2012, 06:09:51 am » |
Hi, Strangely, i can compile and upload the optiloader sketch. but, in the case of the Adaloader project i can only compile, when i try to upload, it gives me this error message: Binary sketch size: 28688 bytes (of a 32256 byte maximum)
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64 avrdude: failed to write flash memory, rc=-4 avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
Does anyone has any idea of what might be the problem? I´m using Arduino UNO.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Online
Shannon Member
Karma: 129
Posts: 10388
|
 |
« Reply #9 on: April 27, 2012, 05:07:22 pm » |
Are you able to upload smaller programs?
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #10 on: April 27, 2012, 06:26:13 pm » |
If you have the original optiboot bootloader, it has a bug that prevents loading sketches longer than 28672 bytes.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 167
|
 |
« Reply #11 on: May 02, 2012, 08:01:22 am » |
Yes i can upload smaller sketches.
I´m using the normal arduino booloader in the AT328P to upload both sketches: optiloader and adaloader.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #12 on: May 05, 2012, 07:50:12 pm » |
I´am digging though the Optiloader code so i can adapt it to program ATmega2560 to.
Does anyone with experience think the task will be to hard?
I think it should be easy, based on the work I did making a sketch that reads in the flash memory: http://www.gammon.com.au/forum/?id=11633The relevant part in my implementation was this function that reads from flash: byte readFlash (unsigned long addr) { // set the extended (most significant) address byte if necessary byte MSB = (addr >> 16) & 0xFF; if (MSB != lastAddressMSB) { program (loadExtendedAddressByte, 0, MSB); lastAddressMSB = MSB; } // end if different MSB byte high = (addr & 1) ? 0x08 : 0; // set if high byte wanted addr >>= 1; // turn into word address return program (readProgramMemory | high, highByte (addr), lowByte (addr)); } // end of readFlash
The first few lines switch the "extended address byte" which controls which part of memory you are addressing. Furthermore the relevant line in the .hex file is here: :020000023000CCIt is an "02" record which is an "Extended Segment Address Record". This sets the high-order byte of the address to 03 (shifted 4 bits left according to Wikipedia). So in the next line: :10E000000D94F6F20D941FF30D941FF30D941FF36EThe address E000 therefore becomes 3E000. So I suggest that when reading the bootloader, if you hit the "02" record (first line) and change the extended address byte, the rest will just follow automatically.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #13 on: May 05, 2012, 07:54:16 pm » |
Ah, you might need to change this part: * We assume that the image does not exceed the 512 bytes that we have * allowed for it to have. that would be bad.
Some of those bootloaders are 8192 bytes. Still I don't see why you can't program a byte at a time.
|
|
|
|
|
Logged
|
|
|
|
|
SF Bay Area (USA)
Offline
Faraday Member
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
|
 |
« Reply #14 on: May 05, 2012, 11:26:06 pm » |
Optiloader currently reads the entire bootloader image (512bytes) into RAM (from .hex format in flash.) This won't be possible with an 8192 byte image. I think this is one of the things that has been improved in the Adafruit version, though. Since there is a worse than 2:1 size difference between hex and binary, it may even be difficult to fit the 8192 byte image in flash (on a 32kbyte part) at all.
|
|
|
|
|
Logged
|
|
|
|
|
|