Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI
on:
push:
paths:
- '.github/workflows/build.yml'
- 'diff/**'

jobs:
build:
name: Build
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Install PlatformIO
run: |
curl -fsSL -o get-platformio.py https://raw.githubusercontent.com/platformio/platformio-core-installer/master/get-platformio.py
python3 get-platformio.py
rm get-platformio.py
echo $PATH
mkdir -p ~/.local/bin
ln -s ~/.platformio/penv/bin/platformio ~/.local/bin/platformio
ln -s ~/.platformio/penv/bin/pio ~/.local/bin/pio
ln -s ~/.platformio/penv/bin/piodebuggdb ~/.local/bin/piodebuggdb
- name: Pre-build to fetch sources
run: |
# Build but ignore failure, will install pre-requisites
pio run -e teensy36 || true
pio run -e teensy41 || true
- name: Patch Teensy/Arduino Source
run: |
# Arduino
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
# Teensy3.6
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff
# Teensy4.1
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff
- name: Build for Teensy 3.1
run: |
pio run -e teensy31
- name: Build for Teensy 3.6
run: |
pio run -e teensy36
- name: Build for Teensy 4.1
run: |
pio run -e teensy41
- name: Prepare firmware folder
run: |
mkdir build
cp .pio/build/teensy31/firmware.hex build/teensy31_firmware.hex
cp .pio/build/teensy36/firmware.hex build/teensy36_firmware.hex
cp .pio/build/teensy41/firmware.hex build/teensy41_firmware.hex
- name: Upload Teensy Firmware
uses: actions/upload-artifact@v3
with:
name: teensy_firmware
path: build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
# PlatformIO installer
get-platformio.py
254 changes: 74 additions & 180 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,204 +8,98 @@ Supports:

Right now the backend uses raw hid reports for debug communication, terminal.py will open an interactive terminal to the device.

### How to flash to the teensy board:
### Building

Pre-requisites:

