Просмотр исходного кода

Merge pull request #530 from hathach/fix-idf-latest

fix usb pin config with idf latest
Ha Thach 5 лет назад
Родитель
Сommit
6442f5afdb

+ 30 - 8
hw/bsp/esp32s2_kaluga_1/esp32s2_kaluga_1.c

@@ -25,11 +25,11 @@
  */
 
 #include "../board.h"
-#include "driver/gpio.h"
-#include "driver/periph_ctrl.h"
+#include "esp_rom_gpio.h"
+#include "hal/gpio_ll.h"
 #include "hal/usb_hal.h"
 #include "soc/usb_periph.h"
-
+#include "driver/periph_ctrl.h"
 #include "driver/rmt.h"
 #include "led_strip/include/led_strip.h"
 
@@ -38,11 +38,10 @@
 //--------------------------------------------------------------------+
 
 #define LED_PIN               45
-
 #define BUTTON_PIN            0
 #define BUTTON_STATE_ACTIVE   0
 
-
+static void configure_pins(usb_hal_context_t *usb);
 static led_strip_t *strip;
 
 // Initialize on-board peripherals : led, button, uart and USB
@@ -72,10 +71,33 @@ void board_init(void)
     .use_external_phy = false // use built-in PHY
   };
   usb_hal_init(&hal);
+  configure_pins(&hal);
+}
 
-  // Pin drive strength
-  gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
-  gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
+static void configure_pins(usb_hal_context_t *usb)
+{
+  /* usb_periph_iopins currently configures USB_OTG as USB Device.
+   * Introduce additional parameters in usb_hal_context_t when adding support
+   * for USB Host.
+   */
+  for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
+    if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
+      esp_rom_gpio_pad_select_gpio(iopin->pin);
+      if (iopin->is_output) {
+        esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
+      } else {
+        esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
+        if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) {
+          gpio_ll_input_enable(&GPIO, iopin->pin);
+        }
+      }
+      esp_rom_gpio_pad_unhold(iopin->pin);
+    }
+  }
+  if (!usb->use_external_phy) {
+    gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
+    gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
+  }
 }
 
 // Turn LED on or off

+ 30 - 7
hw/bsp/esp32s2_saola_1/esp32s2_saola_1.c

@@ -25,11 +25,12 @@
  */
 
 #include "../board.h"
-#include "driver/gpio.h"
-#include "driver/periph_ctrl.h"
+#include "esp_rom_gpio.h"
+#include "hal/gpio_ll.h"
 #include "hal/usb_hal.h"
 #include "soc/usb_periph.h"
 
+#include "driver/periph_ctrl.h"
 #include "driver/rmt.h"
 #include "led_strip/include/led_strip.h"
 
@@ -41,11 +42,10 @@
 // however earlier revision v1.1 WS2812 is connected to GPIO 17
 //#define LED_PIN               17 // v1.1
 #define LED_PIN               18 // v1.2 and later
-
 #define BUTTON_PIN            0
 #define BUTTON_STATE_ACTIVE   0
 
-
+static void configure_pins(usb_hal_context_t *usb);
 static led_strip_t *strip;
 
 // Initialize on-board peripherals : led, button, uart and USB
@@ -75,10 +75,33 @@ void board_init(void)
     .use_external_phy = false // use built-in PHY
   };
   usb_hal_init(&hal);
+  configure_pins(&hal);
+}
 
-  // Pin drive strength
-  gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
-  gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
+static void configure_pins(usb_hal_context_t *usb)
+{
+  /* usb_periph_iopins currently configures USB_OTG as USB Device.
+   * Introduce additional parameters in usb_hal_context_t when adding support
+   * for USB Host.
+   */
+  for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
+    if ((usb->use_external_phy) || (iopin->ext_phy_only == 0)) {
+      esp_rom_gpio_pad_select_gpio(iopin->pin);
+      if (iopin->is_output) {
+        esp_rom_gpio_connect_out_signal(iopin->pin, iopin->func, false, false);
+      } else {
+        esp_rom_gpio_connect_in_signal(iopin->pin, iopin->func, false);
+        if ((iopin->pin != GPIO_FUNC_IN_LOW) && (iopin->pin != GPIO_FUNC_IN_HIGH)) {
+          gpio_ll_input_enable(&GPIO, iopin->pin);
+        }
+      }
+      esp_rom_gpio_pad_unhold(iopin->pin);
+    }
+  }
+  if (!usb->use_external_phy) {
+    gpio_set_drive_capability(USBPHY_DM_NUM, GPIO_DRIVE_CAP_3);
+    gpio_set_drive_capability(USBPHY_DP_NUM, GPIO_DRIVE_CAP_3);
+  }
 }
 
 // Turn LED on or off

+ 1 - 7
hw/bsp/samd11_xplained/board.mk

@@ -1,7 +1,4 @@
 CFLAGS += \
-  -ffunction-sections \
-  -fdata-sections \
-  -Wl,--gc-sections \
   -mthumb \
   -mabi=aapcs-linux \
   -mcpu=cortex-m0plus \
@@ -9,9 +6,7 @@ CFLAGS += \
   -D__SAMD11D14AM__ \
   -DCONF_DFLL_OVERWRITE_CALIBRATION=0 \
   -DOSC32K_OVERWRITE_CALIBRATION=0 \
-  -DCFG_TUSB_MCU=OPT_MCU_SAMD11 \
-  -fshort-enums \
-  -Os
+  -DCFG_TUSB_MCU=OPT_MCU_SAMD11
 
 # All source paths should be relative to the top level.
 LD_FILE = hw/bsp/$(BOARD)/samd11d14am_flash.ld
@@ -50,4 +45,3 @@ JLINK_IF = swd
 # flash using edbg
 flash: $(BUILD)/$(BOARD)-firmware.bin
 	edbg -b -t samd11 -e -pv -f $<
-