AVR ATmega328p bootloader not working

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

I am using AVR109 example of booatloader. This example is basically compiled for ATMEGA328pb. And this example is working well on ATMEGA328pb.

But I needed to use bootloader on ATMEGA328p. So, the same example I compiled with ATMEGA328p by only changing the signature bytes. But it is not working.

it is showing mismatch error.

Please help me. What else I need to change to work this code.

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


AVR109 customization in the first sheet of the spreadsheet :

via AN_1644 AVR109: Using Self Programming on tinyAVR and megaAVR devices

 

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

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

imrana326 wrote:
I compiled with ATMEGA328p by only changing the signature bytes

Each AVR is a bit unique, the source code must be compiled for the target to have a valid hex file to load, you can not flash a hex file for one device into another model and expect it to work.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Thanks for Reply

I have updated device name, baudrate, signature.

 

I am using Atmel studio 7

and when I am trying to upload program from bootloader then I am getting this

 

pi@raspberrypi:~ $ sudo avrdude -c butterfly -p m328p -P net:192.168.0.254:4001 -b 115200 -U flash:w:uartTestCode.hex 

Connecting to programmer: .
Found programmer: Id = "AVRBOOT"; type = S
    Software Version = 1.5; No Hardware Version given.
Programmer supports auto addr increment.
Programmer supports buffered memory access with buffersize=128 bytes.

Programmer supports the following devices:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "uartTestCode.hex"
avrdude: input file uartTestCode.hex auto detected as Intel Hex
avrdude: writing flash (250 bytes):

Writing |                                                    | 0% 0.00savrdude: error: programmer did not respond to command: write block
Writing | #########################                          | 50% 0.02s ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
 ***failed;  
avrdude: Error: butterfly programmer uses avr_write_page() but does not
provide a cmd() method.
 *** page 127 (addresses 0x0000 - 0x007f) failed to write

Writing | ##########################                         | 51% 0.02s ***failed;  
 ***failed;  
Writing | ##########################                         | 52% 0.02s ***failed;  
 ***failed;  
 ***failed;  
Writing | ###########################                        | 53% 0.02s ***failed;  
 ***failed;  
Writing | ###########################                        | 54% 0.02s ***failed;  
 ***failed;  
 ***failed;  
Writing | ############################                       | 55% 0.03s ***failed;  
 ***failed;  
Writing | ############################                       | 56% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #############################                      | 57% 0.03s ***failed;  
 ***failed;  
Writing | #############################                      | 58% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ##############################                     | 59% 0.03s ***failed;  
 ***failed;  
Writing | ##############################                     | 60% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ###############################                    | 61% 0.03s ***failed;  
 ***failed;  
Writing | ###############################                    | 62% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ################################                   | 63% 0.03s ***failed;  
 ***failed;  
Writing | ################################                   | 64% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #################################                  | 65% 0.03s ***failed;  
 ***failed;  
Writing | #################################                  | 66% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ##################################                 | 67% 0.03s ***failed;  
 ***failed;  
Writing | ##################################                 | 68% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ###################################                | 69% 0.03s ***failed;  
 ***failed;  
Writing | ###################################                | 70% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ####################################               | 71% 0.03s ***failed;  
 ***failed;  
Writing | ####################################               | 72% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #####################################              | 73% 0.03s ***failed;  
 ***failed;  
Writing | #####################################              | 74% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ######################################             | 75% 0.03s ***failed;  
 ***failed;  
Writing | ######################################             | 76% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #######################################            | 77% 0.03s ***failed;  
 ***failed;  
Writing | #######################################            | 78% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ########################################           | 79% 0.03s ***failed;  
 ***failed;  
Writing | ########################################           | 80% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #########################################          | 81% 0.03s ***failed;  
 ***failed;  
Writing | #########################################          | 82% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ##########################################         | 83% 0.03s ***failed;  
 ***failed;  
Writing | ##########################################         | 84% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ###########################################        | 85% 0.03s ***failed;  
 ***failed;  
Writing | ###########################################        | 86% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ############################################       | 87% 0.03s ***failed;  
 ***failed;  
