Difference between pages "ARDUINO MEGA Update Bootloader" and "Order Of Operations"

From ROBOTC API Guide
(Difference between pages)
Jump to: navigation, search
(Software Needed)
 
(Operations Level 8)
 
Line 1: Line 1:
'''Note: This document only applies to the MEGA 2560 and MEGA ADK Arduino Boards. All other Arduino boards bootloaders are good!'''
+
{{DISPLAYTITLE: C Order of Operations}}
 +
<yambe:breadcrumb>General|General Programming</yambe:breadcrumb>
 +
{{tl|1|}}
  
== Arduino 2560 Bootloader Issue ==
+
===Operations level 1===
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.
+
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| ++ || x++ || a unary operator that increases the value of "x" by one
 +
|-
 +
| -- || x-- || A unary operator that decreases the value of "x" by one
 +
|-
 +
|}
  
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.
+
===Operations Level 2===
  
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. '''The enhanced bootloader is backwards compatible with the original one.  That means you'll still be able to program it through the Arduino programming environment as before, in addition to ROBOTC for Arduino.'''
+
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| ++ || ++x || a unary operator that increases the value of "x" by one
 +
|-
 +
| -- || --x || A unary operator that decreases the value of "x" by one
 +
|-
 +
| + || +x || A unary operator that does ????????
 +
|-
 +
| - || -x || A unary operator that does ????????
 +
|-
 +
| ! || !x || A logical operator that returns a boolean value that is the opposite of "x" (If "x" is true, then "!x" returns false)
 +
|-
 +
|}
 +
===Operations Level 3===
 +
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| / || a / b || An operator that returns the value of "a divided by b"
 +
|-
 +
| * || a * b || An operator that returns the value of "a multiplied by b"
 +
|-
 +
| % || a % b || An operator that returns the value of "the remainder of a divided by b"
 +
|-
 +
|}
 +
===Operations Level 4===
 +
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| + || a + b || An operator that returns the value of "a plus b"
 +
|-
 +
| - || a - b || An operator that returns the value of "a minus b"
 +
|-
 +
|}
 +
===Operations Level 5===
 +
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| / || a / b || An operator that returns the value of "a divided by b"
 +
|-
 +
| * || a * b || An operator that returns the value of "a multiplied by b"
 +
|-
 +
| % || a % b || An operator that returns the value of "the remainder of a divided by b"
 +
|-
 +
|}
  
== Hardware Needed  ==
+
===Operations Level 6===
To burn a new version of the Arduino bootloader to your MEGA 2560/ADK, you'll need an AVR ISP Compatible downloader.
+
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| >> || a >> b || A bitwise shift to the right ?????????
 +
|-
 +
| << || a << b || A bitwise shift to the left ??????????
 +
|-
 +
|}
 +
===Operations Level 7===
 +
Also known as "boolean operators" for returning boolean values
  
