Skip to content

Commit 3c6d9a8

Browse files
authored
Merge branch 'master' into fix/rainmaker-example
2 parents 9992275 + b1b6228 commit 3c6d9a8

22 files changed

+251
-57
lines changed

Diff for: .github/scripts/tests_run.sh

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ function run_test() {
6969
if [[ -f "$sketchdir/scenario.yaml" ]]; then
7070
extra_args+=" --wokwi-scenario $sketchdir/scenario.yaml"
7171
fi
72+
if [[ -f "$sketchdir/diagram.$target.json" ]]; then
73+
extra_args+=" --wokwi-diagram $sketchdir/diagram.$target.json"
74+
fi
75+
7276
elif [ $platform == "qemu" ]; then
7377
PATH=$HOME/qemu/bin:$PATH
7478
extra_args="--embedded-services qemu --qemu-image-path $build_dir/$sketchname.ino.merged.bin"

Diff for: README.md

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

3-
![Build Status](https://github.com/espressif/arduino-esp32/workflows/ESP32%20Arduino%20CI/badge.svg) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md) [![Hardware Tests](https://github.com/espressif/arduino-esp32/blob/gh-pages/runtime-tests-results/badge.svg)](https://github.com/espressif/arduino-esp32/actions/workflows/tests_results.yml)
3+
[![Build Status](https://github.com/espressif/arduino-esp32/actions/workflows/push.yml/badge.svg?branch=master&event=push)](https://github.com/espressif/arduino-esp32/actions/workflows/push.yml) [![External Libraries Test](https://github.com/espressif/arduino-esp32/actions/workflows/lib.yml/badge.svg?branch=master&event=schedule)](https://github.com/espressif/arduino-esp32/blob/gh-pages/LIBRARIES_TEST.md) [![Hardware Tests](https://github.com/espressif/arduino-esp32/blob/gh-pages/runtime-tests-results/badge.svg)](https://github.com/espressif/arduino-esp32/actions/workflows/tests_results.yml)
44

55
### Need help or have a question? Join the chat at [Gitter](https://gitter.im/espressif/arduino-esp32) or [open a new Discussion](https://github.com/espressif/arduino-esp32/discussions)
66

Diff for: cores/esp32/HardwareSerial.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void serialEventRun(void) {
9696
#endif
9797

9898
HardwareSerial::HardwareSerial(uint8_t uart_nr)
99-
: _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256), _txBufferSize(0), _onReceiveCB(NULL), _onReceiveErrorCB(NULL), _onReceiveTimeout(false), _rxTimeout(2),
99+
: _uart_nr(uart_nr), _uart(NULL), _rxBufferSize(256), _txBufferSize(0), _onReceiveCB(NULL), _onReceiveErrorCB(NULL), _onReceiveTimeout(false), _rxTimeout(1),
100100
_rxFIFOFull(0), _eventTask(NULL)
101101
#if !CONFIG_DISABLE_HAL_LOCKS
102102
,

Diff for: cores/esp32/chip-debug-report.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static void printChipInfo(void) {
9898
rtc_clk_cpu_freq_get_config(&conf);
9999
chip_report_printf(" CPU Frequency : %lu MHz\n", conf.freq_mhz);
100100
chip_report_printf(" XTAL Frequency : %d MHz\n", rtc_clk_xtal_freq_get());
101+
chip_report_printf(" Features Bitfield : %#010x\n", info.features);
101102
chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH) ? "Yes" : "No");
102103
chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM) ? "Yes" : "No");
103104
chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN) ? "Yes" : "No");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static bool ledcDetachBus(void *bus) {
5252
bool channel_found = false;
5353
// Check if more pins are attached to the same ledc channel
5454
for (uint8_t i = 0; i < SOC_GPIO_PIN_COUNT; i++) {
55-
if (!perimanPinIsValid(i)) {
56-
continue; //invalid pin, skip
55+
if (!perimanPinIsValid(i) || i == handle->pin) {
56+
continue; //invalid pin or same pin
5757
}
5858
peripheral_bus_type_t type = perimanGetPinBusType(i);
5959
if (type == ESP32_BUS_TYPE_LEDC) {

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,20 @@ uart_t *uartBegin(
503503
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
504504
uart_config.rx_flow_ctrl_thresh = rxfifo_full_thrhd;
505505
uart_config.baud_rate = baudrate;
506-
// CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6
507-
uart_config.source_clk = UART_SCLK_DEFAULT;
506+
// there is an issue when returning from light sleep with the C6 and H2: the uart baud rate is not restored
507+
// therefore, uart clock source will set to XTAL for all SoC that support it. This fix solves the C6|H2 issue.
508+
#if SOC_UART_SUPPORT_XTAL_CLK
509+
uart_config.source_clk = UART_SCLK_XTAL; // valid for C2, S3, C3, C6, H2 and P4
510+
#elif SOC_UART_SUPPORT_REF_TICK
511+
if (baudrate <= 1000000) {
512+
uart_config.source_clk = UART_SCLK_REF_TICK; // valid for ESP32, S2 - MAX supported baud rate is 1MHz
513+
} else {
514+
uart_config.source_clk = UART_SCLK_APB; // baudrate may change with the APB Frequency!
515+
}
516+
#else
517+
// Default CLK Source: CLK_APB for ESP32|S2|S3|C3 -- CLK_PLL_F40M for C2 -- CLK_PLL_F48M for H2 -- CLK_PLL_F80M for C6
518+
uart_config.source_clk = UART_SCLK_DEFAULT; // baudrate may change with the APB Frequency!
519+
#endif
508520

509521
UART_MUTEX_LOCK();
510522
bool retCode = ESP_OK == uart_driver_install(uart_nr, rx_buffer_size, tx_buffer_size, 20, &(uart->uart_event_queue), 0);
@@ -778,25 +790,25 @@ void uartSetBaudRate(uart_t *uart, uint32_t baud_rate) {
778790
return;
779791
}
780792
UART_MUTEX_LOCK();
781-
uint32_t sclk_freq;
782-
if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) {
783-
uart_ll_set_baudrate(UART_LL_GET_HW(uart->num), baud_rate, sclk_freq);
793+
if (uart_set_baudrate(uart->num, baud_rate) == ESP_OK) {
794+
uart->_baudrate = baud_rate;
795+
} else {
796+
log_e("Setting UART%d baud rate to %d has failed.", uart->num, baud_rate);
784797
}
785-
uart->_baudrate = baud_rate;
786798
UART_MUTEX_UNLOCK();
787799
}
788800

789801
uint32_t uartGetBaudRate(uart_t *uart) {
790802
uint32_t baud_rate = 0;
791-
uint32_t sclk_freq;
792803

793804
if (uart == NULL) {
794805
return 0;
795806
}
796807

797808
UART_MUTEX_LOCK();
798-
if (uart_get_sclk_freq(UART_SCLK_DEFAULT, &sclk_freq) == ESP_OK) {
799-
baud_rate = uart_ll_get_baudrate(UART_LL_GET_HW(uart->num), sclk_freq);
809+
if (uart_get_baudrate(uart->num, &baud_rate) != ESP_OK) {
810+
log_e("Getting UART%d baud rate has failed.", uart->num);
811+
baud_rate = (uint32_t)-1; // return value when failed
800812
}
801813
UART_MUTEX_UNLOCK();
802814
return baud_rate;

Diff for: libraries/Network/src/NetworkUdp.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,14 @@ int NetworkUDP::parsePacket() {
296296
}
297297
struct sockaddr_storage si_other_storage; // enough storage for v4 and v6
298298
socklen_t slen = sizeof(sockaddr_storage);
299-
int len;
299+
int len = 0;
300+
if (ioctl(udp_server, FIONREAD, &len) == -1) {
301+
log_e("could not check for data in buffer length: %d", errno);
302+
return 0;
303+
}
304+
if (!len) {
305+
return 0;
306+
}
300307
char *buf = (char *)malloc(1460);
301308
if (!buf) {
302309
return 0;

Diff for: libraries/WiFi/examples/WiFiScan/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This example demonstrates how to use the WiFi library to scan available WiFi net
44

55
## Supported Targets
66

7-
Currently this example supports the following targets.
7+
Currently, this example supports the following targets.
88

99
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C6 |
1010
| ----------------- | ----- | -------- | -------- | -------- | -------- |
@@ -45,7 +45,7 @@ Nr | SSID | RSSI | CH | Encryption
4545
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
4646
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
4747

48-
If the error persist, you can ask help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
48+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
4949

5050
## Contribute
5151

Diff for: libraries/WiFi/examples/WiFiScanAsync/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This example demonstrates how to use the WiFi library to scan available WiFi net
44

55
## Supported Targets
66

7-
Currently this example supports the following targets.
7+
Currently, this example supports the following targets.
88

99
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C6 |
1010
| ----------------- | ----- | -------- | -------- | -------- | -------- |
@@ -55,7 +55,7 @@ Nr | SSID | RSSI | CH | Encryption
5555
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
5656
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
5757

58-
If the error persist, you can ask help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
58+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
5959

6060
## Contribute
6161

Diff for: libraries/WiFi/examples/WiFiScanTime/README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# WiFiScanTime Example
2+
3+
This example demonstrates how to use the WiFi library to scan available WiFi networks with custom scan timing and print the results.
4+
5+
## Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 | ESP32-C6 |
10+
| ----------------- | ----- | -------- | -------- | -------- | -------- |
11+
12+
## How to Use Example
13+
14+
* How to install the Arduino IDE: [Install Arduino IDE](https://github.com/espressif/arduino-esp32/tree/master/docs/arduino-ide).
15+
16+
#### Using Arduino IDE
17+
18+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
19+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
20+
21+
#### Using Platform IO
22+
23+
* Select the COM port: `Devices` or setting the `upload_port` option on the `platformio.ini` file.
24+
25+
## Example/Log Output
26+
27+
```
28+
Setup done
29+
Scan start
30+
Scan done, elapsed time: 4960 ms
31+
17 networks found
32+
Nr | SSID | RSSI | CH | Encryption
33+
1 | IoTNetwork | -62 | 1 | WPA2
34+
2 | WiFiSSID | -62 | 1 | WPA2-EAP
35+
3 | B3A7992 | -63 | 6 | WPA+WPA2
36+
4 | WiFi | -63 | 6 | WPA3
37+
5 | IoTNetwork2 | -64 | 11 | WPA2+WPA3
38+
...
39+
```
40+
41+
## Troubleshooting
42+
43+
***Important: Be sure you're using a good quality USB cable and you have enough power source for your project.***
44+
45+
* **Programming Fail:** If the programming/flash procedure fails, try to reduce the serial connection speed.
46+
* **COM port not detected:** Check the USB cable connection and the USB to Serial driver installation.
47+
48+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
49+
50+
## Contribute
51+
52+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
53+
54+
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
55+
56+
Before creating a new issue, be sure to try the Troubleshooting and to check if the same issue was already created by someone else.
57+
58+
## Resources
59+
60+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
61+
* ESP32 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf)
62+
* ESP32-S2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf)
63+
* ESP32-C3 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf)
64+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
65+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* This sketch demonstrates how to scan WiFi networks with custom scanning time.
3+
* The API is based on the Arduino WiFi Shield library, but has significant changes as newer WiFi functions are supported.
4+
* E.g. the return value of `encryptionType()` different because more modern encryption is supported.
5+
*/
6+
7+
/*
8+
* WiFi scan timing parameters explained:
9+
*
10+
* min=0, max=0: scan dwells on each channel for 120 ms.
11+
* min>0, max=0: scan dwells on each channel for 120 ms.
12+
* min=0, max>0: scan dwells on each channel for max ms.
13+
* min>0, max>0: the minimum time the scan dwells on each channel is min ms. If no AP is found during this time frame, the scan switches to the next channel. Otherwise, the scan dwells on the channel for max ms.
14+
*/
15+
16+
#include "WiFi.h"
17+
18+
void wifiScan(uint16_t min_time, uint16_t max_time) {
19+
Serial.println("Scan start");
20+
21+
// Set the minimum time per channel for active scanning.
22+
WiFi.setScanActiveMinTime(min_time);
23+
24+
// Capture the start time of the scan.
25+
uint32_t start = millis();
26+
27+
// WiFi.scanNetworks will return the number of networks found.
28+
// Scan networks with those options: Synchrone mode, show hidden networks, active scan, max scan time per channel.
29+
int n = WiFi.scanNetworks(false, true, false, max_time);
30+
Serial.printf("Scan done, elapsed time: %lu ms\n", millis() - start);
31+
if (n == 0) {
32+
Serial.println("no networks found");
33+
} else {
34+
Serial.print(n);
35+
Serial.println(" networks found");
36+
Serial.println("Nr | SSID | RSSI | CH | Encryption");
37+
for (int i = 0; i < n; ++i) {
38+
// Print SSID and RSSI for each network found
39+
Serial.printf("%2d", i + 1);
40+
Serial.print(" | ");
41+
Serial.printf("%-32.32s", WiFi.SSID(i).c_str());
42+
Serial.print(" | ");
43+
Serial.printf("%4ld", WiFi.RSSI(i));
44+
Serial.print(" | ");
45+
Serial.printf("%2ld", WiFi.channel(i));
46+
Serial.print(" | ");
47+
switch (WiFi.encryptionType(i)) {
48+
case WIFI_AUTH_OPEN: Serial.print("open"); break;
49+
case WIFI_AUTH_WEP: Serial.print("WEP"); break;
50+
case WIFI_AUTH_WPA_PSK: Serial.print("WPA"); break;
51+
case WIFI_AUTH_WPA2_PSK: Serial.print("WPA2"); break;
52+
case WIFI_AUTH_WPA_WPA2_PSK: Serial.print("WPA+WPA2"); break;
53+
case WIFI_AUTH_WPA2_ENTERPRISE: Serial.print("WPA2-EAP"); break;
54+
case WIFI_AUTH_WPA3_PSK: Serial.print("WPA3"); break;
55+
case WIFI_AUTH_WPA2_WPA3_PSK: Serial.print("WPA2+WPA3"); break;
56+
case WIFI_AUTH_WAPI_PSK: Serial.print("WAPI"); break;
57+
default: Serial.print("unknown");
58+
}
59+
Serial.println();
60+
delay(10);
61+
}
62+
}
63+
Serial.println("");
64+
65+
// Delete the scan result to free memory for code below.
66+
WiFi.scanDelete();
67+
68+
// Wait a bit before scanning again
69+
delay(2000);
70+
}
71+
72+
void setup() {
73+
Serial.begin(115200);
74+
75+
// Set WiFi to station mode and disconnect from an AP if it was previously connected.
76+
WiFi.mode(WIFI_STA);
77+
WiFi.disconnect();
78+
delay(100);
79+
80+
// Scan WiFi networks with a minimum time of 100 ms per channel and a maximum time of 300 ms per channel (default values).
81+
wifiScan(100, 300);
82+
83+
// Scan WiFi networks with a minimum time of 100 ms per channel and a maximum time of 1500 ms per channel.
84+
wifiScan(100, 1500);
85+
86+
// Scan WiFi networks with a minimum time of 0 ms per channel and a maximum time of 1500 ms per channel.
87+
wifiScan(0, 1500);
88+
}
89+
90+
void loop() {
91+
// Nothing to do here
92+
}

Diff for: libraries/WiFi/examples/WiFiScanTime/ci.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"targets": {
3+
"esp32h2": false
4+
}
5+
}

Diff for: libraries/WiFi/src/WiFiScan.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ bool WiFiScanClass::_scanAsync = false;
4646
uint32_t WiFiScanClass::_scanStarted = 0;
4747
uint32_t WiFiScanClass::_scanTimeout = 60000;
4848
uint16_t WiFiScanClass::_scanCount = 0;
49+
uint32_t WiFiScanClass::_scanActiveMinTime = 100;
50+
4951
void *WiFiScanClass::_scanResult = 0;
5052

5153
void WiFiScanClass::setScanTimeout(uint32_t ms) {
5254
WiFiScanClass::_scanTimeout = ms;
5355
}
5456

57+
void WiFiScanClass::setScanActiveMinTime(uint32_t ms) {
58+
WiFiScanClass::_scanActiveMinTime = ms;
59+
}
60+
5561
/**
5662
* Start scan WiFi networks available
5763
* @param async run in async mode
@@ -80,7 +86,7 @@ int16_t
8086
config.scan_time.passive = max_ms_per_chan;
8187
} else {
8288
config.scan_type = WIFI_SCAN_TYPE_ACTIVE;
83-
config.scan_time.active.min = 100;
89+
config.scan_time.active.min = _scanActiveMinTime;
8490
config.scan_time.active.max = max_ms_per_chan;
8591
}
8692
if (esp_wifi_scan_start(&config, false) == ESP_OK) {

Diff for: libraries/WiFi/src/WiFiScan.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class WiFiScanClass {
3232

3333
public:
3434
void setScanTimeout(uint32_t ms);
35+
void setScanActiveMinTime(uint32_t ms);
3536

3637
int16_t scanNetworks(
3738
bool async = false, bool show_hidden = false, bool passive = false, uint32_t max_ms_per_chan = 300, uint8_t channel = 0, const char *ssid = nullptr,
@@ -62,6 +63,7 @@ class WiFiScanClass {
6263
static uint32_t _scanStarted;
6364
static uint32_t _scanTimeout;
6465
static uint16_t _scanCount;
66+
static uint32_t _scanActiveMinTime;
6567

6668
static void *_scanResult;
6769

0 commit comments

Comments
 (0)