This package manages Victrion VenusOs VeCan (aka CANbus) ports
As of Venus OS v2.90~18: The number of CANbus ports is unlimited GS USB CANbus interfaces will become active when plugged in or at system boot and automatically assigned to a can service (e.g. can3). The order of CANbus interaces detected on USB will determine the can service number. Use of VeCanSetup is OPTIONAL but provides some advantages: insures can service assignments are deterministic regardless of discovery order allows naming the interfaces in the Services menu to reduce confusion alows Raspberry PI CANbus hats to be configured allows slcan USB interfacs to be configured and used as a VE.Can interface note however that slcan interfaces are not recommended (see below)
The setup script's actions are:
Add (or modify) a port's configuraiton
supported interfaces:
CANable with Candelight firmware
Canberry Hat
PCAN-USB (which is also the Victron's CANUSB)
PiCan Hat
Waveshare Hat
Waveshare 2-channel Hat
Waveshare 2-channel FD Hat
slcan USB device (not recommended)
requires customizing parameters
Delete a port's configuration
Install the configured ports into the Venus file system
Uninstall/restore all Venus files installed by this package
leaving the system in a stock configuraiton
CANbus Hat boards (Raspberry PI only) Hat boards that plug onto the 40-pin header on a Raspberry PI 2, 3 or 4 presend unique challenges for the system designer. GPIO pins used by these interfaces may conflict with other uses such as Venus OS relays and digital inputs or other Hat boards. Some dual-channel CANbus Hat boards use a single SPI bus, while others (Waveshare dual-channel FD CANbus Hat) use two SPI buses. There seems to be no consistency for the selection of pins for chip select and interrupt GPIOs. For these reasons, VeCanSetup assumes only one Hat board in the system, regardless of type (CANbus or other). RaspberryPiGpioSetup provides alternate GPIO relay and digital input assignments to avoid conflicts ONLY with the Waveshare dual channel Hats (FD and non-FD versions). Other single-channel hats should work as long as they use GPIO 8 for it's chip select and GPIO 25 for its interrupt. More complex systems are beyond the scope of VeCanSetup.
WARNING: Interfaces based on slcan are not recommended: Packets are sometimes dropped especially with heavy CANbus loading Error recovery from bus errors such as a short may not occur Speeds for the CANbus can not be changed after the interface is brought up
USB interfaces using Candelight or other GS USB firmware are much more reliable and many low cost units are available.
CANable interfaces can even be reflashed to switch from slcan to Candelight.
The script also hooks into SetupHelper's boot-time reinstall mechanism which reinstalls Venus file system modifications after they are overwritten by a Venus OS update
Prior to Venus OS v2.90~18, only two VeCan ports (can0 and can 1) are defined. Built-in, USB and hat interfaces compete for these two ports Starting with v2.90~18, an unlimited number of CANbus interfaces may be configured.
Starting with v2.90~18, USB CANbus devices with GS USB firmware (e.g., Candelight) with no specific udev rules will automatically configure and become operational. These automatic configurations could conflict with each other. For example a USB interface may be assigned can0, blocking a CANbus hat channel assigned to can0 in the dtoverlay instructions. In addition, any built-in ports are assigned beginning with can0. These won't conflict with hat assignments since Raspberry PIs have no built-in ports.
In order to avoid conflicts with automaic configuration VeCanSetup assigns ports starting at can10 for USB interfaces. CANbus hats will be assigned to can8 and can9.
Note that the VeCanSetup setup script must be run from the command line to configure each CANbus port. Following that, VeCanSetup will reinstall without command line intervention.
As stated above, slcan-based interfaces should be avoided.
When a template is not available for a specific interface, this script helps this configuration by pulling information from system logs for inserted USB interfaces: Plug a USB slcan CANbus interface into the GX device. Select install, then add then select custom GS USB or slcan device. The system logs are scanned and any potential USB interfaces are reported one at a time. The user is prompted to use this informaiton, or reject it. The process repeats until there are no more entries found in the log. The user then has the option of entering device vendor and model IDs manually.
USB uniqueness: When multiple USB interfaces are installed, the system must be able to uniquely each one in order to connect an interface to one of the CANbus services.
This script builds udev rules that include a vendor ID, model/product ID and a serial number.
Not all parameters may be required for unique itendtification.
For example, if there is only one instance of for example a model ID, then the connections will be stable.
However, if two of the same devices are connected, their vendor and model IDs will be the same and
the system will need serial numbers for uniqueness
Serial numbers: Device serial numbers help with uniqueness. If used and the interface is replaced, you will need to run VeCanSetup again to update the serial number. Including the serial number is recommended only if you have multiple interfaces of the same make/model), Regardless of the choice of a preconfigured or custom interface, the script does it's best to determine the serial number of a device, by looking at system messages logged when a USB interface is plugged in.
A manual serial number entry is offered as a last resort.
Note: I have tested this package with CANable USB Pro interface running slcand, Candelight and PCAN firmware as well as the Waveshare dual-channel CANbus (non FD) Hat on a Raspberry PI 4.
The configurations for other interfaces were taken from the following link but have not been tested:
https://github.com/victronenergy/venus/wiki/RaspberryPi-CAN-Interfaces
Obviouslly, Hat interfaces only on Raspberry PI platforms.
Conflicts can sometimes occur when modifications to config.txt are needed. For this reason, this script asks before installing overlays into the config.txt file. If overlay lines are not automatically added to config.txt, it will be necessary for the installer to add the necessary lines manually.
As an aid to sorting out GPIO conflicts, I have provided a list of GPIO assignments in this package.
Installation:
VeCanSetup requires that SetupHelper is installed first.
The easiest way to install VeCanSetup is to do a "blind install" of SetupHelper and then add the VeCanSetup package via the PackageManager menus.
Refer to the SetupHelper ReadMe for instructions and for other install options: https://github.com/kwindrem/SetupHelper
Once both packages are installed run setup and follow the prompts. /data/VeCanSetup/setup