Skip to content

Commit 96d4757

Browse files
authored
Merge branch 'release/v3.1.x' into uart_loop_back
2 parents d9c3987 + 9aeb1ba commit 96d4757

File tree

14 files changed

+533
-300
lines changed

14 files changed

+533
-300
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(CORE_SRCS
4949
cores/esp32/esp32-hal-uart.c
5050
cores/esp32/esp32-hal-rmt.c
5151
cores/esp32/Esp.cpp
52+
cores/esp32/freertos_stats.cpp
5253
cores/esp32/FunctionalInterrupt.cpp
5354
cores/esp32/HardwareSerial.cpp
5455
cores/esp32/HEXBuilder.cpp

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Here are the ESP32 series supported by the Arduino-ESP32 project:
5959
| ESP32-S3 | Yes | Yes | [ESP32-S3](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) |
6060
| ESP32-C6 | Yes | Yes | [ESP32-C6](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) |
6161
| ESP32-H2 | Yes | Yes | [ESP32-H2](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) |
62-
| ESP32-P4 | No | No | [ESP32-P4](https://www.espressif.com/sites/default/files/documentation/esp32-p4_datasheet_en.pdf) |
62+
| ESP32-P4 | No | Yes | [ESP32-P4](https://www.espressif.com/sites/default/files/documentation/esp32-p4_datasheet_en.pdf) |
6363

6464
> [!NOTE]
6565
> ESP32-C2 is also supported by Arduino-ESP32 but requires rebuilding the static libraries. This is not trivial and requires a good understanding of the ESP-IDF

cores/esp32/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
199199
#include "Udp.h"
200200
#include "HardwareSerial.h"
201201
#include "Esp.h"
202+
#include "freertos_stats.h"
202203

203204
// Use float-compatible stl abs() and round(), we don't use Arduino macros to avoid issues with the C++ libraries
204205
using std::abs;

cores/esp32/HardwareSerial.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
313313
// map logical pins to GPIO numbers
314314
rxPin = digitalPinToGPIONumber(rxPin);
315315
txPin = digitalPinToGPIONumber(txPin);
316+
int8_t _rxPin = uart_get_RxPin(_uart_nr);
317+
int8_t _txPin = uart_get_TxPin(_uart_nr);
318+
319+
rxPin = rxPin < 0 ? _rxPin : rxPin;
320+
txPin = txPin < 0 ? _txPin : txPin;
316321

317322
HSERIAL_MUTEX_LOCK();
318323
// First Time or after end() --> set default Pins
@@ -343,13 +348,9 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
343348
// do not change RX2/TX2 if it has already been set before
344349
#ifdef RX2
345350
rxPin = _rxPin < 0 ? (int8_t)RX2 : _rxPin;
346-
#else
347-
rxPin = _rxPin;
348351
#endif
349352
#ifdef TX2
350353
txPin = _txPin < 0 ? (int8_t)TX2 : _txPin;
351-
#else
352-
txPin = _txPin;
353354
#endif
354355
}
355356
break;
@@ -360,13 +361,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
360361
// do not change RX2/TX2 if it has already been set before
361362
#ifdef RX3
362363
rxPin = _rxPin < 0 ? (int8_t)RX3 : _rxPin;
363-
#else
364-
rxPin = _rxPin;
365364
#endif
366365
#ifdef TX3
367366
txPin = _txPin < 0 ? (int8_t)TX3 : _txPin;
368367
#else
369-
txPin = _txPin;
370368
#endif
371369
}
372370
break;
@@ -377,13 +375,9 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
377375
// do not change RX2/TX2 if it has already been set before
378376
#ifdef RX4
379377
rxPin = _rxPin < 0 ? (int8_t)RX4 : _rxPin;
380-
#else
381-
rxPin = _rxPin;
382378
#endif
383379
#ifdef TX4
384380
txPin = _txPin < 0 ? (int8_t)TX4 : _txPin;
385-
#else
386-
txPin = _txPin;
387381
#endif
388382
}
389383
break;
@@ -398,6 +392,13 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
398392
return;
399393
}
400394

