Difference between revisions of "ARDUINO MEGA Update Bootloader"
(→Equipment Needed) |
(→Technical Details) |
||
Line 46: | Line 46: | ||
unsigned int data; | unsigned int data; | ||
unsigned char highByte, lowByte; | unsigned char highByte, lowByte; | ||
− | address_t | + | address_t tempaddress = address; |
− | + | ||
if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP ) | if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP ) |
Revision as of 16:08, 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 MEGA 2560/ADK is not compatible with ROBOTC. In its current form, you will be able to download the ROBOTC Firmware to the Arduino MEGA 2560/ADK, but you will not able to download any user programs.
The reason for this is because there is a bug in the Arduino MEGA 2560/ADK firmware that does not allow flash write commands to start at anywhere but the beginning of flash memory (0x000000). See the bottom of this page for more technical details.
Because ROBOTC is not able to burn a new bootloader as of today, you will need to use the Arduino's Open Source language with our a modified bootloader file to re-burn your bootloader on your Arduino MEGA 2560/ADK boards. Once the new bootloader is burned, you will be able to program your Arduino MEGA 2560/ADK with both ROBOTC and the Arduino Open Source language.
Hardware Needed
There are a few ways to burn a new bootloader onto your Arduino MEGA 2560/ADK.
Method 1: Using an AVR ISP (In System Programmer)
- Your Arduino MEGA 2560/ADK (to program)
- An AVR Programmer such as the Pocket Programmer
- An AVR Programming Cable (the pocket programmer comes with one)
Method 2: Using another Arduino as an ISP
- Your Arduino MEGA 2560/ADK (to program)
- A Working Arduino (doesn't matter what kind)
- Some Male-to-Male Jumper Cables
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 }