Difference between pages "Tutorials/Getting Started" and "ARDUINO MEGA Update Bootloader"

From ROBOTC API Guide
< Tutorials(Difference between pages)
Jump to: navigation, search
(Downloading ROBOTC)
 
(Bootload Download Instructions)
 
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
+
'''Note: This document only applies to the MEGA 2560 and MEGA ADK Arduino Boards. All other Arduino boards bootloaders are good!'''
<yambe:breadcrumb self="Getting Started">Tutorials|Tutorials</yambe:breadcrumb>
+
<br />
+
  
{{toc}}
+
== Arduino 2560 Bootloader Issue ==
<br />
+
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.
  
== System Requirements ==
+
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.
{|width="740px"
+
|-
+
|ROBOTC requires basic system specifications to run properly. The development environment is not processor intensive, but the interactive debugger may slow down computer performance on older machines.
+
  
 +
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.'''
  
'''System Requirements:'''<br />
+
== Hardware Needed  ==
Intel® Pentium® processor or compatible, 800 MHz minimum <br />
+
To burn a new version of the Arduino bootloader to your MEGA 2560/ADK, you'll need an AVR ISP Compatible downloader.
Windows XP Professional or Home Edition with Service Pack 2 or greater <br />
+
256MB of RAM minimum <br />
+
Up to 30MB of available hard disk space  <br />
+
1 available USB port <br />
+
Compatible Bluetooth adapter (optional)<br />
+
<br />
+
'''ROBOTC Virtual Worlds System Requirements:'''<br />
+
Intel® Core 2 Duo®/AMD® Athlon X2® or better processor <br />
+
Windows XP Home or Professional Edition with Service Pack 2 or greater, Windows Vista, Windows 7 <br />
+
2048 MB (2 GB) of RAM minimum <br />
+
Minimum 200MB free hard drive space <br />
+
NVIDIA® GeForce® 8800GTS/ATI Radeon™ HD 3850 or better video card <br />
+
DirectX® 9.0 or DirectX® 10 <br />
+
  
For more information on ROBOTC's Virtual World program, see our [http://www.robotc.net/download/rvw/specifications.php Computer Requirements and Performance page.]
+
'''Using an AVR ISP (In System Programmer)'''
 +
*Your Arduino MEGA 2560/ADK (to program)
 +
*An AVR Programmer such as the [http://www.sparkfun.com/products/9825 AVR Pocket Programmer]
 +
*An AVR Programming Cable (the pocket programmer comes with one)
  
ROBOTC will not run natively in any other operating system other than Microsoft Windows. ROBOTC will run with a Virtualization client on a Apple Macintosh. ROBOTC has been tested with VMWare Fusion, Parallels Desktop, and Apple's Boot Camp. You will still need to download/install device drivers found on your purchased CD or on the ROBOTC website.
+
----
|}
+
<br />
+
  
== Downloading ROBOTC ==
+
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.
{|
+
|Before we start programming in ROBOTC, we need to first download and install the client. This can be done by navigating to ROBOTC's website ( http://www.robotc.net) and selecting the 'Downloads' tab.
+
|-
+
|1) From the ROBOTC website, select the individual robotics platform you wish to program on. If you want to use multiple platforms or accidentally download the wrong version, you can manually activate and choose another platform thorugh the ROBOTC program. When you get to the correct platform page, click on the 'Download ROBOTC for X version x.xx' to start the download process:
+
|-
+
|<br />
+
|-
+
|[[File:Install_Download_Firefox.png]]
+
|-
+
|<br />
+
|-
+
|[[File:Install_Download_IE.png]]
+
|-
+
|<br />
+
|-
+
|2) At this point click the 'Save' button to start downloading ROBOTC. You may get a warning pop-up from either Windows, your antivirus program, or both. This is to warn you that some programs downloaded from the internet can be malicious and to use care before running them; click allow to start the download.  
+
|-
+
|<br />
+
|}
+
  
== Installing and Uninstalling ROBOTC ==
+
'''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
  
=== Installing ===
+
For instructions on this method, take a look at the SparkFun.com website: http://www.sparkfun.com/tutorials/247
{|
+
|1) Once the program is done downloading, navigate to the Downloads folder on your computer and start the ROBOTC installer. You may have to right click on the installer and select the "Run as Administrator" depending on individual computer restrictions; ROBOTC must be installed with administrator privileges.
+
|-
+
|<br />
+
|-
+
|[[File:Install_Normal.png]]
+
|-
+
|<br />
+
|-
+
  
|-
+
== Software Needed ==
|2) Before you can proceed, you must read over and accept the End User License Agreement. If you agree to the End User Agreement, check the "I accept" and then the "Next" button to continue the installation.
+
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]
|<br />
+
|-
+
|[[File:Install_End_User.png]]
+
|-
+
|<br />
+
|-
+
|3) Next, select where you would like ROBOTC to install to. The default location is C:/Program Files (x86)/Robomatter Inc/ROBOTC Development Environment.
+
|-
+
|<br />
+
|-
+
|[[File:Install_Select_Directory.png]]
+
|-
+
|<br />
+
|-
+
|4) The installer will ask you to confirm your settings. If everything looks correct, click "Install" to being the installation process. The installer will then begin copying files from the installer to your computer. Please wait until this is complete.<br />
+
|-
+
|<br />
+
|-
+
|[[File:Install_Install_Progress.png]]
+
|-
+
|<br />
+
|-
+
|5) The installer will inform you of when the installation is complete. Click the "Finish" button to complete your install.<br />
+
|-
+
|<br />
+
|-
+
|[[File:Install_Complete.png]]
+
|-
+
|<br />
+
|-
+
|6) Right-Click on the ROBOTC icon and select "Run as Administrator" to run ROBOTC as an administrator (assuming the user account has administrator privileges). You will only need to do this one time.<br />
+
|-
+
|<br />
+
|-
+
|[[File:Install_Run_Admin.png]]
+
|-
+
|<br />
+
|-
+
|Depending on which platform you are installing, ROBOTC may also install additional drivers unique to each platform. If for any reason the drivers are not downloaded and installed properly they can be downloaded and installed manually from the [http://www.robotc.net/download/ ROBOTC website.]
+
|}
+
<br />
+
  
