Skip to content

Commit db37efa

Browse files
authored
Merge branch 'master' into feature/i2s_sr
2 parents 03b4189 + f218209 commit db37efa

File tree

9 files changed

+82
-46
lines changed

9 files changed

+82
-46
lines changed

cores/esp32/HardwareSerial.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ _eventTask(NULL)
183183

184184
HardwareSerial::~HardwareSerial()
185185
{
186-
end();
186+
end(true); // explicit Full UART termination
187187
#if !CONFIG_DISABLE_HAL_LOCKS
188188
if(_lock != NULL){
189189
vSemaphoreDelete(_lock);
@@ -398,7 +398,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
398398
if(_uart) {
399399
// in this case it is a begin() over a previous begin() - maybe to change baud rate
400400
// thus do not disable debug output
401-
end(false);
401+
end(false); // disables IDF UART driver and UART event Task + sets _uart to NULL
402402
}
403403

404404
// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
@@ -413,7 +413,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
413413
yield();
414414
}
415415

416-
end(false);
416+
end(false); // disables IDF UART driver and UART event Task + sets _uart to NULL
417417

418418
if(detectedBaudRate) {
419419
delay(100); // Give some time...
@@ -470,10 +470,8 @@ void HardwareSerial::end(bool fullyTerminate)
470470
// do not invalidate callbacks, detach pins, invalidate DBG output
471471
uart_driver_delete(_uart_nr);
472472
}
473-
474-
uartEnd(_uart_nr);
475-
_uart = 0;
476-
_destroyEventTask();
473+
_destroyEventTask(); // when IDF uart driver is deleted, _eventTask must finish too
474+
_uart = NULL;
477475
}
478476

479477
void HardwareSerial::setDebugOutput(bool en)

cores/esp32/esp32-hal-i2c.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "driver/i2c.h"
3131
#include "esp32-hal-periman.h"
3232

33+
#if SOC_I2C_SUPPORT_APB || SOC_I2C_SUPPORT_XTAL
34+
#include "esp_private/esp_clk.h"
35+
#endif
36+
#if SOC_I2C_SUPPORT_RTC
37+
#include "clk_ctrl_os.h"
38+
#endif
39+
3340
typedef volatile struct {
3441
bool initialized;
3542
uint32_t frequency;
@@ -303,11 +310,6 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
303310
} else if(frequency > 1000000UL){
304311
frequency = 1000000UL;
305312
}
306-
// Freq limitation when using different clock sources
307-
#define I2C_CLK_LIMIT_REF_TICK (1 * 1000 * 1000 / 20) /*!< Limited by REF_TICK, no more than REF_TICK/20*/
308-
#define I2C_CLK_LIMIT_APB (80 * 1000 * 1000 / 20) /*!< Limited by APB, no more than APB/20*/
309-
#define I2C_CLK_LIMIT_RTC (20 * 1000 * 1000 / 20) /*!< Limited by RTC, no more than RTC/20*/
310-
#define I2C_CLK_LIMIT_XTAL (40 * 1000 * 1000 / 20) /*!< Limited by RTC, no more than XTAL/20*/
311313

312314
typedef struct {
313315
soc_module_clk_t clk; /*!< I2C source clock */
@@ -332,22 +334,22 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
332334
} i2c_sclk_t;
333335

