Skip to content

Commit d75852b

Browse files
authored
Merge branch 'master' into SSLClient
2 parents 33af65f + 1e388a2 commit d75852b

File tree

410 files changed

+445
-325
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+445
-325
lines changed

Diff for: .github/scripts/install-platformio-esp32.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export PLATFORMIO_ESP32_PATH="$HOME/.platformio/packages/framework-arduinoespressif32"
44
PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git#feature/arduino-idf-master"
55

6-
TOOLCHAIN_VERSION="8.4.0+2021r2-patch2"
6+
TOOLCHAIN_VERSION="8.4.0+2021r2-patch3"
77
ESPTOOLPY_VERSION="~1.30100.0"
88
ESPRESSIF_ORGANIZATION_NAME="espressif"
99

Diff for: .github/scripts/on-push.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ else
109109
replace_script+="data['packages']['toolchain-xtensa-esp32']['optional']=True;"
110110
replace_script+="data['packages']['toolchain-xtensa-esp32s3']['optional']=False;"
111111
replace_script+="data['packages']['tool-esptoolpy']['owner']='tasmota';"
112-
replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v3.2.1/esptool-3.2.1.zip';"
112+
replace_script+="data['packages']['tool-esptoolpy']['version']='https://github.com/tasmota/esptool/releases/download/v3.3/esptool-3.3.zip';"
113113
replace_script+="fp.seek(0);fp.truncate();json.dump(data, fp, indent=2);fp.close()"
114114
python -c "$replace_script"
115115

Diff for: Makefile.projbuild

-7
This file was deleted.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Arduino core for the ESP32, ESP32-S2 and ESP32-C3
1+
# Arduino core for the ESP32, ESP32-S2, ESP32-S3 and ESP32-C3
22

33
![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![Documentation Status](https://readthedocs.com/projects/espressif-arduino-esp32/badge/?version=latest)](https://docs.espressif.com/projects/arduino-esp32/en/latest/?badge=latest)
44

Diff for: component.mk

-36
This file was deleted.

Diff for: cores/esp32/HardwareSerial.cpp

+46-5
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ void serialEventRun(void)
122122

123123
HardwareSerial::HardwareSerial(int uart_nr) :
124124
_uart_nr(uart_nr),
125-
_uart(NULL),
125+
_uart(NULL),
126126
_rxBufferSize(256),
127127
_txBufferSize(0),
128128
_onReceiveCB(NULL),
129129
_onReceiveErrorCB(NULL),
130+
_onReceiveTimeout(true),
131+
_rxTimeout(10),
130132
_eventTask(NULL)
131133
#if !CONFIG_DISABLE_HAL_LOCKS
132134
,_lock(NULL)
@@ -183,18 +185,49 @@ void HardwareSerial::onReceiveError(OnReceiveErrorCb function)
183185
HSERIAL_MUTEX_UNLOCK();
184186
}
185187

186-
void HardwareSerial::onReceive(OnReceiveCb function)
188+
void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout)
187189
{
188190
HSERIAL_MUTEX_LOCK();
189191
// function may be NULL to cancel onReceive() from its respective task
190192
_onReceiveCB = function;
193+
// When Rx timeout is Zero (disabled), there is only one possible option that is callback when FIFO reaches 120 bytes
194+
_onReceiveTimeout = _rxTimeout > 0 ? onlyOnTimeout : false;
195+
191196
// this can be called after Serial.begin(), therefore it shall create the event task
192197
if (function != NULL && _uart != NULL && _eventTask == NULL) {
193-
_createEventTask(this);
198+
_createEventTask(this); // Create event task
194199
}
195200
HSERIAL_MUTEX_UNLOCK();
196201
}
197202