395+
// if no RX/TX pins are defined, it will not start the UART driver
396+
if (rxPin < 0 && txPin < 0) {
397+
log_e("No RX/TX pins defined. Please set RX/TX pins.");
398+
HSERIAL_MUTEX_UNLOCK();
399+
return;
400+
}
401+
401402
// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
402403
// it will detach previous UART attached pins
403404

cores/esp32/freertos_stats.cpp

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "freertos_stats.h"
16+
#include "sdkconfig.h"
17+
18+
#if CONFIG_FREERTOS_USE_TRACE_FACILITY
19+
#include "freertos/FreeRTOS.h"
20+
#include "freertos/task.h"
21+
#include "freertos/portable.h"
22+
#endif /* CONFIG_FREERTOS_USE_TRACE_FACILITY */
23+
24+
void printRunningTasks(Print &printer) {
25+
#if CONFIG_FREERTOS_USE_TRACE_FACILITY
26+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
27+
#define FREERTOS_TASK_NUMBER_MAX_NUM 256 // RunTime stats for how many Tasks to be stored
28+
static configRUN_TIME_COUNTER_TYPE ulRunTimeCounters[FREERTOS_TASK_NUMBER_MAX_NUM];
29+
static configRUN_TIME_COUNTER_TYPE ulLastRunTime = 0;
30+
configRUN_TIME_COUNTER_TYPE ulCurrentRunTime = 0, ulTaskRunTime = 0;
31+
#endif
32+
configRUN_TIME_COUNTER_TYPE ulTotalRunTime = 0;
33+
TaskStatus_t *pxTaskStatusArray = NULL;
34+
volatile UBaseType_t uxArraySize = 0, x = 0;
35+
const char *taskStates[] = {"Running", "Ready", "Blocked", "Suspended", "Deleted", "Invalid"};
36+
37+
// Take a snapshot of the number of tasks in case it changes while this function is executing.
38+
uxArraySize = uxTaskGetNumberOfTasks();
39+
40+
// Allocate a TaskStatus_t structure for each task.
41+
pxTaskStatusArray = (TaskStatus_t *)pvPortMalloc(uxArraySize * sizeof(TaskStatus_t));
42+
43+
if (pxTaskStatusArray != NULL) {
44+
// Generate raw status information about each task.
45+
uxArraySize = uxTaskGetSystemState(pxTaskStatusArray, uxArraySize, &ulTotalRunTime);
46+
47+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
48+
ulCurrentRunTime = ulTotalRunTime - ulLastRunTime;
49+
ulLastRunTime = ulTotalRunTime;
50+
#endif
51+
printer.printf(
52+
"Tasks: %u"
53+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
54+
", Runtime: %lus, Period: %luus"
55+
#endif
56+
"\n",
57+
uxArraySize
58+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
59+
,
60+
ulTotalRunTime / 1000000, ulCurrentRunTime
61+
#endif
62+
);
63+
printer.printf("Num\t Name"
64+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
65+
"\tLoad"
66+
#endif
67+
"\tPrio\t Free"
68+
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
69+
"\tCore"
70+
#endif
71+
"\tState\r\n");
72+
for (x = 0; x < uxArraySize; x++) {
73+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
74+
if (pxTaskStatusArray[x].xTaskNumber < FREERTOS_TASK_NUMBER_MAX_NUM) {
75+
ulTaskRunTime = (pxTaskStatusArray[x].ulRunTimeCounter - ulRunTimeCounters[pxTaskStatusArray[x].xTaskNumber]);
76+
ulRunTimeCounters[pxTaskStatusArray[x].xTaskNumber] = pxTaskStatusArray[x].ulRunTimeCounter;
77+
ulTaskRunTime = (ulTaskRunTime * 100) / ulCurrentRunTime; // in percentage
78+
} else {
79+
ulTaskRunTime = 0;
80+
}
81+
#endif
82+
printer.printf(
83+
"%3u\t%16s"
84+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
85+
"\t%3lu%%"
86+
#endif
87+
"\t%4u\t%5lu"
88+
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
89+
"\t%4c"
90+
#endif
91+
"\t%s\r\n",
92+
pxTaskStatusArray[x].xTaskNumber, pxTaskStatusArray[x].pcTaskName,
93+
#if CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
94+
ulTaskRunTime,
95+
#endif
96+
pxTaskStatusArray[x].uxCurrentPriority, pxTaskStatusArray[x].usStackHighWaterMark,
97+
#if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID
98+
(pxTaskStatusArray[x].xCoreID == tskNO_AFFINITY) ? '*' : ('0' + pxTaskStatusArray[x].xCoreID),
99+
#endif
100+
taskStates[pxTaskStatusArray[x].eCurrentState]
101+
);
102+
}
103+
104+
// The array is no longer needed, free the memory it consumes.
105+
vPortFree(pxTaskStatusArray);
106+
printer.println();
107+
}
108+
#else
109+
printer.println("FreeRTOS trace facility is not enabled.");
110+
#endif /* CONFIG_FREERTOS_USE_TRACE_FACILITY */
111+
}

