avrdude and bootloader trouble

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I'm using Peter Fleury's bootloader in an atmega32. avrdude can't read the correct signature when communicating with the bl over COM3, and it times out when talking to my avrispmkII. Both COM3 and the avrispmkII (when used in AVRstudio5) work.

Any suggestions?

Thanks,
Borge

With normal application running:

>avrdude -c avrispmkII -p m32
avrdude: stk500_2_ReceiveMessage(): timeout

With bootloader programmed in, avrispmkII removed, and bootloader started:

>avrdude -c stk500v2 -p m32 -P com3

avrdude: AVR device initialized and ready to accept instructions

Reading | | 0% 0.00savrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
avrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
Reading | ################# | 33% 0.05savrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
Reading | ################################################## | 100% 0.07s

avrdude: Device signature = 0x020202
avrdude: Expected signature for ATMEGA32 is 1E 95 02
Double check chip, or use -F to override this check.

avrdude done. Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For the bootloader:

avrdude -c stk500v2 -p m32 -P com3 -b 115200

The serial devices default to 115200 baud. The AVR board is physically wired to the PC via a MAX232 or FTDI chip.

If you have compiled the bootloader for a different speed, you need to change the -b argument.
The Fleury bootloader has several options for 'detecting booting'. e.g. shorting a special GPIO pin to GND.

The AVRISP-2 can't talk to a bootloader. It only talks to your 6-pin ISP header.

avrdude -c avrispmkII -p m32 -P usb

I am surprised that you ever get a "initialized and ready to accept instructions" message. Even so, you are only properly connected when the Signature is correct. Never use the -F option.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks,

I did compile the bl for 115200. The 020202 error persists when I set -b 115200, and also when I specify 9600 to both the bl code and to avrdude.

The error message looks just like I put it int he original post. com3 is fully operational in 115200, that's what my application code uses.

Borge

david.prentice wrote:
For the bootloader:

avrdude -c stk500v2 -p m32 -P com3 -b 115200

The serial devices default to 115200 baud. The AVR board is physically wired to the PC via a MAX232 or FTDI chip.

If you have compiled the bootloader for a different speed, you need to change the -b argument.
The Fleury bootloader has several options for 'detecting booting'. e.g. shorting a special GPIO pin to GND.

The AVRISP-2 can't talk to a bootloader. It only talks to your 6-pin ISP header.

avrdude -c avrispmkII -p m32 -P usb

I am surprised that you ever get a "initialized and ready to accept instructions" message. Even so, you are only properly connected when the Signature is correct. Never use the -F option.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The reason I tested avrdude -c avrispmkII wasn't to use the programmer with the bl, it was merely to see if avrdude could establish a connection to my MCU. My avrdude installation is from WinAVR-20100110.

On another note, I did test the KAVR bootloader as well. It was able to communicate with TeraTerm and receive my .hex file. However, it doesn't boot my code but keeps rebooting itself.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From memory, the Fleury bootloader builds for a mega32.
The makefile will program the flash, fuses and lockbits too.

Note that you need to set the correct F_CPU or XTAL for your board. And any GPIO "boot" pin. And any information LED(s).
But most importantly, you need flash + fuses + lockbits.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe I've set the F_CPU and baud rate correctly. They were easy to copy from my application code. The flash and fuses also seem to be OK. The only thing I couldn't quite figure out was the lock bits to use. At the moment there are no locks implemented.

Do you think that prevents avrdude from talking to the bl? The bl is running. It responds to the button I set to trig it, and it sets the LED correctly. For a while I also had it running with an infinite loop writing to the RS232. When I saw that working I took it out of the code again.

Do you know of a way for me to talk stk500v2 (ascii) from a terminal emulator? Then I could at least check if the bl responds to commands.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The lockbits won't stop the botloader working.

No, it is really difficult to talk stk500v2 from a terminal. However, you can just add -v or -vvvv to avrdude.

Personally, I would make a fresh installation of Fleury. Then set any configuration macros and rebuild. Make a 'notes' of your edits.

If you still have a problem, post your 'notes' here. Then others can try to replicate your problem.

To enter the bootloader, you need to hold your pin low and press the RESET button. Release the pin.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've reinstalled the bl multiple time. Invoking it doesn't seem to be the problem. And I'm able to change the baud rate on both sides. To try to play it safe, I pulled out the peripherals on my board and also set control pins to the soft-power-down configuration of my application. Signature still reads 020202.

-vvv log pasted in below. Reset didn't solve the problem.

Borge

E:>avrdude -c stk500v2 -p m32 -P com3 -b 9600 -vvv

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:\WinAVR-20100110\bin\avrdude.conf"

