Closed colinb2048 closed 10 months ago
Can you provide your SDKConfig. Do you have Enable USB when phy init?
Thanks for the suggestion, it wasn't, but after enabling 'Enable USB when phy init' i get a compilation error: undefined reference to `phy_bbpll_en_usb'
I've found references to the same compilation error but doesn't appear those threads reached a solution?
Hey @colinb2048,
Seems like there could be two problems: either power consumption spikes during WiFi data transfer, which leads to the usb host device disconnection or some interlacing in driver code, which is not so trivial. To proceed, I would like to reproduce the problem and verify all theories.
To be able to do that, may I ask to share the KConfig options as well? (regarding the partitions and other configuration for WiFi). Probably, it will be easy to share the whole project (main, sdkconfig and partitions.csv).
Meanwhile, I'll try to find the problem. Thanks.
Hey @colinb2048,
I have tried to reproduce the problem on ESP32-S2 devkit with example code you had provided, but no luck.
I tried to send UDP packets from HOST with several length, all seems to correctly received from socket in udp_Receive_Task()
in udp_rx_buffer
and then transmitted via vcp->tx_blocking()
as well.
To proceed, I need to clarify some details.
Thanks.
Hi , I'm using micropython/circuitpython , and encountered the same issue.
In fact, it's one of two esp32-s2-lolin boards encountered this issue, while the other one (usually) works fine.
I also modified en pin circuit on both boards, replace pull-up reisstor(r3) with 1k and C14 with 4.7uF.
The input capacitor is too small, so another 220uF capacitor added to VBUS.
REPL works a short while after running code below.
from ssid_passwd import ssid,passwd # ssid and passwd of ap
import esp
esp.osdebug(None) # turn off vendor O/S debugging messages
#esp.osdebug(0) # redirect vendor O/S debugging messages to UART(0)
print('------- boot start --------')
def do_connect():
import network
import time
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.config(pm=wlan.PM_PERFORMANCE)
print('wlan.status()', wlan.status())
t1 = time.ticks_us()
if not wlan.isconnected():
# print('connecting to network...')
wlan.connect(ssid, passwd)
timeout = time.ticks_ms() + 10_000 # timeout 10s
while not wlan.isconnected() and time.ticks_ms() < timeout:
time.sleep(1)
print('wlan.status()', wlan.status())
if not wlan.isconnected():
print('error: connect wifi timeout')
wlan.active( False )
else :
print('ip:', wlan.ifconfig()[0], '\trssi:', wlan.status('rssi'))
print('connect time consume:', time.ticks_diff(time.ticks_us(),t1)/1000, 'ms')
def light_led():
import re, os
from machine import Pin, PWM
str = os.uname().machine
# esp32-s2
#searchObj = re.search(r'ESP32-?S2',str)
if re.search(r'ESP32-?S2',str):
print('MCU:ESP32-S2')
#led = Pin(15, Pin.OUT, value=1)
led = PWM(15, freq=2000, duty=128)
elif re.search(r'ESP32-UNICORE',str):
print ("MCU:ESP32-SOLO-01")
led = PWM(22, freq=2000, duty=228)
else :
print('unknown MCU')
def print_vcp():
import network
import time
import gc
wl = network.WLAN(network.STA_IF)
tm = time.time()
print('---print vcp---')
while True :
if wl.isconnected():
print('uptime', time.time() - tm,'\tip:', wl.ifconfig()[0], '\trssi:', wl.status('rssi'))
else :
print('uptime', time.time() - tm)
time.sleep(0.99)
light_led()
do_connect()
print('------- boot end --------')
print_vcp()
uptime 253 ip: 192.168.1.249 rssi: -55
Hi @mzhboy,
Thanks for the reporting that! I have tried to reproduce the problem, but with another board and didn't succeeded.
I have a couple of questions, answering to them could help us to move forward.
Thanks!
@roma-jam Powering from usb hub, the hub has external PSU, output is 5.2V 3A. Others esp32 boards with onboard usbserial bridge have no issue.
I will investigate this issue with oscilloscope when I have time.
Hi @mzhboy,
Thanks for sharing additional information! But I am not sure that your issue is connected to the topic-starter issue. Anyway, let me clear some things to understand it better.
usb_host
driver from esp-idf components? In case, that it seems that you are not using the usb_host
driver (but please, correct me if I am wrong), seems that you issue 'may be' related but definitely not because you are using the usb_host
driver.
Which means, that the problem is not related to usb_host
driver itself...
Otherwise, for us to be able to proceed, could you please provide the simplest possible example with usb_host
driver usage to reproduce the failure?
Thanks.
esp32 as a USB Device, as micropython don't support usb_host mode
Hi everyone,
Considering the information, that micropython code also has the same problem but doesn't use the usb_host
library, it seems that the problem could be deeper, than the layer usb_host
library works at.
There is a chance, that this issue has the same nature as this one.
Regarding the problem with micropython, I could suggest to create a new ticket if you still have problems with it.
In case there will be any new information, regarding the usb_host
library and working ESP32 as a USB Host, feel free to reopen this ticket.
Thanks.
Hello everyone, we revisited the topic again, but we could not reproduce it. So, I'd like to ask for more information:
esptool chip_id
)espefuse.py -p PORT dump
)
Answers checklist.
IDF version.
5.1.0
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
None
Development Kit.
Wemos Lolin S2
Power Supply used.
External 5V
What is the expected behavior?
Init wifi and usb, the order of which shouldn't matter, receive UDP packets and write the data to usb vcp client, and vice versa
What is the actual behavior?
USB vcp client suddenly disconnects after wifi init. Frequency of disconnect is random when no data flowing, but when receiving udp packet and sending via usb, almost always suddenly disconnects.
Steps to reproduce.
I've merged the wifi init sta and usb host vcp examples to create bidirectional comms between usb and wifi devices. With no wifi, usb works as expected. If usb installed first, wifi fails to connect to access point. With wifi active, trying to send to usb vcp clients almost always suddenly disconnects
Debug Logs.
No response
More Information.
Source: ``
include
include
include
include "esp_log.h"
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include "freertos/semphr.h"
include "usb/cdc_acm_host.h"
include "usb/vcp_ch34x.hpp"
include "usb/vcp_cp210x.hpp"
include "usb/vcp_ftdi.hpp"
include "usb/vcp.hpp"
include "usb/usb_host.h"
include "driver/uart.h"
include "driver/gpio.h"
include "freertos/event_groups.h"
include "esp_system.h"
include "esp_wifi.h"
include "esp_event.h"
include "esp_log.h"
include "nvs_flash.h"
include "lwip/err.h"
include "lwip/sys.h"
include "lwip/sockets.h"
include "esp_heap_caps.h"
include "esp_pm.h"
using namespace esp_usb;
// Change these values to match your needs
define EXAMPLE_BAUDRATE (19200)
define EXAMPLE_STOP_BITS (0) // 0: 1 stopbit, 1: 1.5 stopbits, 2: 2 stopbits
define EXAMPLE_PARITY (0) // 0: None, 1: Odd, 2: Even, 3: Mark, 4: Space
define EXAMPLE_DATA_BITS (8)
define EXAMPLE_ESP_WIFI_SSID "..."
define EXAMPLE_ESP_WIFI_PASS "..."
define EXAMPLE_ESP_MAXIMUM_RETRY 5
define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
define WIFI_CONNECTED_BIT BIT0
define WIFI_FAIL_BIT BIT1
define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
define CONFIG_ESP_WIFI_PW_ID ""
define EXAMPLE_H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
define PACKET_RECEIVE_DELAY 10 // Should be less than the send delay, to prevent buffer overflow & mem issues
namespace { struct sockaddr_storage source_addr; static const char TAG = "VCP example"; static SemaphoreHandle_t device_disconnected_sem; char test_str; int udp_receive_len = 0; char udp_rx_buffer[364]; char usb_rx_buffer[364]; int usb_rx_buffer_counter = 0;
ifdef DEBUG_SERIAL
endif
ifdef DEBUG_SERIAL
endif
}
/**
This function shows how you can use Virtual COM Port drivers */ extern "C" void app_main(void) { esp_pm_config_t pwr_config; pwr_config.max_freq_mhz = 240; esp_pm_configure(&pwr_config); // valid speeds 80, 160, 240 vTaskDelay(pdMS_TO_TICKS(100));
// Enable status LEDS gpio_set_direction(GPIO_NUM_15, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_15, 1);
// UART Init uart_config_t uart_config = { .baud_rate = 19200, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .source_clk = UART_SCLK_APB};
ESP_ERROR_CHECK(uart_param_config(UART_NUM_1, &uart_config)); ESP_ERROR_CHECK(uart_set_pin(UART_NUM_1, GPIO_NUM_17, GPIO_NUM_18, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE)); ESP_ERROR_CHECK(uart_driver_install(UART_NUM_1, 1024, 0, 0, NULL, 0));
// Wifi Init esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret); ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); wifi_init_sta(); xTaskCreate(udp_Receive_Task, "udp_Receive_Task", 4096, NULL, 10, NULL); vTaskDelay(pdMS_TO_TICKS(2000));
// USB Host VCP Init // Install USB Host driver. Should only be called once in entire application ESP_LOGI(TAG, "Installing USB Host"); const usb_host_config_t host_config = { .skip_phy_setup = false, .intr_flags = ESP_INTR_FLAG_LEVEL1, }; ESP_ERROR_CHECK(usb_host_install(&host_config));
// Create a task that will handle USB library events xTaskCreate(usb_lib_task, "usb_lib", 4096, NULL, 10, NULL);
ESP_LOGI(TAG, "Installing CDC-ACM driver"); ESP_ERROR_CHECK(cdc_acm_host_install(NULL));
xTaskCreate(usb_connect_task, "usb_con", 4096, NULL, 10, NULL);
/* Now the USB-to-UART converter is configured and receiving data. You can use standard CDC-ACM API to interact with it. E.g.
ESP_ERROR_CHECK(vcp->set_control_line_state(false, true)); ESP_ERROR_CHECK(vcp->tx_blocking((uint8_t )"Test string", 12)); /
// Send some dummy data // ESP_LOGI(TAG, "Sending data through CdcAcmDevice"); // uint8_t data[] = "test_string"; // ESP_ERROR_CHECK(vcp->tx_blocking(data, sizeof(data))); // ESP_ERROR_CHECK(vcp->set_control_line_state(true, true));
// We are done. Wait for device disconnection and start over // ESP_LOGI(TAG, "Done. You can reconnect the VCP device to run again."); // xSemaphoreTake(device_disconnected_sem, portMAX_DELAY); // } }``