SEGGER Embedded Studio

From SEGGER Wiki
Revision as of 16:25, 5 February 2019 by Leon (talk | contribs) (How to connect to J-Link via J-Link Remote Server)
Jump to: navigation, search

Embedded Studio is a complete all-in-one solution for managing, building, testing and deploying your embedded applications: From the Project Generator which gets you easily started with common ARM microcontrollers, to the powerful Project Manager and source code Editor, the included C/C++ Compiler and the integrated Debugger with advanced debug information windows and direct J-Link integration, right through to version control features for automatic deployment of your applications.

Embedded Studio is based on Rowley's professional IDE - CrossWorks. Its Visual Studio-like style offers the embedded world of engineering the same intuitive usage that PC developers are familiar with.

ETB trace on NXP TWR-K65F

ETB trace with the OpenSDA on-board which is on the NXP TWR-K65F board and for which SEGGER also provide a firmware. Further information regarding the J-Link OpenSDA firmware can be found on the SEGGER webpage: https://www.segger.com/opensda.html. In general, to get ETB up and running, just make sure to configure ETB as Trace Interface Type in the Embedded Studio project settings:

Debugger --> Target Trace Options --> Trace Interface Type --> ETB

ES ProjectConfiguration ETB.png

Once the debug session has been started, the most recent executed instructions will be shown in the instruction backtrace window. The window can be opened at:

Debug --> Other windows --> Execution Trace

File:ES ExecutionTrace ETB.png

Below a sample project that is already prepared for ETB trace on the K65 is available for download.

How to port projects from IAR EWARM to SEGGER Embedded Studio

Introduction

This wiki article describes how to import IAR EWARM projects into SEGGER Embedded Studio using the build in project importer. With the project importer you can either keep using the IAR compiler inside Embedded Studio or
use the GCC/Clang compiler that is used inside Embedded Studio. By switching your project to Embedded Studio you can directly benefit from features like multi-threaded compiling, fast and simple project search, indexing and more.
Many features are even available should you still decide to be using the IAR compiler inside Embedded Studio. A full feature list can be found here.

Setup

The following import tutorial will be based on the following Hardware and Software combinations:

  • SEGGER Embedded Studio 3.12 64-bit (Project importer works on 3.10 or later)
  • IAR EWARM 7.80
  • Target Evalboard: SEGGER emPower

The following file contains the example project for you to try out:

IAR_to_ES_Tutorial.zip

Import tutorial

  • Open your copy of Embedded Studio and go to File -> Import IAR EWARM / Keil MDK Project... then navigate to the project file you want to import and select it.
IAR Example Project Folder
  • Now you will have the opportunity to choose between:
    • External Toolchain: imports the project and configures it to be built with the original toolchain.
    • Internal Toolchain: imports the project and sets the configuration for the Embedded Studio tool chain.
    • Internal and External Toolchains: creates a set of build configurations to build with the original tool chain and one set to build with the Embedded Studio tool chain.
    • "IAR Installation Directory" where you get the option to use a different external IAR compiler if you have multiple IAR EWARM versions installed.
  • To migrate to Embedded Studio it is recommended to create build configurations for internal and external tool chains so you can easily switch between the tool chains later on.
Project importer options
  • If everything worked out well the following status window should pop up:
Successful import
  • Embedded Studio will automatically create build configurations for debug and release versions with the internal and external compiler that have been present in the existing IAR project.
  • To switch between them the drop down menu in the "Project Explorer" can be used.
Build configurations window
  • To debug the example project with the IAR compiler choose "Debug_External" in the drop down menu and build the project by pressing F7.
  • For most projects this will work out of the box, if it does not build out of the box please refer to section "Troubleshooting".

How to switch to internal Embedded Studio compiler

  • To use the full potential of Embedded Studio it is required to use the internal compiler which is based on GCC/Clang.
  • This can be done in the provided example project by simply going to the drop down menu and select "Debug_Internal".
  • The project will now be built when pressing F7 with the internal GCC compiler by default. Clang can be enabled in the project options instead.
  • After a successful build with the internal compiler Embedded Studio will automatically calculate how much flash and RAM will be occupied on your target device and represent it visually in the output window.
