Skip to content

Commit 028227e

Browse files
committed
1.0.0
1 parent 8369117 commit 028227e

41 files changed

Lines changed: 2297 additions & 902 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Mkfile.old
5252
dkms.conf
5353

5454
USBvalve_out
55+
build

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "lib/pico-pio-usb"]
2+
path = lib/pico-pio-usb
3+
url = https://github.com/sekigon-gonnoc/Pico-PIO-USB.git
4+
[submodule "lib/xxhash"]
5+
path = lib/xxhash
6+
url = https://github.com/Cyan4973/xxHash.git

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
# Include the Pico SDK import helper
4+
include(pico_sdk_import.cmake)
5+
6+
project(USBvalve C CXX ASM)
7+
8+
set(CMAKE_C_STANDARD 11)
9+
set(CMAKE_CXX_STANDARD 17)
10+
11+
# Initialize the Pico SDK
12+
pico_sdk_init()
13+
14+
# Add pico-pio-usb library
15+
add_subdirectory(lib/pico-pio-usb)
16+
17+
# Add application
18+
add_subdirectory(src)

Dockerfile.pico1

Lines changed: 0 additions & 39 deletions
This file was deleted.

Dockerfile.pico2

Lines changed: 0 additions & 39 deletions
This file was deleted.

Dockerfile.sdk

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
# To Build:
3+
# docker build -t usbvalve-sdk -f Dockerfile.sdk .
4+
#
5+
# To Run (default: pico, SSD1306 OLED 128x32):
6+
# docker run --rm -v $PWD:/mnt usbvalve-sdk
7+
#
8+
# Options (via environment variables):
9+
# BOARD=pico|pico2 Board target (default: pico)
10+
# OLED_HEIGHT=32|64 OLED display height (default: 32)
11+
# PIWATCH=1 Use GC9A01 round TFT instead of SSD1306
12+
# USE_BOOTSEL=1 Enable BOOTSEL button (disrupts Low Speed USB)
13+
#
14+
# Examples:
15+
# docker run --rm -e BOARD=pico2 -v $PWD:/mnt usbvalve-sdk
16+
# docker run --rm -e PIWATCH=1 -v $PWD:/mnt usbvalve-sdk
17+
# docker run --rm -e BOARD=pico2 -e OLED_HEIGHT=64 -v $PWD:/mnt usbvalve-sdk
18+
#
19+
20+
FROM ubuntu:22.04
21+
WORKDIR /app
22+
23+
# OS setup + ARM toolchain + CMake
24+
RUN apt-get update -y \
25+
&& apt-get install -y git cmake gcc-arm-none-eabi libnewlib-arm-none-eabi \
26+
build-essential libstdc++-arm-none-eabi-newlib python3 \
27+
&& apt-get autoremove -y \
28+
&& apt-get clean \
29+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
30+
31+
# Clone Pico SDK
32+
RUN cd /app \
33+
&& git clone --depth 1 https://github.com/raspberrypi/pico-sdk.git \
34+
&& cd pico-sdk \
35+
&& git submodule update --init
36+
37+
ENV PICO_SDK_PATH=/app/pico-sdk
38+
39+
# Build script
40+
RUN echo '#!/bin/bash' > /app/entrypoint.sh \
41+
&& echo 'set -e' >> /app/entrypoint.sh \
42+
&& echo 'BOARD="${BOARD:-pico}"' >> /app/entrypoint.sh \
43+
&& echo 'if [ -d /mnt/USBvalve-sdk ]; then cd /mnt/USBvalve-sdk; elif [ -f /mnt/src/main.c ]; then cd /mnt; else echo "Error: mount the repo root or USBvalve-sdk dir to /mnt"; exit 1; fi' >> /app/entrypoint.sh \
44+
&& echo 'rm -rf build && mkdir build && cd build' >> /app/entrypoint.sh \
45+
&& echo 'CMAKE_ARGS="-DPICO_BOARD=$BOARD"' >> /app/entrypoint.sh \
46+
&& echo '[ -n "$OLED_HEIGHT" ] && CMAKE_ARGS="$CMAKE_ARGS -DOLED_HEIGHT=$OLED_HEIGHT"' >> /app/entrypoint.sh \
47+
&& echo '[ -n "$PIWATCH" ] && CMAKE_ARGS="$CMAKE_ARGS -DPIWATCH=$PIWATCH"' >> /app/entrypoint.sh \
48+
&& echo '[ -n "$USE_BOOTSEL" ] && CMAKE_ARGS="$CMAKE_ARGS -DUSE_BOOTSEL=$USE_BOOTSEL"' >> /app/entrypoint.sh \
49+
&& echo 'echo "Building for $BOARD with: $CMAKE_ARGS"' >> /app/entrypoint.sh \
50+
&& echo 'cmake $CMAKE_ARGS ..' >> /app/entrypoint.sh \
51+
&& echo 'make -j$(nproc)' >> /app/entrypoint.sh \
52+
&& echo 'SUFFIX="$BOARD"' >> /app/entrypoint.sh \
53+
&& echo '[ -n "$PIWATCH" ] && SUFFIX="${SUFFIX}-piwatch"' >> /app/entrypoint.sh \
54+
&& echo 'mkdir -p /mnt/USBvalve_out' >> /app/entrypoint.sh \
55+
&& echo 'cp src/USBvalve.uf2 /mnt/USBvalve_out/USBvalve-sdk-${SUFFIX}.uf2' >> /app/entrypoint.sh \
56+
&& echo 'echo "Build complete: USBvalve_out/USBvalve-sdk-${SUFFIX}.uf2"' >> /app/entrypoint.sh \
57+
&& chmod +x /app/entrypoint.sh
58+
59+
ENTRYPOINT ["/app/entrypoint.sh"]

