Skip to content

Commit dec0c4b

Browse files
authored
Merge branch 'master' into feature/ipaddress-v6-support
2 parents 60da4a9 + a5f03a8 commit dec0c4b

File tree

649 files changed

+4979
-7380
lines changed

Some content is hidden

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

649 files changed

+4979
-7380
lines changed

Diff for: .github/ISSUE_TEMPLATE/Issue-report.yml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ body:
4141
options:
4242
- latest master (checkout manually)
4343
- latest development Release Candidate (RC-X)
44+
- v2.0.5
4445
- v2.0.4
4546
- v2.0.3
4647
- v2.0.2

Diff for: .github/workflows/upload-idf-component.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ jobs:
1212
submodules: "recursive"
1313

1414
- name: Upload components to the component registry
15-
uses: espressif/github-actions/upload_components@master
15+
uses: espressif/upload-components-ci-action@v1
1616
with:
1717
name: arduino-esp32
18+
version: ${{ github.ref_name }}
1819
namespace: espressif
1920
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

Diff for: boards.txt

+1,308-475
Large diffs are not rendered by default.

Diff for: cores/esp32/Arduino.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@
7979
#define degrees(rad) ((rad)*RAD_TO_DEG)
8080
#define sq(x) ((x)*(x))
8181

82-
#define sei()
83-
#define cli()
82+
// ESP32xx runs FreeRTOS... disabling interrupts can lead to issues, such as Watchdog Timeout
83+
#define sei() portENABLE_INTERRUPTS()
84+
#define cli() portDISABLE_INTERRUPTS()
8485
#define interrupts() sei()
8586
#define noInterrupts() cli()
8687

Diff for: cores/esp32/Esp.cpp

+39-11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
}
3131
#include <MD5Builder.h>
3232

33+
#include "soc/spi_reg.h"
3334
#include "esp_system.h"
3435
#ifdef ESP_IDF_VERSION_MAJOR // IDF 4+
3536
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
@@ -55,6 +56,14 @@ extern "C" {
5556
#define ESP_FLASH_IMAGE_BASE 0x1000
5657
#endif
5758

59+
// REG_SPI_BASE is not defined for S3/C3 ??
60+
61+
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
62+
#ifndef REG_SPI_BASE
63+
#define REG_SPI_BASE(i) (DR_REG_SPI1_BASE + (((i)>1) ? (((i)* 0x1000) + 0x20000) : (((~(i)) & 1)* 0x1000 )))
64+
#endif // REG_SPI_BASE
65+
#endif // TARGET
66+
5867
/**
5968
* User-defined Literals
6069
* usage:
@@ -192,7 +201,7 @@ static uint32_t sketchSize(sketchSize_t response) {
192201
return data.image_len;
193202
}
194203
}
195-
204+
196205
uint32_t EspClass::getSketchSize () {
197206
return sketchSize(SKETCH_SIZE_TOTAL);
198207
}
@@ -305,13 +314,17 @@ const char * EspClass::getSdkVersion(void)
305314
return esp_get_idf_version();
306315
}
307316

317+
uint32_t ESP_getFlashChipId(void)
318+
{
319+
uint32_t id = g_rom_flashchip.device_id;
320+
id = ((id & 0xff) << 16) | ((id >> 16) & 0xff) | (id & 0xff00);
321+
return id;
322+
}
323+
308324
uint32_t EspClass::getFlashChipSize(void)
309325
{
310-
esp_image_header_t fhdr;
311-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
312-
return 0;
313-
}
314-
return magicFlashChipSize(fhdr.spi_size);
326+
uint32_t id = (ESP_getFlashChipId() >> 16) & 0xFF;
327+
return 2 << (id - 1);
315328
}
316329

317330
uint32_t EspClass::getFlashChipSpeed(void)
@@ -325,11 +338,26 @@ uint32_t EspClass::getFlashChipSpeed(void)
325338

326339
FlashMode_t EspClass::getFlashChipMode(void)
327340
{
328-
esp_image_header_t fhdr;
329-
if(flashRead(ESP_FLASH_IMAGE_BASE, (uint32_t*)&fhdr, sizeof(esp_image_header_t)) && fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
330-
return FM_UNKNOWN;
331-
}
332-
return magicFlashChipMode(fhdr.spi_mode);
341+
#if CONFIG_IDF_TARGET_ESP32S2
342+
uint32_t spi_ctrl = REG_READ(PERIPHS_SPI_FLASH_CTRL);
343+
#else
344+
uint32_t spi_ctrl = REG_READ(SPI_CTRL_REG(0));
345+
#endif
346+
/* Not all of the following constants are already defined in older versions of spi_reg.h, so do it manually for now*/
347+
if (spi_ctrl & BIT(24)) { //SPI_FREAD_QIO
348+
return (FM_QIO);
349+
} else if (spi_ctrl & BIT(20)) { //SPI_FREAD_QUAD
350+
return (FM_QOUT);
351+
} else if (spi_ctrl & BIT(23)) { //SPI_FREAD_DIO
352+
return (FM_DIO);
353+
} else if (spi_ctrl & BIT(14)) { // SPI_FREAD_DUAL
354+
return (FM_DOUT);
355+
} else if (spi_ctrl & BIT(13)) { //SPI_FASTRD_MODE
356+
return (FM_FAST_READ);
357+
} else {
358+
return (FM_SLOW_READ);
359+
}
360+
return (FM_DOUT);
333361
}
334362

