Back to selected work

Selected work

USB CAN FD adapter with SD card logging

Firmware and a .NET library to connect up to two CAN FD buses to a PC and record traffic on an SD card. A development-kit prototype allowed communication and logging to be verified before subsequent custom hardware development.

Development for Oakrey s.r.o. · my role: firmware and .NET client library

This case study describes the prototype solution as delivered at that stage of the project. It does not reflect the current design or technical state of Oakrey s.r.o.'s product.

Application
Testing and diagnostics of CAN devices
Hardware
NXP LPCXpresso54618 (LPC54618J512, Cortex-M4F)
Scope
Firmware + .NET client library
Focus
CAN FD, USB, FreeRTOS and SD logging
System diagram of the USB CAN FD adapter: a client application uses a .NET library to communicate over USB with an adapter connected to two CAN FD buses and an SD card.
System view of the main components and their connections. The client application uses a .NET library for configuration and CAN FD communication over USB; the adapter handles two buses and can store received traffic locally on an SD card.

Assignment

Oakrey needed a USB adapter prototype for communication between a PC and up to two CAN FD buses, with received traffic recorded on an SD card. My task was to develop the firmware and a .NET client library for controlling the adapter from a PC.

The company selected an NXP LPCXpresso54618 development kit with an LPC54618J512 microcontroller. The solution needed configuration of both CAN interfaces, message transmission and reception, and reporting of errors and bus states.

Technical implementation

Traffic reception had to run alongside SD-card writes, whose latency can vary. I based the firmware on FreeRTOS to separate CAN reception from slower storage operations and set task priorities.

  • CAN FDI built a CAN interface layer on top of the NXP SDK M_CAN driver, configuring filters and buffers, handling message transmission and reception, and processing both Classical CAN (CAN 2.0) and CAN FD frames. I integrated this layer with the rest of the firmware. During development, I found and corrected an RX FIFO handling defect in NXP SDK 2.7.0 that could cause receive interrupts to be lost.
  • Real-time processingSeparated the real-time CAN path from slower SD writes using dedicated FreeRTOS tasks, stream buffers and an asynchronous FatFs worker, minimising the effect of card latency on traffic reception.
  • LoggingRecorded received messages and error events to an SD card using FatFs, including exFAT support.
  • USBA CDC ACM interface for configuring both CAN channels and transferring messages and diagnostic information.
  • .NET libraryA .NET Framework client library with hardware integration and fuzz tests. Tests sent messages between both CAN interfaces connected to the same physical bus.

Result

I delivered the tested prototype firmware and .NET library. The development kit allowed a PC to configure the CAN interfaces, exchange messages, monitor bus states and record received traffic on an SD card.

This gave Oakrey a working foundation for developing its own hardware. Oakrey handled the firmware adaptation to that hardware independently.

A similar challenge

Are you developing an adapter, gateway or diagnostic device that needs reliable communication and logging?

Send me a short description of what you need to connect or verify.

Tomáš Vávra · independent engineer

tomas@vavrasystems.cz