Open search

CAN Newsletter magazine

Open-source CANopen protocol stack extended

CANopennode is a free and open-source CANopen protocol stack available on Github. Recently, it was extended by a CANopen stack example running on STM32 micro-controllers.

(Source: Adobe Stock)

The complete article is published in the June issue of the CAN Newsletter magazine 2022. This is just an excerpt.

CANopennode is written in Ansi-C in an object-oriented way. It runs on different micro-controllers, as standalone application, or with RTOS (real-time operating system). Variables for CANopen network communication, for CANopen device control, or customer-defined functions are collected in the CANopen object dictionary. These variables are accessible from the C-code and from the CANopen network. The object dictionary editor tool is available. Non-volatile storage for object dictionary or other variables is possible. The software stack is suitable for 16-bit micro-controllers and above. The software is multi-threaded and real-time capable. Power saving and bootloader functions are enabled as well. Currently, the version 4 of the protocol stack is available.

Available features

The provided CANopen object dictionary offers a clear and flexible organization of any variables. Variables can be accessed directly or via read/write functions. The NMT (network management) functionality enables to start, stop, and reset a CANopen device using the simple NMT manager functionality. To monitor the device’s availability in the network, the heartbeat producer and consumer error control is included. PDO (process data object) function block can be used for broadcasting process data with high priority and no protocol overhead. Variables from the object dictionary can be dynamically mapped into the TPDO (transmit PDO), which is then transmitted according to communication rules as specified in CiA 301 CANopen application layer and communication profile (EN 50325-4). This data is received as RPDO (receive PDO) by another device(s).

The SDO (service data object) server functionality, which has to be obligatory implemented in a CANopen device, enables expedited, segmented, and block transfer access to all object dictionary variables inside of this device. An SDO client can access any object dictionary variable on any CANopen device inside the CANopen network. A CANopen device can implement the emergency message producer function. Devices, which have to be informed on emerging failures, implement the emergency consumer function. The provided Sync producer/consumer enables network synchronized transmission, receipt, and processing of exchanged process data, etc.

STM32cube IDE tool is the official ST development studio for any STM32 microcontroller (Source: ST Microelectronics)

The time-stamp producer/consumer enables date and time synchronization of the networked devices. In addition to the basic CANopen functionality as covered by CiA 301, the LSS (layer setting service) implementation is given to setup the device’s node-ID and bit rate. The LSS server and LSS manager functions as well as the LSS fastscan service are part of the open-source protocol stack. To access CANopen via TCP, a CANopen gateway implementation according to CiA 309-3 is given.

This provides an Ascii command interface for NMT manager, LSS manager, and SDO client. For communication in safety-relevant networks, the CANopen Safety module was developed. The functional safety communication based on CANopen is specified in EN 50325-5 (former CiA 304). The community providing the protocol stack claims that the implementation passed the CANopen conformance test using the CANopen conformance test tool. The tool is used to verify that CANopen devices are compliant with the CiA 301.

Protocol stack project modules

The CANopen protocol stack is the base for a CANopen device. It contains no device-specific code (drivers), which must be added separately for each target system. An example (CANopendemo) shows the basic principles, compiles on any system, but does not connect to any CAN hardware. CANopendemo includes a demo program, tutorial, and testing tools. It is based on CANopennode and is included as a git sub-module. CANopeneditor is an external GUI (graphical user interface) tool for editing the CANopen object dictionary for a custom device. It generates the CANopennode C source-code files, electronic data sheet (EDS), and documentation for the device. The tool imports and exports the CANopen electronic data sheets in EDS or XDD (XML device description) format.

If you would like to read the full article, you can download it free of charge or you download the entire magazine.


Publish date

CAN Newsletter June 2022
ST Microelectronics