ch552: Add functionality to dynamically control USB endpoints

- Make it possible to enable and disable endpoints on demand
- Add internal FPGA<->CH552 communication channel (IO_CH552)
- Reorder IO endpoint numbering
- Rename endpoint from TKEYCTRL to DEBUG and update related variables
- Rename endpoint from HID to FIDO and update related variables
This commit is contained in:
Jonas Thörnblad 2025-03-24 16:00:41 +01:00 committed by Michael Cardell Widerkrantz
parent d94387a9e7
commit d43585ee1a
No known key found for this signature in database
GPG key ID: D3DB3DDF57E704E5
8 changed files with 453 additions and 365 deletions

View file

@ -63,10 +63,10 @@ Mode Protocol. It is used in both directions.
The different endpoints: The different endpoints:
| *Name* | *Value* | *Comment* | | *Name* | *Value* | *Comment* |
|--------|---------|---------------------------------------------------------------------| |--------|---------|----------------------------------------------------------------------|
| CTRL | 0x20 | A USB HID special debug pipe. Useful for debug prints. | | DEBUG | 0x20 | A USB HID special debug pipe. Useful for debug prints. |
| CDC | 0x40 | USB CDC-ACM, a serial port on the client. | | CDC | 0x40 | USB CDC-ACM, a serial port on the client. |
| HID | 0x80 | A USB HID security token device, useful for FIDO-type applications. | | FIDO | 0x80 | A USB FIDO security token device, useful for FIDO-type applications. |
On top of the USB Mode Protocol is [the TKey Framing On top of the USB Mode Protocol is [the TKey Framing
Protocol](https://dev.tillitis.se/protocol/) which is described in the Protocol](https://dev.tillitis.se/protocol/) which is described in the

View file

@ -53,8 +53,8 @@ if __name__ == "__main__":
"SerialDesc": "68de5d27-e223-4874-bc76-a54d6e84068f", "SerialDesc": "68de5d27-e223-4874-bc76-a54d6e84068f",
"CdcCtrlInterfaceDesc": "CDC-Ctrl", "CdcCtrlInterfaceDesc": "CDC-Ctrl",
"CdcDataInterfaceDesc": "CDC-Data", "CdcDataInterfaceDesc": "CDC-Data",
"FidoHidInterfaceDesc": "FIDO-HID", "FidoInterfaceDesc": "FIDO",
"TkeyCtrlInterfaceDesc": "TKEY-Ctrl" "DebugInterfaceDesc": "DEBUG"
} }
with open('inc/usb_strings.h', 'w') as f: with open('inc/usb_strings.h', 'w') as f:

View file

@ -195,8 +195,8 @@ Header file for CH554 microcontrollers.
#define USB_IDX_SERIAL_STR 0x03 #define USB_IDX_SERIAL_STR 0x03
#define USB_IDX_INTERFACE_CDC_CTRL_STR 0x04 #define USB_IDX_INTERFACE_CDC_CTRL_STR 0x04
#define USB_IDX_INTERFACE_CDC_DATA_STR 0x05 #define USB_IDX_INTERFACE_CDC_DATA_STR 0x05
#define USB_IDX_INTERFACE_FIDO_HID_STR 0x06 #define USB_IDX_INTERFACE_FIDO_STR 0x06
#define USB_IDX_INTERFACE_TKEY_CTRL_STR 0x07 #define USB_IDX_INTERFACE_DEBUG_STR 0x07
#endif #endif
#ifndef USB_DEVICE_ADDR #ifndef USB_DEVICE_ADDR

View file

@ -1,8 +1,8 @@
#ifndef __CONFIG_H__ #ifndef __CONFIG_H__
#define __CONFIG_H__ #define __CONFIG_H__
#define USE_DEBUG_PRINT /* Enable to print debug messages */ //#define USE_DEBUG_PRINT /* Enable to print debug messages */
#define DEBUG_PRINT_SW /* Enable to print debug messages via FPGA */ //#define DEBUG_PRINT_SW /* Enable to print debug messages via FPGA */
//#define DEBUG_PRINT_HW /* Enable to print debug messages via UART0 */ //#define DEBUG_PRINT_HW /* Enable to print debug messages via UART0 */
#define USE_NUM_U8 #define USE_NUM_U8