203+
// timout is calculates in time to receive UART symbols at the UART baudrate.
204+
// the estimation is about 11 bits per symbol (SERIAL_8N1)
205+
void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
206+
{
207+
HSERIAL_MUTEX_LOCK();
208+
209+
// Zero disables timeout, thus, onReceive callback will only be called when RX FIFO reaches 120 bytes
210+
// Any non-zero value will activate onReceive callback based on UART baudrate with about 11 bits per symbol
211+
_rxTimeout = symbols_timeout;
212+
if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag
213+
214+
if(_uart != NULL) uart_set_rx_timeout(_uart_nr, _rxTimeout); // Set new timeout
215+
216+
HSERIAL_MUTEX_UNLOCK();
217+
}
218+
219+
void HardwareSerial::eventQueueReset()
220+
{
221+
QueueHandle_t uartEventQueue = NULL;
222+
if (_uart == NULL) {
223+
return;
224+
}
225+
uartGetEventQueue(_uart, &uartEventQueue);
226+
if (uartEventQueue != NULL) {
227+
xQueueReset(uartEventQueue);
228+
}
229+
}
230+
198231
void HardwareSerial::_uartEventTask(void *args)
199232
{
200233
HardwareSerial *uart = (HardwareSerial *)args;
@@ -207,14 +240,16 @@ void HardwareSerial::_uartEventTask(void *args)
207240
if(xQueueReceive(uartEventQueue, (void * )&event, (portTickType)portMAX_DELAY)) {
208241
switch(event.type) {
209242
case UART_DATA:
210-
if(uart->_onReceiveCB && uart->available() > 0) uart->_onReceiveCB();
243+
if(uart->_onReceiveCB && uart->available() > 0 &&
244+
((uart->_onReceiveTimeout && event.timeout_flag) || !uart->_onReceiveTimeout) )
245+
uart->_onReceiveCB();
211246
break;
212247
case UART_FIFO_OVF:
213248
log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr);
214249
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_FIFO_OVF_ERROR);
215250
break;
216251
case UART_BUFFER_FULL:
217-
log_w("UART%d Buffer Full. Consider encreasing your buffer size of your Application.", uart->_uart_nr);
252+
log_w("UART%d Buffer Full. Consider increasing your buffer size of your Application.", uart->_uart_nr);
218253
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_BUFFER_FULL_ERROR);
219254
break;
220255
case UART_BREAK:
@@ -317,6 +352,12 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
317352
if (_uart != NULL && (_onReceiveCB != NULL || _onReceiveErrorCB != NULL) && _eventTask == NULL) {
318353
_createEventTask(this);
319354
}
355+
356+
// Set UART RX timeout
357+
if (_uart != NULL) {
358+
uart_set_rx_timeout(_uart_nr, _rxTimeout);
359+
}
360+
320361
HSERIAL_MUTEX_UNLOCK();
321362
}
322363

Diff for: cores/esp32/HardwareSerial.h

+30-6
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,31 @@ class HardwareSerial: public Stream
7373
HardwareSerial(int uart_nr);
7474
~HardwareSerial();
7575

76-
// onReceive will setup a callback for whenever UART data is received
77-
// it will work as UART Rx interrupt -- Using C++ 11 std::fuction
78-
void onReceive(OnReceiveCb function);
76+
// setRxTimeout sets the timeout after which onReceive callback will be called (after receiving data, it waits for this time of UART rx inactivity to call the callback fnc)
77+
// param symbols_timeout defines a timeout threshold in uart symbol periods. Setting 0 symbol timeout disables the callback call by timeout.
78+
// Maximum timeout setting is calculacted automatically by IDF. If set above the maximum, it is ignored and an error is printed on Serial0 (check console).
79+
// Examples: Maximum for 11 bits symbol is 92 (SERIAL_8N2, SERIAL_8E1, SERIAL_8O1, etc), Maximum for 10 bits symbol is 101 (SERIAL_8N1).
80+
// For example symbols_timeout=1 defines a timeout equal to transmission time of one symbol (~11 bit) on current baudrate.
81+
// For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms
82+
void setRxTimeout(uint8_t symbols_timeout);
83+
84+
// onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT)
85+
// UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF)
86+
// UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF)
87+
// onlyOnTimeout parameter will define how onReceive will behave:
88+
// Default: true -- The callback will only be called when RX Timeout happens.
89+
// Whole stream of bytes will be ready for being read on the callback function at once.
90+
// This option may lead to Rx Overflow depending on the Rx Buffer Size and number of bytes received in the streaming
91+
// false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout.
92+
// The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback.
93+
// This option avoid any sort of Rx Overflow, but leaves the UART packet reassembling work to the Application.
94+
void onReceive(OnReceiveCb function, bool onlyOnTimeout = true);
95+
96+
// onReceive will be called on error events (see hardwareSerial_error_t)
7997
void onReceiveError(OnReceiveErrorCb function);
98+
99+
// eventQueueReset clears all events in the queue (the events that trigger onReceive and onReceiveError) - maybe usefull in some use cases
100+
void eventQueueReset();
80101