Code flash and RAM usage
  • Note: this feature is only available when using the internal compilers.
  • For most projects switching to the internal compiler work out of the box, if it does not build out of the box please refer to section "Troubleshooting".

Troubleshooting

While imported projects will usually re-build with the external tool chain out-of-the-box, for GCC/Clang based project build configurations, some manual changes may be required.

In some cases the sources are created to be GCC compatible, then you can seamlessly switch between original tool chain and GCC. When the original project is created from a software pack or SDK, it might already come with GCC compatible source files which can replace the former tool chain compatible files.

The following points list the most common changes which are required to migrate a project to Embedded Studio.

Memory Linker Script

The Embedded Studio project importer does not import linker scripts (e.g. IAR icf files). It sets up the basic memory map for the selected target device, which will put code into the internal flash and data into the internal SRAM.

For more advanced or different configurations, the memory map file and the section placement file have to be set up accordingly.

To place memory segments there are two options available in Embedded Studio:

  1. Place segments directly via project options under "Linker -> Section Placement Segments"
  2. Create a memory map .xml file or edit the default file provided by Embedded Studio and set it in project options under "Linker -> Use Manual Linker Script"

For example, a memory-map file representing a device with two memory segments called FLASH and SRAM could look something like this in the memory-map editor.

<Root name="Device1">
  <MemorySegment name="FLASH" start="0x10000000" size="0x10000" />
  <MemorySegment name="SRAM"  start="0x20000000" size="0x1000" />
</Root>

A corresponding section-placement file will refer to the memory segments of the memory-map file and will list the sections to be placed in those segments. This is done by using a memory-segment name in the section-placement file that matches the corresponding memory-segment name in the memory-map file.

For example, a section-placement file that places a section called .stack in the SRAM segment and the .vectors and .text sections in the FLASH segment would look like this:

<Root name="Flash Section Placement">
  <MemorySegment name="FLASH" >
    <ProgramSection name=".vectors" load="Yes" />
    <ProgramSection name=".text" load="Yes" />
  </MemorySegment>
  <MemorySegment name="SRAM" >
   <ProgramSection name=".stack" load="No" />
  </MemorySegment>
</Root>

To add new segments or sections simply edit the default file linked by Embedded Studio. The linked file can be found in the project options under "Linker -> Section Placement File".

More information about how to setup such files can be found in the Embedded Studio Help window in chapter "Linking and section placement".

Third Party Software and Libraries

Third party software, especially libraries, might be configured for one tool chain and do not compile with other tool chains.

Check if there is a port of the software for Embedded Studio / GCC or configure and rebuild the software for Embedded Studio / GCC.

Although libraries built for another tool chain may link with Embedded Studio, always take care and check that interfacing with the library works as expected.

Assembly Code

The syntax of assembler code and control commands in assembler files can be different across tool chains.

Although the resulting assembled instructions are identical, the assembler code to be written can be different across tool chains, for example numerical constants need to be declared differently for IAR and GCC/Clang.

Control commands which help writing assembler code is different, too. The syntax for symbols, labels, function definitions, and alike needs to be adjusted to work with the GNU assembler.

The following table shows some "popular" assembler directives that can be substituted by the corresponding conjugate:

IAR assembler directive GCC/Clang assembler directive
PUBLIC .global
SECTION .section
MACRO .macro
ENDM .endm
THUMB .thumb_func
END .end
EXTERN .extern
DC32 .word

For a complete list please refer to the corresponding assembler reference manuals.

Preprocessor Defines

Tool chains use different built-in definitions to identify the compiler which is used and to allow conditional compilation based on the configuration of core, device, endianess, and other settings.

It is mandatory to choose the correct definitions and recommended to make sure the code throws a warning or error when required definitions are not defined.

IAR defines __ICCARM__ and __IAR_SYSTEMS_ICC__ which can be used for identification, Embedded Studio defines __SES_ARM and __GNUC__.

