NEWER New Optiboot bootloader

Thanks for your hints.
Interesting: Even a delay(5000) as first instruction of setup does not change anything.
As soon as I power on the arduino, the RX led flashes approx. once a second. Thats it. Only if I press the reset button, the sketch loads and everything runs as it should. And I have tested this with different sketches on different arduinos and different shields (all the same w5100 thou...)

My last hope is to try the delay somewhere in the bootloader, but I cant find out where ^^

You can try changing the code at main, from:

  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF) | _BV(BORF) | _BV(PORF)))
      appStart(ch);

to

  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF)))
     appStart(ch);

That should remove the special treatment of power-on.

Hi,

thank you. I am experiencing a weird problem though...

I am running a Fedora 22 box and compiled optiboot using

make ENV=arduino LED_DATA_FLASH=1 LED_START_FLASHES=3 LED=B0 BAUD_RATE=115200 atmega328

I am getting optiboot_atmega328.hex and optiboot_atmega328.lst
Then I burn it using avrdude:

avrdude -c usbtiny -p m328p -U flash:w:optiboot_atmega328.hex -v

Everything works fine, but when I try to upload a sketch using the arduino environment I am getting:

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00

I think I am having a more basic problem when trying to build / burn optiboot....
The weird thing is, if I burn the optiboot-version which is delivered with the arduino environment everything works fine!?
Does anyone know this problem? Or is this the wanted behaviour?
(Sorry, if this should be too basic for this thread)
/edit: the command I am using (from arduino IDE) to upload the program is

/home/otto/Downloads/arduino-1.6.5/hardware/tools/avr/bin/avrdude -C/home/otto/Downloads/arduino-1.6.5/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:/tmp/build2203132785643432015.tmp/sketch_aug28a.cpp.hex:i

And this is the entry in boards.txt:

uno.name=Arduino Uno

uno.vid.0=0x2341
uno.pid.0=0x0043
uno.vid.1=0x2341
uno.pid.1=0x0001
uno.vid.2=0x2A03
uno.pid.2=0x0043

uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0x05
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO

No one? :frowning:

make ENV=arduino LED_DATA_FLASH=1 LED_START_FLASHES=3 LED=B0 BAUD_RATE=115200 atmega328

So, where are you executing this command? And what are the results?
For instance, you also say:

/home/otto/Downloads/arduino-1.6.5/

But I don't think that the ENV=arduino thing works with 1.6.5...

avrdude -c usbtiny -p m328p -U flash:w:optiboot_atmega328.hex -v

And what's the output from this? It doesn't program the fuses, but if you started with an Uno and can use the stock bootloader, that should mean the fuses are OK.
Do you see the initial three blinks when you press reset or start an upload?

when I try to upload a sketch using the arduino environment I am getting

The "not in sync" error is pretty worthless error messages go. :frowning: Can you turn on verbose uploading and report the output from that as well?

I haven't actually tested the patch I suggested, on a real Uno or otherwise.
(and yes, this should probably be a new thread.)

Thank you!
I opened a new thread for this here: [Help needed] compiling and installing optiboot on Linux for UNO R3 problem - Microcontrollers - Arduino Forum

Does it work on the Atmega1284 (non-P) as well ?

Hi all, just for the sake of anyone interested doing a search, I had to compile Optiboot tonight for a 1284P running with a 12MHz crystal I just reworked onto my board. Although the 1284P @ 5v, 16MHzhas been stable for me and everyone else I've heard from, it does have issues if there's a voltage sag long before hitting the brownout voltage. The datasheet does show however that the 1284P is stable at 12MHz.

Everything worked great the first time - no problem with tons of serial data at 115200, or delay(), etc. Although I guess there's a few libraries out there that may need to be tweaked for 12MHz.

Anyhow, it was very easy to do as long as you've compiled bootloaders before. This was my first time compiling Optiboot, so I just had to read through the makefile a little bit, add in some lines for a 12MHz version, and of course add in a 12MHz version in boards.txt. If you want a 12MHz bootloader for the 1284P, PM me.

Does it work on the Atmega1284 (non-P) as well ?

It should. Like the 328 vs 328p, the differences are pretty subtle. However, I don't have and haven't tested a 1284(non-P)...

I just had to read through the makefile a little bit, add in some lines for a 12MHz version

If all you are doing is changing the clockrate, you should have been able to do it all from the command line like:

 make atmega1284 AVR_FREQ=12000000

CircuitSerialKiller:
Hi all, just for the sake of anyone interested doing a search, I had to compile Optiboot tonight for a 1284P running with a 12MHz crystal I just reworked onto my board. Although the 1284P @ 5v, 16MHzhas been stable for me and everyone else I've heard from, it does have issues if there's a voltage sag long before hitting the brownout voltage. The datasheet does show however that the 1284P is stable at 12MHz.

