-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wifi init causing usb host vcp client to suddenly disconnect, IDF5.1 (IDFGH-10910) #12106
Comments
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 be able to do that, may I ask to share the KConfig options as well? (regarding the partitions and other configuration for WiFi). Meanwhile, I'll try to find the problem. |
Hey @colinb2048, I have tried to reproduce the problem on ESP32-S2 devkit with example code you had provided, but no luck. To proceed, I need to clarify some details.
Thanks. |
Hi , I'm using micropython/circuitpython , and encountered the same issue. REPL works a short while after running code below. ##micropython test code 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()
|
Hi @mzhboy, Thanks for the reporting that! I have a couple of questions, answering to them could help us to move forward.
Thanks! |
@roma-jam I will investigate this issue with oscilloscope when I have time. |
Hi @mzhboy, Thanks for sharing additional information!
In case, that it seems that you are not using the Which means, that the problem is not related to Otherwise, for us to be able to proceed, could you please provide the simplest possible example with |
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 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 |
Hello everyone, we revisited the topic again, but we could not reproduce it. So, I'd like to ask for more information:
|
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 <stdio.h>
#include <string.h>
#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
Serial1.printf("Unable to create socket: errno %d", errno);
#endif
#ifdef DEBUG_SERIAL
Serial1.println("Unable to bind");
#endif
HandleDisconnection();
}
ESP_LOGI(TAG, "Socket bound, port %d", localport);
}
/**
@brief Main application
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);
// }
}``
The text was updated successfully, but these errors were encountered: