Skip to content

Commit d4da76f

Browse files
authored
Merge branch 'espressif:master' into patch-2
2 parents 31bb0ab + 0a26a8c commit d4da76f

File tree

10 files changed

+302
-31
lines changed

10 files changed

+302
-31
lines changed

Diff for: cores/esp32/HWCDC.cpp

+26-20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "esp_intr_alloc.h"
2525
#include "soc/periph_defs.h"
2626
#include "soc/io_mux_reg.h"
27+
#include "soc/usb_serial_jtag_struct.h"
2728
#pragma GCC diagnostic ignored "-Wvolatile"
2829
#include "hal/usb_serial_jtag_ll.h"
2930
#pragma GCC diagnostic warning "-Wvolatile"
@@ -86,7 +87,7 @@ static void hw_cdc_isr_handler(void *arg) {
8687
} else {
8788
connected = true;
8889
}
89-
if (usb_serial_jtag_ll_txfifo_writable() == 1) {
90+
if (tx_ring_buf != NULL && usb_serial_jtag_ll_txfifo_writable() == 1) {
9091
// We disable the interrupt here so that the interrupt won't be triggered if there is no data to send.
9192
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
9293
size_t queued_size;
@@ -164,6 +165,9 @@ bool HWCDC::isCDC_Connected()
164165
}
165166

166167
static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
168+
if(tx_ring_buf == NULL) {
169+
return;
170+
}
167171
uint32_t tx_timeout_ms = 0;
168172
if(HWCDC::isConnected()) {
169173
tx_timeout_ms = requested_tx_timeout_ms;
@@ -238,32 +242,33 @@ void HWCDC::begin(unsigned long baud)
238242
log_e("HW CDC TX Buffer error");
239243
}
240244
}
245+
246+
// the HW Serial pins needs to be first deinited in order to allow `if(Serial)` to work :-(
247+
deinit(NULL);
248+
delay(10); // USB Host has to enumerate it again
249+
250+
// Peripheral Manager setting for USB D+ D- pins
251+
uint8_t pin = USB_DM_GPIO_NUM;
252+
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1)) goto err;
253+
pin = USB_DP_GPIO_NUM;
254+
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1)) goto err;
255+
256+
// Configure PHY
257+
// USB_Serial_JTAG use internal PHY
258+
USB_SERIAL_JTAG.conf0.phy_sel = 0;
259+
// Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1)
260+
USB_SERIAL_JTAG.conf0.pad_pull_override = 0;
261+
// Enable USB D+ pullup
262+
USB_SERIAL_JTAG.conf0.dp_pullup = 1;
263+
// Enable USB pad function
264+
USB_SERIAL_JTAG.conf0.usb_pad_enable = 1;
241265
usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK);
242266
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET);
243267
if(!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK){
244268
isr_log_e("HW USB CDC failed to init interrupts");
245269
end();
246270
return;
247271
}
248-
// Setting USB D+ D- pins
249-
uint8_t pin = ESP32_BUS_TYPE_USB_DM;
250-
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT){
251-
if(!perimanClearPinBus(pin)){
252-
goto err;
253-
}
254-
}
255-
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DM, (void *) this, -1, -1)){
256-
goto err;
257-
}
258-
pin = ESP32_BUS_TYPE_USB_DP;
259-
if(perimanGetPinBusType(pin) != ESP32_BUS_TYPE_INIT){
260-
if(!perimanClearPinBus(pin)){
261-
goto err;
262-
}
263-
}
264-
if(!perimanSetPinBus(pin, ESP32_BUS_TYPE_USB_DP, (void *) this, -1, -1)){
265-
goto err;
266-
}
267272
return;
268273

269274
err:
@@ -289,6 +294,7 @@ void HWCDC::end()
289294
arduino_hw_cdc_event_loop_handle = NULL;
290295
}
291296
HWCDC::deinit(this);
297+
setDebugOutput(false);
292298
connected = false;
293299
}
294300

Diff for: cores/esp32/USB.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#define USB_WEBUSB_ENABLED false
4949
#endif
5050
#ifndef USB_WEBUSB_URL
51-
#define USB_WEBUSB_URL "https://espressif.github.io/arduino-esp32/webusb.html"
51+
#define USB_WEBUSB_URL "https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html"
5252
#endif
5353

5454
#if CFG_TUD_DFU

Diff for: cores/esp32/esp32-hal-uart.c

-2
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
509509
uart->_rxfifo_full_thrhd = rxfifo_full_thrhd;
510510
uart->_rx_buffer_size = rx_buffer_size;
511511
uart->_tx_buffer_size = tx_buffer_size;
512-
uart->_ctsPin = -1;
513-
uart->_rtsPin = -1;
514512
uart->has_peek = false;
515513
uart->peek_byte = 0;
516514
}

Diff for: docs/_static/webusb.html

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<!-- Based on https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/usb/webusb -->
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
<head>
6+
<title>Espressif WebUSB Console Example</title>
7+
</head>
8+
9+
<body>
10+
<script>
11+
var serial = {};
12+
13+
(function() {
14+
'use strict';
15+
16+
serial.getPorts = function() {
17+
return navigator.usb.getDevices().then(devices => {
18+
return devices.map(device => new serial.Port(device));
19+
});
20+
};
21+
22+
serial.requestPort = function() {
23+
const filters = [
24+
{ 'vendorId': 0x10c4, 'productId': 0xea60 },
25+
{ 'vendorId': 0x303a, 'productId': 0x1001 },
26+
{ 'vendorId': 0x303a, 'productId': 0x0002 },
27+
];
28+
return navigator.usb.requestDevice({ 'filters': filters }).then(
29+
device => new serial.Port(device)
30+
);
31+
}
32+
33+
serial.Port = function(device) {
34+
this.device_ = device;
35+
};
36+
37+
serial.Port.prototype.connect = function() {
38+
let readLoop = () => {
39+
const {
40+
endpointNumber
41+
} = this.device_.configuration.interfaces[0].alternate.endpoints[0]
42+
this.device_.transferIn(endpointNumber, 64).then(result => {
43+
this.onReceive(result.data);
44+
readLoop();
45+
}, error => {
46+
this.onReceiveError(error);
47+
});
48+
};
49+
50+
return this.device_.open()
51+
.then(() => {
52+
if (this.device_.configuration === null) {
53+
return this.device_.selectConfiguration(1);
54+
}
55+
})
56+
.then(() => this.device_.claimInterface(0))
57+
.then(() => {
58+
readLoop();
59+
});
60+
};
61+
62+
serial.Port.prototype.disconnect = function() {
63+
return this.device_.close();
64+
};
65+
66+
serial.Port.prototype.send = function(data) {
67+
const {
68+
endpointNumber
69+
} = this.device_.configuration.interfaces[0].alternate.endpoints[1]
70+
return this.device_.transferOut(endpointNumber, data);
71+
};
72+
})();
73+
74+
let port;
75+
76+
function connect() {
77+
port.connect().then(() => {
78+
port.onReceive = data => {
79+
let textDecoder = new TextDecoder();
80+
console.log("Received:", textDecoder.decode(data));
81+
document.getElementById('output').value += textDecoder.decode(data);
82+
}
83+
port.onReceiveError = error => {
84+
console.error(error);
85+
document.querySelector("#connect").style = "visibility: initial";
86+
port.disconnect();
87+
};
88+
});
89+
}
90+
91+
function send(string) {
92+
console.log("sending to serial:" + string.length);
93+
if (string.length === 0)
94+
return;
95+
console.log("sending to serial: [" + string +"]\n");
96+
97+
let view = new TextEncoder('utf-8').encode(string);
98+
console.log(view);
99+
if (port) {
100+
port.send(view);
101+
}
102+
};
103+
104+
window.onload = _ => {
105+
document.querySelector("#connect").onclick = function() {
106+
serial.requestPort().then(selectedPort => {
107+
port = selectedPort;
108+
this.style = "visibility: hidden";
109+
connect();
110+
});
111+
}
112+
113+
document.querySelector("#submit").onclick = () => {
114+
let source = document.querySelector("#input").value;
115+
send(source);
116+
}
117+
}
118+
</script>
119+
120+
<button id="connect" style="visibility: initial">Connect To ESP Device</button>
121+
<br><br><label for="input">Sender: </label> <br>
122+
<textarea id="input" rows="25" cols="80">Send to ESP Device</textarea>
123+
<br><button id="submit">Send</button>
124+
<br><br>
125+
<label for="output">Receiver: </label> <br>
126+
<textarea id="output" rows="25" cols="80"></textarea>
127+
</body>
128+
</html>

Diff for: docs/en/api/usb.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ This function is used to get the ``webUSBURL``.
303303
304304
const char * webUSBURL(void);
305305
306-
The default ``webUSBURL`` is: https://espressif.github.io/arduino-esp32/webusb.html
306+
The default ``webUSBURL`` is: https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html
307307

308308
enableDFU
309309
^^^^^^^^^

Diff for: docs/en/guides/docs_contributing.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ We also recommend you install to grammar check extension to help you to review E
7272
Building
7373
********
7474

75-
To build the documentation and generate the HTLM files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `build/html` folder.
75+
To build the documentation and generate the HTML files, you can use the following command inside the ``docs`` folder. After a successful build, you can check the files inside the `_build/en/generic/html` folder.
7676

7777
.. code-block::
7878
79-
make html
79+
build-docs -l en
8080
8181
This step is essential to ensure that there are no syntax errors and also to see the final result.
8282

@@ -104,7 +104,7 @@ If everything is ok, you will see some output logs similar to this one:
104104
dumping object inventory... done
105105
build succeeded.
106106
107-
The HTML pages are in build/html.
107+
The HTML pages are in `_build/en/generic/html`.
108108

109109
Sections
110110
--------

Diff for: libraries/USB/examples/USBVendor/USBVendor.ino

+6-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void setup() {
164164

165165
USB.onEvent(usbEventCallback);
166166
USB.webUSB(true);
167-
USB.webUSBURL("http://localhost/webusb");
167+
// Set the URL for your WebUSB landing page
168+
USB.webUSBURL("https://docs.espressif.com/projects/arduino-esp32/en/latest/_static/webusb.html");
168169
USB.begin();
169170
}
170171

@@ -176,9 +177,11 @@ void loop() {
176177
if (buttonState == LOW) {
177178
Serial.println("Button Pressed");
178179
Vendor.println("Button Pressed");
180+
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
179181
} else {
180-
Vendor.println("Button Released");
181182
Serial.println("Button Released");
183+
Vendor.println("Button Released");
184+
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
182185
}
183186
delay(100);
184187
}
@@ -188,6 +191,7 @@ void loop() {
188191
uint8_t b[l];
189192
l = Serial.read(b, l);
190193
Vendor.write(b, l);
194+
Vendor.flush(); //Without flushing the data will only be sent when the buffer is full (64 bytes)
191195
}
192196
}
193197
#endif /* ARDUINO_USB_MODE */

0 commit comments

Comments
 (0)