CircuitSerialKiller,
How did you get optiboot to recompile?
I am trying and failing. I have a 'new, fresh' Arduino 1.6.5 environment. Under Windows 7 Profession.

the readme file says to open a cmd line in the optiboot directory:
in my case:

C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\optiboot>

I issue:

omake Makefile.2560

to which windows responds:

C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\optiboot>omake Makefil
e.2560

C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\optiboot>..\..\..\tools\a
vr\tools\bin\make OS=windows ENV=arduino Makefile.2560
The system cannot find the path specified.

C:\Program Files\Arduino\hardware\arduino\avr\bootloaders\optiboot>

The only file make in my Program Files folder is:

C:\Program Files>dir make.* /s/p
 Volume in drive C is win7 boot
 Volume Serial Number is A449-8596

 Directory of C:\Program Files\Arduino\tools\Mangler

06/15/2015  03:20 AM               243 make.sh
               1 File(s)            243 bytes

     Total Files Listed:
               1 File(s)            243 bytes
               0 Dir(s)  1,443,716,280,320 bytes free

C:\Program Files>

Here is the directory structure of my Arduino folder.

hardware{
  arduino{
    avr{
      bootloaders{
        atmega
        atmega8
        bt
        caterina
        caterina-Arduino_Robot
        caterina-LilyPadUSB
        gemma
        lilypad{
          src}
        Old_optiboot
        optiboot
        stk500v2}
      cores{
        arduino}
      firmwares{
        arduinoISP
        atmegaxxu2{
          arduino-usbdfu{
            Board}
          arduino-usbserial{
            Board
            Lib}}
        wifishield{
          binary
          scripts
          wifiHD{
            Release
            src{
              CONFIG
              SOFTWARE_FRAMEWORK{
                ASM
                BOARDS{
                  ARDUINO
                  EVK1105}
                COMPONENTS{
                  MEMORY{
                    DATA_FLASH{
                      AT45DBX}}
                  WIFI{
                    HD{
                      v2.7.0{
                        UCR1{
                          GCC}
                        UCR2{
                          GCC}}}}}
                DRIVERS{
                  CPU{
                    CYCLE_COUNTER}
                  EBI{
                    SMC}
                  EIC
                  FLASHC
                  GPIO
                  INTC
                  PDCA
                  PM
                  RTC
                  SPI
                  TC
                  USART}
                SERVICES{
                  DELAY
                  LWIP{
                    lwip-1.3.2{
                      src{
                        core{
                          ipv4}
                        include{
                          ipv4{
                            lwip}
                          lwip
                          netif}
                        netif}}
                    lwip-port-1.3.2{
                      HD{
                        if{
                          include{
                            arch
                            netif}
                          netif}}}}
                  MEMORY{
                    CTRL_ACCESS}}
                UTILS{
                  DEBUG
                  LIBS{
                    NEWLIB_ADDONS{
                      INCLUDE}}
                  LINKER_SCRIPTS{
                    AT32UC3A{
                      0512{
                        GCC}
                      1256{
                        GCC}}}
                  PREPROCESSOR
                  STARTUP_FILES{
                    GCC}}}}}
          wifi_dnld{
            Release
            src{
              CONFIG
              Doc
              SOFTWARE_FRAMEWORK{
                ASM
                BOARDS{
                  ARDUINO
                  EVK1105}
                COMPONENTS{
                  MEMORY{
                    DATA_FLASH{
                      AT45DBX}}}
                DRIVERS{
                  FLASHC
                  GPIO
                  INTC
                  PM
                  SPI
                  USART}
                SERVICES{
                  MEMORY{
                    CTRL_ACCESS}}
                UTILS{
                  DEBUG
                  LIBS{
                    NEWLIB_ADDONS{
                      INCLUDE}}
                  LINKER_SCRIPTS{
                    AT32UC3A{
                      0512{
                        GCC}
                      1256{
                        GCC}}}
                  PREPROCESSOR
                  STARTUP_FILES{
                    GCC}}}}}}}
      libraries{
        EEPROM{
          examples{
            eeprom_clear
            eeprom_crc
            eeprom_get
            eeprom_iteration
            eeprom_put
            eeprom_read
            eeprom_update
            eeprom_write}}
        SoftwareSerial{
          examples{
            SoftwareSerialExample
            TwoPortReceive}}
        SPI{
          examples{
            BarometricPressureSensor
            DigitalPotControl}}
        Wire{
          examples{
            digital_potentiometer
            master_reader
            master_writer
            SFRRanger_reader
            slave_receiver
            slave_sender}
          utility}}
      variants{
        eightanaloginputs
        ethernet
        gemma
        leonardo
        mega
        micro
        robot_control
        robot_motor
        standard
        yun}}}
  tools{
    avr{
      avr{
        bin
        include{
          avr
          compat
          util}
        lib{
          avr25{
            tiny-stack}
          avr3
          avr31
          avr35
          avr4
          avr5
          avr51
          avr6
          avrtiny
          avrxmega2
          avrxmega4
          avrxmega5
          avrxmega6
          avrxmega7
          ldscripts
          tiny-stack}}
      bin
      etc
      i686-pc-mingw32{
        avr{
          include
          lib}}
      include{
        gdb}
      lib{
        gcc{
          avr{
            4.8.1{
              avr25{
                tiny-stack}
              avr3
              avr31
              avr35
              avr4
              avr5
              avr51
              avr6
              avrtiny
              avrxmega2
              avrxmega4
              avrxmega5
              avrxmega6
              avrxmega7
              include
              include-fixed
              install-tools{
                include}
              tiny-stack}}}}
      libexec{
        gcc{
          avr{
            4.8.1{
              install-tools}}}}}}}

