Skip to content

Commit

Permalink
Simplify G0/G4 pin configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Feb 5, 2024
1 parent 41c3b5f commit a9765e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/schema/library.json",
"name": "USBPowerDelivery",
"version": "1.0.4",
"version": "1.0.5",
"description": "USB Power Delivery for Arduino. Create a USB PD protocol analyzer, trigger board or power sink for no or only few additional components. Supports several STM32 boards.",
"keywords": "usb,usb-pd,usb-power-delivery,protocol-analyzer,trigger-board",
"homepage": "https://github.com/manuelbl/usb-pd-arduino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=USBPowerDelivery
version=1.0.4
version=1.0.5
author=Manuel Bl. <[email protected]>
maintainer=Manuel Bl. <[email protected]>
sentence=USB Power Delivery for Arduino.
Expand Down
24 changes: 12 additions & 12 deletions src/NucleoSNK1MK1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
void SNK1MK1Controller::init() {

#if defined(ARDUINO_NUCLEO_G474RE)
// Pin PB1: DB_OUT -> PIN_A9
// Pin PC10: VCC_OUT -> 16
pinMode(PIN_A9, OUTPUT);
digitalWrite(PIN_A9, HIGH);
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
// Pin PB1: DB_OUT
// Pin PC10: VCC_OUT
pinMode(PB1, OUTPUT);
digitalWrite(PB1, HIGH);
pinMode(PC10, OUTPUT);
digitalWrite(PC10, HIGH);
#elif defined(ARDUINO_NUCLEO_G071RB)
// Pin PB6: DB_OUT -> 46
// Pin PC10: VCC_OUT -> 16
pinMode(46, OUTPUT);
digitalWrite(46, HIGH);
pinMode(16, OUTPUT);
digitalWrite(16, HIGH);
// Pin PB6: DB_OUT
// Pin PC10: VCC_OUT
pinMode(PB6, OUTPUT);
digitalWrite(PB6, HIGH);
pinMode(PC10, OUTPUT);
digitalWrite(PC10, HIGH);
#endif
}

Expand Down
25 changes: 6 additions & 19 deletions src/PDPhySTM32UCPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,29 @@
// STM32G4 family: CC1 -> PB6, CC2 -> PB4
#define GPIO_CC1 GPIOB
#define PIN_CC1 LL_GPIO_PIN_6
#define ARDUINO_PIN_CC1 PB6
#define GPIO_CC2 GPIOB
#define PIN_CC2 LL_GPIO_PIN_4
#define ARDUINO_PIN_CC2 PB4
#define DMA_RX DMA1
#define DMA_CHANNEL_RX LL_DMA_CHANNEL_1
#define DMA_TX DMA1
#define DMA_CHANNEL_TX LL_DMA_CHANNEL_2
#define UCPD_IRQ UCPD1_IRQn

#if defined(ARDUINO_NUCLEO_G431KB)
#define PIN_CC1_ARDUINO D12
#define PIN_CC2_ARDUINO D6
#elif defined(ARDUINO_NUCLEO_G431RB) || defined(ARDUINO_NUCLEO_G474RE) || defined(ARDUINO_NUCLEO_G491RE)
#define PIN_CC1_ARDUINO D10
#define PIN_CC2_ARDUINO D5
#else
#endif

#elif defined(STM32G0xx)
// STM32G0 family: CC1 -> PA8, CC2 -> PB15
#define GPIO_CC1 GPIOA
#define PIN_CC1 LL_GPIO_PIN_8
#define ARDUINO_PIN_CC1 PA8
#define GPIO_CC2 GPIOB
#define PIN_CC2 LL_GPIO_PIN_15
#define ARDUINO_PIN_CC2 PB15
#define DMA_RX DMA1
#define DMA_CHANNEL_RX LL_DMA_CHANNEL_1
#define DMA_TX DMA1
#define DMA_CHANNEL_TX LL_DMA_CHANNEL_2
#define UCPD_IRQ UCPD1_2_IRQn

#if defined(ARDUINO_NUCLEO_G071RB)
#define PIN_CC1_ARDUINO D7
#define PIN_CC2_ARDUINO D47
#endif
#endif
#if !defined(PIN_CC1_ARDUINO) || !defined(PIN_CC2_ARDUINO)
#error "Arduiono board not yet supported - please define PIN_CC1_ARDUINO and PIN_CC2_ARDUINO"
#endif


Expand Down Expand Up @@ -85,8 +72,8 @@ void PDPhySTM32UCPD::init(bool isMonitor) {

// Use Arduino function for basic pin configuration so the Arduino library is aware
// if the most important settings (such as GPIO clock initialization).
pinMode(PIN_CC1_ARDUINO, INPUT_ANALOG);
pinMode(PIN_CC2_ARDUINO, INPUT_ANALOG);
pinMode(ARDUINO_PIN_CC1, INPUT_ANALOG);
pinMode(ARDUINO_PIN_CC2, INPUT_ANALOG);

// initialize UCPD1
LL_UCPD_InitTypeDef ucpdInit = {};
Expand Down

0 comments on commit a9765e7

Please sign in to comment.