16 Commits

Author SHA1 Message Date
cecio
8369117d73 updated README 2025-05-31 22:00:14 +02:00
cecio
13422f4c8c bump to release 0.21.1 2025-05-31 21:51:57 +02:00
cecio
c1618bc201 bump to release 0.21.0 2025-02-02 16:27:37 +01:00
cecio
d756e20eb4 new HID count and freq adjustment 2025-02-02 16:25:26 +01:00
cecio
1387103199 adjusted versions and freq 2025-02-02 16:24:30 +01:00
cecio
f4e9ed918b updates 2024-12-22 22:34:12 +01:00
cecio
c551015cd7 added comment to PIWATCH 2024-12-22 22:26:48 +01:00
cecio
08e047811a bump to release 0.20.0 2024-12-22 22:13:53 +01:00
cecio
113158f9ad Update README.md 2024-11-27 21:55:22 +01:00
cecio
251db8f30d bump to release 0.19.1 2024-10-27 22:07:03 +01:00
cecio
384684bdf4 bump to release 0.19.0 2024-09-03 13:45:11 +02:00
LiPolymer
35f4a00326 Fix Document Mistake(#50) (#51)
* Add Notification for R7&R8 of USBPipe

* Document improvements
2024-08-04 12:53:44 +02:00
cecio
59815ce63d Update README.md 2024-07-19 00:27:25 +02:00
cecio
7aee69d8e1 Update README.md 2024-07-18 21:38:13 +02:00
cecio
64f44c1a1c update version 2024-07-07 12:31:05 +02:00
cecio
7cfedce646 bump to release 0.18.2 2024-07-07 12:23:07 +02:00
14 changed files with 121 additions and 24 deletions

View File

@@ -1,9 +1,9 @@
# #
# To Build: # To Build:
# docker build -t usbvalve/arduino-cli . # docker build -t usbvalve-pico1/arduino-cli -f Dockerfile.pico1 .
# #
# To Run: # To Run:
# docker run --rm --name usbvalve -v $PWD:/mnt usbvalve/arduino-cli /mnt/USBvalve # docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico1/arduino-cli /mnt/USBvalve
# #
FROM ubuntu:22.04 FROM ubuntu:22.04
@@ -23,17 +23,17 @@ RUN cd /app \
&& ./install.sh \ && ./install.sh \
&& export PATH=$PATH:/app/arduino-cli/bin \ && export PATH=$PATH:/app/arduino-cli/bin \
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core search 2040 \ && arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core search 2040 \
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040 \ && arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040@4.5.4 \
&& arduino-cli lib install "Adafruit TinyUSB Library" \ && arduino-cli lib install "Adafruit TinyUSB Library@3.6.0" \
&& arduino-cli lib install "Adafruit SSD1306" \ && arduino-cli lib install "Adafruit SSD1306@2.5.14" \
&& arduino-cli lib install "Pico PIO USB" \ && arduino-cli lib install "Pico PIO USB@0.7.2" \
&& arduino-cli lib install "XxHash_arduino" \ && arduino-cli lib install "XxHash_arduino@2.1.0" \
&& arduino-cli lib install "GFX Library for Arduino" && arduino-cli lib install "GFX Library for Arduino@1.6.0"
# Compilation setup # Compilation setup
RUN echo "#!/bin/bash" > /app/entrypoint.sh \ RUN echo "#!/bin/bash" > /app/entrypoint.sh \
&& echo "export PATH=\$PATH:/app/arduino-cli/bin" >> /app/entrypoint.sh \ && echo "export PATH=\$PATH:/app/arduino-cli/bin" >> /app/entrypoint.sh \
&& echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico --board-options \"usbstack=tinyusb\" --board-options \"freq=120\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \ && echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico --build-property \"build.extra_flags=-DCFG_TUD_CDC=1\" --board-options \"usbstack=tinyusb\" --board-options \"freq=240\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
&& chmod +x /app/entrypoint.sh && chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"] ENTRYPOINT ["/app/entrypoint.sh"]

39
Dockerfile.pico2 Normal file
View File

@@ -0,0 +1,39 @@
#
# To Build:
# docker build -t usbvalve-pico2/arduino-cli -f Dockerfile.pico2 .
#
# To Run:
# docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico2/arduino-cli /mnt/USBvalve
#
FROM ubuntu:22.04
WORKDIR /app
# OS setup
RUN apt-get update -y \
&& apt-get install -y git wget python3 \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# arduino-cli setup
RUN cd /app \
&& git clone --recursive https://github.com/arduino/arduino-cli.git \
&& cd arduino-cli \
&& ./install.sh \
&& export PATH=$PATH:/app/arduino-cli/bin \
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core search 2040 \
&& arduino-cli --additional-urls https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json core install rp2040:rp2040@4.5.4 \
&& arduino-cli lib install "Adafruit TinyUSB Library@3.6.0" \
&& arduino-cli lib install "Adafruit SSD1306@2.5.14" \
&& arduino-cli lib install "Pico PIO USB@0.7.2" \
&& arduino-cli lib install "XxHash_arduino@2.1.0" \
&& arduino-cli lib install "GFX Library for Arduino@1.6.0"
# Compilation setup
RUN echo "#!/bin/bash" > /app/entrypoint.sh \
&& echo "export PATH=\$PATH:/app/arduino-cli/bin" >> /app/entrypoint.sh \
&& echo "arduino-cli compile --fqbn rp2040:rp2040:rpipico2 --build-property \"build.extra_flags=-DCFG_TUD_CDC=1\" --board-options \"usbstack=tinyusb\" --board-options \"freq=240\" --output-dir \"/mnt/USBvalve_out\" \"\$1\"" >> /app/entrypoint.sh \
&& chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]

