Import, Build and Load Keil examples

Note

Only supported in Windows

Prerequisites

Import and build example projects (WINDOWS ONLY)

  • In Vscode, select CMSIS from the sidebar.

  • Navigate to the keil_arm_clang folder in the SDK example and press Open Solution in Workspace and select the file from the drop down menu.

    Import Project
  • To open the Sysconfig GUI : Click on the .syscfg file in the project and it opens the sysconfig GUI in a pop up window.

    Open Sysconfig from Keil

    The Sysconfig will open as a standalone application.

  • To build the project, click on Build Solution.

    Build Project

Executing the examples (WINDOWS ONLY)

  • Click on Load and debug application

    Debug Project

Note

Keil supports multiple debuggers. The default example is configured for CMSIS-DAP mode (used for XDS110)

Note

For the program to run correctly on the first load, the reset sequence in .vscode/launch.json must set the vector table offset, stack pointer and program counter explicitly. In the gdbtarget configuration, replace the "monitor reset halt" entry with the following entries:

"monitor reset halt",
"set *(unsigned int *)0xE000ED08 = 0x0",
"set $sp = *(unsigned int *)0x0",
"set $pc = *(unsigned int *)0x4",

These commands do the following:

  • 0xE000ED08 is the VTOR register; it is set to 0x0 so that the vector table is taken from the start of flash.

  • $sp is loaded with the initial stack pointer stored at address 0x0 (first vector table entry).

  • $pc is loaded with the reset handler address stored at address 0x4 (second vector table entry).

Warning

Known Keil debugger instability: restarting the debug session (using the restart button) may cause the program to enter a fault handler. If this happens, terminate the debugger connection, trigger nRST or power cycle the board, and then relaunch the debug session.

Note

For the program to run correctly on the first load, the reset sequence in .vscode/launch.json must set the vector table offset, stack pointer and program counter explicitly. In the gdbtarget configuration, replace the "monitor reset halt" entry with the following entries:

"monitor reset halt",
"set *(unsigned int *)0xE000ED08 = 0x0",
"set $sp = *(unsigned int *)0x0",
"set $pc = *(unsigned int *)0x4",

These commands do the following:

  • 0xE000ED08 is the VTOR register; it is set to 0x0 so that the vector table is taken from the start of flash.

  • $sp is loaded with the initial stack pointer stored at address 0x0 (first vector table entry).

  • $pc is loaded with the reset handler address stored at address 0x4 (second vector table entry).

Warning

Known Keil debugger instability: restarting the debug session (using the restart button) may cause the program to enter a fault handler. If this happens, terminate the debugger connection, trigger nRST or power cycle the board, and then relaunch the debug session.

Building examples from Command-Line

  • Using Powershell, enter following command from root of SDK:

    cmake --build .\build\am13e230x\m33_keil_arm_clang_release\ --target ex_gpio_output_toggle_lp.elf
    

    The target binary should now be built within the build directory and can be debugged using an IDE of your choice.

  • Use make showtargets to reveal list of targets that can be built by CMake:

gmake showtargets

Note

There are two directories within which binaries are present:

  • m33_keil_arm_clang_debug: Binaries are compiled at lower optimization, easier to debug.

  • m33_keil_arm_clang_release: Binaries are compiled at higher optimization for performance, but can be harder to debug.

It is recommended to build debug binaries from command-line to improve ease of debug.

Building examples using Keil CLI (cbuild)

In addition to the CMake/Ninja flow above, Keil Studio examples can also be built using the same cbuild/csolution command-line tools used by Keil Studio IDE itself (CMSIS-Toolbox), mirroring the CCS/IAR CLI build flow.

Important

cbuild and csolution must be resolvable on PATH. Open a terminal from VS Code with the Arm CMSIS-Toolbox / Keil Studio Pack extension installed to activate this automatically, or add the toolbox’s bin directory to PATH directly.

make also needs a POSIX shell (sh) resolvable on PATH to run recipe lines (same requirement as the rest of the SDK’s make targets, see the Developer’s Guide’s “Build the SDK” chapter). A CMSIS-Toolbox-activated terminal does not add one by itself, so run these commands from a bash shell (e.g. Git Bash on Windows) with the CMSIS-Toolbox PATH also present – or merge Git’s bin/usr/bin directories into the CMSIS-Toolbox terminal’s PATH. Without a POSIX shell on PATH, make silently falls back to invoking recipe words directly (e.g. echo) and fails with CreateProcess ... The system cannot find the file specified.

  • Build all Keil Studio examples for a device:

    make -f make/{{TI_SDK_DEVICE}}/makefile_keil_projects_{{TI_SDK_DEVICE}}.mk build
    
  • export (csolution pack/dependency resolution) and clean targets are also available:

    make -f make/{{TI_SDK_DEVICE}}/makefile_keil_projects_{{TI_SDK_DEVICE}}.mk export
    make -f make/{{TI_SDK_DEVICE}}/makefile_keil_projects_{{TI_SDK_DEVICE}}.mk clean
    
  • Do make -f make/{{TI_SDK_DEVICE}}/makefile_keil_projects_{{TI_SDK_DEVICE}}.mk help to see all available targets, including per-example targets

Note

Unlike IAR/CCS, Keil projects are built in place (no shared workspace directory), since the generated .cproject.yml uses paths relative to its own location in the repo tree. export therefore runs csolution convert in place (pack/dependency resolution) rather than copying files out to a shared workspace.

Note

On Windows, cbuild defaults to the Ninja generator but does not discover a ninja executable on its own, so the generated makefiles prepend the repo-vendored tools/ninja.exe to PATH for the build target. On Linux, ninja is expected to already be resolvable on PATH (no repo-vendored binary is provided for Linux).

The KEIL_CLI (cbuild) and CSOLUTION_CLI (csolution) command names used by the generated makefiles can be overridden, e.g. make ... KEIL_CLI=/path/to/cbuild build, if they should not be resolved from PATH directly.