[Solved] Help with bootloader for mega32

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

Hi,

I'm trying to get a bootloader to work with the Atmega32. Looking around, it seemed that Peter Fleury's stk500v2 bootloader (found at http://homepage.hispeed.ch/peter...)fit the bill. I seem to be having some trouble getting it to work, though, and any help would be appreciated.

- The bootloader compiles fine, and produces a file larger than 512 words. I dont mind the space. I changed the boot size to 2048 words in the C file, changed the start address in the Makefile to 3800 (0x3800). Also, since I'm using a 11.0592 MHz crystal, I changed F_CPU in the makefile to 11059200 and also, for good measure in the c file to 11059200UL.

- As per the comment in the code,

AVRdude:
        Please uncomment #define REMOVE_CMD_SPI_MULTI when using AVRdude.
        Comment #define REMOVE_PROGRAM_LOCK_BIT_SUPPORT to reduce code size

I've left REMOVE_CMD_SPI_MULTI uncommented (it already was in the vanilla copy) and left REMOVE_PROGRAM_LOCK_BIT_SUPPORT commented, since I don't really care how big it is.

- The LED seems to be glowing fine, when the appropriate pin is held low during reset. It also turns on even if the pin is brought low _after_ reset, and I'm guessing this is because the rest of the chip is empty.

- I attempt to communicate using avrdude, and it fails, with a handful of errors and a rather incorrect signature read. The full output is listed below.

- The IC itself works, since I can do everything normally with the dapa programmer I have lying around. The crystal also is fine since the chip communicates well over UART in regular code with the same LFUSE setting.

# avrdude -p m32 -P /dev/ttyUSB0 -c stk500v2 -t

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.01savrdude: stk500v2_command(): command failed
avrdude: stk500v2_cmd(): failed to send command
Reading | ################################################## | 100% 0.01s

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

avrdude done.  Thank you.
Last Edited: Sat. Dec 22, 2012 - 01:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I've gotten it to work. Turns out REMOVE_CMD_SPI_MULTI was the culprit. I had to comment it out for it to play well with avrdude. Also, the bootloader seems to compile to slightly larger than 1024 bytes, so I've configured the fuses to set a boot size of 1024 words. Thats a start address in the Makefile of 7800 (and the start address in the previous post was flat out wrong, and my bad).

(For the record, I also changed the baud rate to 19200 somewhere along the way and haven't bothered to change it back, although I'm guessing it should work.)

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

If you want the bootloader to appear as a genuine STK500, you need to use 115200 baud. And to 'give all the right answers' to common STK500 commands.

Note that avrdude is likely to use slightly different commands to stk500.exe or AS4 or AS6 or ImageCraft or CodeVision ...

Yes, you can get the Fleury code to squeeze into a 512 word boot section for a mega32. A mega324 or mega328 is bit more of a struggle.

All the same, 1024 words is no great sacrifice for a 16k word (32kB device).

David.

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

Indeed. I'll be very surprised if i have to actively squeeze things in. In my experience, clock speed and IOs generally get to the limit first. I've never seen the top of an atmega16 either, for that matter. Only with a, 48 did I ever feel the crunch, and that with a big boat of dead code for possible workarounds for possible future problems.

Now that i do have an extra 800 or so words, though, I'm trying to see if I can slip in an LCD driver with it to make firmware updates little more friendly. Looks like the code i have is making far too many function calls, though, and refuses to work as is.