View file

@ -0,0 +1,18 @@
#ifndef __IO_H__
#define __IO_H__
enum ioend {
IO_NONE = 0x00, // No endpoint
IO_UART = 0x01, // Only destination, raw UART access
IO_QEMU = 0x02, // Only destination, QEMU debug port
IO_CH552 = 0x10, // Internal CH552 control port
IO_DEBUG = 0x20, // HID debug port
IO_CDC = 0x40, // CDC "serial port"
IO_FIDO = 0x80, // FIDO security token port
};
enum ch552cmd {
SET_ENDPOINTS = 0x01, // Config enabled/disabled USB endpoints on the CH552
};
#endif

View file

@ -46,19 +46,17 @@ unsigned char FLASH CdcDataInterfaceDesc[] = { // "CDC-Data"
'D', 0, 'a', 0, 't', 0, 'a', 0, 'D', 0, 'a', 0, 't', 0, 'a', 0,
}; };
unsigned char FLASH FidoHidInterfaceDesc[] = { // "FIDO-HID" unsigned char FLASH FidoInterfaceDesc[] = { // "FIDO"
18, // Length of this descriptor (in bytes) 10, // Length of this descriptor (in bytes)
0x03, // Descriptor type (String) 0x03, // Descriptor type (String)
'F', 0, 'I', 0, 'D', 0, 'O', 0, 'F', 0, 'I', 0, 'D', 0, 'O', 0,
'-', 0, 'H', 0, 'I', 0, 'D', 0,
}; };
unsigned char FLASH TkeyCtrlInterfaceDesc[] = { // "TKEY-Ctrl" unsigned char FLASH DebugInterfaceDesc[] = { // "DEBUG"
20, // Length of this descriptor (in bytes) 12, // Length of this descriptor (in bytes)
0x03, // Descriptor type (String) 0x03, // Descriptor type (String)
'T', 0, 'K', 0, 'E', 0, 'Y', 0, 'D', 0, 'E', 0, 'B', 0, 'U', 0,
'-', 0, 'C', 0, 't', 0, 'r', 0, 'G', 0,
'l', 0,
}; };
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -3,12 +3,11 @@
#include "config.h" #include "config.h"
#include "debug.h" #include "debug.h"
#include "io.h"
#include "lib.h" #include "lib.h"
#include "mem.h" #include "mem.h"
#include "print.h" #include "print.h"
#define MODE_CH552 0x10
void printStr(uint8_t *str) void printStr(uint8_t *str)
{ {
#ifdef USE_DEBUG_PRINT #ifdef USE_DEBUG_PRINT
@ -19,7 +18,7 @@ void printStr(uint8_t *str)
} }
#elif defined(DEBUG_PRINT_SW) #elif defined(DEBUG_PRINT_SW)
uint32_t str_len = strlen(str); uint32_t str_len = strlen(str);
CH554UART1SendByte(MODE_CH552); CH554UART1SendByte(IO_CH552);
CH554UART1SendByte(str_len); CH554UART1SendByte(str_len);
CH554UART1SendBuffer(str, str_len); CH554UART1SendBuffer(str, str_len);
#endif #endif
@ -34,7 +33,7 @@ void printChar(uint8_t c)
#if defined(DEBUG_PRINT_HW) #if defined(DEBUG_PRINT_HW)
CH554UART0SendByte(c); CH554UART0SendByte(c);
#elif defined(DEBUG_PRINT_SW) #elif defined(DEBUG_PRINT_SW)
CH554UART1SendByte(MODE_CH552); CH554UART1SendByte(IO_CH552);
CH554UART1SendByte(1); CH554UART1SendByte(1);
CH554UART1SendByte(c); CH554UART1SendByte(c);
#endif #endif