Skip to content

Commit

Permalink
Merge branch 'master' into release/v3.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev authored Oct 10, 2024
2 parents af40992 + f083e2d commit 774f275
Show file tree
Hide file tree
Showing 9 changed files with 732 additions and 32 deletions.
473 changes: 473 additions & 0 deletions boards.txt

Large diffs are not rendered by default.

23 changes: 9 additions & 14 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@
#endif

void serialEvent(void) __attribute__((weak));
void serialEvent(void) {}

#if SOC_UART_HP_NUM > 1
void serialEvent1(void) __attribute__((weak));
void serialEvent1(void) {}
#endif /* SOC_UART_HP_NUM > 1 */
#endif /* SOC_UART_NUM > 1 */

#if SOC_UART_HP_NUM > 2
void serialEvent2(void) __attribute__((weak));
void serialEvent2(void) {}
#endif /* SOC_UART_HP_NUM > 2 */
#endif /* SOC_UART_NUM > 2 */

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
// There is always Seria0 for UART0
Expand All @@ -48,37 +45,35 @@ HardwareSerial Serial2(2);

#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event
extern void HWCDCSerialEvent(void) __attribute__((weak));
void HWCDCSerialEvent(void) {}
#endif

#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
// Used by Hardware Serial for USB CDC events
extern void USBSerialEvent(void) __attribute__((weak));
void USBSerialEvent(void) {}
#endif

