CAN Board: A STM32G4 based CAN communication Node

CAN Board: A STM32G4 based CAN communication Node

CAN Board consists of a STM32G473CBT6 coupled with a CAN FD transceiver. The board is expandable with the help of various connectors. The main purpose of the board is to facilitate CAN communication by four wire: CAN_H, CAN_L, GND, BUS Voltage. Bus Voltage can range from 12V-36V as the board has a built-in regulator which regulates required voltage to the microcontroller and peripherals.

For our autonomous go-kart, we wanted to have multiple independent nodes that could communicate with each other without much disruption when some nodes are lost. We wanted our system to be robust enough combat failures if there were to appear any. We searched our available market for boards that could provide us with these features but were unable to find a suitable one. So I decided to build one myself.

Part selection was very tricky for us. I had to order everything from overseas and I needed to make everything right on one go. This was challenging because of our low budget and high import prices.

I wanted a cheap microcontroller that could support CAN FD, I was not bound to the STM ecosystem but availability was our key aspect when selecting the product. After much market analysis and price comparison, I decided to go with STM32G4 series chip. It has a lot of timers, three CAN-FD bus, and plenty of peripheral support. It only had one problem which was the tiny 128kb of EPROM.

This was a problem because I wanted to have some graphical display attached to some node and graphical visuals take some good amount of memory. The next thing was I wanted to run micro-python so that it would be easy to prototype with different sensors.

I quickly ditched the micro-python route when I discovered Zephyr RTOS. I had used FREERTOS previously and moving to zephyr made a lot of sense. Writing drivers was very easy. It had great industry and community support. Best of all it had native CANOpen support, which meant it was very easy to get started with CAN communication. So I decided to go ahead with the STM32G473CBT6.

I started to design the board in Altium Designer, thanks to its educational license it was free to use and evaluate. Above is a 3d rendered model of our board in Altium Designer.

As I went along with the design guidelines provided by ST for STM32G4 series boards, one particular difficulty was in oscillator choice. I chose a bypass oscillator rather than a crystal. The main difference is that oscillator produces the clock signal by itself(active device) and the microcontroller is able to read that signal through a single pin. Crystal on the other hand are passive components, need matching capacitors and resonate to their fundamental frequency. Two pins are needed to probe the input and output of the oscillator circuit and provide necessary feedback to maintain oscillation.

After completing the design in Altium I ordered the parts through Digikey and PCB through JLCPCB.

The boards were of good quality and with the parts arrived I started to work on assembling the board. I did not have a heat plate so I had to get creative here. I cut the excess stencil and put the board on top. Concentrated heat is not good for any PCB. I put the PCB on top of the stencil and heated the stencil warming up the board then heating the components from top which is illustrated in the video.

0:00
/1:33

After the assembly I wrote a quick code to test the built-in led of the chip, which was a success.

0:00
/0:11

Later I wrote a simple CAN program to transmit data which was viewed in an oscilloscope.

I started to port Zephyr RTOS to this custom board and could run all the example programs.

GitHub - krishbin/magic_carpet_zephyr
Contribute to krishbin/magic_carpet_zephyr development by creating an account on GitHub.

We also needed a USB to CAN bus adapter, STM32G473CBT can also be used as a USB slave device. I ported the candlelight firmware to our boards.

GitHub - krishbin/cannode_fw: Firmware derivate from candlelight_fw and budgetcan_fw for cannode based on STM32G473xB.
Firmware derivate from candlelight_fw and budgetcan_fw for cannode based on STM32G473xB. - krishbin/cannode_fw

Overall, this was a great success for me, as this was the first board I had designed.