335363
uint32_t EspClass::magicFlashChipSize(uint8_t byte)

Diff for: cores/esp32/HardwareSerial.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ _txBufferSize(0),
140140
_onReceiveCB(NULL),
141141
_onReceiveErrorCB(NULL),
142142
_onReceiveTimeout(true),
143-
_rxTimeout(10),
143+
_rxTimeout(2),
144144
_eventTask(NULL)
145145
#if !CONFIG_DISABLE_HAL_LOCKS
146146
,_lock(NULL)
@@ -212,6 +212,18 @@ void HardwareSerial::onReceive(OnReceiveCb function, bool onlyOnTimeout)
212212
HSERIAL_MUTEX_UNLOCK();
213213
}
214214

215+
// This function allow the user to define how many bytes will trigger an Interrupt that will copy RX FIFO to the internal RX Ringbuffer
216+
// ISR will also move data from FIFO to RX Ringbuffer after a RX Timeout defined in HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
217+
// A low value of FIFO Full bytes will consume more CPU time within the ISR
218+
// A high value of FIFO Full bytes will make the application wait longer to have byte available for the Stkech in a streaming scenario
219+
// Both RX FIFO Full and RX Timeout may affect when onReceive() will be called
220+
void HardwareSerial::setRxFIFOFull(uint8_t fifoBytes)
221+
{
222+
HSERIAL_MUTEX_LOCK();
223+
uartSetRxFIFOFull(_uart, fifoBytes); // Set new timeout
224+
HSERIAL_MUTEX_UNLOCK();
225+
}
226+
215227
// timout is calculates in time to receive UART symbols at the UART baudrate.
216228
// the estimation is about 11 bits per symbol (SERIAL_8N1)
217229
void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
@@ -223,7 +235,7 @@ void HardwareSerial::setRxTimeout(uint8_t symbols_timeout)
223235
_rxTimeout = symbols_timeout;
224236
if (!symbols_timeout) _onReceiveTimeout = false; // only when RX timeout is disabled, we also must disable this flag
225237

226-
if(_uart != NULL) uart_set_rx_timeout(_uart_nr, _rxTimeout); // Set new timeout
238+
uartSetRxTimeout(_uart, _rxTimeout); // Set new timeout
227239

228240
HSERIAL_MUTEX_UNLOCK();
229241
}
@@ -250,6 +262,7 @@ void HardwareSerial::_uartEventTask(void *args)
250262
for(;;) {
251263
//Waiting for UART event.
252264
if(xQueueReceive(uartEventQueue, (void * )&event, (portTickType)portMAX_DELAY)) {
265+
hardwareSerial_error_t currentErr = UART_NO_ERROR;
253266
switch(event.type) {
254267
case UART_DATA:
255268
if(uart->_onReceiveCB && uart->available() > 0 &&
@@ -258,28 +271,32 @@ void HardwareSerial::_uartEventTask(void *args)
258271
break;
259272
case UART_FIFO_OVF:
260273
log_w("UART%d FIFO Overflow. Consider adding Hardware Flow Control to your Application.", uart->_uart_nr);
261-
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_FIFO_OVF_ERROR);
274+
currentErr = UART_FIFO_OVF_ERROR;
262275
break;
263276
case UART_BUFFER_FULL:
264277
log_w("UART%d Buffer Full. Consider increasing your buffer size of your Application.", uart->_uart_nr);
265-
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_BUFFER_FULL_ERROR);
278+
currentErr = UART_BUFFER_FULL_ERROR;
266279
break;
267280
case UART_BREAK:
268281
log_w("UART%d RX break.", uart->_uart_nr);
269-
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_BREAK_ERROR);
282+
currentErr = UART_BREAK_ERROR;
270283
break;
271284
case UART_PARITY_ERR:
272285
log_w("UART%d parity error.", uart->_uart_nr);
273-
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_PARITY_ERROR);
286+
currentErr = UART_PARITY_ERROR;
274287
break;
275288
case UART_FRAME_ERR:
276289
log_w("UART%d frame error.", uart->_uart_nr);
277-
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(UART_FRAME_ERROR);
290+
currentErr = UART_FRAME_ERROR;
278291
break;
279292
default:
280293
log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type);
281294
break;
282295
}
296+
if (currentErr != UART_NO_ERROR) {
297+
if(uart->_onReceiveErrorCB) uart->_onReceiveErrorCB(currentErr);
298+
if(uart->_onReceiveCB && uart->available() > 0) uart->_onReceiveCB(); // forces User Callback too
299+
}
283300
}
284301
}
285302
}
@@ -366,9 +383,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
366383
}
367384