=== Uninstalling ===
+
In addition, you'll need the ROBOTC modified bootloader. You can download that here:
{|
+
*ROBOTC Modified MEGA 2560/ADK Bootloader - [cdn.robotc.net/downloads/arduino/stk500boot_v2_mega2560.hex Modified Bootloader]
|-
+
|To uninstall ROBOTC, follow the steps below:<br />
+
|-
+
|<br />
+
|-
+
|1) Open the Control Panel from your Windows "Start Menu"<br />
+
|-
+
|[[File:Uninstall_Control_Panel.png]]
+
|-
+
|2) Inside of the Control Panel, select "Programs -> Uninstall a Program" or "Add or Remove Programs" (depending on view settings).<br />
+
|-
+
|3) Navigate through the "Add or Remove Programs" list until you find the version of ROBOTC that you wish to uninstall. Press the "Uninstall" button.<br />
+
|-
+
|<br />
+
|-
+
||[[File:Uninstall_ROBOTC.png]]
+
|-
+
|<br />
+
|-
+
|4) Windows will start the uninstall process. When the window below disappears and you are returned to the "Add or Remove Programs" list, ROBOTC has been successfully uninstalled.<br />
+
|}
+
<br />
+
  
=== Building Licenses ===
+
== Bootload Download Instructions ==
{|
+
* 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
|-
+
* Copy the Modified Bootloader File into the /Arduino-1.0/hardware/arduino/bootloaders/stk500v2/ and overwrite the existing bootloader.
|There is a special type of ROBOTC license called a Building License . These licenses do not require an online activation but rather have a unique building license file that must be installed with the software in order for ROBOTC to work properly. When you order a building license you will be sent an email with a unique building license file.  
+
[[File:CopyBootloader.png|800px]]
|-
+
* Power up your Arduino MEGA 2560/ADK (either via USB or external power)
|<br />
+
* Plug in your AVR ISP Programmer to your computer (make sure you have any required drivers installed)
|-
+
* 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)
|To activate ROBOTC with a building license, download and run the installer as normal. Once the program is installed, copy the building license file into the ROBOTC directory (typically C:/Program Files (x86)/Robomatter Inc/ROBOTC Developement Environment).  
+
* Launch the Arduino Open Source Software
|-
+
[[File:ArduinoLaunch.png]]
|<br />
+
* Change your settings in the Arduino Software to look for an Arduino MEGA 2560/ADK
|-
+
[[File:ArduinoSelectPlatform.png]]
|[[File:Building_License_Location.png]]
+
* Change your settings in the Arduino Software to select your ISP Programmer Type (Check your programmer's documentation for the exact model)
|-
+
[[File:ArduinoSelectProgrammer.png]]
|One of the advantages of building licenses is that they help make automated installs easy. To roll out ROBOTC to multiple computers using a building license, make sure the base image has ROBOTC installed and the building license files in the correct directory. As long as those two conditions are met, ROBOTC should be active on each computer the image is rolled out to with no futher action required.  
+
* 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.
|-
+
[[File:BurnBootloader.png]]
|<br />
+
* You should be all set to download ROBOTC firmware and start using your Arduino MEGA 2560/ADK with ROBOTC!
|-
+
|There is, however, an exception. If ROBOTC is being run from a centralized network, each computer that needs to access ROBOTC must also install a Network Dependencies package (available from the ROBOTC downloads page). The building license file must also be properly installed on the network in order for networked computers to access ROBOTC.
+
|-
+
|}
+
  
