Skip to content

gbdve/zephyr_can_counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.. zephyr:code-sample:: can-counter
   :name: Controller Area Network (CAN) counter
   :relevant-api: can_controller

   Send and receive CAN messages.

Overview

This sample demonstrates how to use the Controller Area Network (CAN) API. Messages with standard and extended identifiers are sent over the bus. Messages are received using message-queues and work-queues. Reception is indicated by blinking the LED (if present) and output of received counter values to the console.

Repository-specific changes

This repository is based on the official Zephyr samples/drivers/can/counter sample and adds support for CAN-FD operation on the STM32 NUCLEO-C562RE.

The following changes have been introduced:

  • Added CAN-FD mode support by enabling CAN_MODE_FD during controller initialization.
  • Modified the transmitted frame to use CAN-FD with Bit Rate Switching (BRS) by setting the CAN_FRAME_FDF and CAN_FRAME_BRS flags.
  • Added a board-specific overlay for the STM32 NUCLEO-C562RE to:
    • enable the FDCAN peripheral;
    • configure the required pin multiplexing;
    • configure the FDCAN kernel clock to 100 MHz.

The default board clock configuration does not allow the automatic timing calculation required for a 5 Mbps CAN-FD data phase. The provided overlay configures the FDCAN kernel clock to 100 MHz, allowing reliable operation with:

  • Nominal (arbitration) bitrate: 1 Mbps
  • Data bitrate (BRS): 5 Mbps

Building and Running

In loopback mode, the board receives its own messages. This could be used for standalone testing.

The LED output pin is defined in the board's devicetree.

The sample can be built and executed for boards with a SoC that have an integrated CAN controller or for boards with a SoC that has been augmented with a stand alone CAN controller.

Integrated CAN controller

For the NXP TWR-KE18F board:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/can/counter
   :board: twr_ke18f
   :goals: build flash

Stand alone CAN controller

For the nrf52dk/nrf52832 board combined with the DFRobot CAN bus V2.0 shield that provides the MCP2515 CAN controller:

.. zephyr-app-commands::
   :zephyr-app: samples/drivers/can/counter
   :board: nrf52dk/nrf52832
   :shield: dfrobot_can_bus_v2_0
   :goals: build flash

Sample output

Change LED filter ID: 0
Finished init.
Counter filter id: 4

uart:~$ Counter received: 0
Counter received: 1
Counter received: 2
Counter received: 3

Note

The values shown above might differ.

STM32 NUCLEO-C562RE

The CAN-FD configuration has been verified using two STM32 NUCLEO-C562RE boards connected through their onboard CAN-FD transceivers.

The board overlay included in this repository configures the FDCAN kernel clock to 100 MHz, allowing reliable communication at 1 Mbps nominal bitrate and 5 Mbps data bitrate.

About

Adaptation of the Zephyr CAN counter sample for the STM32 NUCLEO-C562RE with full CAN-FD support (1 Mbps nominal, 5 Mbps data), including the board overlay for the required FDCAN clock configuration (100 MHz kernel clock).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors