Skip to content

Commit 96d70c2

Browse files
committed
Support Opta
Since host and device are shared, deinit device stack and configure the FUSB to act as SRC before any further operation
1 parent 72d0aa6 commit 96d70c2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/targets/TARGET_STM/USBHALHost_STM.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,44 @@ void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum,
156156

157157
USBHALHost *USBHALHost::instHost;
158158

159+
#if defined(TARGET_OPTA)
160+
#include <usb_phy_api.h>
161+
#include <Wire.h>
162+
#endif
159163

160164
void USBHALHost::init()
161165
{
166+
#if defined(TARGET_OPTA)
167+
get_usb_phy()->deinit();
168+
169+
Wire1.begin();
170+
171+
// reset FUSB registers
172+
Wire1.beginTransmission(0x21);
173+
Wire1.write(0x5);
174+
Wire1.write(0x1);
175+
Wire1.endTransmission();
176+
177+
Wire1.beginTransmission(0x21);
178+
Wire1.write(0x5);
179+
Wire1.write(0x0);
180+
Wire1.endTransmission();
181+
182+
delay(100);
183+
184+
// setup port as SRC
185+
Wire1.beginTransmission(0x21);
186+
Wire1.write(0x2);
187+
Wire1.write(0x3);
188+
Wire1.endTransmission();
189+
190+
// enable interrupts
191+
Wire1.beginTransmission(0x21);
192+
Wire1.write(0x3);
193+
Wire1.write(1 << 1);
194+
Wire1.endTransmission();
195+
#endif
196+
162197
NVIC_DisableIRQ(USBHAL_IRQn);
163198
NVIC_SetVector(USBHAL_IRQn, (uint32_t)(_usbisr));
164199
HAL_HCD_Init((HCD_HandleTypeDef *) usb_hcca);

src/targets/TARGET_STM/USBHALHost_STM.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ static gpio_t gpio_powerpin;
127127
#define USB_POWER_OFF 1
128128
#define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOJ_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PJ_6, USB_POWER_OFF);}
129129

130+
#elif defined(TARGET_OPTA)
131+
#define USB_POWER_ON 0
132+
#define USB_POWER_OFF 1
133+
#define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOG_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PG_1, USB_POWER_OFF);}
134+
130135
#else
131136
#error "USB power pin is not configured !"
132137
#endif
@@ -320,7 +325,7 @@ USBHALHost::USBHALHost()
320325
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DM
321326
pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS)); // DP
322327

323-
#elif defined(TARGET_PORTENTA_H7_M7) || defined(TARGET_PORTENTA_H7_M4)
328+
#elif defined(TARGET_PORTENTA_H7_M7) || defined(TARGET_PORTENTA_H7_M4) || defined(TARGET_OPTA)
324329

325330
__HAL_RCC_GPIOA_CLK_ENABLE();
326331
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG2_FS)); // DM

0 commit comments

Comments
 (0)