Writing | ############################################       | 88% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #############################################      | 89% 0.03s ***failed;  
 ***failed;  
Writing | #############################################      | 90% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ##############################################     | 91% 0.03s ***failed;  
 ***failed;  
Writing | ##############################################     | 92% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ###############################################    | 93% 0.03s ***failed;  
 ***failed;  
Writing | ###############################################    | 94% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ################################################   | 95% 0.03s ***failed;  
 ***failed;  
Writing | ################################################   | 96% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | #################################################  | 97% 0.03s ***failed;  
 ***failed;  
Writing | #################################################  | 98% 0.03s ***failed;  
 ***failed;  
 ***failed;  
Writing | ################################################## | 99% 0.03s ***failed;  
 ***failed;  
avrdude: Error: butterfly programmer uses avr_write_page() but does not
provide a cmd() method.
 *** page 121 (addresses 0x007a - 0x00f9) failed to write

Writing | ################################################## | 100% 0.03s

avrdude: 250 bytes of flash written
avrdude: verifying flash memory against uartTestCode.hex:
avrdude: load data flash data from input file uartTestCode.hex:
avrdude: input file uartTestCode.hex auto detected as Intel Hex
avrdude: input file uartTestCode.hex contains 250 bytes
avrdude: reading on-chip flash data:

Reading |                                                    | 0% 0.00savrdude: error: programmer did not respond to command: set addr
avrdude: butterfly_recv(): programmer is not responding
Reading | #########################                          | 50% 5.01savrdude: butterfly_recv(): programmer is not responding
Reading | ################################################## | 100% 10.02s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xfe != 0x0c
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK (E:FC, H:D9, L:FF)

avrdude done.  Thank you.

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

Hi Everyone,

If someone have worked on this please help me.

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

You have to select a device name that exists on the Part definition page. Since the ATMEGA328p doesn't have an entry, you need to add it. Copy the ATMEGA328PB (not ATMEGA328PB_1) row to a new row. Change the device name on the new row to the ATMEGA328B and change the device signature bytes. Now you change the device name on the device_h page with macros enabled and the magic should happen.

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

Thanks for your reply.

Where I can get  Part definition page???

 

Thanks You

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

imrana326 wrote:
Where I can get  Part definition page???
AN_1644 AVR109: Using Self Programming on tinyAVR and megaAVR devices

zip file, preprocessor.xls (a spreadsheet), 'Part definitions' tab

 

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

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

In parts.txt file I have added last line but still not working

 

#Extracted from "Part definitions" of preprocessor.xls
#dev    include    pagesz    nrwwpag    totpag    avr910    sig1    sig2    sig3    baudlo    uartc    uarts    txen    rxen    txc    rxc    udr    spmcr
ATmega8    iom8.h    32    32    128    0x77    0x1E    0x93    0x07    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega8515    iom8515.h    32    32    128    0x3B    0x1E    0x93    0x06    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega8535    iom8535.h    32    32    128    0x6A    0x1E    0x93    0x08    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega88    iom88.h    32    32    128        0x1E    0x93    0x0A    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCSR
ATmega16    iom16.h    64    16    128    0x75    0x1E    0x94    0x03    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega162    iom162.h    64    16    128    0x63    0x1E    0x94    0x04    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCR
ATmega163    iom163.h    64    16    128    0x66    0x1E    0x94    0x02    UBRRLO    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega165    iom165.h    64    16    128        0x1E    0x94    0x07    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCSR
ATmega168    iom168.h    64    16    128        0x1E    0x94    0x06    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCSR
ATmega169    iom169.h    64    16    128    0x79    0x1E    0x94    0x05    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCSR
ATmega32    iom32.h    64    32    256    0x7F    0x1E    0x95    0x02    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega323    iom323.h    64    16    256    0x73    0x1E    0x95    0x01    UBRRL    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCR
ATmega329    iom329.h    64    32    256        0x1E    0x95    0x03    UBRR    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCSR
ATmega3290    iom3290.h    64    32    256        0x1E    0x95    0x04    UBRR    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCSR
ATmega64    iom64.h    128    32    256    0x46    0x1E    0x96    0x02    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCR
ATmega649    iom649.h    128    32    256        0x1E    0x96    0x03    UBRR    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCSR
ATmega6490    iom6490.h    128    32    256        0x1E    0x96    0x04    UBRR    UCSRB    UCSRA    TXEN    RXEN    TXC    RXC    UDR    SPMCSR
ATmega128    iom128.h    128    32    512    0x44    0x1E    0x97    0x02    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCSR
ATmega128_1    iom128.h    128    32    512    0x44    0x1E    0x97    0x02    UBRR1L    UCSR1B    UCSR1A    TXEN1    RXEN1    TXC1    RXC1    UDR1    SPMCSR
ATmega328P    iom328p.h    128    32    512    0x44    0x1E    0x95    0x0F    UBRR0L    UCSR0B    UCSR0A    TXEN0    RXEN0    TXC0    RXC0    UDR0    SPMCSR

 

 

 

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

