Skip to content

CANopen quickstart application for the STM32F446 to illustrate how the free CANopen Stack is used in your project.

Notifications You must be signed in to change notification settings

embedded-office/canopen-stm32f4xx

Repository files navigation

Repository Structure

+- cmake        : submodule referencing the repository 'cmake-scripts'
+- debug        : debugger configurations
+- dependencies : external managed components
+- src          : canopen example project
|  +- app       : application source code
|  +- config    : configuration of startup and HAL
|  +- driver    : canopen target specific drivers

CANopen Demo for STM32F4xx Microcontrollers

This project demonstrates the usage of the free CANopen Stack Project. The included application is the Quickstart - "CANopen clock application", described in detail at the project website.

We use the STM32Cube MCU Full Package for the STM32F4 series made by ST Microelectronics as the low-level foundation for the chip configuration, the startup, and the driver implementation. With some slight enhancements to match our CMake build environment, we provide a small source code package out of a forked repository for integration in our demo projects.

My hardware setup for this development and testing is:

The wiring is pretty simple. For your reference, see the essence in a small diagram:

Collection of relevant hardware information

For details, check:

Usage

Development Tools

Download and install these free tools for your system:

Note: on my Windows machine, I use the Ozone debugger with the free ST-Link Reflash Utility from Segger. The generated debug information in the ELF image should be suitable for all other debuggers, too.

Submodule: cmake-scripts

The basic collection of re-usable CMake scripts are placed as a Git submodule in the directory /cmake. The Git submodule is a reference to a specific commit hash of the Git repository cmake-scripts.

Small reminder: when cloning this repository you need to initialize and update the submodules:

# clone Git repository and initialize submodules:
$ git clone --recurse-submodules <repository>

# or, in case you have already cloned the Git repository:
$ git clone <repository>
$ cd <repository-directory>
$ git submodule update --init

Project dependencies

We use two extern managed components to build our target application. When using external projects it is important to define naming rules for exported CMake target names to eliminate name collisions.

For the example application in this repository we use:

  • Target stm32f4xx-hal - a fork of the STM32CubeF4 package with enhancements for usage with CMake
  • Target canopen-stack - the free CANopen Stack, provided by Embedded Office

Note: The used versions of the dependencies are defined in the directory /dependencies.

Build instructions

Just type in the project root directory:

# configure the project for debugging
$ cmake --preset debug

# build the application for your target
$ cmake --build ./build/debug

The target image file canopen-stm32f4xx.elf and the corresponding map file canopen-stm32f4xx.map are generated and placed in out/debug.

Load and Executing on target

For the Ozone debugger there is a basic debugger configuration debug/ozone.jdebug, which loads the image to the target and runs to function main().

  • power up your STM32F446 nucleo board
  • double-click the debugger configuration
  • watch the uploading and running to main ...

... and have fun playing with this tiny CANopen quickstart application :)

If you encounter any improvement in descriptions, project setup, build system, implementation or documentation, please rise an issue and help me to simplify the life of Embedded software engineers.