I installed Optiboot onto my ATmega324PB, how do I get applications on it now?

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

I tried using AVRdude, but that lead to a few problems. When I use the option -c avr109 I get this result:

Connecting to programmer: .
Found programmer: Id = "@ e"; type =
    Software Version =  . ; Hardware Version =  .
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

 

I am not really familiar with bootloaders, and I can't seem to find any examples on the internet, everyone seems to use this for Arduino, but I am not using Arduino, I have a collection of C files that I am compiling into a hex.

 

Any advice about what to do or where to look would be greatly appreciated.

 

Thanks,

B.U.B.

 

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

Bottoms_Up_Bob wrote:
Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
stk500v1 for programmer-id

In avrdude.conf, there should be an entry for ATmega324PB.

 

Introduction | HowOptibootWorks · Optiboot/optiboot Wiki · GitHub

Index of /releases/avrdude/

AVR Downloader/UploaDEr - Bugs: bug #58495, Add atmega324pb support to... [Savannah]

 

edit :

avrdude-doc-6.3.pdf

[middle of page 12]

If config-file is written as +filename then this file is read after the system wide and user configuration files. This can be used to add entries to the configuration without patching your system wide configuration file. It can be used several times, the files are read in same order as given on the command line.

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Jun 8, 2021 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps you need -c optiboot or -c stk500

Moderation in all things. -- ancient proverb

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

Bottoms_Up_Bob wrote:
... everyone seems to use this for Arduino, but I am not using Arduino,
fyi, other mega324PB bootloaders in an Arduino context :

MightyCore/avr/bootloaders/optiboot_flash/bootloaders/atmega324pb at master · MCUdude/MightyCore · GitHub

 

"Dare to be naïve." - Buckminster Fuller

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

This got me a lot further along. I wasn't sure how to patch a conf file, I took my best stab at it, I think I got it to work.
My new error is:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

 

I assume this means I messed up the actual flashing of the bootloader if it's not recognizing the signature?

 

Thanks,

B.U.B.

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

Copy / Paste your avrdude command line in full, until you can read the signature, nothing will work.

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

D:\GitHub\KAMPNet.Device\Debug>avrdude -c stk500v1 -p m324pb -P com3 -u -U flash:w:KAMP4.hex

 

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

'-v' to enable and increase verbosity.

Bottoms_Up_Bob wrote:
I assume this means I messed up the actual flashing of the bootloader if it's not recognizing the signature?
If the bootloader is communicating with the AVRDUDE loader then the bootloader flashed.

Guess - missing iom324pb.h (sources the signature)

AVR C Runtime Library - Bugs: bug #58699, Add support for Atmega324PB [Savannah]

 


Building from source | MightyCore/avr/bootloaders/optiboot_flash at master · MCUdude/MightyCore · GitHub

avrdude-doc-6.3.pdf

[page 17]

-v Enable verbose output. More -v options increase verbosity level.

"Dare to be naïve." - Buckminster Fuller

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

avrdude: Device signature = 0x000000

That error ought to impossible to get out of optiboot; it doesn't even read the actual device signature - it gets hard-coded into the binary.

Where/how did you obtain the version of optiboot that you are using?

 

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

I am using the ATmega324PB version of this.

https://github.com/MCUdude/Might...

 

Which Binary is it hardcoded into? The bootloader hex?

Last Edited: Thu. Jun 10, 2021 - 06:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I did not know that. I have pasted the verbose response. These files have been programed onto the board with the Atmel ISP before, so it is getting the correct signature in that way.

 

D:\GitHub\KAMPNet.Device\Debug>avrdude -c stk500v1 -p m324pb -P com3 -u -v -U flash:w:KAMP4.hex

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

         Using Port                    : com3
         Using Programmer              : stk500v1
         AVR Part                      : ATMEGA324PB
         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        65    10   128    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6   256    0 yes     32768  128    256  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 3
         Firmware Version: 8.0
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

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

Update: Using the -F override flashes the board. I don't have a test software written to test every single function of the chip, but the sample software I put on works correctly. So if I use -F it seems to work correctly?

Is this a safe long term work around? I am going to have to rewrite this software to fit my own needs as I need to enable an FOTA system, but I wanted to start simply and possible rewrite someone else's code. This may end up being an even bigger struggle as so much of it is in assembly and c++. I know C and C# so I am confident I can learn them, but it's just another hurdle for me to cross.

 

B.U.B.

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

Bottoms_Up_Bob wrote:
Is this a safe long term work around?
No (mega324 variants share packages, reel or tray is mis-read by one at the distributor or PCBA manufacturer)

Thanks for stating the signature is correct by AVR ICSP.

The reason why the bootloader isn't either correctly reading or sending the signature escapes me.

OCD via JTAG is available; otherwise, a logic analyzer or a spare UART.

Bottoms_Up_Bob wrote:
... but it's just another hurdle for me to cross.
Luck!

 

edit :

         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

That smells.

A guess is the two UARTs aren't syncing.

try

-b baudrate

Override the RS-232 connection baud rate specified in the respective programmer’s entry of the configuration file.

 

edit2 :

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23

Wowwink 

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Thu. Jun 10, 2021 - 05:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am still awaiting a schematic from the person who did the hardware (I know I know, he made it really easy on me). but the JTAG is disabled to use other pins, so I am not sure I can actually reach those pins with ease (if he did it right he would have left them connected to the programmer so if I ever needed them I could use them).

Unfortunately my other UARTs are tied up at the moment, and the spare one I use for debug is the one that I am using to upload the bootloader. But I don't even have access to a oscope or data analyzer at the moment (it is on the list).

 

That smells.

A guess is the two UARTs aren't syncing.

try

-b baudrate

Override the RS-232 connection baud rate specified in the respective programmer’s entry of the configuration file.

 

Which baud rate are you referring too? If I am using a usb to serial plugged into the UART2 on the board, wouldn't the buadrate be whatever I defined it to be? I am using 115200 fyi? The bootloader I put on there I selected the 115200 version, would I need to change that?
I am using the STK500v1 per your suggestion, the documentation for that doesn't specify a baudrate.

 

I was having trouble installing AVRdude so I am just using the WinAVR package, I guess it has a really old AVRdude.

 

Thanks,

B.U.B.

Last Edited: Thu. Jun 10, 2021 - 06:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bottoms_Up_Bob wrote:
But I don't even have access to a oscope or data analyzer at the moment (it is on the list).
Logic analyzers that sample fast enough for some AVR are inexpensive to very inexpensive.

Bottoms_Up_Bob wrote:
Which baud rate are you referring too?
PC's (AVRDUDE via Windows)

Bottoms_Up_Bob wrote:
If I am using a usb to serial plugged into the UART2 on the board, wouldn't the buadrate be whatever I defined it to be?
AVRDUDE sets the baud per STK500 in avrdude.conf, or, by the baudrate argument.

Bottoms_Up_Bob wrote:
I am using 115200 fyi?
A logic analyzer can confirm the baud.

Bottoms_Up_Bob wrote:
The bootloader I put on there I selected the 115200 version, would I need to change that?
No

Bottoms_Up_Bob wrote:
I am using the STK500v1 per your suggestion, the documentation for that doesn't specify a baudrate.
Baud is in the STK500 guide instead of the STK500v1 protocol.

Bottoms_Up_Bob wrote:
I was having trouble installing AVRdude so I am just using the WinAVR package, I guess it has a really old AVRdude.
Sources of AVRDUDE on Windows :

  • AVRDUDE's home
  • PlatformIO
  • somewhat common in Windows package managers

 


Logic analyzers | Supported hardware - sigrok

1BitSquared - BitMagic Basic Logic Analyzer (Cypress USB 8051 with GPIFTM engine)

Tigard Bitmagic Logic Analyzer - Crowd Supply | Mouser

 

Protocol decoder:uart - sigrok

 

AVR STK500 User Guide

[bottom of page 7]

 115200 baud RS-232 port (COM port)

 

Index of /releases/avrdude/ (search for 'mingw')

Packages | Atmel AVR · Platforms · PlatformIO (2/3 page for avrdude)

Chocolatey Software | AVR Downloader/UploaDEr 6.3

Package: mingw-w64-x86_64-avrdude - MSYS2 Packages

avrdude returns 53 | AVR Freaks (Windows 10)

 

"Dare to be naïve." - Buckminster Fuller

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

Force baudrate to 115200 results look the same.

I is there a way to easily verify that the correct device idea is in the binary file? I guess I could rewrite the file to UART output device id initially,

I attached the hex file incase there is a way to decode it for device ID, my cursory glance did not reveal any combination of 0x1E9517, but I also don't really understand hex files other than they are locations for values.

 

D:\GitHub\KAMPNet.Device\Debug>avrdude -c stk500v1 -p m324pb -P com3 -u -v -b 115200 -U flash:w:KAMP4.hex

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

         Using Port                    : com3
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 115200
         AVR Part                      : ATMEGA324PB
         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        65    10   128    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6   256    0 yes     32768  128    256  4500  4500 0xff 0xff
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel STK500 Version 1.x firmware
         Hardware Version: 3
         Firmware Version: 8.0
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

 

 

