Outroot and things
Electronics, programming, computers, and geek stuff by Kevin Darlington

Speeding up the Sanguino reset time

San­guino

I decided to use a San­guino for my next project and I noticed that every time I reset it with the push­but­ton, it would take around 10 sec­onds to start the pro­gram. I thought this was absurd since the reg­u­lar Arduino doesn’t take that long. I decided to dive into the boot­loader firmware and find out the prob­lem. The San­guino ver­sion I’m deal­ing with is v1.4 r1.

After look­ing at the code, I could see that it would wait for “MAX_TIME_COUNT” iter­a­tions for a response on UART. Look­ing at the Make­file, it was set to 8000000»1 which is the equiv­a­lent of 4000000. So the getch() func­tion would keep incre­ment­ing a counter and check­ing for a response on UART, and finally time­out when the count exceeded 4000000. Obvi­ously, this was tak­ing too long for my tastes.

Changes

In the Make­file con­tained in hardware/sanguino/bootloaders/atmega644p, make the fol­low­ing changes:

  1. Change line 21 to point to an avr-gcc that is of ver­sion 3.x.x (not needed for OSX)
  2. On line 33, change “8000000»1″ to “F_CPU»4″. Use “F_CPU»5″ if you want 0.5 sec­onds faster.
  3. On line 43, change “avr-gcc” to “$(CC)”

I have to explain the #1 part. The San­guino boot­loader was made to com­pile with the 3.x.x series of the gcc com­piler. The newest ver­sions of WinAVR and avr-gcc for osx/linux, use gcc 4.x.x. The boot­loader will not com­pile cor­rectly with this ver­sion. Here are some instruc­tions on get­ting the 3.x.x ver­sion of avr-gcc:

  • Win­dows: Down­load WinAVR-20060421. It con­tains avr-gcc 3.4.6
  • OSX: Type “avr-gcc-select 3″ in a ter­mi­nal. Be sure to change it back to “avr-gcc-select 4″ when you’re done compiling.
  • Linux: Down­load gcc-3.4.6 and apply this patch.

I only tested this on Win­dows, so I can­not say if the OSX and Linux solu­tions will work.

I also changed the ATmegaBOOT.c code to not blink the LED 3 times but to blink it once. I saved some pre­cious mil­lisec­onds. You can do this be set­ting NUM_LED_FLASHES on line 77 to 1.

Com­pil­ing and uploading

Just run “make” in the atmega644p folder to build the hex file. If your hex file ends up being over 6KB, then you’re still using gcc 4.x.x and not 3.x.x.

To upload the boot­loader, I used the Arduino IDE and went to Tools > Burn Boot­loader > USBtiny­ISP. Select what­ever pro­gram­mer you have. Make sure you have “San­guino” as the selected board in Tools > Board.

Speed com­par­i­son

Before: ~10.5 sec­onds reset time

With F_CPU»4: ~2.5 sec­onds reset time

With F_CPU»5: ~2 sec­onds reset time

Con­clu­sion

I’m unsure why the delay is so long in the Make­file. Cur­rently, I see no ill effects from mak­ing this change. Be sure not to make the delay too low because then you won’t be able to seri­ally pro­gram the device.

Files

Make­file

ATmegaBOOT.c

Leave a Comment

CommentLuv Enabled

Anti-Spam Protection by WP-SpamFree


Bad Behavior has blocked 63 access attempts in the last 7 days.