81102
void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112);
82103
void end(bool fullyTerminate = true);
@@ -141,14 +162,17 @@ class HardwareSerial: public Stream
141162
size_t _txBufferSize;
142163
OnReceiveCb _onReceiveCB;
143164
OnReceiveErrorCb _onReceiveErrorCB;
165+
// _onReceive and _rxTimeout have be consistent when timeout is disabled
166+
bool _onReceiveTimeout;
167+
uint8_t _rxTimeout;
144168
TaskHandle_t _eventTask;
169+
#if !CONFIG_DISABLE_HAL_LOCKS
170+
SemaphoreHandle_t _lock;
171+
#endif
145172

146173
void _createEventTask(void *args);
147174
void _destroyEventTask(void);
148175
static void _uartEventTask(void *args);
149-
#if !CONFIG_DISABLE_HAL_LOCKS
150-
SemaphoreHandle_t _lock;
151-
#endif
152176
};
153177

154178
extern void serialEventRun(void) __attribute__((weak));

Diff for: libraries/Ethernet/src/ETH.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,19 @@ ETHClass::ETHClass()
226226
ETHClass::~ETHClass()
227227
{}
228228

229-
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode)
229+
bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t type, eth_clock_mode_t clock_mode, bool use_mac_from_efuse)
230230
{
231231
#if ESP_IDF_VERSION_MAJOR > 3
232232
eth_clock_mode = clock_mode;
233233
tcpipInit();
234234

235+
if (use_mac_from_efuse)
236+
{
237+
uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
238+
esp_efuse_mac_get_custom(p);
239+
esp_base_mac_addr_set(p);
240+
}
241+
235242
tcpip_adapter_set_default_eth_handlers();
236243

237244
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
@@ -363,6 +370,14 @@ bool ETHClass::begin(uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_typ
363370
}
364371

365372
tcpipInit();
373+
374+
if (use_mac_from_efuse)
375+
{
376+
uint8_t p[6] = { 0x00,0x00,0x00,0x00,0x00,0x00 };
377+
esp_efuse_mac_get_custom(p);
378+
esp_base_mac_addr_set(p);
379+
}
380+
366381
err = esp_eth_init(&eth_config);
367382
if(!err){
368383
initialized = true;

Diff for: libraries/Ethernet/src/ETH.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ETHClass {
7575
ETHClass();
7676
~ETHClass();
7777

78-
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE);
78+
bool begin(uint8_t phy_addr=ETH_PHY_ADDR, int power=ETH_PHY_POWER, int mdc=ETH_PHY_MDC, int mdio=ETH_PHY_MDIO, eth_phy_type_t type=ETH_PHY_TYPE, eth_clock_mode_t clk_mode=ETH_CLK_MODE, bool use_mac_from_efuse=false);
7979

8080
bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, IPAddress dns2 = (uint32_t)0x00000000);
8181

0 commit comments

Comments
 (0)