Skip to content

Commit 23f3600

Browse files
authored
Merge branch 'master' into release/v3.3.x
2 parents 03e9c45 + 571c2f7 commit 23f3600

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

cores/esp32/esp32-hal-ledc.c

+32-6
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,31 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
126126
return false;
127127
}
128128
} else {
129-
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = clock_source};
129+
ledc_timer_config_t ledc_timer;
130+
memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t));
131+
ledc_timer.speed_mode = group;
132+
ledc_timer.timer_num = timer;
133+
ledc_timer.duty_resolution = resolution;
134+
ledc_timer.freq_hz = freq;
135+
ledc_timer.clk_cfg = clock_source;
136+
130137
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
131138
log_e("ledc setup failed!");
132139
return false;
133140
}
134141

135142
uint32_t duty = ledc_get_duty(group, (channel % 8));
136143

137-
ledc_channel_config_t ledc_channel = {
138-
.speed_mode = group, .channel = (channel % 8), .timer_sel = timer, .intr_type = LEDC_INTR_DISABLE, .gpio_num = pin, .duty = duty, .hpoint = 0
139-
};
144+
ledc_channel_config_t ledc_channel;
145+
memset((void *)&ledc_channel, 0, sizeof(ledc_channel_config_t));
146+
ledc_channel.speed_mode = group;
147+
ledc_channel.channel = (channel % 8);
148+
ledc_channel.timer_sel = timer;
149+
ledc_channel.intr_type = LEDC_INTR_DISABLE;
150+
ledc_channel.gpio_num = pin;
151+
ledc_channel.duty = duty;
152+
ledc_channel.hpoint = 0;
153+
140154
ledc_channel_config(&ledc_channel);
141155
}
142156

@@ -256,7 +270,13 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
256270

257271
uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4);
258272

259-
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = 10, .freq_hz = freq, .clk_cfg = clock_source};
273+
ledc_timer_config_t ledc_timer;
274+
memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t));
275+
ledc_timer.speed_mode = group;
276+
ledc_timer.timer_num = timer;
277+
ledc_timer.duty_resolution = 10;
278+
ledc_timer.freq_hz = freq;
279+
ledc_timer.clk_cfg = clock_source;
260280

261281
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
262282
log_e("ledcWriteTone configuration failed!");
@@ -307,7 +327,13 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) {
307327
}
308328
uint8_t group = (bus->channel / 8), timer = ((bus->channel / 2) % 4);
309329

310-
ledc_timer_config_t ledc_timer = {.speed_mode = group, .timer_num = timer, .duty_resolution = resolution, .freq_hz = freq, .clk_cfg = clock_source};
330+
ledc_timer_config_t ledc_timer;
331+
memset((void *)&ledc_timer, 0, sizeof(ledc_timer_config_t));
332+
ledc_timer.speed_mode = group;
333+
ledc_timer.timer_num = timer;
334+
ledc_timer.duty_resolution = resolution;
335+
ledc_timer.freq_hz = freq;
336+
ledc_timer.clk_cfg = clock_source;
311337

312338
if (ledc_timer_config(&ledc_timer) != ESP_OK) {
313339
log_e("ledcChangeFrequency failed!");

libraries/ESP32/examples/Serial/RxTimeout_Demo/RxTimeout_Demo.ino

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
If UART receives less than 120 bytes, it will wait RX Timeout to understand that the bus is IDLE and
2222
then copy the data from the FIFO to the Arduino internal buffer, making it available to the Arduino API.
2323
24+
There is an important detail about how HardwareSerial works using ESP32 and ESP32-S2:
25+
If the baud rate is lower than 250,000, it will select REF_TICK as clock source in order to avoid that
26+
the baud rate may change when the CPU Frequency is changed. Default UART clock source is APB, which changes
27+
when CPU clock source is also changed. But when it selects REF_TICK as UART clock source, RX Timeout is limited to 1.
28+
Therefore, in order to change the ESP32/ESP32-S2 RX Timeout it is necessary to fix the UART Clock Source to APB.
29+
30+
In the case of the other SoC, such as ESP32-S3, C3, C6, H2 and P4, there is no such RX Timeout limitation.
31+
Those will set the UART Source Clock as XTAL, which allows the baud rate to be high and it is steady, not
32+
changing with the CPU Frequency.
2433
*/
2534

2635
#include <Arduino.h>
@@ -45,6 +54,12 @@ void setup() {
4554

4655
// UART1 will have its RX<->TX cross connected
4756
// GPIO4 <--> GPIO5 using external wire
57+
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
58+
// UART_CLK_SRC_APB will allow higher values of RX Timeout
59+
// default for ESP32 and ESP32-S2 is REF_TICK which limits the RX Timeout to 1
60+
// setClockSource() must be called before begin()
61+
Serial1.setClockSource(UART_CLK_SRC_APB);
62+
#endif
4863
Serial1.begin(BAUD, SERIAL_8N1, RXPIN, TXPIN); // Rx = 4, Tx = 5 will work for ESP32, S2, S3 and C3
4964
#if USE_INTERNAL_PIN_LOOPBACK
5065
uart_internal_loopback(TEST_UART, RXPIN);

0 commit comments

Comments
 (0)