For the target device IAR defines __ARM7M__ and __CORE__=__ARM7M__ when compiling for Cortex-M4, Embedded Studio uses __ARM_ARCH_7M__ instead.

Tool Chain Intrinsics

Compiler-specific functions like __disable_interrupt() or __no_operation() might not be available in Embedded Studio. Write corresponding replacement functions or avoid using them at all.

A replacement function for __no_operation() could look like this for GCC/Clang:

#define NO_OPERATION() __asm volatile ("nop")

To make it backwards compatible with IAR such a redefinition can be nested within preprocessor defines; __ICCARM__ for IAR EWARM and __SES_ARM for Embedded Studio.

Project Settings

Most project settings are set automatically by the project importer for the external and internal build configuration. In some more complex projects certain project settings need to be added manually.

For example by default no files are excluded from the internal build configuration, so if there is a compiler incompatible file the compiler will try to compile it and show errors (e.g. GCC/Clang incompatible assembler files).

To do this right click your project in the project explorer and select "Edit options". More information about the individual settings can be found in the Embedded Studio user manual.

User Included Directories

Many more complex projects link their sources from multiple folders in different paths. Make sure all needed folders are included in the build configuration under "Preprocessor -> User Include Directories".

Pre/Post Build Commands

Embedded Studio offers the possibility to use pre/post build commands familiar to the ones in IAR EWARM. However the project importer does not import these as the syntax between IAR and Embedded studio differs.

Should you be using such commands in IAR make sure you mimic them in Embedded Studio in the internal and external build configurations accordingly .

To execute multiple commands at once the use of a batch script is possible.

For example to enable a post link batch script go into the project options for the intended build config, go to "User Build Step" and edit the entry "Post-Link Command".

Now enter the relative or absolute path of the bat file and the optional parameters: Path/Example.bat Param1 Param2 ...

How to configure Embedded Studio to use SWO

SEGGER Embedded Studio can use SWO for printf Output to the Debug Terminal and for code profiling and execution trace. This article describes the configuration of a project in Embedded Studio to enable SWO.

Example Setup

The setup guide will be based on the following hardware and software components:

  • J-Link Software Package V6.18c or later
  • Embedded Studio V3.26a or later
  • SEGGER emPower evaluation board
  • Any J-Link/J-Trace hardware
  • Physically connected SWO pin to debug interface

Setup Guide

  1. Open your project in Embedded Studio
  2. In the Project Explorer select the project and go to Project-> Edit Options...
  3. Go to Debug -> Target Trace
  4. Select SWO as Trace Interface Type
  5. Enter the Trace Clock Speed: The trace clock speed is usually the target CPU speed while the application is running.
  6. Enter the SWO Baud Rate: The SWO baud rate (or SWO speed) needs to match the trace clock speed and the used J-Link.
  7. Click OK
  8. Start a debug session
  9. Open the Execution Profile Window (View -> More Debug Windows -> Execution Profile)
  10. Open the Execution Trace Window (View -> More Debug Windows -> Execution Trace)
Check if correct device and debugger is selected
Set SWO speed and baud rate
Execution Profile
Execution Trace

A basic ES project for the emPower board with all settings applied can be found here: emPower_ES_SWO.zip

Measuring CPU speed

If the target CPU speed is not known it can be measured with J-Link Commander or J-Link SWO Viewer.

Measuring with J-Link Commander

  • Open J-Link Commander
  • Connect to your device
  • Execute "testcspeed <RamAddress>"
Measure CPU clock in J-Link Commander

Measuring with J-Link SWO Viewer

  • Open J-Link SWO Viewer
  • Select target device
  • Click measure
Measure SWO clock

Calculating the SWO speed

The supported SWO speeds depend on the connected emulator. They can be retrieved from the emulator. To get the supported SWO speeds for your emulator, use J-Link Commander, connect to your target and execute the command "SWOSpeed" without quotations marks. The listed speeds can be set as SWO baud rate.