334336
// i2c clock characteristic, The order is the same as i2c_sclk_t.
335-
static i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = {
337+
i2c_clk_alloc_t i2c_clk_alloc[I2C_SCLK_MAX] = {
336338
{0, 0},
337339
#if SOC_I2C_SUPPORT_APB
338-
{SOC_MOD_CLK_APB, I2C_CLK_LIMIT_APB}, /*!< I2C APB clock characteristic*/
340+
{SOC_MOD_CLK_APB, esp_clk_apb_freq()}, /*!< I2C APB clock characteristic*/
339341
#endif
340342
#if SOC_I2C_SUPPORT_XTAL
341-
{SOC_MOD_CLK_XTAL, I2C_CLK_LIMIT_XTAL}, /*!< I2C XTAL characteristic*/
343+
{SOC_MOD_CLK_XTAL, esp_clk_xtal_freq()}, /*!< I2C XTAL characteristic*/
342344
#endif
343345
#if SOC_I2C_SUPPORT_RTC
344-
{SOC_MOD_CLK_RC_FAST, I2C_CLK_LIMIT_RTC}, /*!< I2C 20M RTC characteristic*/
346+
{SOC_MOD_CLK_RC_FAST, periph_rtc_dig_clk8m_get_freq()}, /*!< I2C 20M RTC characteristic*/
345347
#endif
346348
#if SOC_I2C_SUPPORT_REF_TICK
347-
{SOC_MOD_CLK_REF_TICK, I2C_CLK_LIMIT_REF_TICK},/*!< I2C REF_TICK characteristic*/
349+
{SOC_MOD_CLK_REF_TICK, REF_CLK_FREQ},/*!< I2C REF_TICK characteristic*/
348350
#endif
349351
};
350-
352+
351353
i2c_sclk_t src_clk = I2C_SCLK_DEFAULT;
352354
ret = ESP_OK;
353355
for (i2c_sclk_t clk = I2C_SCLK_DEFAULT + 1; clk < I2C_SCLK_MAX; clk++) {
@@ -367,6 +369,11 @@ esp_err_t i2cSetClock(uint8_t i2c_num, uint32_t frequency){
367369
} else {
368370
i2c_hal_context_t hal;
369371
hal.dev = I2C_LL_GET_HW(i2c_num);
372+
#if SOC_I2C_SUPPORT_RTC
373+
if(src_clk == I2C_SCLK_RTC){
374+
periph_rtc_dig_clk8m_enable();
375+
}
376+
#endif
370377
i2c_hal_set_bus_timing(&(hal), frequency, i2c_clk_alloc[src_clk].clk, i2c_clk_alloc[src_clk].clk_freq);
371378
bus[i2c_num].frequency = frequency;
372379
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2

cores/esp32/esp32-hal-uart.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -884,32 +884,29 @@ void uartStartDetectBaudrate(uart_t *uart) {
884884
return;
885885
}
886886

887-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
887+
// Baud rate detection only works for ESP32 and ESP32S2
888+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
889+
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
890+
hw->auto_baud.glitch_filt = 0x08;
891+
hw->auto_baud.en = 0;
892+
hw->auto_baud.en = 1;
893+
#else
888894

889895
// ESP32-C3 requires further testing
890896
// Baud rate detection returns wrong values
891897

892-
log_e("ESP32-C3 baud rate detection is not supported.");
898+
log_e("baud rate detection for this SoC is not supported.");
893899
return;
894900

895901
// Code bellow for C3 kept for future recall
896902
//hw->rx_filt.glitch_filt = 0x08;
897903
//hw->rx_filt.glitch_filt_en = 1;
898904
//hw->conf0.autobaud_en = 0;
899905
//hw->conf0.autobaud_en = 1;
900-
#elif CONFIG_IDF_TARGET_ESP32S3
901-
log_e("ESP32-S3 baud rate detection is not supported.");
902-
return;
903-
#else
904-
uart_dev_t *hw = UART_LL_GET_HW(uart->num);
905-
hw->auto_baud.glitch_filt = 0x08;
906-
hw->auto_baud.en = 0;
907-
hw->auto_baud.en = 1;
908906
#endif
909907
}
910908

911-
unsigned long
912-
uartDetectBaudrate(uart_t *uart)
909+
unsigned long uartDetectBaudrate(uart_t *uart)
913910
{
914911
if(uart == NULL) {
915912
return 0;
@@ -955,11 +952,7 @@ uartDetectBaudrate(uart_t *uart)
955952

956953
return default_rates[i];
957954
#else
958-
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2
959-
log_e("ESP32-C3 baud rate detection is not supported.");
960-
#else
961-
log_e("ESP32-S3 baud rate detection is not supported.");
962-
#endif
955+
log_e("baud rate detection this SoC is not supported.");
963956
return 0;
964957
#endif
965958
}

libraries/BLE/examples/Beacon_Scanner/Beacon_Scanner.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ void setup()
111111
void loop()
112112
{
113113
// put your main code here, to run repeatedly:
114-
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
114+
BLEScanResults *foundDevices = pBLEScan->start(scanTime, false);
115115
Serial.print("Devices found: ");
116-
Serial.println(foundDevices.getCount());
116+
Serial.println(foundDevices->getCount());
117117
Serial.println("Scan done!");
118118
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
119119
delay(2000);

libraries/BLE/examples/Scan/Scan.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void setup() {
3131

3232
void loop() {
3333
// put your main code here, to run repeatedly:
34-
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
34+
BLEScanResults *foundDevices = pBLEScan->start(scanTime, false);
3535
Serial.print("Devices found: ");
36-
Serial.println(foundDevices.getCount());
36+
Serial.println(foundDevices->getCount());
3737
Serial.println("Scan done!");
3838
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
3939
delay(2000);

libraries/BLE/src/BLEScan.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,11 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b
426426
* @param [in] duration The duration in seconds for which to scan.
427427
* @return The BLEScanResults.
428428
*/
429-
BLEScanResults BLEScan::start(uint32_t duration, bool is_continue) {
429+
BLEScanResults* BLEScan::start(uint32_t duration, bool is_continue) {
430430
if(start(duration, nullptr, is_continue)) {
431431
m_semaphoreScanEnd.wait("start"); // Wait for the semaphore to release.
432432
}
433-
return m_scanResults;
433+
return &m_scanResults;
434434
} // start
435435

436436

@@ -500,8 +500,8 @@ BLEAdvertisedDevice BLEScanResults::getDevice(uint32_t i) {
500500
return dev;
501501
}
502502

503-
BLEScanResults BLEScan::getResults() {
504-
return m_scanResults;
503+
BLEScanResults* BLEScan::getResults() {
504+
return &m_scanResults;
505505
}
506506

507507
void BLEScan::clearResults() {

libraries/BLE/src/BLEScan.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ class BLEScan {
7171
void setInterval(uint16_t intervalMSecs);
7272
void setWindow(uint16_t windowMSecs);
7373
bool start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue = false);
74-
BLEScanResults start(uint32_t duration, bool is_continue = false);
74+
BLEScanResults* start(uint32_t duration, bool is_continue = false);
7575
void stop();
7676
void erase(BLEAddress address);
77-
BLEScanResults getResults();
77+
BLEScanResults* getResults();
7878
void clearResults();
7979

8080
#ifdef SOC_BLE_50_SUPPORTED
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
This Sketch demonstrates how to detect and set the baud rate when the UART0 is connected to
3+
some port that is sending data. It can be used with the Arduino IDE Serial Monitor to send the data.
4+
5+
Serial.begin(0) will start the baud rate detection. Valid range is 300 to 230400 baud.
6+
It will try to detect for 20 seconds, by default, while reading RX.
7+
This timeout of 20 seconds can be changed in the begin() function through <<timeout_ms>> parameter:
8+
9+
void HardwareSerial::begin(baud, config, rxPin, txPin, invert, <<timeout_ms>>, rxfifo_full_thrhd)
10+
11+
It is necessary that the other end sends some data within <<timeout_ms>>, otherwise the detection won't work.
12+
13+
IMPORTANT NOTE: baud rate detection seem to only work with ESP32 and ESP32-S2.
14+
In other other SoCs, it doesn't work.
15+
16+
*/
17+
18+
// Open the Serial Monitor with testing baud start typing and sending caracters
19+
void setup() {
20+
Serial.begin(0); // it will try to detect the baud rate for 20 seconds
21+
22+
Serial.print("\n==>The baud rate is ");
23+
Serial.println(Serial.baudRate());
24+
25+
//after 20 seconds timeout, when not detected, it will return zero - in this case, we set it back to 115200.
26+
if (Serial.baudRate() == 0) {
27+
// Trying to set Serial to a safe state at 115200
28+
Serial.end();
29+
Serial.begin(115200);
30+
Serial.setDebugOutput(true);
31+
delay(1000);
32+
log_e("Baud rate detection failed.");
33+
}
34+
}
35+
36+
void loop() {
37+
}

libraries/LittleFS/src/LittleFS.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ bool LittleFSFS::begin(bool formatOnFail, const char * basePath, uint8_t maxOpen
8282
.base_path = basePath,
8383
.partition_label = partitionLabel_,
8484
.format_if_mount_failed = false,
85-
.dont_mount = false
85+
.dont_mount = false,
86+
.grow_on_mount = true
8687
};
8788

8889
esp_err_t err = esp_vfs_littlefs_register(&conf);

0 commit comments

Comments
 (0)