- [Install PlatformIO](https://docs.platformio.org/en/latest/core/installation/index.html)

###### Pre-build

Build all of the platforms you need. It will fetch source and dependencies but
will fail! After this first attempt at building, the patches listed below need
to be applied.

```sh
pio run -e teensy41 --target upload
pio run -e teensy31 --target upload
pio run -e teensy36 --target upload
pio run -e teensy41
pio run -e teensy31
pio run -e teensy36
```

### Modifications required to teensy 3.1 codebase:

For this to work you need to modify the teensy source code to set the RAWHID iInterface field to 2 to use the product string around line 1136 in `~/.platformio/packages/framework-arduinoteensy/cores/teensy3/usb_desc.c`

```c
#ifdef RAWHID_INTERFACE
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
RAWHID_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
2, // bNumEndpoints
0x03, // bInterfaceClass (0x03 = HID)
0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol
2, // iInterface <-------------------Modify this!
###### Patching Arduino Source

Required for all teensy versions.

```sh
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
```

`usb_desc.h`
```c
// Add the following to the usb definitions section after USB_EVERYTHING
#elif defined(USB_RAWHID_TRIPLESERIAL)
#define VENDOR_ID 0x16C0
#define PRODUCT_ID 0x048C
#define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF
#define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
#define MANUFACTURER_NAME_LEN 11
#define PRODUCT_NAME {'C','M','S','I','S','-','D','A','P'}
#define PRODUCT_NAME_LEN 9
#define EP0_SIZE 64
#define NUM_ENDPOINTS 12
#define NUM_USB_BUFFERS 32
#define NUM_INTERFACE 7
#define CDC_IAD_DESCRIPTOR 1 // Serial
#define CDC_STATUS_INTERFACE 0
#define CDC_DATA_INTERFACE 1
#define CDC_ACM_ENDPOINT 2
#define CDC_RX_ENDPOINT 3
#define CDC_TX_ENDPOINT 4
#define CDC_ACM_SIZE 16
#define CDC_RX_SIZE 64
#define CDC_TX_SIZE 64
#define CDC2_STATUS_INTERFACE 2 // SerialUSB1
#define CDC2_DATA_INTERFACE 3
#define CDC2_ACM_ENDPOINT 5
#define CDC2_RX_ENDPOINT 6
#define CDC2_TX_ENDPOINT 7
#define CDC2_ACM_SIZE 16
#define CDC2_RX_SIZE 64
#define CDC2_TX_SIZE 64
#define CDC3_STATUS_INTERFACE 4 // SerialUSB2
#define CDC3_DATA_INTERFACE 5
#define CDC3_ACM_ENDPOINT 8
#define CDC3_RX_ENDPOINT 9
#define CDC3_TX_ENDPOINT 10
#define CDC3_ACM_SIZE 16
#define CDC3_RX_SIZE 64
#define CDC3_TX_SIZE 64
#define RAWHID_INTERFACE 6 // RawHID
#define RAWHID_TX_ENDPOINT 11
#define RAWHID_TX_SIZE 64
#define RAWHID_TX_INTERVAL 1
#define RAWHID_RX_ENDPOINT 12
#define RAWHID_RX_SIZE 64
#define RAWHID_RX_INTERVAL 1
#define ENDPOINT2_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_ONLY
#define ENDPOINT4_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT5_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_ONLY
#define ENDPOINT7_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT8_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_ONLY
#define ENDPOINT10_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT11_CONFIG ENDPOINT_TRANSMIT_ONLY
#define ENDPOINT12_CONFIG ENDPOINT_RECEIVE_ONLY
###### Patching Teensy3 Source

```sh
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.c.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_desc.h.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/usb_inst.cpp.diff
patch -d ~/.platformio/ -p0 < diff/teensy3/yield.cpp.diff
```

###### Patching Teensy4 Source

`yeld.cpp`
```c
// Need to add USB_RAWHID_TRIPLESERIAL wherever USB_TRIPLE_SERIAL is.
defined(USB_TRIPLE_SERIAL) || defined(USB_RAWHID_TRIPLESERIAL)
```sh
patch -d ~/.platformio/ -p0 < diff/arduino.py.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.c.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_desc.h.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/usb_inst.cpp.diff
patch -d ~/.platformio/ -p0 < diff/teensy4/yield.cpp.diff
```

`usb_inst.cpp`
```c
// Add defined(USB_RAWHID_TRIPLESERIAL) to
defined(USB_SERIAL) || defined(USB_DUAL_SERIAL) ||....
###### Build again

Now all the builds should succeed.

```sh
pio run -e teensy41
pio run -e teensy31
pio run -e teensy36
```

`./platforms/teensy/builder/frameworks/arduino.py`
```c
// Add USB_RAWHID_TRIPLESERIAL
// to the section
BUILTIN_USB_FLAGS = (
### Flashing to Teensy

Flash to whatever teensy hardware you have attached.

```sh
pio run -e teensy41 --target upload
pio run -e teensy31 --target upload
pio run -e teensy36 --target upload
```

### EC Serial

### Modifications required for teensy 4.1
For this to work you need to modify the teensy source code to set the RAWHID iInterface field to 2 to use the product string
--------------------------------------
Around line 1191 in `~/.platformio/packages/framework-arduinoteensy/cores/teensy4/usb_desc.c`
```c
#ifdef RAWHID_INTERFACE
// configuration for 480 Mbit/sec speed
// interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12
9, // bLength
4, // bDescriptorType
RAWHID_INTERFACE, // bInterfaceNumber
0, // bAlternateSetting
2, // bNumEndpoints
0x03, // bInterfaceClass (0x03 = HID)
0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol
2, // iInterface
```sh
# For example with tio
tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if04

# Or picocom/minicom/screen
picocom /dev/ttyACM2 -b 115200
```

### Flashing EC firmware

Run the script for your target platform

`usb_desc.h`
```c
#elif defined(USB_RAWHID_TRIPLESERIAL)
#define VENDOR_ID 0x16C0
#define PRODUCT_ID 0x048C
#define RAWHID_USAGE_PAGE 0xFFAB // recommended: 0xFF00 to 0xFFFF
#define RAWHID_USAGE 0x0200 // recommended: 0x0100 to 0xFFFF
#define MANUFACTURER_NAME {'T','e','e','n','s','y','d','u','i','n','o'}
#define MANUFACTURER_NAME_LEN 11
#define PRODUCT_NAME {'T','r','i','p','l','e',' ','S','e','r','i','a','l'}
#define PRODUCT_NAME_LEN 13
#define EP0_SIZE 64
#define NUM_ENDPOINTS 9
#define NUM_INTERFACE 7
#define CDC_IAD_DESCRIPTOR 1 // Serial
#define CDC_STATUS_INTERFACE 0
#define CDC_DATA_INTERFACE 1
#define CDC_ACM_ENDPOINT 2
#define CDC_RX_ENDPOINT 3
#define CDC_TX_ENDPOINT 3
#define CDC_ACM_SIZE 16
#define CDC_RX_SIZE_480 512
#define CDC_TX_SIZE_480 512
#define CDC_RX_SIZE_12 64
#define CDC_TX_SIZE_12 64
#define SEREMU_TX_SIZE 64
#define CDC2_STATUS_INTERFACE 2 // SerialUSB1
#define CDC2_DATA_INTERFACE 3
#define CDC2_ACM_ENDPOINT 4
#define CDC2_RX_ENDPOINT 5
#define CDC2_TX_ENDPOINT 5
#define CDC3_STATUS_INTERFACE 4 // SerialUSB2
#define CDC3_DATA_INTERFACE 5
#define CDC3_ACM_ENDPOINT 6
#define CDC3_RX_ENDPOINT 7
#define CDC3_TX_ENDPOINT 7
#define RAWHID_INTERFACE 6 // RawHID
#define RAWHID_TX_ENDPOINT 8
#define RAWHID_TX_SIZE 64
#define RAWHID_TX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed
#define RAWHID_RX_ENDPOINT 9
#define RAWHID_RX_SIZE 64
#define RAWHID_RX_INTERVAL 1 // TODO: is this ok for 480 Mbit speed
#define ENDPOINT2_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
#define ENDPOINT3_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
#define ENDPOINT4_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
#define ENDPOINT5_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
#define ENDPOINT6_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
#define ENDPOINT7_CONFIG ENDPOINT_RECEIVE_BULK + ENDPOINT_TRANSMIT_BULK
/* for raw hid */
#define ENDPOINT8_CONFIG ENDPOINT_RECEIVE_UNUSED + ENDPOINT_TRANSMIT_INTERRUPT
#define ENDPOINT9_CONFIG ENDPOINT_RECEIVE_INTERRUPT + ENDPOINT_TRANSMIT_UNUSED
```sh
./scripts/flash_tgl_ec.sh
./scripts/flash_adl_ec.sh
```

### Teensy Control Serial

Only for advanced usage, you can probably ignore this.

`./platforms/teensy/builder/frameworks/arduino.py`
```c
// Add USB_RAWHID_TRIPLESERIAL
// to the section
BUILTIN_USB_FLAGS = (
```
```sh
# For example with tio
tio /dev/serial/by-id/usb-Framework_CMSIS-DAP_13993040-if00

# Or picocom/minicom/screen
picocom /dev/ttyACM0 -b 115200
```
10 changes: 10 additions & 0 deletions diff/arduino.py.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:06:57.115267304 +0800
+++ platforms/teensy/builder/frameworks/arduino.py 2023-12-11 17:07:13.059123524 +0800
@@ -41,6 +41,7 @@
"USB_SERIAL",
"USB_DUAL_SERIAL",
"USB_TRIPLE_SERIAL",
+ "USB_RAWHID_TRIPLESERIAL",
"USB_KEYBOARDONLY",
"USB_TOUCHSCREEN",
"USB_HID_TOUCHSCREEN",
11 changes: 11 additions & 0 deletions diff/teensy3/usb_desc.c.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:29.574251846 +0800
+++ packages/framework-arduinoteensy/cores/teensy3/usb_desc.c 2023-12-11 17:01:36.194190540 +0800
@@ -1133,7 +1133,7 @@
0x03, // bInterfaceClass (0x03 = HID)
0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol
- 0, // iInterface
+ 2, // iInterface <-------------------Change this from 0 to 2!
// HID interface descriptor, HID 1.11 spec, section 6.2.1
9, // bLength
0x21, // bDescriptorType
Loading