Skip to content

Commit

Permalink
usb-pd commands and fork link
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Dec 14, 2020
1 parent 356ec70 commit a8dcd4e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 664 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Canapé - gets CAN the party started!

The Canapé is a USB-C CAN interface. It is a variant of the open source [candleLight](https://github.com/HubertD/candleLight) platform and its many spawns. Not only does it add USB-C, it brings new features and USB-PD for powering devices under test.
The Canapé is a USB-C CAN interface. It is a variant of the open source [candleLight](https://github.com/HubertD/candleLight) platform and its many spawns. Not only does it add USB-C, it brings new features and CAN/USB controlled USB-PD for powering devices under test.

## Features

Expand Down Expand Up @@ -107,13 +107,36 @@ The 4 bit DIP switch sets unique runtime settings when in the 'ON' position; for
| 3 | 4 | Enable VBUS -> VBS always not just when USB-PD profile valid. |
| 4 | 8 | Enable 120 ohm CAN_H/CAN_L termination resistor |

**NOTE** both DFU and 'Enable VBUS' will require power cycling the device for the change to be reflected.

## USB Power Delivery (USB-PD)

__TODO setup commands__
The on-board USB-C controller (STUSB4500) is configured for 5 V / 1A power delivery by default (PDO 2). One can configure the controller using the below CAN bus commands when using the [**candleLight_fw**](https://github.com/tuna-f1sh/candleLight_fw) fork and with the [internal CAN IDs switch](#dip-switches) set.

These commands are scrapped from the recieved gs_usb Tx commands and will not be forwarded to the CAN bus when the switch is set. Ensure the DLC is 8 bytes, the ID is correct and byte seven is the Canapé key '0xAF'.

The commands are also scrapped from the `can_recieved` callback but for this to work a USB connection must be enumerated and CAN bus setup in order for the CAN perphieral to be enabled with the correct bit-timing. In the future I may save the previous bit-timing to flash in order to enable this without USB connection.


| ID | Cmd | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Action |
|-------|--------------|------|------------|------------|-----------|-----------|-----------|-----------|------|-------------------------------------------------------------------------|
| 0x010 | VBUS EN | 0x01 | NVM (bool) | SET (bool) | 0x00 | 0x00 | 0x00 | 0x00 | 0xAF | Set VBUS always enable (NVM) or try to enable VBUS by setting profile 1 |
| 0x010 | Set PDO | 0x02 | NVM (bool) | PROFILE | VOLTAGE_L | VOLTAGE_H | CURRENT_L | CURRENT_H | 0xAF | Set power delivery profile number (1-3) voltage (mV) and current (mA) |
| 0x010 | Set Profiles | 0x03 | NVM (bool) | PROFILES | 0x00 | 0x00 | 0x00 | 0x00 | 0xAF | Set number of profile in use (1-3) |
| 0x010 | Set VBUS | 0x04 | VOLTAGE_L | VOLTAGE_H | 0x00 | 0x00 | 0x00 | 0x00 | 0xAF | Request voltage on VBUS (volatile) |
| 0x010 | Get RDO | 0x05 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0x00 | 0xAF | Get enumerated profile number |

### Usage Notes

* NVM flag will write to the NVM rather than volatile register. If a write is required, the **STUSB4500 will be soft reset** in order to re-enumerate the USB-PD profiles. The LEDs will flash rapidly 20 times when a NVM flash occurs. The volatile settings will also trigger a soft reset in order to re-enumerate. **A soft reset will mean the CAN network will need re-creating on the host**.
* The NVM VBUS enable is the only concrete way to force VBUS; the volatile method attempts to enumerate a 5 V power delivery profile but this may not work with non-compliant devices.
* When profile 2 is enumerated, the orange 'PD-OK' will illuminate. This can be changed to profile 3 with the solder link on the underside of the board.
* Refer to the [STUSB4500 programming guide](https://www.st.com/resource/en/user_manual/dm00664189-the-stusb4500-software-programing-guide-stmicroelectronics.pdf) for more information.
* **Excerise caution** configuring these and ideally use a USB-PD checker/multimeter to verify your configuration prior to powering a device!

## Firmware

* [**candleLight_fw**](https://github.com/tuna-f1sh/candleLight_fw) - [[BIN DOWNLOAD]](./bin/canape_fw.bin): Default firmware shipping with Canapé. Works with [Linux SocketCAN](#linux-socketcan) and the [Cangaroo](#cangaroo-gui) GUI. Includes support for configuration of the on-board STUSB4500 USB-C controller and DFU without setting DIP switch.
* [**candleLight_fw Canapé fork**](https://github.com/tuna-f1sh/candleLight_fw) - [[BIN DOWNLOAD]](./bin/canape_fw.bin): Default firmware shipping with Canapé. Works with [Linux SocketCAN](#linux-socketcan) and the [Cangaroo](#cangaroo-gui) GUI. Includes support for configuration of the on-board STUSB4500 USB-C controller and DFU without setting DIP switch.
* [**PCAN CANtact**](https://github.com/tuna-f1sh/pcan_cantact/tree/hsi48) - [[BIN DOWNLOAD]](./bin/pcan_canape_hw.bin): Open source PCAN compatible firmware; works like a PCAN USB adaptor with the PCAN software suite and python-can module. Does not include USB-PD configuration or DFU.
* [**cantact_slcan**](https://github.com/normaldotcom/cantact-fw): slcand is a USART CAN daemon for Linux, which emulates a CAN network socket over USART. The pre-cursor of the candleLight_fw and gs_usb driver, it offers no real advantage since it is still over USB as a CDC. I've found it to drop frames at common bus rates and so do not recommend it. USART pins are exposed however if one wishes to play with slcan over physical USART. A virtual network interface can be created: `sudo slcand -o -s8 -t hw -S 3000000 /dev/ttyS0` and then used like a [SocketCAN](#linux-socketcan) interface.

Expand Down
Loading

0 comments on commit a8dcd4e

Please sign in to comment.