Skip to content

Repository files navigation

ClearCore CMake Template

This repository is a starter template for building a Teknic ClearCore application with CMake on Windows.

It is designed to work with both Visual Studio Code and Visual Studio, while still using the ClearCore Arduino package, the Arduino toolchain, and Teknic's wrapper libraries behind the scenes. The template gives you a standard CMake project structure so you can configure, build, and generate firmware outside the Arduino IDE.

What This Template Provides

  • A minimal ClearCore application entry point in src/main.cpp
  • A CMake build that targets the ClearCore ARM toolchain
  • Support for generating .bin and .uf2 firmware outputs
  • CMake presets for Debug and Release builds
  • A PowerShell init script that replaces the placeholder project name throughout the template

Requirements

This template is Windows only.

You need the following installed before you can configure or build the project:

  • Arduino IDE
  • Teknic ClearCore Arduino wrapper/package
  • CMake 3.25 or newer
  • Ninja

By default, CMake looks for Arduino packages under %LOCALAPPDATA%\Arduino15\packages. It expects the ClearCore package at ClearCore\hardware\sam\<version> within that directory and automatically selects the newest installed numeric version. It also finds the matching Arduino CMSIS installation under arduino\tools\CMSIS\<version>.

If your packages are installed elsewhere, set the ARDUINO_PACKAGES_ROOT CMake cache variable to the directory that contains the ClearCore and arduino package folders. To select a specific installed version instead of the newest one, set CLEARCORE_VERSION and/or CMSIS_VERSION.

Arduino IDE comes with a bundled GCC. You will need to add this to your path. It should be located in C:\Users\USERNAME\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin

Project Layout

  • CMakeLists.txt: Main CMake build file for the ClearCore firmware target
  • CMakePresets.json: Default Debug and Release configure/build presets
  • cmake/arm-none-eabi-toolchain.cmake: Cross-compilation toolchain configuration
  • cmake/FindArduinoPackages.cmake: Finds the required packages from your Arduino IDE installation
  • src/main.cpp: Minimal example firmware entry point
  • init-project.ps1: PowerShell script that initializes the template project
  • .github/workflows/ci.yml: A GitHub Actions workflow that builds the project

Getting Started

  1. Install the requirements listed above.
  2. Clone or copy this template into a new project folder.
  3. Run the init script to replace the placeholder project name.
  4. Configure the project with CMake using one of the provided presets.
  5. Build the firmware from your editor or from the command line.

Using The Init Script

The template uses @PROJECT_NAME@ as a placeholder in the CMake and text files. Run the init script once to replace that placeholder with your real project name.

.\init-project.ps1 -Name MyClearCoreProject

The script updates the template files in place and prints a confirmation message when it finishes. After that, the project name will be used in the generated target name and firmware outputs.

Notes:

  • Use the exact project name you want to appear in the build artifacts.
  • The script only updates text-based template files in the repository.
  • You can delete init-project.ps1 after initialization if you do not need it anymore.

Building

The included presets are:

  • clearcore-debug
  • clearcore-release

Example build flow:

cmake --preset clearcore-debug
cmake --build --preset clearcore-debug

The build produces an ELF file and, after the post-build step runs, matching .bin and .uf2 firmware files in the build directory.

Flashing the firmware

  1. Connect the ClearCore to your PC using its USB port. The ClearCore should also have its normal DC power connected.
  2. Double-press the RESET button on the ClearCore to enter the UF2 bootloader. Windows should mount a removable drive named CLEAR_BOOT
  3. Copy the .uf2 file from the output directory onto the CLEAR_BOOT drive.

Notes

  • src/main.cpp is only a starting point. Replace it with your actual application code.
  • The Arduino-style setup() and loop() functions are declared with C linkage so the ClearCore runtime can call them.
  • When adding more files, remember to add them to the list of files in the main executable definition in CMakeLists.txt
  • If you move the ClearCore package, CMSIS, or UF2 builder, update the CMake cache variables accordingly.
  • If you want to continue using the included CI workflow, remove the step that runs the init script.

License

This template is licensed under the MIT No Attribution License (MIT-0).

Projects created from this template may be used under any license, including proprietary licenses. You are not required to retain this template's copyright notice or license in generated projects.

About

Teknic ClearCore CMake starter template for building and flashing firmware on Windows. Works with VSCode and Visual Studio.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages