The target interface system uses CrossStudio’s JavaScript (ECMAScript) interpreter to support board and target-specific behaviour.

The main use for this is to support non-standard target and board reset schemes and also to configure the target after reset, see Reset Script for more information.

The target script system can also be used to carry out target specific operations when the target interface connects or disconnects or when the debugger attaches, stops or starts the target. See Connect Script, Disconnect Script, Attach Script, Stop Script, and Run Script for more information.

In order to reduce script duplication, when the target interface runs a reset, attach, run or stop script it first looks in the current active project for a file marked with a project property File Type set to Reset Script. If a file of this type is found it will be loaded prior to executing the scripts, each of the scripts can then call functions within this script file.

## Reset Script

The Reset Script property held in the Target project property group is used to define a script to execute to reset and configure the target.

The aim of the reset script is to get the processor into a known state. When the script has executed the processor should be reset, stopped on the first instruction and configured appropriately.

As an example, the following script demonstrates the reset script for an Evaluator 7T target board with a memory configuration that re-maps SRAM to start from 0x00000000. The Evaluator7T_Reset function carries out the standard ARM reset and stops the processor prior to executing the first instruction. The Evaluator7T_ResetWithRamAtZero function calls this reset function and then configures the target memory by accessing the configuration registers directly. See TargetInterface Object for a description of the TargetInterface object which is used by the reset script to access the target hardware.

    function Evaluator7T_Reset()
    {
      TargetInterface.setNSRST(0);
      TargetInterface.setICEBreakerBreakpoint(0, 0x00000000, 0xFFFFFFFF,
                                              0x00000000, 0xFFFFFFFF, 0x100, 0xF7);
      TargetInterface.setNSRST(1);
      TargetInterface.waitForDebugState(1000);
      TargetInterface.trst();
    }

    function Evaluator7T_ResetWithRamAtZero()
    {
      Evaluator7T_Reset();

      /***************************************************************************
       * Register settings for the following memory configuration:
       *
       *     +----------------------+
       *     | ROMCON0 - 512K FLASH | 0x01800000 - 0x0187FFFF
       *     +----------------------+
       *     | ROMCON2 - 256K SRAM  | 0x00040000 - 0x0007FFFF
       *     +----------------------+
       *     | ROMCON1 - 256K SRAM  | 0x00000000 - 0x0003FFFF
       *     +----------------------+
       *
       ***************************************************************************/

      TargetInterface.pokeWord(0x03FF0000, 0x07FFFFA0); // SYSCFG
      TargetInterface.pokeWord(0x03FF3000, 0x00000000); // CLKCON
      TargetInterface.pokeWord(0x03FF3008, 0x00000000); // EXTACON0
      TargetInterface.pokeWord(0x03FF300C, 0x00000000); // EXTACON1
      TargetInterface.pokeWord(0x03FF3010, 0x0000003E); // EXTDBWIDTH
      TargetInterface.pokeWord(0x03FF3014, 0x18860030); // ROMCON0
      TargetInterface.pokeWord(0x03FF3018, 0x00400010); // ROMCON1
      TargetInterface.pokeWord(0x03FF301C, 0x00801010); // ROMCON2
      TargetInterface.pokeWord(0x03FF3020, 0x08018020); // ROMCON3
      TargetInterface.pokeWord(0x03FF3024, 0x0A020040); // ROMCON4
      TargetInterface.pokeWord(0x03FF3028, 0x0C028040); // ROMCON5
      TargetInterface.pokeWord(0x03FF302C, 0x00000000); // DRAMCON0
      TargetInterface.pokeWord(0x03FF3030, 0x00000000); // DRAMCON1
      TargetInterface.pokeWord(0x03FF3034, 0x00000000); // DRAMCON2
      TargetInterface.pokeWord(0x03FF3038, 0x00000000); // DRAMCON3
      TargetInterface.pokeWord(0x03FF303C, 0x9C218360); // REFEXTCON
    }

## Connect Script

The Connect Script property held in the Target project property group is used to define a script that is executed when the user connects to the target interface.

See TargetInterface Object for a description of the TargetInterface object which is used by the connect script to access the target hardware.

## Disconnect Script

The Disconnect Script property held in the Target project property group is used to define a script that is executed when the user disconnects from the target interface.

See TargetInterface Object for a description of the TargetInterface object which is used by the disconnect script to access the target hardware.

## Attach Script

The Attach Script property held in the Target project property group is used to define a script that is executed when the debugger first attaches to an application. This can be after a download or reset before the program is run or after an attach to a running application. The aim of the attach script is to carry out any target specific configuration before the debugger first attaches to the application being debugged.

See TargetInterface Object for a description of the TargetInterface object which is used by the attach script to access the target hardware.

## Stop Script

The Stop Script property held in the Target project property groups is used to define a script that is executed when the target enters debug/stopped state. This can be after the application hits a breakpoint or when the Debug | Break operation has been carried out. The aim of the stop script is to carry out any target specific operations before the debugger starts accessing target memory. This is particularly useful when debugging applications that have caches enabled as the script can disable and flush the caches enabling the debugger to access the current memory state.

See TargetInterface Object for a description of the TargetInterface object which is used by the stop script to access the target hardware.

## Run Script

This Run Script property held in the Target project property group is used to define a script that is executed when the target enters run state. This can be when the application is run for the first time or when the Debug | Go operation has been carried out after the application has hit a breakpoint or been stopped using the Debug | Break operation. The aim of the run script is to carry out any target specific operations after the debugger has finished accessing target memory. This can be useful to re-enable caches previously disabled by the stop script.

See TargetInterface Object for a description of the TargetInterface object which is used by the run script to access the target hardware.