Skip to content

Commit

Permalink
Configuration / composition
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Apr 3, 2024
1 parent b724126 commit b25d12e
Show file tree
Hide file tree
Showing 39 changed files with 638 additions and 3,439 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/arduino-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ jobs:
include:
- board: STMicroelectronics:stm32:Nucleo_32
board_options: pnum=NUCLEO_G431KB
- board: STMicroelectronics:stm32:Nucleo_32
board_options: pnum=NUCLEO_L432KC
- board: STMicroelectronics:stm32:Nucleo_64
board_options: pnum=NUCLEO_G071RB
- board: STMicroelectronics:stm32:Nucleo_64
board_options: pnum=NUCLEO_G474RE
- board: STMicroelectronics:stm32:GenF1
board_options: pnum=BLACKPILL_F103C8
- board: STMicroelectronics:stm32:GenF4
board_options: pnum=BLACKPILL_F401CC
- board: esp32:esp32:esp32s3
board_options: ''

Expand All @@ -35,9 +29,6 @@ jobs:
- name: Install ESP32 core
run: arduino-cli core install esp32:esp32 --additional-urls 'https://espressif.github.io/arduino-esp32/package_esp32_index.json'
if: ${{ startsWith(matrix.board, 'esp32') }}
- name: Build ProtocolAnalyzer
if: ${{ ! startsWith(matrix.board, 'esp32') }}
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} --board-options "${{ matrix.board_options }}" examples/ProtocolAnalyzer/ProtocolAnalyzer.ino
- name: Build ListCapabilities
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} --board-options "${{ matrix.board_options }}" examples/ListCapabilities/ListCapabilities.ino
- name: Build TriggerBoard
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/pio-builds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
- name: Install PlatformIO Core
run: pip install --upgrade platformio

- name: Build ProtocolAnalyzer
run: pio run
working-directory: ./dev/ProtocolAnalyzer

- name: Build ListCapabilities
run: pio run
working-directory: ./dev/ListCapabilities
Expand Down
29 changes: 2 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# USB Power Delivery for Arduino

Implement a USB PD protocol analyzer, a USB PD trigger board or a more sophisticated power sink using a few additional components and simple Arduino code. Supports several STM32 microcontrollers.

Depending on the microcontroller, a comparator and a few resistors are needed, or just the resistors or no additional component at all. See below for more details. For 5 USD in parts, you can build a USB PD protocol analyzer.
Implement a USB PD trigger board or a more sophisticated power sink using simple Arduino code. Supports STM32 microcontrollers with UCPD peripheral and ESP32 microcontrollers with an external FUSB302 PD controller.



## Supported Boards

| Board | Required additional components |
| - | - |
| Blue Pill (STM32F103C8) | Dual comparator, several resistors |
| Black Pill (STM32F401CC) | Dual comparator, several resistors |
| Nucleo-L432KC | Several resistors (for power sink) or none (for protocol analyzer) |
| Nucleo-G071RB | None |
| Nucleo-G431KB | None |
| Nucleo-G474RE | None |
| ESP32 | FUSB302 USB PD controller |

All boards require an additional USB C connector as the standard connector is not ready for USB Power Delivery (no USB C connector, CC1/CC2 signals not available, voltage regular cannot handle more than 5V).
For the Nucelo boards in Nucleo-64 form factor, the X-NUCLEO-SNK1M1 shield can be used.
Expand All @@ -37,27 +33,6 @@ See the Wiki for how to wire the board and the additional components.

## Examples

### Protocol Analyzer

The protocol analyzer can be connected between two USB PD devices to monitor the USB PD communication.

```c++
#include "USBPowerDelivery.h"

void setup() {
Serial.begin(115200);
PowerController.startMonitor();
}

void loop() {
PDProtocolAnalyzer.poll();
}
```

See the Wiki for details regarding the required components and wiring.



### Trigger Board

The trigger boards communicates with a USB power supply and requests a different voltage than the initial 5V.
Expand Down
32 changes: 0 additions & 32 deletions dev/ListCapabilities/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,6 @@ build_flags =
-Wall
-Wextra

