This mini-guide provides the essentials for quickly setting up a "hello world" project for an Arm Cortex-M4 target built with the IAR Build Tools for Arm (BXARM) using CMake on Visual Studio Code on an Ubuntu Desktop. In the end we will debug it using the IAR C-SPY Debugger.
Warning
The information provided in this repository is subject to change without notice and does not represent a commitment on any part of IAR. While the information contained herein might be useful as reference, IAR assumes no responsibility for any errors or omissions.
Below you will find the software and their versions used in this guide. Newer versions might work with little or no modification(s).
Software | Version | Link |
---|---|---|
Ubuntu Desktop | 22.04.4 | link |
IAR Build Tools for Arm | 9.50.2 | link |
Microsoft Visual Studio Code | 1.87.2 | link |
IAR C-SPY Debug Extension | 1.30.4 | link |
Microsoft C/C++ Extension Pack | 1.3.0 | link |
CMake | 3.29.0-rc3 | link |
Ninja | 1.10 | link |
This guide assumes a functional Ubuntu Linux Desktop already in place as starting point.
IAR customers can login into IAR MyPages then use the download links provided from the following page:
- IAR Build Tools for Arm 9.50.2
- Download installer for Ubuntu (/Debian) (filename:
bxarm-9.50.2.deb
). - SHA256 checksum for Ubuntu installer (filename:
bxarm-9.50.2.deb.sha256
). - Device support package (Ubuntu) (filename:
bxarm-cspy-device-support-9.50.2.deb
).
- Download installer for Ubuntu (/Debian) (filename:
- And finally install the required packages:
cd ~/Downloads
sha256sum --check bxarm-9.50.2.sha256
sudo apt install ./bxarm-*.deb
Tip
Follow the Command Line User Guide for setting up your license. If you encounter problems with your license, reach out to IAR Support.
Install VSCode:
sudo apt update
sudo apt install -y curl git apt-transport-https
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt-get update
sudo apt-get install -y code
code
- Select you trust the repository's folder. Optionally you can "Trust the authors of all files in the parent folder
<folder-name>
":
- Use the "Welcome" wizard to set up Visual Studio Code (or skip it with "Mark Done" if you are ok with its defaults).
The "Welcome" window offers many options to start, including "Walkthroughs - Learn the Fundamentals":
- Choose "Clone Git Repository..."
- Type:
https://github.com/felipe-iar/iar-vscode-cmake-ubuntu.git
. - Click
Select as Repository Destination
to clone it to your home folder. Open
the cloned repository.
Tip
Optionally you can use the aforementioned repository as a template to create your own. For more information refer to Creating a repository from a template.
- VSCode will offer to "Install the recommended extensions from Microsoft and IAR for this repository". Click
Install
:
Once the extensions are downloaded, you will see them in the Extensions panel:
- Press CtrlShift` to open a bash terminal inside VSCode.
- For installing the latest CMake follow the instructions provided at https://apt.kitware.com.
Tip
Alternatively, for installing the distribution-provided version, use sudo apt install cmake
.
sudo apt update
sudo apt install -y ninja-build
ninja --version
- Invoke the palette (CTRLSHIFTP).
- Perform CMake: Configure.
- Select BXARM from the drop-down list.
- Invoke the palette
- Perform CMake: Build.
Output:
[main] Building folder: iar-vscode-cmake-ubuntu
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/felipeto/iar-vscode-cmake-ubuntu/build --config Debug --target all --
[build] [1/2 50% :: 0.039] Building C object CMakeFiles/hello.dir/main.o
[build] [2/2 100% :: 0.101] Linking C executable hello.elf
[driver] Build completed: 00:00:00.144
[build] Build finished with exit code 0
Once the executable was built:
- Select the Run & Debug panel (CTRLSHIFTD).
- Select which configuration to use in the drop-down selector (defaults to
IAR C-SPY Simulator
)
- In
main.c
, click on the left curb of the line which increments the counter (++counter;
) to set a breakpoint. - Go to Run → Start Debugging (F5) to start the debugging session.
Note
The IAR C-SPY I-jet launch configuration comes ready for the STM32F4-Discovery board as an example. For customization, refer to the IAR C-SPY Debug extension documentation.