[SOLVED] Olimex AVR-ISP500 -> Slow uploading

I have an Olimex AVR-ISP500 hooked up to a 328p on a breadboard. So that I can use it with the Arduino IDE, I added the following to the programmers.txt file:

olimexisp.name=AVR ISP 500 Olimex  
olimexisp.communication=serial
olimexisp.protocol=stk500v2

and in boards.txt I added this:

##############################################################  
avr500atmega328.name=AVR500v2 programmer with ATmega328  
avr500atmega328.upload.using=olimexisp  
avr500atmega328.bootloader.low_fuses=0xFF  
avr500atmega328.bootloader.high_fuses=0xDA  
avr500atmega328.bootloader.extended_fuses=0x05  
avr500atmega328.bootloader.path=atmega  
avr500atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex  
avr500atmega328.bootloader.unlock_bits=0x3F  
avr500atmega328.bootloader.lock_bits=0x3F  
avr500atmega328.build.mcu=atmega328p
avr500atmega328.build.f_cpu=16000000L  
avr500atmega328.build.core=arduino  
##############################################################

Now, I can burn a bootloader by selecting the proper programmer (AVR ISP 500 Olimex) and board in the IDE, and I can also burn sketches with 'Upload using programmer'. The problem is, It. Is. Very. Slow.

This first manifests itself when writing the bootloader. It writes fine, however it never verifies because it times out several times during that step and eventually the IDE quits and says it can't verify. But the bootloader's burned just fine. I say this because I have an LED connected to pin 13 and it blinks like it should after you've burned a bootloader. And, I can upload a sketch (though that blows away the bootloader) and that too works. I have not tried to do any kind of serial communications between this 328p and another ...

What I can't figure out is if it's normal for it to be so slow. Burning the bootloader (prior to verifying) takes almost five minutes. Burning a sketch that just turns on then off that LED takes about a minute and a half. Is it because there's no speed declaration in the programmers.txt file? Or is it slow by design?

The 328p has a resonator on it (16MHz), power, everything works, it's just very slow and never passes the bootloader verification (which I suspect is because it times out waiting for data.)

Ideas?

KirAsh4:
What I can't figure out is if it's normal for it to be so slow. Burning the bootloader (prior to verifying) takes almost five minutes.

No. That is not normal. It should take a few seconds.

Is it because there's no speed declaration in the programmers.txt file?

No. Unless the Olimex folks did something dumb, communications between the PC and the programmer should always be at 12 Mbs. From their webpage... "connects to PC via USB 2.0 Full speed".

Or is it slow by design?

That is certainly a possibility. But I cannot imagine why they would do that.

Ideas?

Post the verbose output. Let's see what commands avrdude is sending.

It is probably the default sck clock speed set very low on the AVR-ISP500. If it is similar to other stk500v2 programmers then, it will use the last sck clock speed set from the programming software (AVRStudio or avrdude).

You can try using avrdude with a faster clock setting and see if it will keep that setting when using the Arduino IDE.

Try this (change the COM port to your setting):

avrdude -c stk500v2 -PCOM3 -B1 -p m328p -v

Note: the -B1 option will set the sck clock period to 1 microsecond.

Hopefully, if it is similar to other stk500v2 or avrispmkii programmers then it will save this sck clock setting in it's internal flash memory and use it as a new default for later use.

Edit: The problem is with the Arduino IDE does not utilize the software sck clock option with avrdude. Which limits the IDE to using whatever default sck clock the programmer uses. Hopefully they may add this feature to the IDE to be able to set the -B option to avrdude.

hiduino:
Try this (change the COM port to your setting):

avrdude -c stk500v2 -PCOM3 -B1 -p m328p -v

Ok, this fixed it. It now burns the bootloader in seconds, which is what I'm used to when I use an Uno as an ISP programmer.

I also unplugged the programmer, let it sit for a while, plugged it back in and tried burning a bootloader and it appears to have retained the setting. Speaking of, when I ran the above command, this is what it spewed back, in case either of you want to read it. The only thing that stood out to me was the sck_period being too small and it getting increased to 1.1 us instead:

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\WinAVR-20100110\bin\avrdude.conf"

         Using Port                    : COM2
         Using Programmer              : stk500v2
         Setting bit clk period        : 1.0
avrdude: stk500v2_set_sck_period(): p = 1.0 us too small, using 1.1 us
         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 : STK500V2
         Description     : Atmel STK500 Version 2.x firmware
         Programmer Model: STK500
         Hardware Version: 2
         Firmware Version Master : 2.10
         Topcard         : Unknown
         Vtarget         : 5.1 V
         SCK period      : 1.1 us
         Varef           : 5.1 V
         Oscillator      : 60.433 kHz

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Why's the oscillator showing up as 60.433 kHz ? I'm assuming this isn't the same as the external 16MHz resonator that I have on the 328p? Other than that, I have no idea what I'm reading. I may have to go back to the datasheet and see if I can figure out what all those various parameters and variables mean. :slight_smile:

Thanks for the help!

KirAsh4:
Why's the oscillator showing up as 60.433 kHz ?

To confuse us.

I'm assuming this isn't the same as the external 16MHz resonator that I have on the 328p?

My guess is that it is whatever value happens to be in a register or memory location when the Olimex programmer prepares the return buffer.

Well, either way, it works now.

And after configuring it to work with Atmel Studio 6, AND not being a C++ programmer, I was able to modify a blink program to blink two LEDs, one on what would be pin 13 (or PB5) and pin 1 (or PD1). Still trying to understand all the operators though ..

#define F_CPU 16000000    // AVR clock frequency in Hz, used by util/delay.h
#include <avr/io.h>
#include <util/delay.h>

int main() {
  DDRB |= (1<<DDB5);
  DDRD |= (1<<DDD1);
  while (1) {
    PORTD |= (1<<PORTD1);
    _delay_ms(100);
    PORTD &= ~(1<<PORTD1);
    _delay_ms(100);
    PORTB |= (1<<PORTB5);
    _delay_ms(100);
    PORTB &= ~(1<<PORTB5);
    _delay_ms(700);
  }
}

Now to figure out how to get Arduino libraries to play nice with AS6.0 ... And learn to write C++ ...