Troubleshooting

  • The Terminal I/O windows are still not showing any information even after following the setup guide step by step.
    • Make sure the SWO pin is actually connected to your J-Link debug hardware, many J-Link OBs for example do not have SWO routed to them.
    • Check if the selected target device is correct.
  • I want to use SWO and JTAG simultaniously, how can i do that?
    • This is not possible as the TDO (JTAG) signal is sharing the same pin as SWO. To be able to use SWO a SWD debug connection is required.
  • I can't start a debug session
    • Is the target device powered properly? You can open the J-Link Commander to see what voltage is currently showing as VTREF in the console output. Is that value expected?


If there are still issues persisting feel free to contact our support: support@segger.com

VCS configuration

Version Control System (VCS) is an essential tool for individuals or development teams. SEGGER Embedded Studio integrates with several popular source-control systems to provide this feature for files in your Embedded Studio projects.

The source-control capability is implemented by a number of third-party providers, but the set of functions provided by Embedded Studio aims to be provider independent. This article will explain how to set up such a system and how to use it.

Set up source control system

Embedded Studio supports Subversion, Git, and Mercurial as source-control systems. To enable Embedded Studio to utilize source-control features, you need to install the appropriate command line client on your operating system for the source-control systems that you will use.

Once you have installed the command line client, you must configure Embedded Studio to use it.

To configure Subversion:

  1. Choose Tools > Options.
  2. Select the Source Control category in the options dialog.
  3. Set the Executable environment option of the Subversion Options group to point to Subversion svn command. On Windows operating systems, the Subversion command is svn.exe.

To configure Git:

  1. Choose Tools > Options.
  2. Select the Source Control category in the options dialog.
  3. Set the Executable environment option of the Git Options group to point to Git git command. On Windows operating systems, the Git command is git.exe.

To configure Mercurial:

  1. Choose Tools > Options.
  2. Select the Source Control category in the options dialog.
  3. Set the Executable environment option of the Mercurial Options group to point to Mercurial hg command. On Windows operating systems, the Git command is hg.exe.
Example with SVN

Source control capabilities

The source-control integration capability provides:

  • Connecting to the source-control repository and mapping files in the Embedded Studio project to those in source control.
  • Showing the source-control status of files in the project.
  • Adding files in the project to source control.
  • Fetching files in the project from source control.
  • Optionally locking and unlocking files in the project for editing.
  • Comparing a file in the project with the latest version in source control.
  • Updating a file in the project by merging changes from the latest version in source control.
  • Committing changes made to project files into source control.

When Embedded Studio loads a project, it examines the file system folder that contains the project to determine the source-control system the project uses. If Embedded Studio cannot determine, from the file system, the source-control system in use, it disables source-control integration.

That is, if you have not set up the paths to the source-control command line clients, even if a working copy exists and the appropriate command line client is installed, Embedded Studio cannot establish source-control integration for the project.

User credentials

You can set the credentials that the source-control system uses, for commands that require credentials, using VCS > Options > Configure. From here you can set the user name and password. These details are saved to the session file (the password is encrypted) so you won't need to specify this information each time the project is loaded.

Note

Embedded Studio has no facility to create repositories from scratch, nor to clone, pull, or checkout repositories to a working copy: it is your responsibility to create a working copy outside of Embedded Studio using your selected command-line client or Windows Explorer extension.

The "Tortoise" products are a popular set of tools to provide source-control facilities in the Windows shell. Use Google to find TortoiseSVN, TortoiseGit, and TortoiseHG and see if you like them.

Source-control operations

Source-control operations can be performed on single files or recursively on multiple files in the Project Explorer hierarchy. Single-file operations are available on the Source Control toolbar and on the text editor's shortcut menu. All operations are available using the Project > VCS menu. The operations are described in terms of the Project Explorer shortcut menu.

More information can be found in the Embedded Studio user manual: SEGGER Embedded Studio > SEGGER Embedded Studio User guide > Using source control

Set up external diff tool

To show the differences between the file in the project and the version checked into source control you can use the build in diff tool:

  1. In the Project Explorer, right-click the file.
  2. From the shortcut menu, choose Source Control > Compare.
ES internal diff tool