AN_1644 AVR109: Using Self Programming on tinyAVR and megaAVR devices

[PDF, mid page 9]

For instructions on how to customize the bootloader for different AVR devices and boot section sizes, refer to the step-by-step instructions in the preprocessor.xls Microsoft Excel file.

 

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

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

I have followed all the instructions one by one.

And build the code normally in atmel studio.

 But it is showing same error.

is I am doing mistake in building the file?

So, I am attaching the file where i have made the changes. 

Please cross check it and build the solution and send me back.

I will be highly thankful. Please help me.

 

 

I have also generated a new code by choosing atmega328p by including serial, flash and defines.h So, that IDE will handle make file types of things.

but this one is also not working

 

Thanks.

Attachment(s): 

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

imrana326 wrote:
is I am doing mistake in building the file?
Compare yours against the directory AVR109_AS7-Example in AVR109.zip

First guess is a toolchain version difference between Microchip AVR109 and your copy of Atmel Studio; second guess is a device package difference.

imrana326 wrote:
Please cross check it ...
Unable to (Chrome OS, zip is native, rar isn't though there's likely an Android app for that)

imrana326 wrote:
... and build the solution ...
Unable to (Chrome OS and didn't install the FSF GCC AVR toolchain for Android)

imrana326 wrote:
Please help me.
Hopefully another one is able to.

 


AN_1644 AVR109: Using Self Programming on tinyAVR and megaAVR devices

 

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

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

Thanks Everyone.

Problem resolved.

There was issue with my uart to RS485 converter in transferring data at that speed.

 

But Now I am facing another issue.

Everything is working fine when I am uploading main code generated by Atmel Stdio 7.

But when I am generating same main code from Arduino IDE then bootloader code stops working.

Is there any solution from which I can upload Arduino generated code without effecting boot loader

 

Last Edited: Tue. Jan 7, 2020 - 09:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

imrana326 wrote:
But when I am generating same main code from Arduino IDE then bootloader code stops working.
You say "same" but is it really? Could it simply be that the Arduino build (not known for its efficiency) is large and bloaty and too big to fit in the space below the bootloader?

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

Same that means functionality wise.

 

I think main code generated by Arduino is overlapping Boot loader area.

for your reference I am attaching hex file of my bootloader and Arduino generated main code. 

Attachment(s): 

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

Nope that INO code gets no where near a bootloader. The bootloader starts at 0x7000. The highest address in the INO code is 0x0884 so there's barely more than 2K from tjhe 28K available used.

 

It seems much more likely that the actual code operation is different between Arduino and AS7 projects. Or are you saying that the AS7 build is simply an unchanged Arduino project import ?

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

Switch from arduino to AVR109.

Arduino's mega328P bootloader is an Optiboot (subset of STK500)

 

AVRDUDE

-c programmer-id

arduino

avr109

 

https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/optiboot

https://github.com/Optiboot/optiboot/wiki/HowOptibootWorks#introduction

AVRDUDE - AVR Downloader/UploaDEr

 

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