void serialEventRun(void) {
#if HWCDC_SERIAL_IS_DEFINED == 1 // Hardware JTAG CDC Event
if (HWCDCSerial.available()) {
if (HWCDCSerialEvent && HWCDCSerial.available()) {
HWCDCSerialEvent();
}
#endif
#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
if (USBSerial.available()) {
if (USBSerialEvent && USBSerial.available()) {
USBSerialEvent();
}
#endif
// UART0 is default serialEvent()
if (Serial0.available()) {
if (serialEvent && Serial0.available()) {
serialEvent();
}
#if SOC_UART_HP_NUM > 1

This comment has been minimized.

Copy link
@Jason2866

Jason2866 Oct 10, 2024

Collaborator

@me-no-dev is the change correct?
Isn't it still SOC_UART_HP_NUM?

This comment has been minimized.

Copy link
@me-no-dev

me-no-dev Oct 10, 2024

Author Member

fixed here: 81d2cbc

if (Serial1.available()) {
#if SOC_UART_NUM > 1
if (serialEvent1 && Serial1.available()) {
serialEvent1();
}
#endif
#if SOC_UART_HP_NUM > 2
if (Serial2.available()) {
#if SOC_UART_NUM > 2
if (serialEvent2 && Serial2.available()) {
serialEvent2();
}
#endif
Expand Down
39 changes: 21 additions & 18 deletions libraries/AsyncUDP/src/AsyncUDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ extern "C" {

#include "lwip/priv/tcpip_priv.h"

#ifdef CONFIG_LWIP_TCPIP_CORE_LOCKING
#define UDP_MUTEX_LOCK() \
if (!sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
LOCK_TCPIP_CORE(); \
}

#define UDP_MUTEX_UNLOCK() \
if (sys_thread_tcpip(LWIP_CORE_LOCK_QUERY_HOLDER)) { \
UNLOCK_TCPIP_CORE(); \
}
#else // CONFIG_LWIP_TCPIP_CORE_LOCKING
#define UDP_MUTEX_LOCK()
#define UDP_MUTEX_UNLOCK()
#endif // CONFIG_LWIP_TCPIP_CORE_LOCKING

static const char *netif_ifkeys[TCPIP_ADAPTER_IF_MAX] = {"WIFI_STA_DEF", "WIFI_AP_DEF", "ETH_DEF", "PPP_DEF"};

static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void **netif) {
Expand All @@ -28,7 +43,9 @@ static esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void **net
if (netif_index < 0) {
return ESP_FAIL;
}
UDP_MUTEX_LOCK();
*netif = (void *)netif_get_by_index(netif_index);
UDP_MUTEX_UNLOCK();
} else {
*netif = netif_default;
}
Expand Down Expand Up @@ -232,9 +249,6 @@ static bool _udp_task_stop(){
}
*/

#define UDP_MUTEX_LOCK() //xSemaphoreTake(_lock, portMAX_DELAY)
#define UDP_MUTEX_UNLOCK() //xSemaphoreGive(_lock)

AsyncUDPMessage::AsyncUDPMessage(size_t size) {
_index = 0;
if (size > CONFIG_TCP_MSS) {
Expand Down Expand Up @@ -473,12 +487,14 @@ bool AsyncUDP::_init() {
if (_pcb) {
return true;
}
UDP_MUTEX_LOCK();
_pcb = udp_new();
if (!_pcb) {
UDP_MUTEX_UNLOCK();
return false;
}
//_lock = xSemaphoreCreateMutex();
udp_recv(_pcb, &_udp_recv, (void *)this);
UDP_MUTEX_UNLOCK();
return true;
}

Expand All @@ -493,22 +509,19 @@ AsyncUDP::~AsyncUDP() {
close();
UDP_MUTEX_LOCK();
udp_recv(_pcb, NULL, NULL);
UDP_MUTEX_UNLOCK();
_udp_remove(_pcb);
_pcb = NULL;
UDP_MUTEX_UNLOCK();
//vSemaphoreDelete(_lock);
}

void AsyncUDP::close() {
UDP_MUTEX_LOCK();
if (_pcb != NULL) {
if (_connected) {
_udp_disconnect(_pcb);
}
_connected = false;
//todo: unjoin multicast group
}
UDP_MUTEX_UNLOCK();
}

bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port) {
Expand All @@ -520,14 +533,11 @@ bool AsyncUDP::connect(const ip_addr_t *addr, uint16_t port) {
return false;
}
close();
UDP_MUTEX_LOCK();
_lastErr = _udp_connect(_pcb, addr, port);
if (_lastErr != ERR_OK) {
UDP_MUTEX_UNLOCK();
return false;
}
_connected = true;
UDP_MUTEX_UNLOCK();
return true;
}

Expand All @@ -544,13 +554,10 @@ bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port) {
IP_SET_TYPE_VAL(_pcb->local_ip, addr->type);
IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type);
}
UDP_MUTEX_LOCK();
if (_udp_bind(_pcb, addr, port) != ERR_OK) {
UDP_MUTEX_UNLOCK();
return false;
}
_connected = true;
UDP_MUTEX_UNLOCK();
return true;
}

Expand Down Expand Up @@ -624,12 +631,10 @@ bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl
return false;
}

UDP_MUTEX_LOCK();
_pcb->mcast_ttl = ttl;
_pcb->remote_port = port;
ip_addr_copy(_pcb->remote_ip, *addr);
//ip_addr_copy(_pcb->remote_ip, ip_addr_any_type);
UDP_MUTEX_UNLOCK();

return true;
}
Expand All @@ -651,7 +656,6 @@ size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr,
if (pbt != NULL) {
uint8_t *dst = reinterpret_cast<uint8_t *>(pbt->payload);
memcpy(dst, data, len);
UDP_MUTEX_LOCK();
if (tcpip_if < TCPIP_ADAPTER_IF_MAX) {
void *nif = NULL;
tcpip_adapter_get_netif((tcpip_adapter_if_t)tcpip_if, &nif);
Expand All @@ -663,7 +667,6 @@ size_t AsyncUDP::writeTo(const uint8_t *data, size_t len, const ip_addr_t *addr,
} else {
_lastErr = _udp_sendto(_pcb, pbt, addr, port);
}
UDP_MUTEX_UNLOCK();
pbuf_free(pbt);
if (_lastErr < ERR_OK) {
return 0;
Expand Down
14 changes: 14 additions & 0 deletions tests/validation/psram/ci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"platforms": {
"qemu": false,
"wokwi": false
},
"requires": [
"CONFIG_SPIRAM=y"
],
"targets": {
"esp32c3": false,
"esp32c6": false,
"esp32h2": false
}
}
112 changes: 112 additions & 0 deletions tests/validation/psram/psram.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <Arduino.h>
#include <unity.h>

#define MAX_TEST_SIZE 512 * 1024 // 512KB

void *buf = NULL;

void test_malloc_success(void) {
buf = ps_malloc(MAX_TEST_SIZE);
TEST_ASSERT_NOT_NULL(buf);
free(buf);
buf = NULL;
}

void test_calloc_success(void) {
buf = ps_calloc(MAX_TEST_SIZE, 1);
TEST_ASSERT_NOT_NULL(buf);
free(buf);
buf = NULL;
}

void test_realloc_success(void) {
buf = ps_malloc(MAX_TEST_SIZE);
TEST_ASSERT_NOT_NULL(buf);
buf = ps_realloc(buf, MAX_TEST_SIZE + 1024);
TEST_ASSERT_NOT_NULL(buf);
free(buf);
buf = NULL;
}

void test_malloc_fail(void) {
buf = ps_malloc(0xFFFFFFFF);
TEST_ASSERT_NULL(buf);
}

void test_memset_all_zeroes(void) {
memset(buf, 0, MAX_TEST_SIZE);
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
TEST_ASSERT_EQUAL(0, ((uint8_t *)buf)[i]);
}
}

void test_memset_all_ones(void) {
memset(buf, 0xFF, MAX_TEST_SIZE);
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
TEST_ASSERT_EQUAL(0xFF, ((uint8_t *)buf)[i]);
}
}

void test_memset_alternating(void) {
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
((uint8_t *)buf)[i] = i % 2 == 0 ? 0x00 : 0xFF;
}
memset(buf, 0xAA, MAX_TEST_SIZE);
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
TEST_ASSERT_EQUAL(0xAA, ((uint8_t *)buf)[i]);
}
}