[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
build_flags =
${env.build_flags}
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D HAL_PCD_MODULE_ENABLED
-D USBD_VID=0xCAFE
-D USBD_PID=0xDEAD
-D USB_MANUFACTURER_STRING="\"Codecrete\""
-D USB_PRODUCT_STRING="\"USB PD Capabilities\""

[env:blackpill_f401cc]
platform = ststm32
board = blackpill_f401cc
debug_tool = stlink
build_flags =
${env.build_flags}
-Wno-unused-parameter
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D HAL_PCD_MODULE_ENABLED
-D USBD_VID=0xCAFE
-D USBD_PID=0xDEAD
-D USB_MANUFACTURER_STRING="\"Codecrete\""
-D USB_PRODUCT_STRING="\"USB PD Capabilities\""

[env:nucleo_g071rb]
platform = ststm32
board = nucleo_g071rb
Expand Down
27 changes: 22 additions & 5 deletions dev/ListCapabilities/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@
#include <Wire.h>
#include "USBPowerDelivery.h"

#if defined(ARDUINO_ARCH_ESP32)

typedef PDPhyFUSB302 PDPhy;

#elif defined(ARDUINO_ARCH_STM32)

#if defined(STM32G0xx) || defined(STM32G4xx)
typedef PDPhySTM32UCPD PDPhy;
#endif

#endif


static void handleEvent(PDSinkEventType eventType);
static void listCapabilities();
static const char* getSupplyTypeName(PDSupplyType type);

static PDPhy pdPhy;
static PDController<PDPhy> powerController(&pdPhy);
static PDSink<PDController<PDPhy>> sink(&powerController);

void setup() {
Serial.begin(115200);
while (!Serial)
Expand All @@ -28,28 +45,28 @@ void setup() {
Wire.begin(SDA, SCL, 1000000);
#endif

PowerSink.start(handleEvent);
sink.start(handleEvent);

#if defined(SNK1M1_SHIELD)
NucleoSNK1MK1.init();
#endif
}

void loop() {
PowerSink.poll();
sink.poll();
}

void handleEvent(PDSinkEventType eventType) {
if (eventType == PDSinkEventType::sourceCapabilitiesChanged && PowerSink.isConnected())
if (eventType == PDSinkEventType::sourceCapabilitiesChanged && sink.isConnected())
listCapabilities();
}

void listCapabilities() {
Serial.println("USB PD capabilities:");
Serial.println("__Type_________Vmin____Vmax____Imax");

for (int i = 0; i < PowerSink.numSourceCapabilities; i += 1) {
auto cap = PowerSink.sourceCapabilities[i];
for (int i = 0; i < sink.numSourceCapabilities; i += 1) {
auto cap = sink.sourceCapabilities[i];
Serial.printf(" %-9s %6d %6d %6d", getSupplyTypeName(cap.supplyType), cap.minVoltage, cap.maxVoltage, cap.maxCurrent);
Serial.println();
}
Expand Down
5 changes: 0 additions & 5 deletions dev/ProtocolAnalyzer/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions dev/ProtocolAnalyzer/.vscode/extensions.json

This file was deleted.

58 changes: 0 additions & 58 deletions dev/ProtocolAnalyzer/platformio.ini

This file was deleted.

31 changes: 0 additions & 31 deletions dev/ProtocolAnalyzer/src/main.cpp

This file was deleted.

41 changes: 7 additions & 34 deletions dev/VoltageChange/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,6 @@ build_flags =
-Wall
-Wextra

[env:nucleo_l432kc]
platform = ststm32
board = nucleo_l432kc

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
build_flags =
${env.build_flags}
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D HAL_PCD_MODULE_ENABLED
-D USBD_VID=0xCAFE
-D USBD_PID=0xDEAD
-D USB_MANUFACTURER_STRING="\"Codecrete\""
-D USB_PRODUCT_STRING="\"Voltage Switcher\""

[env:blackpill_f401cc]
platform = ststm32
board = blackpill_f401cc
debug_tool = stlink
build_flags =
${env.build_flags}
-Wno-unused-parameter
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D USBCON
-D HAL_PCD_MODULE_ENABLED
-D USBD_VID=0xCAFE
-D USBD_PID=0xDEAD
-D USB_MANUFACTURER_STRING="\"Codecrete\""
-D USB_PRODUCT_STRING="\"Voltage Switcher\""

[env:nucleo_g071rb]
platform = ststm32
board = nucleo_g071rb
Expand Down Expand Up @@ -71,10 +39,15 @@ build_flags =
[env:esp32-s3-devkitc-1]
platform = espressif32
board = esp32-s3-devkitc-1
build_flags =
-D PD_DEBUG
lib_deps =
${common.lib_deps_pd}
Wire
upload_protocol = esp-builtin
debug_tool = esp-builtin

[env:esp32-c3-devkitc-02]
platform = espressif32
board = esp32-c3-devkitc-02
lib_deps =
${common.lib_deps_pd}
Wire
Loading

0 comments on commit b25d12e

Please sign in to comment.