Attachment(s): 

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

WinAVR is FSF AVR GCC v4; IIRC, Arduino is at v7.

Microchip Studio is v5.

 

Try a different AVR GCC.

Details | optiboot/CompilingOptiboot.md at master · Optiboot/optiboot · GitHub

Building from source | MightyCore/README.md at master · MCUdude/MightyCore · GitHub

...

Install Arduino IDE 1.8.9 or newer to be able to build for the new ATmega324PB and ATmega328PB.

...

 

"Dare to be naïve." - Buckminster Fuller

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

The .hex file you posted does contain the correct signature values:

 

    7f5a:       8e e1           ldi     r24, 0x1E       ; 30
    7f5c:       1a d0           rcall   .+52            ;  0x7f92
    7f5e:       85 e9           ldi     r24, 0x95       ; 149
    7f60:       18 d0           rcall   .+48            ;  0x7f92
    7f62:       87 e1           ldi     r24, 0x17       ; 23
    7f64:       97 cf           rjmp    .-210           ;  0x7e94

 

stk500v1 is not really the correct programmer type for uploading using the bootloader - at some point the author decided that almost everything was going to be implemented via the "raw spi transaction" command (which are obnoxious to decode when you're NOT doing ISP programming, and optiboot only supports a very small subset of them); you really want to find a version of avrdude that supports "-carduino"

 

optiboot_flash_atmega324pb_UART2_115200_16000000L_B0.hex

Is that the actual .hex file you're using?  Elsewhere you mentioned KAMP4.hex or something.
 

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

How do I make the AVRdude run from the Arduino AVRdude instead of the WinAVR AVRdude it is defaulting to now?

 

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

This that is the hex file for the bootloader. I thought that was the file you were suggesting didn't have the right device ID. The KAMP4.hex is just some simple led flash program I through together to validate if the bootloader update was working. Is that the one you want to see? KAMP4 has no problem being programmed to the board when using the Atmel ICE just for your information.

 

Atmel ICE: A09-2096/06 in case anyone needed to know

The serial port I am updating on for the bootloader is UART2 via USB to Serial CP210x chip

 

Side note, how did you decode that? Seems like a useful thing for me to know.

 

Thanks,

B.U.B.

Last Edited: Fri. Jun 11, 2021 - 06:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually by PATH though there are other ways; complete path to all of AVRDUDE for an external tool in Microchip Studio.

avrdude-doc-6.3.pdf

[middle of page 40]

A.2.2.2 How AVRDUDE finds the configuration files.

AVRDUDE on Windows has a different way of searching for the system and user configuration files. Below is the search method for locating the configuration files:

1. The directory from which the application loaded.

2. The current directory.

3. The Windows system directory. On Windows NT, the name of this directory is SYSTEM32.

4. Windows NT: The 16-bit Windows system directory. The name of this directory is SYSTEM.

5. The Windows directory.

6. The directories that are listed in the PATH environment variable.

Arduino to Atmel Studio 7 external programmers, ISP and serial programming | AVR Freaks

 

"Dare to be naïve." - Buckminster Fuller

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

How do I make the AVRdude run from the Arduino AVRdude instead of the WinAVR AVRdude it is defaulting to now?

The easiest solution is to copy the new avrdude over the old one.  (maybe rename the old version, just in case.)

You'll need both the .exe and the default config file.

 

Side note, how did you decode that? Seems like a useful thing for me to know.

avr-objdump -D -mavr /Downloads/optiboot_flash_atmega324pb_UART2_115200_16000000L_B0.hex

 

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

I suggest that you completely stop trying to use a bootloader on your ATmega324PB, and use the standard ISP method of loading flash code and EEPROM values.  I believe that your main goal is to load C programs into the the 324PB and get them working.  A bootloader doesn't help do this and can get you drowning in technical details of the bootloader interface.

 

A bootloader is code that gets called when the device is powered up or reset.  It configures the USART and waits for data to arrive.  This data is burned into the flash memory of the AVR to make a new application program.  If no USART data arrives, the bootloader goes to the application already in the flash memory.

 

To use a bootloader, you need to first load it into special memory locations and then re-configure the fuses so that the bootloader will run before the application.  You will also need a USB-to-serial interface for your ATmega324PB.

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

The reason I am fiddling around with the serial bootloaders is as a precursor to doing FOTA. I figured learning things about an already developed method for my chip couldn't hurt my chances.

 

B.U.B.