368385
// Set UART RX timeout
369-
if (_uart != NULL) {
370-
uart_set_rx_timeout(_uart_nr, _rxTimeout);
371-
}
386+
uartSetRxTimeout(_uart, _rxTimeout);
372387

373388
HSERIAL_MUTEX_UNLOCK();
374389
}

Diff for: cores/esp32/HardwareSerial.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "freertos/semphr.h"
5858

5959
typedef enum {
60+
UART_NO_ERROR,
6061
UART_BREAK_ERROR,
6162
UART_BUFFER_FULL_ERROR,
6263
UART_FIFO_OVF_ERROR,
@@ -81,6 +82,12 @@ class HardwareSerial: public Stream
8182
// For a baudrate of 9600, SERIAL_8N1 (10 bit symbol) and symbols_timeout = 3, the timeout would be 3 / (9600 / 10) = 3.125 ms
8283
void setRxTimeout(uint8_t symbols_timeout);
8384

85+
// setRxFIFOFull(uint8_t fifoBytes) will set the number of bytes that will trigger UART_INTR_RXFIFO_FULL interrupt and fill up RxRingBuffer
86+
// This affects some functions such as Serial::available() and Serial.read() because, in a UART flow of receiving data, Serial internal
87+
// RxRingBuffer will be filled only after these number of bytes arrive or a RX Timeout happens.
88+
// This parameter can be set to 1 in order to receive byte by byte, but it will also consume more CPU time as the ISR will be activates often.
89+
void setRxFIFOFull(uint8_t fifoBytes);
90+
8491
// onReceive will setup a callback that will be called whenever an UART interruption occurs (UART_INTR_RXFIFO_FULL or UART_INTR_RXFIFO_TOUT)
8592
// UART_INTR_RXFIFO_FULL interrupt triggers at UART_FULL_THRESH_DEFAULT bytes received (defined as 120 bytes by default in IDF)
8693
// UART_INTR_RXFIFO_TOUT interrupt triggers at UART_TOUT_THRESH_DEFAULT symbols passed without any reception (defined as 10 symbos by default in IDF)
@@ -91,7 +98,7 @@ class HardwareSerial: public Stream
9198
// false -- The callback will be called when FIFO reaches 120 bytes and also on RX Timeout.
9299
// The stream of incommig bytes will be "split" into blocks of 120 bytes on each callback.
93100
// 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);
101+
void onReceive(OnReceiveCb function, bool onlyOnTimeout = false);
95102

96103
// onReceive will be called on error events (see hardwareSerial_error_t)
97104
void onReceiveError(OnReceiveErrorCb function);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){
211211
capb = calculateApb(&cconf);
212212
//New APB
213213
apb = calculateApb(&conf);
214-
log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL)?"PLL":((conf.source == RTC_CPU_FREQ_SRC_APLL)?"APLL":((conf.source == RTC_CPU_FREQ_SRC_XTAL)?"XTAL":"8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb);
214+
215215
//Call peripheral functions before the APB change
216216
if(apb_change_callbacks){
217217
triggerApbChangeCallback(APB_BEFORE_CHANGE, capb, apb);
@@ -241,6 +241,7 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){
241241
if(apb_change_callbacks){
242242
triggerApbChangeCallback(APB_AFTER_CHANGE, capb, apb);
243243
}
244+
log_d("%s: %u / %u = %u Mhz, APB: %u Hz", (conf.source == RTC_CPU_FREQ_SRC_PLL)?"PLL":((conf.source == RTC_CPU_FREQ_SRC_APLL)?"APLL":((conf.source == RTC_CPU_FREQ_SRC_XTAL)?"XTAL":"8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz, apb);
244245
return true;
245246
}
246247

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

+44-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
162162
uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd;
163163
uart_config.source_clk = UART_SCLK_APB;
164164

165-
166165
ESP_ERROR_CHECK(uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0));
167166
ESP_ERROR_CHECK(uart_param_config(uart_nr, &uart_config));
168167
ESP_ERROR_CHECK(uart_set_pin(uart_nr, txPin, rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
@@ -172,13 +171,56 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
172171
// invert signal for both Rx and Tx
173172
ESP_ERROR_CHECK(uart_set_line_inverse(uart_nr, UART_SIGNAL_TXD_INV | UART_SIGNAL_RXD_INV));
174173
}
175-
174+
176175
UART_MUTEX_UNLOCK();
177176

178177
uartFlush(uart);
179178
return uart;
180179
}
181180

181+
// This code is under testing - for now just keep it here
182+
void uartSetFastReading(uart_t* uart)
183+
{
184+
if(uart == NULL) {
185+
return;
186+
}
187+
188+
UART_MUTEX_LOCK();
189+
// override default RX IDF Driver Interrupt - no BREAK, PARITY or OVERFLOW
190+
uart_intr_config_t uart_intr = {
191+
.intr_enable_mask = UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT, // only these IRQs - no BREAK, PARITY or OVERFLOW
192+
.rx_timeout_thresh = 1,
193+
.txfifo_empty_intr_thresh = 10,
194+
.rxfifo_full_thresh = 2,
195+
};
196+
197+
ESP_ERROR_CHECK(uart_intr_config(uart->num, &uart_intr));
198+
UART_MUTEX_UNLOCK();
199+
}
200+
201+
202+
void uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout)
203+
{
204+
if(uart == NULL) {
205+
return;
206+
}
207+
208+
UART_MUTEX_LOCK();
209+
uart_set_rx_timeout(uart->num, numSymbTimeout);
210+
UART_MUTEX_UNLOCK();
211+
}
212+
213+
void uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull)
214+
{
215+
if(uart == NULL) {
216+
return;
217+
}
218+
219+
UART_MUTEX_LOCK();
220+
uart_set_rx_full_threshold(uart->num, numBytesFIFOFull);
221+
UART_MUTEX_UNLOCK();
222+
}
223+
182224
void uartEnd(uart_t* uart)
183225
{
184226
if(uart == NULL) {

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

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ void uartSetBaudRate(uart_t* uart, uint32_t baud_rate);
8282
uint32_t uartGetBaudRate(uart_t* uart);
8383

8484
void uartSetRxInvert(uart_t* uart, bool invert);
85+
void uartSetRxTimeout(uart_t* uart, uint8_t numSymbTimeout);
86+
void uartSetRxFIFOFull(uart_t* uart, uint8_t numBytesFIFOFull);
87+
void uartSetFastReading(uart_t* uart);
8588

8689
void uartSetDebug(uart_t* uart);
8790
int uartGetDebug();

Diff for: cores/esp32/esp_arduino_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" {
2323
/** Minor version number (x.X.x) */
2424
#define ESP_ARDUINO_VERSION_MINOR 0
2525
/** Patch version number (x.x.X) */
26-
#define ESP_ARDUINO_VERSION_PATCH 4
26+
#define ESP_ARDUINO_VERSION_PATCH 5
2727

2828
/**
2929
* Macro to convert ARDUINO version number into an integer

Diff for: docs/source/boards/boards.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Development Boards
88
You will need a development board or a custom board with the ESP32 (see Supported SoC's) to start playing.
99
There is a bunch of different types and models widely available on the Internet. You need to choose one that covers all your requirements.
1010

11-
To help you on this selection, we point out some facts about choosing the proper boardsto help you to save money and time.
11+
To help you on this selection, we point out some facts about choosing the proper boards to help you to save money and time.
1212

1313
**One ESP32 to rule them all!**
1414

@@ -112,4 +112,4 @@ Resources
112112

113113
.. |board_lolin_d32_pro| raw:: html
114114

115-
<a href="https://www.wemos.cc/en/latest/d32/d32_pro.html" target="_blank">LOLIN D32 Pro</a>
115+
<a href="https://www.wemos.cc/en/latest/d32/d32_pro.html" target="_blank">LOLIN D32 Pro</a>

Diff for: docs/source/esp-idf_component.rst

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Installation
3737
cd ../.. && \
3838
idf.py menuconfig
3939
40+
.. note:: If you use Arduino with ESP-IDF often, you can place the arduino folder into global components folder.
41+
4042
Configuration
4143
-------------
4244

Diff for: docs/source/faq.rst

+4
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ To use the arduino-esp32 core with a modified sdkconfig option, you need to use
1111

1212
Note that modifying ``sdkconfig`` or ``sdkconfig.h`` files found in the arduino-esp32 project tree **does not** result in changes to these options. This is because ESP-IDF libraries are included into the arduino-esp32 project tree as pre-built libraries.
1313

14+
How to compile libs with different debug level?
15+
-----------------------------------------------
16+
17+
The short answer is ``esp32-arduino-lib-builder/configs/defconfig.common:44``. A guide explaining the process can be found here <guides/core_debug>

0 commit comments

Comments
 (0)