This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new fc2398da5 tinyusb/stm32_fsdev: Add dcd_connect/dcd_disconnect
fc2398da5 is described below
commit fc2398da56e27c38d32bd448869fa5277c6c4194
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Nov 4 19:26:00 2025 +0100
tinyusb/stm32_fsdev: Add dcd_connect/dcd_disconnect
STM32F1/F3 do not have internal pull-up resistor on D+
line that can be automatically attached.
Many board have external pull-up resistor that is
connected all the time.
So far when USB_DP_HAS_EXTERNAL_PULL_UP was 1 (default)
code was shorting D+ line to the ground as GPIO output
for a wile during startup.
It is possible to have external pull-up resistor that
is switchable at runtime (via transistor or resistor
is just sourced from one of the GPIO pins).
For this purpose now dcd_connect and dcd_disconnect
functions are provided that can enabled pull-up resistor
in several ways.
With such setup device that is connected to USB just
for power does not have to be detected by host system
as broken one.
Signed-off-by: Jerzy Kasenberg <[email protected]>
---
hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c | 39 +++++++++++++++++++++++++++
hw/usb/tinyusb/stm32_fsdev/stm32f3/syscfg.yml | 27 -------------------
hw/usb/tinyusb/stm32_fsdev/syscfg.yml | 25 +++++++++++++++++
3 files changed, 64 insertions(+), 27 deletions(-)
diff --git a/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
index 593ee756d..9829d5c9e 100755
--- a/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
+++ b/hw/usb/tinyusb/stm32_fsdev/src/stm32_fsdev.c
@@ -32,6 +32,44 @@ USB_IRQHandler(void)
tud_int_handler(0);
}
+#define IS_PIN_MODE(m) MYNEWT_VAL_CHOICE(USB_DP_PULLUP_CONTROL_PIN_MODE, m)
+
+void
+dcd_disconnect(uint8_t rhport)
+{
+ (void)rhport;
+
+ if (MYNEWT_VAL_USB_DP_PULLUP_CONTROL_PIN >= 0) {
+ if (IS_PIN_MODE(enable_1_disable_0) ||
IS_PIN_MODE(enable_input_disable_0)) {
+ hal_gpio_init_out(MYNEWT_VAL_USB_DP_PULLUP_CONTROL_PIN, 0);
+ } else if (IS_PIN_MODE(enable_0_disable_1) ||
+ IS_PIN_MODE(enable_input_disable_1)) {
+ hal_gpio_init_out(MYNEWT_VAL_USB_DP_PULLUP_CONTROL_PIN, 1);
+ } else if (IS_PIN_MODE(enable_0_disable_input) ||
+ IS_PIN_MODE(enable_1_disable_input)) {
+ hal_gpio_deinit(MYNEWT_VAL_USB_DP_PULLUP_CONTROL_PIN);
+ }
+ }
+}
+
+void
+dcd_connect(uint8_t rhport)
+{
+ (void)rhport;
+
+ if (MYNEWT_VAL_USB_DP_PULLUP_CONTROL_PIN >= 0) {
+ if (IS_PIN_MODE(enable_1_disable_0) ||
IS_PIN_MODE(enable_1_disable_input)) {
+ hal_gpio_init_out(MYNEWT_VAL(USB_DP_PULLUP_CONTROL_PIN), 1);
+ } else if (IS_PIN_MODE(enable_0_disable_1) ||
+ IS_PIN_MODE(enable_0_disable_input)) {
+ hal_gpio_init_out(MYNEWT_VAL(USB_DP_PULLUP_CONTROL_PIN), 0);
+ } else if (IS_PIN_MODE(enable_input_disable_0) ||
+ IS_PIN_MODE(enable_input_disable_1)) {
+ hal_gpio_deinit(MYNEWT_VAL(USB_DP_PULLUP_CONTROL_PIN));
+ }
+ }
+}
+
void
tinyusb_hardware_init(void)
{
@@ -43,6 +81,7 @@ tinyusb_hardware_init(void)
NVIC_SetVector(USBWakeUp_IRQn, (uint32_t)USB_IRQHandler);
NVIC_SetPriority(USBWakeUp_IRQn, 2);
+ dcd_disconnect(0);
/*
* USB Pin Init
* PA11- DM, PA12- DP
diff --git a/hw/usb/tinyusb/stm32_fsdev/stm32f3/syscfg.yml
b/hw/usb/tinyusb/stm32_fsdev/stm32f3/syscfg.yml
index 23bafda07..eae4e3b61 100644
--- a/hw/usb/tinyusb/stm32_fsdev/stm32f3/syscfg.yml
+++ b/hw/usb/tinyusb/stm32_fsdev/stm32f3/syscfg.yml
@@ -17,30 +17,3 @@
# under the License.
#
-syscfg.defs:
- USB_DP_PULLUP_CONTROL_PIN:
- description: >
- Set pin number (other then PA11) that connects 1.5k resistor to D+
- value: -1
-
-syscfg.defs.(USB_DP_PULLUP_CONTROL_PIN!=-1):
- USB_DP_PULLUP_CONTROL_PIN_MODE:
- description: >
- 1.5 kOhm Resistor can be connected directly to one of the output
pins,
- or it can use additional switch to connect resistor.
- choices:
- # Following two cases are used when 1.5k is connected when MCU is
down
- # and needs some control pin value to be shorted to ground
- - enable_input_disable_0
- - enable_input_disable_1
- # This is rare case when both disable and enable requires control
pin
- # to be connected and set to certain value
- - enable_1_disable_0
- - enable_0_disable_1
- # Current can be drawn directly from control PIN it there is not
additional
- # switching hardware element.
- - enable_1_disable_input
- # Case when resistor is connected from MCU pin via inverting
transistor
- # current is not drawn from MCU pin.
- - enable_0_disable_input
- value:
diff --git a/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
index 37f2fbea5..0dc43f94c 100644
--- a/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
+++ b/hw/usb/tinyusb/stm32_fsdev/syscfg.yml
@@ -25,3 +25,28 @@ syscfg.defs:
then device is discovered by host.
value: 1
+ USB_DP_PULLUP_CONTROL_PIN:
+ description: >
+ Set pin number (other then PA11) that connects 1.5k resistor to D+
+ value: -1
+
+ USB_DP_PULLUP_CONTROL_PIN_MODE:
+ description: >
+ 1.5 kOhm Resistor can be connected directly to one of the output
pins,
+ or it can use additional switch to connect resistor.
+ choices:
+ # Following two cases are used when 1.5k is connected when MCU is
down
+ # and needs some control pin value to be shorted to ground
+ - enable_input_disable_0
+ - enable_input_disable_1
+ # This is rare case when both disable and enable requires control
pin
+ # to be connected and set to certain value
+ - enable_1_disable_0
+ - enable_0_disable_1
+ # Current can be drawn directly from control PIN it there is not
additional
+ # switching hardware element.
+ - enable_1_disable_input
+ # Case when resistor is connected from MCU pin via inverting
transistor
+ # current is not drawn from MCU pin.
+ - enable_0_disable_input
+ value: enable_1_disable_0