Difference between revisions of "ARDUINO MEGA Update Bootloader"

From ROBOTC API Guide
Jump to: navigation, search
(Arduino 2560 Bootloader Issue)
Line 5: Line 5:
  
 
The reason for this is because there is a bug in the Arduino 2560 firmware that does not allow flash-write commands to begin anywhere other than address 0x00000.
 
The reason for this is because there is a bug in the Arduino 2560 firmware that does not allow flash-write commands to begin anywhere other than address 0x00000.
 +
 +
== Equipment Needed  ==
 +
To burn the bootloader, you'll need to buy an AVR-ISP (in-system programmer), USBtinyISP or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.
 +
== Software Needed ==
 +
ROBOTC is not currently able to burn a bootloader onto an Arduino board, so you'll need to download a copy of the latest versio
 +
 +
== Technical Details ==
 +
ROBOTC's Fix:   
  
 
<syntaxhighlight lang="ROBOTC">
 
<syntaxhighlight lang="ROBOTC">
Line 39: Line 47:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Equipment Needed  ==
+
<syntaxhighlight lang="ROBOTC">
To burn the bootloader, you'll need to buy an AVR-ISP (in-system programmer), USBtinyISP or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.
+
case CMD_PROGRAM_FLASH_ISP:
== Software Needed ==
+
case CMD_PROGRAM_EEPROM_ISP:
ROBOTC is not currently able to burn a bootloader onto an Arduino board, so you'll need to download a copy of the latest versio
+
{
 +
  unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2];
 +
  unsigned char *p = msgBuffer+10;
 +
  unsigned int data;
 +
  unsigned char highByte, lowByte;
 +
  address_t tempaddress = address;
 +
 
 +
 
 +
  if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
 +
  {
 +
    eraseAddress = address & 0xFFFFFF00;  // ROBOTC Custom Bootloader Addition
 +
 
 +
    // erase only main section (bootloader protection)
 +
    if (eraseAddress < APP_END )
 +
    {
 +
      boot_page_erase(eraseAddress); // Perform page erase
 +
      boot_spm_busy_wait(); // Wait until the memory is erased.
 +
      eraseAddress += SPM_PAGESIZE; // point to next page to be erase
 +
    }
 +
</syntaxhighlight>

Revision as of 15:42, 11 May 2012

Note: This document only applies to the MEGA 2560 and MEGA ADK Arduino Boards. All other Arduino boards bootloaders are good!

Arduino 2560 Bootloader Issue

The current bootloader burned onto the Arduino 2560 is not compatible with ROBOTC. In its current form, you will be able to download the ROBOTC Firmware to the Arduino, but you will not able to download any user programs.

The reason for this is because there is a bug in the Arduino 2560 firmware that does not allow flash-write commands to begin anywhere other than address 0x00000.

Equipment Needed

To burn the bootloader, you'll need to buy an AVR-ISP (in-system programmer), USBtinyISP or build a ParallelProgrammer. The programmer should be connected to the ICSP pins (the 2 by 3 pin header) - make sure you plug it in the right way. The board must be powered by an external power supply or the USB port.

Software Needed

ROBOTC is not currently able to burn a bootloader onto an Arduino board, so you'll need to download a copy of the latest versio

Technical Details

ROBOTC's Fix:

case CMD_LOAD_ADDRESS:
 #if defined(RAMPZ)
  address = (((address_t)(msgBuffer[1])<<24)|((address_t)(msgBuffer[2])<<16)|
            ((address_t)(msgBuffer[3])<<8)|msgBuffer[4]))<<1;
 #else
  address = (((msgBuffer[3])<<8)|(msgBuffer[4]))<<1;  //convert word to byte address
 #endif
 msgLength = 2;
 msgBuffer[1] =	STATUS_CMD_OK;
 break;
 
case CMD_PROGRAM_FLASH_ISP:
case CMD_PROGRAM_EEPROM_ISP:
{
  unsigned int	size	=	((msgBuffer[1])<<8) | msgBuffer[2];
  unsigned char	*p	=	msgBuffer+10;
  unsigned int	data;
  unsigned char	highByte, lowByte;
  address_t		tempaddress	=	address;
 
 
  if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
  {
    // erase only main section (bootloader protection)
    if (eraseAddress < APP_END )
    {
      boot_page_erase(eraseAddress);	// Perform page erase
      boot_spm_busy_wait();		// Wait until the memory is erased.
      eraseAddress += SPM_PAGESIZE;	// point to next page to be erase
    }
case CMD_PROGRAM_FLASH_ISP:
case CMD_PROGRAM_EEPROM_ISP:
{
  unsigned int	size	=	((msgBuffer[1])<<8) | msgBuffer[2];
  unsigned char	*p	=	msgBuffer+10;
  unsigned int	data;
  unsigned char	highByte, lowByte;
  address_t		tempaddress	=	address;
 
 
  if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
  {
    eraseAddress = address & 0xFFFFFF00;   // ROBOTC Custom Bootloader Addition
 
    // erase only main section (bootloader protection)
    if (eraseAddress < APP_END )
    {
      boot_page_erase(eraseAddress);	// Perform page erase
      boot_spm_busy_wait();		// Wait until the memory is erased.
      eraseAddress += SPM_PAGESIZE;	// point to next page to be erase
    }