Can a ARDUINO MEGA be programmed (FLASHED) from another micro-controller (uVGA)

Hi,

The project I am working on involves a ARDUINO MEGA that will communicate with a uVGA-III card in GFX mode (http://www.4dsystems.com.au/prod.php?id=149). The uVGA-III although being primarily a graphic chip, acts has an independant micro-controller and has 2 UARTs and 1 I2C. In my set-up, there will be a connection between the UART1 of the uVGA-III and the UART0 port on the ARDUINO MEGA. The PORT0 is used to program the ARDUINO MEGA through USB with the help of the BootLoader. I was wondering if it would be possible for the uVGA-III to send the ARDUINO program into the ARDUINO FLASH memory, just like a PC does it with the ARDUINO IDE or AVRDUDE?. The ARDUINO program will actually be read from the micro-SD card of the uVGA-III and then be transmitted to the ARDUINO so that the Bootloader puts that program in the FLASH memory.

My aim is to have the firmware updates for the ARDUINO MEGA onto the micro-SD card of the uVGA-III so that they can be loaded in ARDUINO MEGA. This would avoid having to update the ARDUINO MEGA through a USB connection .

I have seen a post about updating the bootloader of an ARDUINO from another ARDUINO so updating the FLASH program of the ARDUINO from another micro-controller sounds feasible.

Thanks in advance for the help, and happy new year to all.

Cheers, ERIC

It should work if you give the uVGA a way to reset the Arduino. After reset you have a brief time to start an upload through the serial port.

Thanks John,

I didn’t have a clue that’s why I asked. Ok It is that simple.

So, after sending a reset signal (a HIGH on the reset pin ?), I quickly get uVGA-III to send the .hex file generated to the UART0 of the ARDUINO. The bootloader receives the code and puts it in FLASH and then start the loaded program (or reset ?). And that’s it the newly loaded program runs on the ARDUINO?

Just a few questions:

  • does the UART communication between the uVGA-III and the ARDUINO has to be set at 9600 baud ?
  • doesn’t the bootloader retransmit back the received program to the uVGA-III for error checking purpuse?
  • is there a source (like ARDUINO site) that describe this process in detail.
  • has anybody tried that kind of FLASH update from another micro-controller?

Cheers,
ERIC

Can a ARDUINO MEGA be programmed (FLASHED) from another micro-controller (uVGA)

Yes. The mega (or any other mcu) doens't know nor does it care which device is programming it, as long as the right pulses show up.

does the UART communication between the uVGA-III and the ARDUINO has to be set at 9600 baud ?

Depends on which bootloader you have installed.

doesn't the bootloader retransmit back the received program to the uVGA-III for error checking purpuse?

The bootloader uses the same protocol as an ISP. You send messages to set the address. Send messages to write data to memory. Send messages to request data from memory (for verification). For the Mega you need to use the STK500V2 protocol (the smaller chips use the STK500V1 protocol).

is there a source (like ARDUINO site) that describe this process in detail.

I don't know if there is a protocol manual for STK500V2. You could look at the bootloader sources to see what kind of messages they handle.

has anybody tried that kind of FLASH update from another micro-controller?

AVRDUDE does it all the time.

Thanks again John for the help.

I am not sure witch bootloader is on my ARDUINO MEGA. Should be a "standart" ARDUINO bootloader. Is there any way to find out?

Ok so the STK500V2 protocol is the way to go. I found this: Atmega chip stand-alone programmer to upload .hex files - http://www.gammon.com.au/forum/?id=11638 from Nick Gommon The updloading seems to be done through the ISP with the SPI protocol. But this process seems to bypass the ARDUINO bootloader. Looks like a Serial version of this sketch could be doing the job (+ translation of the language from ARDUINO to uVGA-III 4DGL language). Or since the uVGA-III will be connected to the UART0 and the bootloader will be used it might actually be simpler?

Ok I will check the bootloader source.

AFAIK, AVRDUDE only run in PC environnement not from another microcontroller.

Does anybody know of a program (with shared code) that already implements the STK500V2 protocol to upload .hex files though the USB-serial (UART0) link of the ARUINO MEGA. Be it either from a microcontroller or PC ...

PALYGAP: I found this: Atmega chip stand-alone programmer to upload .hex files - http://www.gammon.com.au/forum/?id=11638 from Nick Gommon

G[u]a[/u]mmon.

That programmer uses the ICSP interface (which uses SPI) to use the on-chip programming function. A boot loader is just normal code running which listens to where-ever you want (eg. the serial port). The STK500V2 protocol is a serial protocol.

The simplest (IMHO) is to use the ICSP interface because you don't have this extra layer of another protocol.

However the Arduino as ISP sketch (which comes with the Arduino IDE) implements the STK500 protocol and thus just interposes between avrdude, the target micro, and the programming PC.

Thanks Nick for the answer

That programmer uses the ICSP interface (which uses SPI) to use the on-chip programming function. A boot loader is just normal code running which listens to where-ever you want (eg. the serial port). The STK500V2 protocol is a serial protocol.

So does that mean that the "on-chip programming function" are different from the STK500V2 protocol ?

OK, programming through the ICSP/SPI interface is more direct, but I want to program the ARDUINO MEGA from the uVGA-II and this microcontroller only has UART and I2C interfaces.

So, If I understand it right, the ArduinoISP sketch allows to send a program from a PC with avrdude using the STK500V1 protocol to a ARDUINO running the ArduinoISP. The ARDUINO then forward the program thru SPI connection to another ARDUINO.

The "Atmega chip stand-alone programmer to upload .hex files" program that you did does not require the PC/AVRDUDE but use a SD card reader. Furthermore it does not need to use the STK500V2 protocol but uses the "on-chip programming function".

Please tell me if I am wrong in my understanding.

Cheers, ERIC

bump

So does that mean that the "on-chip programming function" are different from the STK500V2 protocol ?

Yes. The ISP device gets STK500V2 messages from AVRDUDE and translates those to the Serial Programming protocol built into the processor. The two protocols are likely to be highly correlated but not the same.

See Atmel Application Note AVR068: STK500 Communication Protocol http://www.atmel.com/Images/doc2591.pdf "This document describes the 2.0 version of the communication protocol between the Atmel STK500 and the PC controlling the STK500."

PALYGAP: So does that mean that the "on-chip programming function" are different from the STK500V2 protocol ?

...

The ARDUINO then forward the program thru SPI connection to another ARDUINO.

That's right.

PALYGAP: The "Atmega chip stand-alone programmer to upload .hex files" program that you did does not require the PC/AVRDUDE but use a SD card reader. Furthermore it does not need to use the STK500V2 protocol but uses the "on-chip programming function".

Correct. There is no serial protocol used in that case. Another programmer I wrote (similar to Optiloader written by Westfw) reads code directly from the programming device's memory, and sends that down the ICSP interface to the target.

but I want to program the ARDUINO MEGA from the uVGA-II and this microcontroller only has UART and I2C interfaces.

This seems a little roundabout as you can buy a programmer for $10 or make your own from an Atmega328 chip for around the same price. However as an exercise, if you don't have an SPI interface, you would have to use the STK500 protocol via the serial interface.

Thanks John and Nick for the confirmations.

Quote but I want to program the ARDUINO MEGA from the uVGA-II and this microcontroller only has UART and I2C interfaces.

This seems a little roundabout as you can buy a programmer for $10 or make your own from an Atmega328 chip for around the same price. However as an exercise, if you don't have an SPI interface, you would have to use the STK500 protocol via the serial interface.

Actually I am in the process of building a MIDI product. The uVGA has the advantage to have an integrated microSD card reader. Since I plan to distribute update of the product's software, I want to have all the updates (for the ARDUINO and the uVGA) on the same uSD card. That way the users will only need to write the updated files on the uSD card for the uVGA program and the ARDUINO program to be updated. This should be more practical.