Go Down

Topic: NEWER New Optiboot bootloader (Read 38062 times) previous topic - next topic

otto001

#15
Aug 23, 2015, 07:29 pm Last Edit: Aug 23, 2015, 08:32 pm by otto001
Hi all,

first of all: thanks for this wonderful work!

I am just trying to get an UNO R3 together with a W5100 shield to work.
However, in case of power loss (or first power up) the sketch does not properly load, but as soon as I press reset, everything works fine.
As far as I could find out the arduino boots so fast, that the shield cannot properly initialize.
So I tried to add a delay to optiboot for my special purpose - all I could achieve was that I could not burn a program any more, as avrdude ran into timeouts.

So my question: can anyone please tell me, WHERE exactly in the optiboot.c code a delay could be placed without interfering with the flashing routines?

/edit: the TIMEOUT_MS could point in that direction, but seems not to be supported (yet)?

Thanks in advance!

Otto

westfw

While it is "interesting" that the normal Bootloader timeout is sufficient to allow the WS5100 shield to initialize, the proper place to insert a delay is surely in the sketch itself, rather than the bootloader.  A "delay(1500)" at the beginning of setup() should be indistinguishable from a delay in the bootloader.  (Ideally, there should be some way for the code to check whether the ws5100 is 'ready' for whatever is being done to it.  But I don't know whether there is.  The WS5100 has a lot of signals that are not connected to Arduino at all...)

(It DOES make sense that you're seeing insufficient delay on poweron, but not normal reset.   The bootloader has a feature called "fast start" that starts the sketch code immediately after poweron, and only runs the bootloader (which delays for about 1500ms looking for new code) on an explicit "reset.")

john1993

i always set opti timeout to half second regardless of reset type. just enough time for the "button pushers" and plenty snappy for auto-reset. instant run after flash.

btw if you are responsible for the alternate boards.txt in there mucho grassy-asss. it was a huge problem solver.

otto001

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 ^^

westfw

You can try changing the code at main, from:
Code: [Select]
  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF) | _BV(BORF) | _BV(PORF)))
      appStart(ch);


to

Code: [Select]
  ch = MCUSR;
  MCUSR = 0;
  if (ch & (_BV(WDRF)))
     appStart(ch);


That should remove the special treatment of power-on.

otto001

#20
Aug 27, 2015, 07:41 pm Last Edit: Aug 28, 2015, 04:55 pm by otto001
Hi,

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

I am running a Fedora 22 box and compiled optiboot using

Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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
Code: [Select]
/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:
Code: [Select]
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

otto001


westfw

Code: [Select]
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:
Code: [Select]
/home/otto/Downloads/arduino-1.6.5/



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

Code: [Select]
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?


Quote
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. :-(  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.)


otto001

#23
Aug 30, 2015, 04:48 pm Last Edit: Aug 30, 2015, 04:48 pm by otto001
Thank you!
I opened a new thread for this here: http://forum.arduino.cc/index.php?topic=344873.0

AlxDroidDev

Does it work on the Atmega1284 (non-P) as well ?
Some of my projects:
Shield for DS1337+, DS1624 and AT24C1024B (RTC, temp & mem): http://forum.arduino.cc/index.php/topic,126197.0.html
CHDK Camera remote shutter (BT, IR, USB): http://forum.arduino.cc/index.php?topic=295377.0

CircuitSerialKiller

#25
Oct 04, 2015, 06:31 am Last Edit: Oct 04, 2015, 06:33 am by 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.

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.
It doesn't matter if a thread is a year old or 10 years old. If you have something to add to it, post it. Search engines don't discriminate by date, and no one likes coming across a thread that doesn't have an answer or outdated information!

westfw

Quote
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)...


Quote
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:
Code: [Select]
make atmega1284 AVR_FREQ=12000000


chucktodd

#27
Oct 07, 2015, 12:35 am Last Edit: Oct 07, 2015, 12:37 am by chucktodd Reason: highlights
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:
Code: [Select]

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

I issue:
Code: [Select]

omake Makefile.2560

to which windows responds:

Code: [Select]

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:

Code: [Select]


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.

Code: [Select]

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
Currently building mega http server 90% done, the Last 10% is killing me.

westfw

Quote
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. :-(
https://github.com/Optiboot/optiboot/issues/118
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.


chucktodd

#29
Oct 07, 2015, 01:08 am Last Edit: Oct 07, 2015, 01:12 am by chucktodd Reason: link
The arduino team has removed "make" from the arduino tools distribution. :-(
https://github.com/Optiboot/optiboot/issues/118
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.
Currently building mega http server 90% done, the Last 10% is killing me.

Go Up