void test_memset_random(void) {
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
((uint8_t *)buf)[i] = random(0, 256);
}
memset(buf, 0x55, MAX_TEST_SIZE);
for (size_t i = 0; i < MAX_TEST_SIZE; i++) {
TEST_ASSERT_EQUAL(0x55, ((uint8_t *)buf)[i]);
}
}

void test_memcpy(void) {
void *buf2 = malloc(1024); // 1KB
TEST_ASSERT_NOT_NULL(buf2);
memset(buf, 0x55, MAX_TEST_SIZE);
memset(buf2, 0xAA, 1024);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-arith"

for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) {
memcpy(buf + i, buf2, 1024);
}

for (size_t i = 0; i < MAX_TEST_SIZE; i += 1024) {
TEST_ASSERT_NULL(memcmp(buf + i, buf2, 1024));
}

#pragma GCC diagnostic pop

free(buf2);
}

void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}

UNITY_BEGIN();
RUN_TEST(test_malloc_success);
RUN_TEST(test_malloc_fail);
RUN_TEST(test_calloc_success);
RUN_TEST(test_realloc_success);
buf = ps_malloc(MAX_TEST_SIZE);
RUN_TEST(test_memset_all_zeroes);
RUN_TEST(test_memset_all_ones);
RUN_TEST(test_memset_alternating);
RUN_TEST(test_memset_random);
RUN_TEST(test_memcpy);
UNITY_END();
}

void loop() {}
2 changes: 2 additions & 0 deletions tests/validation/psram/test_psram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_psram(dut):
dut.expect_unity_test_output(timeout=120)
31 changes: 31 additions & 0 deletions variants/BharatPi-A7672S-4G/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

static const uint8_t LED_BUILTIN = 2;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN

static const uint8_t A0 = 14;
static const uint8_t A1 = 13;
static const uint8_t A2 = 12;
static const uint8_t A3 = 4;
static const uint8_t A4 = 2;
static const uint8_t A5 = 0;

static const uint8_t TX = 1;
static const uint8_t RX = 3;

static const uint8_t TX_4G = 17;
static const uint8_t RX_4G = 16;

static const uint8_t SDA = 21;
static const uint8_t SCL = 22;

static const uint8_t SS = 5;
static const uint8_t MOSI = 23;
static const uint8_t MISO = 19;
static const uint8_t SCK = 18;

#endif /* Pins_Arduino_h */
Loading

0 comments on commit 774f275

Please sign in to comment.