== Activate Online ==
+
== Technical Details ==
{|
+
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.
|-
+
|'''To continue using ROBOTC past the 30 day trial period''', you must purchase a ROBOTC license and then activate the license on each computer.
+
  
 +
When writing a page of memory to the arduino, the Arduino bootloader will erase the existing page and write a whole new page.
  
To activate ROBOTC, you will need the '''License ID and Password''' that was sent to you during the purchase process.
+
In the scenario of downloading firmware, everything is great because the Erase Address and the Loaded Address both start at zero.
  
*If you purchased a ROBOTC license online, the License ID and Password were sent to the email address specified.
+
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.
*If you ordered the CD-ROM version of ROBOTC, the License ID and Password are printed on the CD label.
+
  
'''If you are Activating the ROBOTC license on computers with internet access, follow the Activation instructions below.'''  
+
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!
  
'''''NOTE:''' ROBOTC must be activated on each individual computer. ROBOTC can no longer be activated offline; the computers must be activated with a working internet connection. Once activation is complete, the computers do not need to remain online to stay activated.''
+
=== Original Bootloader ===
 +
<syntaxhighlight lang="ROBOTC">
 +
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;
  
Follow these steps to activate on a computer with internet access:
+
  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
 +
    }
 +
</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;
  
1) Open ROBOTC and navigate to the Help menu. From there, select 'Manage Licenses -> Add License'. If you do not already have a ROBOTC license, you may purchase one by clicking the 'Purchase License' option. <br />
 
  
 +
  if ( msgBuffer[0] == CMD_PROGRAM_FLASH_ISP )
 +
  {
 +
    eraseAddress = address & 0xFFFFFF00;  // ROBOTC Custom Bootloader Addition
  
[[File:Activating_Manage.png]]
+
    // erase only main section (bootloader protection)
 
+
    if (eraseAddress < APP_END )
<br />
+
    {
2)  From the Manage License menu, select the 'Add License' button. Note that there is also a greyed out option for "Deactivate License". This allows you to deactivate the license (where applicable; not all licenses can be deactivated) and reactivate it on another computer. Once a license is activated, you can also see the registration information and create a desktop icon for ROBOTC by clikcing on their respective buttons.<br />
+
      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
[[File:Activating_Add_Main.png]]
+
    }
 
+
</syntaxhighlight>
<br />
+
3) Clicking the Add License button will bring up a 'Add New ROBOTC License' window. From here you must first select which type of license you have and then enter your License ID and Password (to see the password characters as you type, uncheck the 'mask' checkbox). <br />
+
 
+
 
+
[[File:Activating_Add_Select.png]]
+
 
+
[[File:Activating_Add_Activate.png]]
+
 
+
<br />
+
4) Once the information is entered, click the 'Activate Online' button to activate the product. If you wish to activate multiple products, simply repeat the process. You may also start a trial of any of the ROBOTC versions (assuming the trial has not already been activated on the computer) by selecting the program you'd wish to try and selecting "Start Trial". <br />
+
 
+
|}
+
<br />
+
 
+
==  Select Platform Type ==
+
{|width="740px"
+
|-
+
|Open the "Robot" menu in ROBOTC and hover your cursor over the "Platform Type" menu option. This will open up the platform select menu. Select the platform you wish you use with ROBOTC. You can change the platform type at any time.  
+
 
+
ROBOTC for MINDSTORMS has support for five different platforms:
+
* LEGO Mindstorms NXT
+
* LEGO Mindstorms NXT + TETRIX/MATRIX
+
* Natural Language (NXT)
+
* Natural Language (TETRIX/MATRIX)
+
* Robot Algebra (NXT)
+
 
+
Before you use ROBOTC, make sure to select which platform you are currently using (in this example, the Lego Mindstorms/TETRIX/MATRIX platform is selected).
+
 
+
 
+
[[File:Selecting_Platform_Type.png]]
+
|}
+
<br />
+

Revision as of 18:46, 3 March 2014

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. 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.

Hardware Needed

To burn a new version of the Arduino bootloader to your MEGA 2560/ADK, you'll need an AVR ISP Compatible downloader.

Using an AVR ISP (In System Programmer)

  • Your Arduino MEGA 2560/ADK (to program)
  • An AVR Programmer such as the AVR Pocket Programmer
  • An AVR Programming Cable (the pocket programmer comes with one)

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.

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

For instructions on this method, take a look at the SparkFun.com website: http://www.sparkfun.com/tutorials/247

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 version of the Arduino Open-Source programming language.

In addition, you'll need the ROBOTC modified bootloader. You can download that here:

  • ROBOTC Modified MEGA 2560/ADK Bootloader - [cdn.robotc.net/downloads/arduino/stk500boot_v2_mega2560.hex Modified Bootloader]

Bootload Download Instructions

CopyBootloader.png

  • 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)
  • 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

ArduinoLaunch.png

  • Change your settings in the Arduino Software to look for an Arduino MEGA 2560/ADK

ArduinoSelectPlatform.png

  • Change your settings in the Arduino Software to select your ISP Programmer Type (Check your programmer's documentation for the exact model)

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.

BurnBootloader.png

  • You should be all set to download ROBOTC firmware and start using your Arduino MEGA 2560/ADK with ROBOTC!

Technical Details

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.

When writing a page of memory to the arduino, the Arduino bootloader will erase the existing page and write a whole new page.

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.

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!

Original Bootloader

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
    }

ROBOTC Compatible Modification

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
    }