README.md

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<h1><img width="300" alt="logo, landscape, dark text, transparent background" src="https://github.com/cecio/USBvalve/blob/main/pictures/USBvalve_logo_scaled.png"></a></h1>
22

3+
> [!NOTE]
4+
> **USBvalve Version 1.0.0**
5+
> A complete rewrite of the application has been done:
6+
> - moved away from Arduino IDE environment, now the code is written for the [Pi Pico SDK](https://github.com/raspberrypi/pico-sdk)
7+
> - dependencies on external libraries has been reduced a lot
8+
> - USB host support for Low Speed devices is now more robust (ATTiny85, EvilCrow, etc)
9+
> - hardware and functionalities are almost unchanged, see the [notes](https://github.com/cecio/USBvalve#notes-about-bootsel-and-version--100) below for details
10+
311
### *Expose USB activity on the fly*
412

513
<p float="left">
@@ -42,11 +50,11 @@ This is also fully compatible with the [Waveshare RP2040-LCD-1.28](https://www.w
4250

4351
`docs`: documentation about the project, with a presentation where you can have a look to all the features
4452

45-
`firmware`: pre-built firmware for the Raspberry Pi Pico. You can just use these and flash them on the board. I prepared the two versions for 32 and 64 OLED versions
53+
`firmware`: pre-built firmwares for the Raspberry Pi Pico. You can just use these and flash them on the board. We have several different versions, for 32 or 64 lines OLEDs, for Pico 1 or Pico2, Pi Pico Watch, etc
4654

4755
`PCB`: Gerber file if you want to print the custom PCB . It's not mandatory, you can use your own or build it on a breadboard
4856

49-
`USBvalve`: sources, if you want to modify and build the firmware by yourself
57+
`src` and `data`: sources, if you want to modify and build the firmware yourself
5058

5159
`utils`: some utilities you may use to build a custom FS
5260

@@ -60,11 +68,25 @@ This is also fully compatible with the [Waveshare RP2040-LCD-1.28](https://www.w
6068

6169
If you want to build your own, you need:
6270

63-
- A Raspberry Pi Pico 1 or 2 (or another RP2040 based board, like Arduino Nano RP2040)
64-
- an I2C OLED screen 128x64 or 128x32 (SSD1306)
71+
- A Raspberry Pi Pico 1 or 2 (or another RP2040 based board)
72+
- an I2C OLED screen 128x64 or 128x32 (**SSD1306**)
6573
- (optional) a **USBvalve** PCB or a breadboard
6674
- (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
6775

76+
### Notes about BOOTSEL and version >= 1.0.0
77+
78+
In the `0.x.x` versions, BOOTSEL was used to reset the device or print the number of HID events (press > 2s).
79+
The polling of BOOTSEL was creating some issues to the *BADUSB* detection so this was removed from version `1.0.0` and replaced with the following two options:
80+
- solder a button between `GP0` and `GND` (pads 1 and 3, see pic below to see an example) to have the same functions
81+
- use the commands `r` (reset) and `h` (HID events) from the serial monitor
82+
83+
<img src="https://github.com/cecio/USBvalve/blob/main/pictures/reset_button.jpg" width="35%" height="35%" />
84+
85+
~~In `PCB` you'll find also a version `1.3` of the board, with some holes on pads 1 and 3 to facilitate the mount of the button. But as you can see, you can also use your old version~~. (still waiting the new printed PCB to test it before publishing)
86+
87+
If you are not using the *BADUSB* functions or if you prefer to have less coverage on detection but keep BOOTSEL usage, I'm also providing a firmware created with *bootsel* enabled (see folder and releases).
88+
89+
6890
### Building instructions
6991

7092
> 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.
@@ -165,10 +187,10 @@ It's done!
165187

166188
I don't know if it will ever be the case, but you may want to customize the firmware in order to avoid detection done by *USBvalve-aware* malware :-)
167189

168-
I grouped most of the variables you may want to modify in this section ([see Dockerfile below for rebuilding](https://github.com/cecio/USBvalve#dockerfile))
190+
I grouped most of the variables you may want to modify in this section of `usb_config.h` ([see Dockerfile below for rebuilding](https://github.com/cecio/USBvalve#dockerfile))
169191

170192
```C
171-
// Anti-Detection settings.
193+
// USB anti-detection settings
172194
//
173195
// Set USB IDs strings and numbers, to avoid possible detections.
174196
// Remember that you can cusotmize FAKE_DISK_BLOCK_NUM as well
@@ -179,39 +201,55 @@ I grouped most of the variables you may want to modify in this section ([see Doc
179201
// Example:
180202
// 0x0951 0x16D5 VENDORID_STR: Kingston PRODUCTID_STR: DataTraveler
181203
//
182-
#define USB_VENDORID 0x0951 // This override the Pi Pico default 0x2E8A
183-
#define USB_PRODUCTID 0x16D5 // This override the Pi Pico default 0x000A
184-
#define USB_DESCRIPTOR "DataTraveler" // This override the Pi Pico default "Pico"
185-
#define USB_MANUF "Kingston" // This override the Pi Pico default "Raspberry Pi"
186-
#define USB_SERIAL "123456789A" // This override the Pi Pico default. Disabled by default. \
187-
// See "setSerialDescriptor" in setup() if needed
188-
#define USB_VENDORID_STR "Kingston" // Up to 8 chars
189-
#define USB_PRODUCTID_STR "DataTraveler" // Up to 16 chars
190-
#define USB_VERSION_STR "1.0" // Up to 4 chars
204+
#define USB_VENDORID 0x0951
205+
#define USB_PRODUCTID 0x16D5
206+
#define USB_DESCRIPTOR "DataTraveler"
207+
#define USB_MANUF "Kingston"
208+
#define USB_SERIAL "123456789A"
209+
#define USB_VENDORID_STR "Kingston" // Up to 8 chars
210+
#define USB_PRODUCTID_STR "DataTraveler" // Up to 16 chars
211+
#define USB_VERSION_STR "1.0" // Up to 4 chars
191212
```
192213
193214
194215
### Building your firmware
195216
196-
Obviously you can also build your own firmware. To build the *standard* one I used:
197-
198-
- Arduino IDE `2.3.4`
199-
- `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`
200-
- `Adafruit_SSD1306` OLED library version `2.5.14`
217+
Obviously you can also build your own firmware. To build you need the *Raspberry Pi Pico SDK* and this repoository.
201218
202-
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).
219+
Basic recompile instructions:
220+
```
221+
export PICO_SDK_PATH=</path/to/pico-sdk>
222+
mkdir build && cd build
223+
cmake -DPICO_BOARD=pico .. # or pico2 for standard build
224+
make -j$(nproc)
225+
# Output: build/src/USBvalve.uf2
226+
```
203227

204228
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.
205229

206230
#### Dockerfile
207231

208-
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.
232+
If you want to build your own firmware, after you customized it, I provide a `Dockerfile` which builds a complete building environment and compile the firmware.
209233

210-
Enter the following commands in the main `USBvalve` folder to build for Pico `v1`:
234+
Enter the following commands in the main `USBvalve` folder to build:
211235

212236
```
213-
docker build -t usbvalve-pico1/arduino-cli -f Dockerfile.pico1 .
214-
docker run --rm --name usbvalve -v $PWD:/mnt usbvalve-pico1/arduino-cli /mnt/USBvalve
237+
# To Build:
238+
# docker build -t usbvalve-sdk -f Dockerfile.sdk .
239+
#
240+
# To Run (default: pico, SSD1306 OLED 128x32):
241+
# docker run --rm -v $PWD:/mnt usbvalve-sdk
242+
#
243+
# Options (via environment variables):
244+
# BOARD=pico|pico2 Board target (default: pico)
245+
# OLED_HEIGHT=32|64 OLED display height (default: 32)
246+
# PIWATCH=1 Use GC9A01 round TFT instead of SSD1306
247+
# USE_BOOTSEL=1 Enable BOOTSEL button (disrupts Low Speed USB)
248+
#
249+
# Examples:
250+
# docker run --rm -e BOARD=pico2 -v $PWD:/mnt usbvalve-sdk
251+
# docker run --rm -e PIWATCH=1 -v $PWD:/mnt usbvalve-sdk
252+
# docker run --rm -e BOARD=pico2 -e OLED_HEIGHT=64 -v $PWD:/mnt usbvalve-sdk
215253
```
216254

217255
The firmware will be placed with extension `uf2` in folder `USBvalve_out`.

0 commit comments

Comments
 (0)