'''Using an AVR ISP (In System Programmer)'''
+
{|class="wikitable"
*Your Arduino MEGA 2560/ADK (to program)
+
|-
*An AVR Programmer such as the [http://www.sparkfun.com/products/9825 AVR Pocket Programmer]
+
! Operator !! Syntax !! Explanation
*An AVR Programming Cable (the pocket programmer comes with one)
+
|-
 +
| < || a < b || A logical statement that returns "true" if "a" is less than "b"
 +
|-
 +
| * || a <= b || A logical statement that returns "true" if "a" is less than or equal to "b"
 +
|-
 +
| > || a > b || A logical statement that returns "true" if "a" is greater than "b"
 +
|-
 +
| >= || a >= b || A logical statement that returns "true" if "a" is greater than or equal to "b"
 +
|-
 +
|}
 +
===Operations Level 8===
 +
Also known as "boolean operators" for returning boolean values
  
----
+
{|class="wikitable"
 +
|-
 +
! Operator !! Syntax !! Explanation
 +
|-
 +
| == || a == b || A logical statement that returns "true" if "a" is equal to "b"
 +
|-
 +
| != || a != b || A logical statement that returns "true" if "a" NOT equal to "b"
 +
|-
 +
|}
  
If you have extra Arduino boards, but no ISP programmer, SparkFun.com has a cool tutorial on how to flash a bootloader using an Arduino as an ISP.
+
===Operations Level 9===
 
+
{|class="wikitable"
'''Using another Arduino as an ISP'''
+
|-
*Your Arduino MEGA 2560/ADK (to program)
+
! Operator !! Syntax !! Explanation
*A Working Arduino (doesn't matter what kind)
+
|-
*Some Male-to-Male Jumper Cables
+
| & || a & b || A bitwise operator AND ????????
 
+
|-
For instructions on this method, take a look at the SparkFun.com website: http://www.sparkfun.com/tutorials/247
+
|}
 
+
===Operations Level 10===
== Software Needed ==
+
{|class="wikitable"
ROBOTC is not currently able to burn a bootloader onto an Arduino board, so you'll need to download a copy of the latest version of the Arduino Open-Source programming language.
+
|-
*Arduino Official Programming Language - [http://arduino.cc/en/Main/Software|Arduino Download Page]
+
! Operator !! Syntax !! Explanation
 
+
|-
In addition, you'll need the ROBOTC modified bootloader. You can download that here:
+
| ^ || a ^ b || A bitwise operator ExclusiveOR ????????
*ROBOTC Modified MEGA 2560/ADK Bootloader - [cdn.robotc.net/downloads/arduino/stk500boot_v2_mega2560.hex| Modified Bootloader]
+
|-
 
+
|}
== Bootload Download Instructions ==
+
===Operations Level 11===
* Download the [http://arduino.cc/en/Main/Software Arduino Open Source Software] and a copy of the [http://cdn.robotc.net/downloads/arduino/stk500boot_v2_mega2560.hex Modified Bootloader] File
+
{|class="wikitable"
* Copy the Modified Bootloader File into the /Arduino-1.0/hardware/arduino/bootloaders/stk500v2/ and overwrite the existing bootloader.
+
|-
[[File:CopyBootloader.png|800px]]
+
! Operator !! Syntax !! Explanation
* Power up your Arduino MEGA 2560/ADK (either via USB or external power)
+
|-
* Plug in your AVR ISP Programmer to your computer (make sure you have any required drivers installed)
+
| <nowiki>|</nowiki> || <nowiki>a | b</nowiki> || A bitwise operator OR ????????
* Connect your AVR ISP Programmer into your Arduino MEGA 2560/ADK Board via the ISP Header (the 2x3 header pins right above the Arduino Logo)
+
|-
* Launch the Arduino Open Source Software
+
|}
[[File:ArduinoLaunch.png]]
+
===Operations Level 12===
* Change your settings in the Arduino Software to look for an Arduino MEGA 2560/ADK
+
{|class="wikitable"
[[File:ArduinoSelectPlatform.png]]
+
|-
* Change your settings in the Arduino Software to select your ISP Programmer Type (Check your programmer's documentation for the exact model)
+
! Operator !! Syntax !! Explanation
[[File:ArduinoSelectProgrammer.png]]
+
|-
* Select the "Burn Bootloader" option under the "Tools" menu. The modified bootloader will now be sent to your Arduino. This typically take a minute or so.
+
| && || a && b  || Returns "true" if both "a" and "b" are also true
[[File:BurnBootloader.png]]
+
|-
* You should be all set to download ROBOTC firmware and start using your Arduino MEGA 2560/ADK with ROBOTC!
+
|}
 
+
===Operations Level 13===
== Technical Details ==
+
{|class="wikitable"
The Arduino Bootloader sets the "eraseAddress" to zero every time the bootloader is called. ROBOTC called the "Load Address" command to set the address in which we want to write/verify when downloading program.
+
|-
 
+
! Operator !! Syntax !! Explanation
When writing a page of memory to the arduino, the Arduino bootloader will erase the existing page and write a whole new page.
+
|-
 
+
| <nowiki>||</nowiki> || <nowiki>a || b</nowiki> || Returns "true" if either "a" or "b" is true
In the scenario of downloading firmware, everything is great because the Erase Address and the Loaded Address both start at zero.
+
|-
 
+
|}
In the scenario of writing a user program, we start writing at memory location 0x7000, but the Bootloader erases information starting at location zero because the "Load Address" command doesn't update where to erase.
+
===Operations Level 14===
 
+
{|class="wikitable"
Our modification is to set both the Load Address and the Erase Address so the activity of writing a user program doesn't cause the firmware to be accidentally erased!
+
|-
 
+
! Operator !! Syntax !! Explanation
=== Original Bootloader ===
+
|-
<syntaxhighlight lang="ROBOTC">
+
| ?: || a ? b : c || Ternary operations: see [[Tertiary_operators]]
case CMD_LOAD_ADDRESS:
+
|-
#if defined(RAMPZ)
+
|}
  address = (((address_t)(msgBuffer[1])<<24)|((address_t)(msgBuffer[2])<<16)|
+
===Operations Level 15===
            ((address_t)(msgBuffer[3])<<8)|msgBuffer[4]))<<1;
+
{|class="wikitable"
#else
+
|-
  address = (((msgBuffer[3])<<8)|(msgBuffer[4]))<<1;  //convert word to byte address
+
! Operator !! Syntax !! Explanation
#endif
+
|-
msgLength = 2;
+
| = || a = b || Assigns the value of "b" to "a"
msgBuffer[1] = STATUS_CMD_OK;
+
|-
break;
+
| += || a += b || Assigns the value of "a + b" to "a"
 
+
|-
case CMD_PROGRAM_FLASH_ISP:
+
| -= || a -= b || Assigns the value of "a - b" to "a"
case CMD_PROGRAM_EEPROM_ISP:
+
|-
{
+
| /= || a /= b || Assigns the value of "a / b" to "a"
  unsigned int size = ((msgBuffer[1])<<8) | msgBuffer[2];
+
|-
  unsigned char *p = msgBuffer+10;
+
| *= || a *= b || Assigns the value of "a * b" to "a"
  unsigned int data;
+
|-
  unsigned char highByte, lowByte;
+
| %= || a %= b || Assigns the value of "a % b" to "a"
  address_t tempaddress = address;
+
|-
 
+
| <<= || a <<= b || Assigns the value of "a << b" to "a" ????????
  if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
+
|-
  {
+
| >>= || a >>= b || Assigns the value of "a >> b" to "a" ????????
    // erase only main section (bootloader protection)
+
|-
    if (eraseAddress < APP_END )
+
| &= || a &= b || Assigns the value of "a & b" to "a" ?????????
    {
+
|-
      boot_page_erase(eraseAddress); // Perform page erase
+
| ^= || a ^= b || Assigns the value of "a ^ b" to "a" ?????????
      boot_spm_busy_wait(); // Wait until the memory is erased.
+
|-
      eraseAddress += SPM_PAGESIZE; // point to next page to be erase
+
| <nowiki>|= </nowiki>|| <nowiki>a |= b</nowiki> || Assigns the value of <nowiki>"a |= b"</nowiki> to "a" ??????????
    }
+
|-
</syntaxhighlight>
+
|}
=== ROBOTC Compatible Modification ===
+
<syntaxhighlight lang="ROBOTC">
+
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
+
    }
+
</syntaxhighlight>
+

Latest revision as of 20:47, 20 March 2014

General Programming → ARDUINO MEGA Update Bootloader

Operations level 1

Operator Syntax Explanation
++ x++ a unary operator that increases the value of "x" by one
-- x-- A unary operator that decreases the value of "x" by one

Operations Level 2

Operator Syntax Explanation
++ ++x a unary operator that increases the value of "x" by one
-- --x A unary operator that decreases the value of "x" by one
+ +x A unary operator that does ????????
- -x A unary operator that does ????????
 !  !x A logical operator that returns a boolean value that is the opposite of "x" (If "x" is true, then "!x" returns false)

Operations Level 3

Operator Syntax Explanation
/ a / b An operator that returns the value of "a divided by b"
* a * b An operator that returns the value of "a multiplied by b"
 % a % b An operator that returns the value of "the remainder of a divided by b"

Operations Level 4

Operator Syntax Explanation
+ a + b An operator that returns the value of "a plus b"
- a - b An operator that returns the value of "a minus b"

Operations Level 5

Operator Syntax Explanation
/ a / b An operator that returns the value of "a divided by b"
* a * b An operator that returns the value of "a multiplied by b"
 % a % b An operator that returns the value of "the remainder of a divided by b"

Operations Level 6

Operator Syntax Explanation
>> a >> b A bitwise shift to the right ?????????
<< a << b A bitwise shift to the left ??????????

Operations Level 7

Also known as "boolean operators" for returning boolean values

Operator Syntax Explanation
< a < b A logical statement that returns "true" if "a" is less than "b"
* a <= b A logical statement that returns "true" if "a" is less than or equal to "b"
> a > b A logical statement that returns "true" if "a" is greater than "b"
>= a >= b A logical statement that returns "true" if "a" is greater than or equal to "b"

Operations Level 8

Also known as "boolean operators" for returning boolean values

Operator Syntax Explanation
== a == b A logical statement that returns "true" if "a" is equal to "b"
 != a != b A logical statement that returns "true" if "a" NOT equal to "b"

Operations Level 9

Operator Syntax Explanation
& a & b A bitwise operator AND ????????

Operations Level 10

Operator Syntax Explanation
^ a ^ b A bitwise operator ExclusiveOR ????????

Operations Level 11

Operator Syntax Explanation
| a | b A bitwise operator OR ????????

Operations Level 12

Operator Syntax Explanation
&& a && b Returns "true" if both "a" and "b" are also true

Operations Level 13

Operator Syntax Explanation
|| a || b Returns "true" if either "a" or "b" is true

Operations Level 14

Operator Syntax Explanation
 ?: a ? b : c Ternary operations: see Tertiary_operators

Operations Level 15

Operator Syntax Explanation
= a = b Assigns the value of "b" to "a"
+= a += b Assigns the value of "a + b" to "a"
-= a -= b Assigns the value of "a - b" to "a"
/= a /= b Assigns the value of "a / b" to "a"
*= a *= b Assigns the value of "a * b" to "a"
 %= a %= b Assigns the value of "a % b" to "a"
<<= a <<= b Assigns the value of "a << b" to "a" ????????
>>= a >>= b Assigns the value of "a >> b" to "a" ????????
&= a &= b Assigns the value of "a & b" to "a" ?????????
^= a ^= b Assigns the value of "a ^ b" to "a" ?????????
|= a |= b Assigns the value of "a |= b" to "a" ??????????