cores/esp32/freertos_stats.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#ifdef __cplusplus
18+
19+
#include "Print.h"
20+
21+
/*
22+
* Executing this function will cause interrupts and
23+
* the scheduler to be blocked for some time.
24+
* Please use only for debugging purposes.
25+
*/
26+
void printRunningTasks(Print &printer);
27+
28+
#endif

libraries/BLE/src/BLEAdvertising.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
352352
switch (uuid.bitSize()) {
353353
case 16:
354354
{
355-
// [Len] [0x02] [LL] [HH]
355+
// [Len] [0x03] [LL] [HH]
356356
cdata[0] = 3;
357357
cdata[1] = ESP_BLE_AD_TYPE_16SRV_CMPL; // 0x03
358358
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid16, 2));
@@ -361,7 +361,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
361361

362362
case 32:
363363
{
364-
// [Len] [0x04] [LL] [LL] [HH] [HH]
364+
// [Len] [0x05] [LL] [LL] [HH] [HH]
365365
cdata[0] = 5;
366366
cdata[1] = ESP_BLE_AD_TYPE_32SRV_CMPL; // 0x05
367367
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid32, 4));
@@ -370,7 +370,7 @@ void BLEAdvertisementData::setCompleteServices(BLEUUID uuid) {
370370

371371
case 128:
372372
{
373-
// [Len] [0x04] [0] [1] ... [15]
373+
// [Len] [0x07] [0] [1] ... [15]
374374
cdata[0] = 17;
375375
cdata[1] = ESP_BLE_AD_TYPE_128SRV_CMPL; // 0x07
376376
addData(String(cdata, 2) + String((char *)uuid.getNative()->uuid.uuid128, 16));
@@ -453,7 +453,7 @@ void BLEAdvertisementData::setPartialServices(BLEUUID uuid) {
453453

454454
case 128:
455455
{
456-
// [Len] [0x04] [0] [1] ... [15]
456+
// [Len] [0x06] [0] [1] ... [15]
457457
cdata[0] = 17;
458458
cdata[1] = ESP_BLE_AD_TYPE_128SRV_PART; // 0x06
459459
addData(String(cdata, 2) + String((char *)&uuid.getNative()->uuid.uuid128, 16));

libraries/Ethernet/src/ETH.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
210210

211211
#if CONFIG_IDF_TARGET_ESP32
212212
#undef DEFAULT_RMII_CLK_GPIO
213-
#define DEFAULT_RMII_CLK_GPIO (emac_rmii_clock_gpio_t)(CONFIG_ETH_RMII_CLK_IN_GPIO)
213+
#define DEFAULT_RMII_CLK_GPIO (emac_rmii_clock_gpio_t)(0)
214214
#endif
215215

216216
eth_esp32_emac_config_t mac_config = ETH_EMAC_DEFAULT_CONFIG();

0 commit comments

Comments
 (0)