CrossStudio for ARM supports Flash programming (and subsequent debugging) by loading a program into the RAM of the target and transmitting it the data to be programmed.

The use of a target loader is determined by the value of the Loader File Path project property defined for the appropriate configuration of the project. The Loader File Path property specifies the location of the loader executable to use, if this is defined the loader executable will be downloaded onto the target an run prior to download of the main application.

In addition to the Loader File Path property, the Loader File Type project property must be specified. This tells CrossStudio how to communicate with the loader program. The various communication mechanisms available are explained in more detail later. The Load File Type property may be set to one of the following:

The functionality a loader provides to CrossStudio is:

CrossStudio can communicate with the loader running on the ARM in one of two ways:

To simplify the creation of a new loader program, a number of files have been supplied in the target/loader directory:

In order to implement a loader, the following loader entry points should be implemented:

A loader that uses loader_ram.c must also define the program section in RAM called .comm_buffer. The RAM this section occupies is used to write the data sent to and from the loader. The size to set the .comm_buffer section to is dependent on how much RAM you have free, however the larger you set the .comm_buffer the faster the loader will run.

The loader projects and source code for all the supported targets can be found in the target-specific directories contained in the targets directory

The following code demonstrates the structure of a loader implementation:

#include "../loader/loader.h"

void
loaderBegin()
{
}

void
loaderEnd()
{
}

int
loaderPoke(unsigned char *address, unsigned int length)
{
  while (length)
    {
      unsigned int data = loaderReadWord();
      int i;
      for (i = 4; i && length; --i)
        {
          if (ADDRESS_IN_FLASH(address))
            flash_write_byte(address++, (unsigned char)data);
          else          
            *address++ = (unsigned char)data;                 
          data >>= 8;
          length--;
        }
    }
  return 1;
}

int
loaderMemset(unsigned char *address, unsigned int length,  unsigned char c)
{
  while(length--)
    {
      if (ADDRESS_IN_FLASH(address))
        flash_write_byte(address++, (unsigned char)c);
      else
        *address++ = (unsigned char)c;
    }
  return 1;
}

int
loaderErase(unsigned char *address, unsigned int length)
{
  if (!is_erased(address, length))
    flash_erase(address, length);
  return 1;
}

int
loaderEraseAll()
{
  if (!is_erased(FLASH_START_ADDRESS, FLASH_END_ADDRESS))
    flash_erase_all(FLASH_START_ADDRESS);
  return 1;
}

The targets directory contains a directory for each supported target. The loader source code for each target can be found in these directories. In order to view, edit and build a loader project open the Loader.hzp solution for the required target. By default CrossStudio picks the loaders from the Release/Loader.exe directory of each target directory.