Any Ideas on how to make optiboot?

Chuck.

Attached is a complete foldable directory tree of Program Files\Arduino

t.txt (15.1 KB)

How did you get optiboot to recompile?
I have a 'new, fresh' Arduino 1.6.5 environment.

The arduino team has removed "make" from the arduino tools distribution. :frowning:

So the easiest solution now is to install the Arduino IDE 1.0.x; a better (but more difficult) solution is to install the Atmel command-line tools, or add make and bash separately.

westfw:
The arduino team has removed "make" from the arduino tools distribution. :frowning:
"omake" build tools don't work with Arduino 1.5.x and 1.6.x IDE versions · Issue #118 · Optiboot/optiboot · GitHub
So the easiest solution now is to install the Arduino IDE 1.0.x; a better (but more difficult) solution is to install the Atmel command-line tools, or add make and bash separately.

ATMEL Command Line Tool Chain

Ok, I got the Atmel command-line tools, where do install it to? It defaults to my Downloads folder.

but? I just expanded it into a temp folder, and no make file anywhere?

Chuck.

Hmm. You're right. Let me check...

(so far, avrfreaks is leaning toward "install the 2010 version of WinAVR, and replace the compiler bits with the new files from the Atmel Toolchain.) (Actually, WINAVR alone is sufficient to compile Optiboot, even with the old compiler.)

How does Optiloader deal with an alternate clock frequency? I have a custom designed board with the ATMega328 running an internal clock. The bootloader must have an "awareness" of the clock frequency in order to set a known baud rate. It is unclear to me how to do this. The internal clock is set for 8 MHz.

Related, when creating a sketch to download to the bootloader, what should be selected for the board type in Sketch? There doesn't appear to be a valid board configuration that matches the 328 (not 328P) with an 8MHz clock.

Thanks in advance.
Kevin

You need to either compile an optiboot for your changed clock rate, or adjust the baud rate in boards.txt (which is easier.)

For a 328 at 8MHz, the "semi-official" preferred method is to load the stock 328P 16MHz bootloader, and use a boards.txt entry that says "328p at 8MHz, 57600bps upload speed." The sketch/compile step doesn't need to know about 328 vs 328p issues, and the bootloader will lie and say it's a 328p anyway.

Thanks. That makes perfect sense.

Hi,

On a sightly different theme, how do I read/test which version of Optiboot I am looking at?

It would be useful to be able to read what is on chip – maybe an AVRDude command?
And also the supplied binary that I may be considering loading to a chip – Hex Editor to look at a known location?

Or even, a PlugIn to the Arduino IDE!

Regards, Martin

how do I read/test which version of Optiboot I am looking at?

The optiboot version number is stored in the last two bytes of the chip. or .hex file.
You can read this from the .hex file or with a programmer, but it is usually protected from the arduino sketches by the lock bits (sigh. I tried to change the lockbits, but it "seemed too dangerous" to make official code. If you're using the optiboot boards.txt or makefies to burn the new bootloader, you'll get a "readable" bootloader, and a program like FuseBytes will show the version number. But not if you have a stock arduino.)

Note that the bytes show up "reversed" in the hex file, so ending with 0x02 0x06 is version 6.2

Thank you Bill,

So the current (latest?) versions at: GitHub - Optiboot/optiboot: Small and Fast Bootloader for Arduino and other Atmel AVR chips are v6.6?

Regards, Martin