Pages: [1]   Go Down
Author Topic: Problems with Optiboot vs. Standard Arduino Bootloader on Custom Board  (Read 983 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I'm hoping one of you might be able to help determine where the problem I'm encountering is coming from.

I'm having an issue attempting to use the optiboot bootloader on a custom board, where the standard arduino bootloader (from bootloaders/atmega/ATmegaBOOT_168_atmega328.hex) works fine. 

First, a quick description of the board: it's using an Atmega328P-AU chip, with 16Mhz crystal, running at 5V.

I am attempting to upload the bootloader using ISP via an Olimex AVR-ISP500.

Burning the standard arduino bootloader works as expected, and the bootloader behaves as expected - I am able to upload sketches over serial.  However, attempting to burn the optiboot_atmega328.hex to the board results in the start flash sequence only happening once - immediately after ISP programming completes.  This sequence is never displayed again, and the bootloader does not respond to upload data over serial.

I have tried all of the following ways of uploading the optiboot bootloader:
 - make atmega328_isp in the optiboot directory
 - select board type as 'Uno' and burn via the Arduino IDE
 - running avrdude manually

The fuses seem to all be set correct: efuse = 0x05, hfuse = 0xDE, lfuse = 0xFF

A note as to how I am uploading sketches via serial: the board does not have an FTDI chip, so I am using a Diecimila with no chip installed, sharing ground and TX/RX with my board - power cycling my board at the right moment so that it starts just a moment before the upload starts.  This, again, works perfectly with the standard arduino bootloader.

Any advice on where I'm going wrong, or how to correct the issue?  I'd like to use optiboot, as I need to test a few changes to the bootloader for my needs, and the standard arduino bootloader is of unknown source, given that the supplied arduino bootloader source does -not compile- without modifications.

Thanks!
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The timeout of optiboot after reset is rather short. So if you don't get the timing right 100%, you're done for. You should make auto-reset work for your project as well. Or increase the number in the source code + recompile it.
Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Unfortunately, auto-reset won't work b/c I won't be using anything with an RTS signal.  (It will be running on an RS-485 bus and adding a USB interface, while possible, is not preferred due to added cost and size constraints.)

As for adjusting the timeout - I presume it is the watchdog timer that handles this? i.e., would changing this in main() do what I think it will?

From:
Code:
  // Set up watchdog to trigger after 500ms
  watchdogConfig(WATCHDOG_1S);

  /* Set LED pin as output */
  LED_DDR |= _BV(LED);

To:

Code:
  // Set up watchdog to trigger after 500ms
  watchdogConfig(WATCHDOG_2S);

  /* Set LED pin as output */
  LED_DDR |= _BV(LED);

Unfortunately, anything longer seems to only be supported by atmega8.

However, even without the longer timer - shouldn't the start led flash sequence happen at every power-on?  As I stated before, it only happens immediately after programming w/ ISP, and never flashes again under any circumstances.

Thanks!
Logged

"The old Europe"
Offline Offline
Edison Member
*
Karma: 1
Posts: 2005
Bootloaders suck!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  if (!(ch & _BV(EXTRF))) appStart();

It only checks for an 'external reset', which is not the same as 'power on reset', 'brown out reset' or 'watchdog reset'.

There are also multiple typos in 'optiboot.c' that comes with arduino 0022.

This is the corrected part regarding the watchdog:

Code:
#ifndef __AVR_ATmega8__
#define WATCHDOG_4S (_BV(WDP3) | _BV(WDE))
#define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE))
#endif
« Last Edit: November 09, 2011, 11:39:06 am by madworm » Logged

• Upload doesn't work? Do a loop-back test.
• There's absolutely NO excuse for not having an ISP!
• Your AVR needs a brain surgery? Use the online FUSE calculator.
My projects: RGB LED matrix, RGB LED ring, various ATtiny gadgets...
• Microsoft is not the answer. It is the question, and the answer is NO!

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 // Adaboot no-wait mod
  ch = MCUSR;
  MCUSR = 0;
  if (!(ch & _BV(EXTRF))) appStart();

It only checks for an 'external reset', which is not the same as 'power on reset', 'brown out reset' or 'watchdog reset'.


That's an excellent pointer - it worked like a charm changing it to this:

Code:
if (!(ch & _BV(EXTRF)) && !(ch & _BV(PORF)) ) appStart();

Now, I can upload sketches and they run fine!

Thanks again!

« Last Edit: November 09, 2011, 12:37:04 pm by drone » Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 124
Posts: 6653
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd encourage you to get the newer optiboot source from the 1.0 release candidate distributions...

When you say it only flashes after the initial ISP, are you saying you also see no flashes with a manual reset, or hard poweron?
Logged

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 323
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd encourage you to get the newer optiboot source from the 1.0 release candidate distributions...

When you say it only flashes after the initial ISP, are you saying you also see no flashes with a manual reset, or hard poweron?


I'll check out the 1.0 version, thanks - although I think I do currently have the latest, unless the Arduino 1.0 branch is a different version than 4.4.

Yeah, the problem was that optiboot (at least the version I have here), as noted above only waited for a firmware upload when an external reset was triggered, adding the check against PORF resolved that, allowing me to upload after a power-on (since the boards do not have a reset switch, although fashioning one is possible using the ISP pins, IIRC).

I can upload using the standard UART lines now after a power-on, which is a good start on my quest.  I'll post another topic on the current troubles I'm having, which have little to do with optiboot, and more to do with my changes =)

Logged

Pages: [1]   Go Up
Jump to: