Skip to content

S3 tasmota work #120

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

Merged
merged 27 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9b9744f
publish.yml: Limit the running scope of the publish Workflow. (#6428)
Ouss4 Mar 14, 2022
e87b87d
Add missing include in AsyncUDP.h (#6412)
mrengineer7777 Mar 14, 2022
ba8024c
Some board variant fixes (#6411)
ladyada Mar 14, 2022
d977359
Added another overloaded WiFiSTAClass::begin() function that provides…
jpswensen Mar 15, 2022
0b10c8b
[Docs] Added the guideline for documentation (#6409)
pedrominatel Mar 18, 2022
8fe0efe
Fix boot freeze when trying to init PSRAM on Pico D4 (#6434)
s-hadinger Mar 23, 2022
77e9531
Adds HardwareSerial::setTxBufferSize() (#6383)
gonzabrusco Mar 28, 2022
6014ff4
Fixes USB CDC setRxBufferSize(), begin(), _onRX() (#6413)
SuGlider Mar 28, 2022
c25feca
Change "python" to "python3" (#6448)
tomorrow56 Mar 28, 2022
905f8f2
Warns about SSP only available for ESP32 (#6455)
SuGlider Mar 28, 2022
7b89b39
Edited VFSFileImpl::read to use both read/fread (#6456)
P-R-O-C-H-Y Mar 28, 2022
528c071
Adding sectorsize() and numSectors() to SD (#6457)
tobozo Mar 28, 2022
e03a9f5
(boards.txt) Add partition scheme menu for WeMos WiFi&Bluetooth Batte…
garubi Mar 28, 2022
3f79097
Add Preferences library API and tutorial documents (#6442)
Xylopyrographer Mar 28, 2022
8ee5f0a
Esp32 s3 support (#6341)
me-no-dev Mar 28, 2022
ab34321
add variant init code for the feather s2 tft (#6447)
ladyada Mar 28, 2022
ca341e3
remove Rainmaker
Jason2866 Mar 28, 2022
0bb7afb
Merge branch 'orig_master_espressif' into s3_tasmota_work
Jason2866 Mar 28, 2022
411c54d
Update boards.txt
Jason2866 Mar 28, 2022
9945886
Update HardwareSerial.h
Jason2866 Mar 28, 2022
e0b9957
Update USBCDC.cpp
Jason2866 Mar 28, 2022
9e8f246
Update esptool.py
Jason2866 Mar 28, 2022
a88e3cd
Update platformio-build-esp32.py
Jason2866 Mar 28, 2022
fe779f4
Update platformio-build-esp32c3.py
Jason2866 Mar 28, 2022
b875147
Update platformio-build-esp32s2.py
Jason2866 Mar 28, 2022
97bac88
Update platformio-build-esp32s3.py
Jason2866 Mar 28, 2022
1e9112d
fix merge errors
Jason2866 Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
425 changes: 422 additions & 3 deletions boards.txt

Large diffs are not rendered by default.

31 changes: 22 additions & 9 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void serialEvent(void) {}
#ifndef RX1
#if CONFIG_IDF_TARGET_ESP32
#define RX1 9
#elif CONFIG_IDF_TARGET_ESP32S2
#elif CONFIG_IDF_TARGET_ESP32S2
#define RX1 18
#elif CONFIG_IDF_TARGET_ESP32C3
#define RX1 18
Expand Down Expand Up @@ -86,8 +86,6 @@ void serialEvent2(void) {}
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
HardwareSerial Serial0(0);
#elif ARDUINO_HW_CDC_ON_BOOT
HardwareSerial Serial0(0);
#else
HardwareSerial Serial(0);
#endif
Expand All @@ -102,8 +100,6 @@ void serialEventRun(void)
{
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
if(Serial0.available()) serialEvent();
#elif ARDUINO_HW_CDC_ON_BOOT
if(Serial0.available()) serialEvent();
#else
if(Serial.available()) serialEvent();
#endif
Expand All @@ -127,7 +123,8 @@ void serialEventRun(void)
HardwareSerial::HardwareSerial(int uart_nr) :
_uart_nr(uart_nr),
_uart(NULL),
_rxBufferSize(256),
_rxBufferSize(256),
_txBufferSize(0),
_onReceiveCB(NULL),
_onReceiveErrorCB(NULL),
_eventTask(NULL)
Expand Down Expand Up @@ -295,7 +292,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
}

// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, invert, rxfifo_full_thrhd);
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd);
if (!baud) {
// using baud rate as zero, forces it to try to detect the current baud rate in place
uartStartDetectBaudrate(_uart);
Expand All @@ -309,7 +306,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in

if(detectedBaudRate) {
delay(100); // Give some time...
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, invert, rxfifo_full_thrhd);
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize, _txBufferSize, invert, rxfifo_full_thrhd);
} else {
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
_uart = NULL;
Expand Down Expand Up @@ -458,10 +455,26 @@ size_t HardwareSerial::setRxBufferSize(size_t new_size) {
}

if (new_size <= SOC_UART_FIFO_LEN) {
log_e("RX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN);
log_e("RX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
return 0;
}

_rxBufferSize = new_size;
return _rxBufferSize;
}

size_t HardwareSerial::setTxBufferSize(size_t new_size) {

if (_uart) {
log_e("TX Buffer can't be resized when Serial is already running.\n");
return 0;
}

if (new_size <= SOC_UART_FIFO_LEN) {
log_e("TX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
return 0;
}

_txBufferSize = new_size;
return _txBufferSize;
}
6 changes: 4 additions & 2 deletions cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ class HardwareSerial: public Stream
void setHwFlowCtrlMode(uint8_t mode = HW_FLOWCTRL_CTS_RTS, uint8_t threshold = 64); // 64 is half FIFO Length

size_t setRxBufferSize(size_t new_size);
size_t setTxBufferSize(size_t new_size);

protected:
int _uart_nr;
uart_t* _uart;
size_t _rxBufferSize;
size_t _txBufferSize;
OnReceiveCb _onReceiveCB;
OnReceiveErrorCb _onReceiveErrorCB;
TaskHandle_t _eventTask;
Expand All @@ -156,10 +158,10 @@ extern void serialEventRun(void) __attribute__((weak));
#define ARDUINO_USB_CDC_ON_BOOT 0
#endif
#if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC
#if !ARDUINO_USB_MODE
#include "USB.h"
#include "USBCDC.h"
extern HardwareSerial Serial0;
#elif ARDUINO_HW_CDC_ON_BOOT
#endif
extern HardwareSerial Serial0;
#else
extern HardwareSerial Serial;
Expand Down
60 changes: 38 additions & 22 deletions cores/esp32/USBCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,39 @@ size_t USBCDC::setRxBufferSize(size_t rx_queue_len){
size_t currentQueueSize = rx_queue ?
uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0;

if (rx_queue && (!rx_queue_len || rx_queue_len != currentQueueSize)) {
vQueueDelete(rx_queue);
rx_queue = NULL;
}
if(!rx_queue_len || rx_queue_len == currentQueueSize){
return 0;
}
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
if(!rx_queue){
return 0;
if (rx_queue_len != currentQueueSize) {
xQueueHandle new_rx_queue = NULL;
if (rx_queue_len) {
new_rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
if(!new_rx_queue){
log_e("CDC Queue creation failed.");
return 0;
}
if (rx_queue) {
size_t copySize = uxQueueMessagesWaiting(rx_queue);
if (copySize > 0) {
for(size_t i = 0; i < copySize; i++) {
uint8_t ch = 0;
xQueueReceive(rx_queue, &ch, 0);
if (!xQueueSend(new_rx_queue, &ch, 0)) {
arduino_usb_cdc_event_data_t p;
p.rx_overflow.dropped_bytes = copySize - i;
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
log_e("CDC RX Overflow.");
break;
}
}
}
vQueueDelete(rx_queue);
}
rx_queue = new_rx_queue;
return rx_queue_len;
} else {
if (rx_queue) {
vQueueDelete(rx_queue);
rx_queue = NULL;
}
}
}
return rx_queue_len;
}
Expand Down Expand Up @@ -249,26 +272,19 @@ void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _pari
}

void USBCDC::_onRX(){
arduino_usb_cdc_event_data_t p;
uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE+1];
uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE);

if(rx_queue == NULL) {
return;
}
if (uxQueueSpacesAvailable(rx_queue) < count) {
//this VTaskDelay gives, to Arduino's task, time to the CPU do its processing
//without it, data may be lost when the number of bytes received is higher than CDC buffer size
vTaskDelay(10);
}
for(uint32_t i=0; i<count; i++){
if(!xQueueSend(rx_queue, buf+i, 0)){
// rx_queue overflow - data will be lost
if(rx_queue == NULL || !xQueueSend(rx_queue, buf+i, 10)) {
p.rx_overflow.dropped_bytes = count - i;
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_OVERFLOW_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
log_e("CDC RX Overflow.");
count = i;
break;
}
}
if (count) {
arduino_usb_cdc_event_data_t p;
p.rx.len = count;
arduino_usb_event_post(ARDUINO_USB_CDC_EVENTS, ARDUINO_USB_CDC_RX_EVENT, &p, sizeof(arduino_usb_cdc_event_data_t), portMAX_DELAY);
}
Expand Down
4 changes: 4 additions & 0 deletions cores/esp32/USBCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef enum {
ARDUINO_USB_CDC_LINE_CODING_EVENT,
ARDUINO_USB_CDC_RX_EVENT,
ARDUINO_USB_CDC_TX_EVENT,
ARDUINO_USB_CDC_RX_OVERFLOW_EVENT,
ARDUINO_USB_CDC_MAX_EVENT,
} arduino_usb_cdc_event_t;

Expand All @@ -50,6 +51,9 @@ typedef union {
struct {
size_t len;
} rx;
struct {
size_t dropped_bytes;
} rx_overflow;
} arduino_usb_cdc_event_data_t;

class USBCDC: public Stream
Expand Down
4 changes: 2 additions & 2 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void uartSetHwFlowCtrlMode(uart_t *uart, uint8_t mode, uint8_t threshold) {
}


uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd)
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd)
{
if(uart_nr >= SOC_UART_NUM) {
return NULL;
Expand Down Expand Up @@ -163,7 +163,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
uart_config.source_clk = UART_SCLK_APB;


ESP_ERROR_CHECK(uart_driver_install(uart_nr, 2*queueLen, 0, 20, &(uart->uart_event_queue), 0));
ESP_ERROR_CHECK(uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0));
ESP_ERROR_CHECK(uart_param_config(uart_nr, &uart_config));
ESP_ERROR_CHECK(uart_set_pin(uart_nr, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));

Expand Down
2 changes: 1 addition & 1 deletion cores/esp32/esp32-hal-uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern "C" {
struct uart_struct_t;
typedef struct uart_struct_t uart_t;

uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd);
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd);
void uartEnd(uart_t* uart);

// This is used to retrieve the Event Queue pointer from a UART IDF Driver in order to allow user to deal with its events
Expand Down
Loading