Skip to content

Cyphal application

PonomarevDA edited this page Mar 7, 2024 · 3 revisions

1. Hardware requirements

The following hardware are required:

Required device Example Image
1 Target device Mini v2 or Micro node drawing
2 Programmer, CAN-sniffer RL sniffer and programmer drawing

Actually the repository can be suitable for any RaccoonLab nodes with HW version v2 (it basically means a stm32f103 board with a few specific design rules), but it is primarily intended for RaccoonLab Mini v2 node.

2. Software requirements

You are expected to use the following software:

3. Design notes

3.1. Structure and dependencies

The project depends on a few libraries which are attached to the repository as submodules. The dependency graph can be illustrated as shown below:

drawing

A few notes:

  • Libs/stm32-cube-project is a project generated with the STM32CubeMX. It is based on .ioc file corresponded to the default firmware of the Mini v2 node. You may only need to change it if you want to use an a different peripheral configuration.
  • Src/libparams is a simple library with ROM driver implementation that allows to store configuration parameters in persistent memory.
  • Libs/Cyphal (cyphal_application) is a general-purpose application based on the Cyphal libcanard, o1heap and other libraries with minimal required features to start and some features related to UDRAL/DS015.

3.2. Makefile

The project is based on the CMake build system, but it is suggested to interract with Makefile. This is just a wrapper under CMake, useful for its autocompletion.

Check Makefile for additional commands and details.

The main commads are following:

1. Generate DSDL

Before first build you need to generate DSDL with:

make generate_dsdl

This command calls the script to generate C++ headers for Cyphal data types serialization using nunavut. The output goes into build/compile_output and build/nunavut_out folders. It is expected that you doesn't often change DSDL, so you typically need to call it only once.

2. Build an exacutable and run in SITL mode

make sitl_cyphal run

3. Build and upload a binary

To build a binary and upload it to the target, you can type:

make cyphal upload

The result binary will be built in automatically created build folder.

3.3. Pre-build step

When you run make cyphal before actual build process, a few additional source files are automatically generated into build/src such as:

3.4. Periphery

The periphery drivers are divided into 2 groups.

The drivers interfaces are represented by classes defined in header files in Src/periphery folder as shown below:

drawing

An actual implementation toy can find in source files in [Src/platform] folder. Depending in which mode you are building the application (SITL ubuntu or stm32f103) and the board type (mini v2 or a custom one) it uses different implementations:

  • stm32 implementations depend on STM32CubeMX generated HAL drivers (though it is not required and you can write your optimized implementation),
  • Ubuntu drivers implementations usually are just a mock drivers.

3.5. Modules

A module is a specific independant unit of an application functionality. It can be implemented in a different way, for example as RTOS task. But let's keep it baremetal for a while because typically (but not always) a Cyphal/DroneCAN application is simple and resource limited.

An example of modules for a minimal CAN-PWM application is shown below:

drawing

Typically, we recommend having at least CircuitStatus module that is responsible for internal status measurements including:

  • 5V (after DC-DC),
  • Vin (before DC-DC),
  • STM32 internal temperature,
  • Hardware version (from ADC_VERSION).

Some boards can have a current sensor and external temperature sensor or other ADC sensors.

Each module is expected to have a yaml file with his parameters.

3.6. Application entry point

After the peripheral initialization the application goes to the application_entry_point() in Src/cyphal_application/application.cpp. It is assumed that a user will provide a custom application here.

4. Running SITL mode

4.1. Clone the repo with submodules

git clone https://github.com/RaccoonlabDev/mini_v2_node --recursive
cd mini_v2_node
git submodule update --init --recursive

4.2. Build the project and upload the firmware

make generate_dsdl  # call once before the first build
make sitl_cyphal run

4.3. Setup the environment and run Yukon/Yukon

5. Building and uploading the provided application

5.1. Clone the repo with submodules

git clone https://github.com/RaccoonlabDev/mini_v2_node --recursive
cd mini_v2_node
git submodule update --init --recursive

5.2. Connect Sniffer and Programmer to Mini v2 node

An example of connection scheme suitable for bench test for Mini v2 node and RL Programmer-Sniffer is shown below:

drawing

You can also use other sniffer and programmers. For details refer to: Programmer usage and Sniffer usage pages.

5.3. Build the project and upload the firmware

make generate_dsdl  # call once before the first build
make cyphal
make upload  #  works only with RL sniffer-programmer yet

As a short form, you can build and upload the firmware with a single command:

make cyphal upload

5.4. Try Yakut

Yakut is well-supported cli tool to interract with a Cyphal node.

drawing

5.5. Try Yukon

Using Yukon you can visualize the node info and interface.

Configure the Yukon related environment variables using the command below (or use the official yukon/yakut instructions).

source scripts/init.sh
~/Download/Yukon
drawing

A few comments:

  • Blue window has the node info,
  • Green topics (port id: 7510, 7509, 2001) is what the node publish,
  • Red topics (port id = 2000) is what the node subscribes on,
  • Grey topics (435, 430, 385, 384) is related to RPC-services. The node can respond on node.ExecuteCommand, node.GetInfo, register.List and register.Access.

You can subscribe on topics by clicking on the related topics. Let's subscribe on CircuitStatus.

drawing

Please, refer to the Mini node docs. It has a detailed steps about how to perform bench testing of the node.

6. Customizing the application

The following steps assume that you are already successful with the default application provided in this repository and want to customize it.

6.1. Make a template or fork

Make a template or fork of the repository. Then clone it. Don't forget about the submodules.

git clone https://github.com/RaccoonlabDev/mini_v2_node --recursive
cd mini_v2_node
git submodule update --init --recursive

Here, instead of RaccoonlabDev you should type the name of your org or profile.

6.2. Modify periphery config

Mini v2 node has 6 user's pins. By default 4 of them are configured as PWM and 2 of them as UART RX. The pinout configuration is shown on the image below:

Pinout Default config
drawing drawing

If you want to use a custom periphery configuration, update the Libs/stm32-cube-project/project.ioc file with STM32CubeIDE or STM32CubeMX and regenerate the project.

Since Libs/stm32-cube-project is submodule, you can either use your own submodule (make a fork or template RaccoonLabHardware/mini-v2-software) or just remove the submodule and include the source code in the root repository.

6.3. Modify the application

The main application is started in Src/cyphal_application/application.cpp. By default it just blinks the RGB LED, subscribes to the setpoint topic to control PWM1 and publishes a feedback with the latest applied setpoint.

Note, that the application is as simple as possible: it controls only a single PWM and doesn't have safety features like TTL, but you are free to extend it as you want.

6.4. Add custom Cyphal-topics

You may consider Src/cyphal_application/setpoint and Src/cyphal_application/feedback as examples of Cyphal-subscriber and Cyphal-publisher. If you create subjects by inhereting from CyphalPublisher and CyphalSubscriber, it will automatically add all topics to the port.List array, so the node is able to advertise its capabilities. This approach doesn't automatically create registers, so you need to add them in yaml file as shown in the examples.

6.5. Add custom registers

Each Cyphal topics requires a pair of Integer (for port id) and String (for port type) registers.

This section is in progress. Please, check examples or libparams for the details.

When you add your custom module, don't forget to add source file and path to the file with registers to Src/cyphal_application/CMakeLists.txt.

You can also easily create custom Integer and String registers. An example is shown in Src/cyphal_application/params.yaml.

6.6. Build and upload

make cyphal upload