You can also use an external diff tool in preference to the built-in Embedded Studio diff tool. To define the diff command line Embedded Studio generates, choose Tools > Options > Source Control > Diff Command Line. The command line is defined as a list of strings to avoid problems with spaces in arguments. The diff command line can contain the following macros:

  • $(localfile): The filename of the file in the project.
  • $(remotefile): The filename of the latest version of the file in source control.
  • $(localname): A display name for $(localfile).
  • $(remotename): A display name for $(remotefile).
Cmd line example with WinMerge

Installation on newer Linux versions

On some newer Linux versions root rights for installing Embedded Studio are not granted per default. To counter that issue the following workaround can be applied. Simply execute the following command in the terminal:

xhost si:localuser:root

This workaround has been confirmed to work for:

  • Ubuntu 17.10
  • Fedora 26

...

This list will be updated once other Linux versions have been confirmed to work with that workaround.


Note: We strongly suggest to revoke the root rights after a successfull installation. To do that simply execute the following command in terminal:

xhost -si:localuser:root

How to enable RTOS thread awareness

Enable thread awareness for embOS

Thread awareness for other OSs

The following thread awareness scripts are provided as is without claim for support. Setup steps are the same as with embOS.

FreeRTOS thread awareness scripts

Note: When using FreeRTOS the scripts require FreeRTOS to be compiled such that the referenced symbols do not have static qualifier (so the debugger can access them).

How to place a function in RAM

For some situations it may be beneficial or even necessary to place a function in RAM instead of flash. This for example is needed in case a bootloader (that runs from flash) shall update a firmware (running from the same flash but different sectors). As the flash is not accessible for read accesses while it is programmed, the flash programming routines itself need to run from RAM.

In order to put a function into RAM, it needs to be placed into the .fast section. This is done as follows:

__attribute__ ((section(".fast")))  // Place the following function in RAM
void _Delay(void) {
  [...]
}

How to use an external toolchain with Embedded Studio

Embedded Studio offers the option to build project with an external toolchain of your choice. The following guide will show an example implementation of such a setup with the ARM GCC toolchain.

Example implementation with external GCC toolchain

  • First install the external toolchain of your liking, in this example the currently latest ARM GCC 7-2017-q4-major will be used.
  • Create a new externally build project using the Embedded Studio project wizard and selecting A C/C++ executable for ... processor(internal and external GNU tools).
New external build project
  • Select your target device, next set the toolchain path and finish the project setup by letting all settings on default.
  • Make sure the memory section placement segments are located in the correct memory areas. This can be found int he Common project settings under Linker-> Section Placement Segments
  • Now select build configuration "Debug External" and build the project to build with the external toolchain.
  • If the build succeeds you can download it into your target application and debug it.

Optional steps for more complex builds

When adding more complex projects to Embedded Studio as an external build usually additional steps are required to make full use of the external compiler. The following are the most common:

  • Preprocessor definitions: Under Preprocessor->Preprocessor Definitions in the external build configs missing preprocessor definitions can be set.
  • User include directories: Under Preprocessor->User Include Directories in the external build configs missing include directories can be added.
  • All other commands that can't be set directly through the Embedded Studio GUI need to be set manually to the external build command line which can be found under External Build in one of the external build project configurations.

Connecting to J-Link via J-Link Remote Server

The J-Link Remote Server makes it possible for Embedded Studio to connect to a J-Link remotely, without needing a physical connection to the J-Link.

In order to use the J-Link Remote Server using Embedded Studio, follow these instructions:

  • Open your project options (right click on your project in the Project Explorer and select 'Options')
  • Select the 'J-Link' menu item under 'Debug' and edit the 'Host connection' field
  • In the property editor, set the Host Connection
    • For a remote server running in LAN mode, enter "IP <RemoteServerIP>".
    • For a remote server running in tunneling mode, enter "IP tunnel:<SN/Nickname>[:<Pasword>[:tunnelserver[:port]]]"
File:ES ConnectToRemoteServer 2.jpg
Property editor for J-Link host connection
  • Click 'OK'

From then on, the J-Link is handled the same as if it was connected directly via USB.