Using Port : com3
Using Programmer : stk500v2
Overriding Baud Rate : 9600
avrdude: stk500_2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): found AVRISP programmer
AVR Part : ATMEGA32
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
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 4 10 64 0 no 1024 4 0 9000 9000 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
flash 33 6 64 0 yes 32768 128 256 4500 4500 0xff 0xff
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
hfuse 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
lock 0 0 0 0 no 1 0 0 2000 2000 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00

Programmer Type : STK500V2
Description : Atmel STK500 Version 2.x firmware
Programmer Model: AVRISP
Hardware Version: 15
Firmware Version Master : 2.10
Vtarget : 0.0 V
SCK period : 207.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | | 0% 0.00savrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
avrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
Reading | ################# | 33% 0.09savrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
Reading | ################################################## | 100% 0.15s

avrdude: Device signature = 0x020202
avrdude: Expected signature for ATMEGA32 is 1E 95 02
Double check chip, or use -F to override this check.

avrdude done. Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is strange. I got 0x020202 with an RS232-USB cable on one computer. On a different computer with a standard RS232 cable I get signature=0x010101, both with 9600 and 115200 baud.

The RS232 port in my application code has the same F_CPU setting as the bl and 115200baud. It works on both computers and cables.

One weird thing is that my application works with the avrispmkII plugged in, while the boot loader needs it to be unplugged.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What edits have you made to the virgin installation?

I am going out with my dog now.

When I get home, I can try the virgin code on a real mega32 board with 8MHz crystal. (hence I can't get 115200 baud)

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is what I edited:

#define F_CPU 3686400UL // Here and in makefile
...
#define PROG_PORT  PORTC // PORTD
#define PROG_DDR   DDRC  // DDRD
#define PROG_IN    PINC  // PIND
#define PROG_PIN   PINC2 // PIND2
...
#define PROGLED_PORT PORTD // PORTB
#define PROGLED_DDR  DDRD  // DDRB
#define PROGLED_PIN  PIND7 // PINB1
#define LED_IS_ACTIVE_HIGH // BSB addition
...
#ifndef REMOVE_BOOTLOADER_LED
    PROGLED_DDR  |= (1<<PROGLED_PIN); // Define output

	#ifdef LED_IS_ACTIVE_HIGH
        /* PROG_PIN pulled high, indicate with LED that bootloader is active */
        PROGLED_PORT |= (1<<PROGLED_PIN); // Set bit
	#else
        /* PROG_PIN pulled low, indicate with LED that bootloader is active */
        PROGLED_PORT &= ~(1<<PROGLED_PIN); // Clear bit
	#endif
#endif

Thanks for wanting to help out! Let me know which baud rate you end up with, and I can try 8MHz here as well.

My MCU runs from 5V. Fuses are H:0xDC, L:0xDE. The XO is

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. I tried it for myself. I had to make several edits:
1. Makefile: MCU = atmega32
2. Makefile: F_CPU = 8000000
3. Makefile: BOOTLOADER_ADDRESS = 7800
4. Makefile: AVRDUDE_PORT = com3
5. *boot.c: #define BAUDRATE 19200
6. *boot.c: //#define REMOVE_CMD_MULTI

Note that you will need to change your hfuse to 0xDA (1024 words BOOTSIZ)

Yes, with care, you can get the m32 .HEX to be <= 512 words. However, you need to get the thing working first.

Note the docs tell you about the MULTI #define.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David, I owe you a few beers now :-) Let me know if you're ever in Oslo.

It was probably the multi which did it. Thanks a lot!

I have contact, and I'll spend the next few afternoons perfecting it. My goal is to have one rear plug through which I can program the MCU, upload calibration data and also dump the image for an FPGA.

And I'll order some FTDI USB cables to determine if I should let the modern age in and let their FT230X replace the MAX232 which sits there now.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Fleury bootloader will only do a sub-set of the ISP commands. You can get all of them into 512 words if you go carefully.

Since you are currently on 1024 words, you don't need worry about size when implementing every supported feature. (and more)

All the same, the mega32 can't read its own calibration data. It would be nice to know if a mega32A owner can try it. (the modern m324 or m328 chips can do it)

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In my application I'm running off an external XO, so MCU calibration isn't top on my list. The unit has an external DAC whose DC calibration is stored in MCU eeprom. I got everything I needed up and running yesterday with programming and readback of flash, ee and fuses.

Which lock bit settings do you recommend? The text in the bootloader isn't a 1:1 match with the lock bit names in AVRstudio5.

Borge

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You set the lockbits for "SPM is not allowed to write to the Boot Loader section."

This is all that you need. (in case you try bootloading an app that overwrites the boot section)

Without looking at the Fleury code, it may test for this anyway. After all, an "Erase" specifically avoids the Boot section.

Modern AVRs can read their own Signature and Calibration bytes. The mega32 can't do this. Hence the "Read Signature" command simply returns a fixed value. Which is no problem since a bootloader was compiled for the specific target MCU.

David.