Binary file not shown.

Binary file not shown.

View File

@@ -60,14 +60,14 @@ This is also fully compatible with the [Waveshare RP2040-LCD-1.28](https://www.w
If you want to build your own, you need: If you want to build your own, you need:
- A Raspberry Pi Pico (or another RP2040 based board, like Arduino Nano RP2040) - A Raspberry Pi Pico 1 or 2 (or another RP2040 based board, like Arduino Nano RP2040)
- an I2C OLED screen 128x64 or 128x32 - an I2C OLED screen 128x64 or 128x32 (SSD1306)
- (optional) a **USBvalve** PCB or a breadboard - (optional) a **USBvalve** PCB or a breadboard
- (optional) a 3D printed spacer to isolate the screen from the board (https://www.thingiverse.com/thing:4748043), but you can use a piece of electrical tape instead - (optional) a 3D printed spacer to isolate the screen from the board (https://www.thingiverse.com/thing:4748043), but you can use a piece of electrical tape instead
### Building instructions ### Building instructions
> Thanks to [Tz1rf](https://github.com/Tz1rf) we have a great [Video](https://youtu.be/7ymk8hD7-Hc) explaining the building process step-by-step. > Thanks to [Tz1rf](https://github.com/Tz1rf) we also have two great videos: one explaining the [building](https://youtu.be/7ymk8hD7-Hc) process step-by-step, and another showing how to [upload firmware](https://youtu.be/Tp8xvrlqxUY) and use the tool.
Almost all the job is done directly on the board by the software, so you just need to arrange the connection with the OLED for output. Almost all the job is done directly on the board by the software, so you just need to arrange the connection with the OLED for output.
@@ -133,15 +133,21 @@ If you want to use the DEBUG functions, you can also place a header on the 3 SWD
> This PCB is for experienced electronic makers > This PCB is for experienced electronic makers
> **DON'T USE IT IF YOU AREN'T SURE YOU CAN HANDLE IT!** > **DON'T USE IT IF YOU AREN'T SURE YOU CAN HANDLE IT!**
<img src="./pictures/USB_pipe_finished_oled.jpg" alt="USBpipe PCB"/> > [!NOTE]
> R7 and R8 aren't actually connected to anything. They are added for circuit debugging purposes.
> So they don't show up in the BOM
<img src="./pictures/USB_pipe_finished_oled.jpg" alt="USBpipe PCB" width="15%" height="15%"/>
<img src="./pictures/USB_pipe_using.jpg" alt="USBpipe" width="15%" height="15%"/>
[USBpipe](https://github.com/LiPolymer/smartUSBPipe) is a dedicated PCB for this project. [USBpipe](https://github.com/LiPolymer/smartUSBPipe) is a dedicated PCB for this project.
You can find everything you need in `./PCB/USBpipe/` folder. You can find everything you need in `./PCB/USBpipe/` folder.
<img src="./pictures/USB_pipe_front.png" alt="Front"/> <img src="./pictures/USB_pipe_front.png" alt="Front" width="20%" height="20%"/>
<img src="./pictures/USB_pipe_back.png" alt="Back"/> <img src="./pictures/USB_pipe_back.png" alt="Back" width="20%" height="20%"/>
### Flash Firmware ### Flash Firmware
@@ -189,19 +195,23 @@ I grouped most of the variables you may want to modify in this section ([see Doc
Obviously you can also build your own firmware. To build the *standard* one I used: Obviously you can also build your own firmware. To build the *standard* one I used:
- Arduino IDE `2.3.2` - Arduino IDE `2.3.4`
- `Adafruit TinyUSB Library` version `3.1.4`, `Pico-PIO-USB` version `0.5.2`, Board `Raspberry Pi RP2040 (3.8.1)` setting Tools=>CPU Speed at `120MHz` and Tools=>USB Stack to `Adafruit TinyUSB` - `Adafruit TinyUSB Library` version `3.6.0`, `Pico-PIO-USB` version `0.7.2`, Board `Raspberry Pi RP2040 (4.5.4)` setting Tools=>CPU Speed at `133MHz` and Tools=>USB Stack to `Adafruit TinyUSB`
- `Adafruit_SSD1306` OLED library version `2.5.10` - `Adafruit_SSD1306` OLED library version `2.5.14`
Remember to add `https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json` in the `Additional Board Manager URLs` to install the proper board. Also, starting from `TinyUSB` version `3.4.2` is necessary to force the following macro setting `DCFG_TUD_CDC=1`. I strongly suggest you to use the provided *Dockerfiles* (see below).
If you want to re-create a new fake filesystem, you may want to have a look to the `utils` folder, where I placed some utilities to build a new one. If you want to re-create a new fake filesystem, you may want to have a look to the `utils` folder, where I placed some utilities to build a new one.
#### Dockerfile #### Dockerfile
If you want to build your own firmware, after you customized it, I provide a `Dockerfile` which builds a complete **Arduino** environment and compile the firmware. Enter the following commands in the main `USBvalve` folder: If you want to build your own firmware, after you customized it, I provide a `Dockerfile` which builds a complete **Arduino** environment and compile the firmware. I added them for both `Pico` version 1 and 2.
Enter the following commands in the main `USBvalve` folder to build for Pico `v1`:
``` ```
docker build -t usbvalve/arduino-cli . docker build -t usbvalve-pico1/arduino-cli -f Dockerfile.pico1 .
docker run --rm --name usbvalve -v $PWD:/mnt usbvalve/arduino-cli /mnt/USBvalve docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico1/arduino-cli /mnt/USBvalve
``` ```
The firmware will be placed with extension `uf2` in folder `USBvalve_out`. The firmware will be placed with extension `uf2` in folder `USBvalve_out`.

View File

@@ -116,7 +116,7 @@ bool activeState = false;
// //
// USBvalve globals // USBvalve globals
// //
#define VERSION "USBvalve - 0.18.1" #define VERSION "USBvalve - 0.21.1"
boolean readme = false; boolean readme = false;
boolean autorun = false; boolean autorun = false;
boolean written = false; boolean written = false;
@@ -125,6 +125,9 @@ boolean written_reported = false;
boolean deleted_reported = false; boolean deleted_reported = false;
boolean hid_sent = false; boolean hid_sent = false;
boolean hid_reported = false; boolean hid_reported = false;
uint hid_event_num = 0;
static spin_lock_t *lock;
// //
// Anti-Detection settings. // Anti-Detection settings.
@@ -159,6 +162,9 @@ uint valid_hash = 2362816530;
// Core 0 Setup: will be used for the USB mass device functions // Core 0 Setup: will be used for the USB mass device functions
void setup() { void setup() {
// Initialize the spinlock
lock = spin_lock_instance(0);
// Change all the USB Pico settings // Change all the USB Pico settings
TinyUSBDevice.setID(USB_VENDORID, USB_PRODUCTID); TinyUSBDevice.setID(USB_VENDORID, USB_PRODUCTID);
TinyUSBDevice.setProductDescriptor(USB_DESCRIPTOR); TinyUSBDevice.setProductDescriptor(USB_DESCRIPTOR);
@@ -247,7 +253,12 @@ void setup() {
// Core 1 Setup: will be used for the USB host functions for BADUSB detector // Core 1 Setup: will be used for the USB host functions for BADUSB detector
void setup1() { void setup1() {
// Set a custom clock (multiple of 12Mhz) to achieve maximum compatibility for HID // Set a custom clock (multiple of 12Mhz) to achieve maximum compatibility for HID
// Differntiated between Pico 1 and Pico 2
#ifdef PICO_RP2350
set_sys_clock_khz(144000, true); set_sys_clock_khz(144000, true);
#elif defined PICO_RP2040
set_sys_clock_khz(240000, true);
#endif
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG; pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
pio_cfg.pin_dp = HOST_PIN_DP; pio_cfg.pin_dp = HOST_PIN_DP;
@@ -303,8 +314,22 @@ void loop() {
} }
if (BOOTSEL) { if (BOOTSEL) {
printout("\n[+] RESETTING"); uint32_t press_start = to_ms_since_boot(get_absolute_time());
swreset(); while (BOOTSEL) {
sleep_ms(10);
}
uint32_t press_end = to_ms_since_boot(get_absolute_time());
uint32_t press_duration = press_end - press_start;
if (press_duration > 2000) { // Press duration > 2sec
// Print the number of HID events detected so far
char outstr[22];
snprintf(outstr, 21, "\n[+] HID Evt# %d", hid_event_num);
printout(outstr);
} else {
printout("\n[+] RESETTING");
swreset();
}
} }
} }
@@ -537,6 +562,9 @@ static uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
// Invoked when device with hid interface is mounted // Invoked when device with hid interface is mounted
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) { void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
uint32_t lock_num = spin_lock_blocking(lock);
uint16_t vid, pid; uint16_t vid, pid;
const char* protocol_str[] = { "None", "Keyboard", "Mouse" }; const char* protocol_str[] = { "None", "Keyboard", "Mouse" };
@@ -557,20 +585,27 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
if (!tuh_hid_receive_report(dev_addr, instance)) { if (!tuh_hid_receive_report(dev_addr, instance)) {
SerialTinyUSB.printf("Error: cannot request to receive report\r\n"); SerialTinyUSB.printf("Error: cannot request to receive report\r\n");
} }
spin_unlock(lock, lock_num);
} }
// Invoked when device with hid interface is un-mounted // Invoked when device with hid interface is un-mounted
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) { void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
uint32_t lock_num = spin_lock_blocking(lock);
SerialTinyUSB.printf("HID device address = %d, instance = %d unmounted\r\n", dev_addr, instance); SerialTinyUSB.printf("HID device address = %d, instance = %d unmounted\r\n", dev_addr, instance);
// Reset HID sent flag // Reset HID sent flag
hid_sent = false; hid_sent = false;
hid_reported = false; hid_reported = false;
hid_event_num = 0;
spin_unlock(lock, lock_num);
} }
// Invoked when received report from device // Invoked when received report from device
void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) { void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) {
uint32_t lock_num = spin_lock_blocking(lock);
static bool kbd_printed = false; static bool kbd_printed = false;
static bool mouse_printed = false; static bool mouse_printed = false;
@@ -588,6 +623,7 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
mouse_printed = false; mouse_printed = false;
} }
process_kbd_report((hid_keyboard_report_t const*)report); process_kbd_report((hid_keyboard_report_t const*)report);
hid_event_num++;
break; break;
case HID_ITF_PROTOCOL_MOUSE: case HID_ITF_PROTOCOL_MOUSE:
@@ -597,17 +633,21 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
kbd_printed = false; kbd_printed = false;
} }
process_mouse_report((hid_mouse_report_t const*)report); process_mouse_report((hid_mouse_report_t const*)report);
hid_event_num++;
break; break;
default: default:
// Generic report: for the time being we use kbd for this as well // Generic report: for the time being we use kbd for this as well
process_kbd_report((hid_keyboard_report_t const*)report); process_kbd_report((hid_keyboard_report_t const*)report);
hid_event_num++;
break; break;
} }
if (!tuh_hid_receive_report(dev_addr, instance)) { if (!tuh_hid_receive_report(dev_addr, instance)) {
SerialTinyUSB.println("Error: cannot request to receive report"); SerialTinyUSB.println("Error: cannot request to receive report");
} }
spin_unlock(lock, lock_num);
} }
static inline bool find_key_in_report(hid_keyboard_report_t const* report, uint8_t keycode) { static inline bool find_key_in_report(hid_keyboard_report_t const* report, uint8_t keycode) {
@@ -727,24 +767,32 @@ void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
// Invoked when a device with MassStorage interface is mounted // Invoked when a device with MassStorage interface is mounted
void tuh_msc_mount_cb(uint8_t dev_addr) { void tuh_msc_mount_cb(uint8_t dev_addr) {
uint32_t lock_num = spin_lock_blocking(lock);
printout("\n[++] Mass Device"); printout("\n[++] Mass Device");
SerialTinyUSB.printf("Mass Device attached, address = %d\r\n", dev_addr); SerialTinyUSB.printf("Mass Device attached, address = %d\r\n", dev_addr);
spin_unlock(lock, lock_num);
} }
// Invoked when a device with MassStorage interface is unmounted // Invoked when a device with MassStorage interface is unmounted
void tuh_msc_umount_cb(uint8_t dev_addr) { void tuh_msc_umount_cb(uint8_t dev_addr) {
uint32_t lock_num = spin_lock_blocking(lock);
SerialTinyUSB.printf("Mass Device unmounted, address = %d\r\n", dev_addr); SerialTinyUSB.printf("Mass Device unmounted, address = %d\r\n", dev_addr);
spin_unlock(lock, lock_num);
} }
// Invoked when a device with CDC (Communication Device Class) interface is mounted // Invoked when a device with CDC (Communication Device Class) interface is mounted
void tuh_cdc_mount_cb(uint8_t idx) { void tuh_cdc_mount_cb(uint8_t idx) {
uint32_t lock_num = spin_lock_blocking(lock);
printout("\n[++] CDC Device"); printout("\n[++] CDC Device");
SerialTinyUSB.printf("CDC Device attached, idx = %d\r\n", idx); SerialTinyUSB.printf("CDC Device attached, idx = %d\r\n", idx);
spin_unlock(lock, lock_num);
} }
// Invoked when a device with CDC (Communication Device Class) interface is unmounted // Invoked when a device with CDC (Communication Device Class) interface is unmounted
void tuh_cdc_umount_cb(uint8_t idx) { void tuh_cdc_umount_cb(uint8_t idx) {
uint32_t lock_num = spin_lock_blocking(lock);
SerialTinyUSB.printf("CDC Device unmounted, idx = %d\r\n", idx); SerialTinyUSB.printf("CDC Device unmounted, idx = %d\r\n", idx);
spin_unlock(lock, lock_num);
} }
// END of OTHER Host devices detector section // END of OTHER Host devices detector section

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 MiB

After

Width:  |  Height:  |  Size: 408 KiB

BIN
pictures/USB_pipe_using.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 KiB