Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syncing ESP-IDF v5.3 changes #815

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions .github/workflows/ArduinoBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:

- name: Generate OpenMRNLite library
run: |
mkdir --parents $HOME/Arduino/libraries/OpenMRNLite
$GITHUB_WORKSPACE/arduino/libify.sh $HOME/Arduino/libraries/OpenMRNLite $GITHUB_WORKSPACE -f
mkdir --parents $GITHUB_WORKSPACE/CustomOpenMRNLite
$GITHUB_WORKSPACE/arduino/libify.sh $GITHUB_WORKSPACE/CustomOpenMRNLite $GITHUB_WORKSPACE -f
rm -f $GITHUB_WORKSPACE/arduino/examples/Stm*/build_opt.h

- name: Compile STM32 examples
Expand All @@ -37,7 +37,6 @@ jobs:
sketch-names: Stm32*.ino
build-properties: '{ "All": "-DHAL_CAN_MODULE_ENABLED" }'
debug-compile: true
required-libraries: OpenMRNLite

build-esp32:
name: Build Arduino ${{ matrix.target }} examples
Expand All @@ -52,19 +51,18 @@ jobs:

- name: Generate OpenMRNLite library
run: |
mkdir --parents $HOME/Arduino/libraries/OpenMRNLite
$GITHUB_WORKSPACE/arduino/libify.sh $HOME/Arduino/libraries/OpenMRNLite $GITHUB_WORKSPACE -f
mkdir --parents $GITHUB_WORKSPACE/CustomOpenMRNLite
$GITHUB_WORKSPACE/arduino/libify.sh $GITHUB_WORKSPACE/CustomOpenMRNLite $GITHUB_WORKSPACE -f
rm -f $GITHUB_WORKSPACE/arduino/examples/Stm*/build_opt.h

- name: Compile ESP32 examples
uses: ArminJo/arduino-test-compile@v3
with:
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-board-fqbn: esp32:esp32:node32s
sketch-names: ESP32CanLoadTest.ino,ESP32IOBoard.ino,ESP32SerialBridge.ino,ESP32WifiCanBridge.ino
sketch-names: ESP32CanLoadTest.ino,ESP32IOBoard.ino,ESP32WifiCanBridge.ino
debug-compile: true
required-libraries: OpenMRNLite
arduino-platform: esp32:[email protected]
arduino-platform: esp32:[email protected]
if: ${{ matrix.target == 'esp32' }}

- name: Compile ESP32-C3 examples
Expand All @@ -74,8 +72,7 @@ jobs:
arduino-board-fqbn: esp32:esp32:esp32c3
sketch-names: ESP32C3CanLoadTest.ino,ESP32C3IOBoard.ino
debug-compile: true
required-libraries: OpenMRNLite
arduino-platform: esp32:[email protected]
arduino-platform: esp32:[email protected]
if: ${{ matrix.target == 'esp32c3' }}

- name: Compile ESP32-S2 examples
Expand All @@ -85,6 +82,5 @@ jobs:
arduino-board-fqbn: esp32:esp32:esp32s2
sketch-names: ESP32S2CanLoadTest.ino,ESP32S2IOBoard.ino
debug-compile: true
required-libraries: OpenMRNLite
arduino-platform: esp32:[email protected]
arduino-platform: esp32:[email protected]
if: ${{ matrix.target == 'esp32s2' }}
30 changes: 30 additions & 0 deletions arduino/OpenMRNLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,33 @@ ssize_t os_get_free_heap()
#endif // ESP_PLATFORM

} // namespace openmrn_arduino

#ifdef ESP_PLATFORM

#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/netif.h"

/*
temporary hack due to:

/home/runner/.cache/arduino/cores/esp32_esp32_esp32c3_e60f223ab547c7c01b5bb8c151783c5f/core.a @/home/runner/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-cfea4f7c-v1/esp32c3/flags/ld_libs -Wl,--end-group -Wl,-EL -o /home/runner/.cache/arduino/sketches/1429F777C89502EA84E469B35328AFC7/ESP32C3IOBoard.ino.elf
/home/runner/.arduino15/packages/esp32/tools/esp-rv32/2405/bin/../lib/gcc/riscv32-esp-elf/13.2.0/../../../../riscv32-esp-elf/bin/ld: /home/runner/.arduino15/packages/esp32/tools/esp32-arduino-libs/idf-release_v5.3-cfea4f7c-v1/esp32c3/lib/liblwip.a(ip6.c.obj): in function `ip6_input':
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/core/ipv6/ip6.c:1127:(.text.ip6_input+0xa2): undefined reference to `lwip_hook_ip6_input'
collect2: error: ld returned 1 exit status

tracked as https://github.com/espressif/arduino-esp32/issues/10084
below snippet was copied from the issue and must be placed in global namespace
*/
extern "C" int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp) __attribute__((weak));
extern "C" int lwip_hook_ip6_input(struct pbuf *p, struct netif *inp)
{
if (ip6_addr_isany_val(inp->ip6_addr[0].u_addr.ip6))
{
// We don't have an LL address -> eat this packet here, so it won't get accepted on input netif
pbuf_free(p);
return 1;
}
return 0;
}
#endif
12 changes: 6 additions & 6 deletions arduino/examples/ESP32C3CanLoadTest/ESP32C3CanLoadTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <Arduino.h>
#include <SPIFFS.h>
#include <esp_spi_flash.h>
#include <esp_private/cache_utils.h>

#include <OpenMRNLite.h>
#include <openlcb/TcpDefs.hxx>
Expand Down Expand Up @@ -219,15 +220,14 @@ void setup()

// Register hardware timer zero to use a 1Mhz resolution and to count up
// from zero when the timer triggers.
auto timer = timerBegin(0, 80, true);
auto timer = timerBegin(80);
// Attach our callback function to be called when the timer is ready to
// fire. Note that the edge parameter is not used/supported on the
// ESP32-C3.
timerAttachInterrupt(timer, record_cpu_usage, true);
// fire.
timerAttachInterrupt(timer, &record_cpu_usage);
// Configure the trigger point to be roughly 163 times per second.
timerAlarmWrite(timer, 1000000/163, true);
timerWrite(timer, 1000000/163);
// Enable the timer.
timerAlarmEnable(timer);
timerStart(timer);

// Initialize the SPIFFS filesystem as our persistence layer
if (!SPIFFS.begin())
Expand Down
2 changes: 1 addition & 1 deletion arduino/examples/ESP32C3CanLoadTest/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// catch invalid configuration at compile time
#if !defined(USE_TWAI) && !defined(USE_WIFI)
#error "Invalid configuration detected, USE_CAN or USE_WIFI must be defined."
#error "Invalid configuration detected, USE_TWAI or USE_WIFI must be defined."
#endif

namespace openlcb
Expand Down
58 changes: 27 additions & 31 deletions arduino/examples/ESP32CanLoadTest/ESP32CanLoadTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <Arduino.h>
#include <SPIFFS.h>
#include <esp_spi_flash.h>
#include <esp_private/cache_utils.h>

#include <OpenMRNLite.h>
#include <openlcb/TcpDefs.hxx>
Expand All @@ -45,20 +46,13 @@


// Pick an operating mode below, if you select USE_WIFI it will expose this
// node on WIFI. If USE_CAN / USE_TWAI / USE_TWAI_ASYNC are enabled the node
// node on WIFI. If USE_TWAI / USE_TWAI_ASYNC are enabled the node
// will be available on CAN.
//
// Enabling both options will allow the ESP32 to be accessible from
// both WiFi and CAN interfaces.
//
// NOTE: USE_TWAI and USE_TWAI_ASYNC are similar to USE_CAN but utilize the
// new TWAI driver which offers both select() (default) or fnctl() (async)
// access.
// NOTE: USE_CAN is deprecated and no longer supported upstream by ESP-IDF as
// of v4.2 or arduino-esp32 as of v2.0.0.
// both WiFi and TWAI interfaces.

#define USE_WIFI
//#define USE_CAN
//#define USE_TWAI
//#define USE_TWAI_ASYNC

Expand All @@ -73,11 +67,6 @@
#define USE_TWAI
#endif // USE_TWAI_ASYNC && !USE_TWAI

// Verify that both CAN and TWAI are not enabled.
#if defined(USE_CAN) && defined(USE_TWAI)
#error Enabling both USE_CAN and USE_TWAI is not supported.
#endif // USE_CAN && USE_TWAI

#if defined(USE_TWAI) && ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,3,0)
#error Esp32HardwareTwai is not supported on this version of arduino-esp32.
#endif // USE_TWAI && IDF < v4.3
Expand Down Expand Up @@ -197,17 +186,23 @@ namespace openlcb
}

CpuLoad cpu_load;
hw_timer_t * timer = nullptr;
CpuLoadLog* cpu_log = nullptr;

void IRAM_ATTR onTimer()
// Callback function for the hardware timer configured to fire roughly 163
// times per second.
void ARDUINO_ISR_ATTR record_cpu_usage()
{
if (spi_flash_cache_enabled())
#if CONFIG_ARDUINO_ISR_IRAM
// if the ISR is called with flash disabled we can not safely recored the
// cpu usage.
if (!spi_flash_cache_enabled())
{
// Retrieves the vtable pointer from the currently running executable.
unsigned *pp = (unsigned *)openmrn.stack()->executor()->current();
cpuload_tick(pp ? pp[0] | 1 : 0);
return;
}
#endif
// Retrieves the vtable pointer from the currently running executable.
unsigned *pp = (unsigned *)openmrn.stack()->executor()->current();
cpuload_tick(pp ? pp[0] | 1 : 0);
}

void setup()
Expand All @@ -217,11 +212,16 @@ void setup()
#endif
Serial.begin(115200L);

timer = timerBegin(3, 80, true); // timer_id = 3; divider=80; countUp = true;
timerAttachInterrupt(timer, &onTimer, true); // edge = true
// 1MHz clock, 163 ticks per second desired.
timerAlarmWrite(timer, 1000000/163, true);
timerAlarmEnable(timer);
// Register hardware timer zero to use a 1Mhz resolution and to count up
// from zero when the timer triggers.
auto timer = timerBegin(80);
// Attach our callback function to be called when the timer is ready to
// fire.
timerAttachInterrupt(timer, &record_cpu_usage);
// Configure the trigger point to be roughly 163 times per second.
timerWrite(timer, 1000000/163);
// Enable the timer.
timerStart(timer);

// Initialize the SPIFFS filesystem as our persistence layer
if (!SPIFFS.begin())
Expand Down Expand Up @@ -261,17 +261,13 @@ void setup()
openmrn.stack()->print_all_packets();
#endif // PRINT_PACKETS

#if defined(USE_CAN)
// Add the hardware CAN device as a bridge
openmrn.add_can_port(
new Esp32HardwareCan("esp32can", CAN_RX_PIN, CAN_TX_PIN));
#elif defined(USE_TWAI_ASYNC)
#if defined(USE_TWAI_ASYNC)
// add TWAI driver with non-blocking usage
openmrn.add_can_port_async("/dev/twai/twai0");
#elif defined(USE_TWAI)
// add TWAI driver with select() usage
openmrn.add_can_port_select("/dev/twai/twai0");
#endif // USE_TWAI_SELECT / USE_TWAI
#endif // USE_TWAI_ASYNC / USE_TWAI
}

void loop()
Expand Down
35 changes: 10 additions & 25 deletions arduino/examples/ESP32IOBoard/ESP32IOBoard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,14 @@
#include "utils/GpioInitializer.hxx"

// Pick an operating mode below, if you select USE_WIFI it will expose this
// node on WIFI. If USE_CAN / USE_TWAI / USE_TWAI_ASYNC are enabled the node
// node on WIFI. If USE_TWAI / USE_TWAI_ASYNC are enabled the node
// will be available on CAN.
//
// Enabling both options will allow the ESP32 to be accessible from
// both WiFi and CAN interfaces.
//
// NOTE: USE_TWAI and USE_TWAI_ASYNC are similar to USE_CAN but utilize the
// new TWAI driver which offers both select() (default) or fnctl() (async)
// access.
// NOTE: USE_CAN is deprecated and no longer supported upstream by ESP-IDF as
// of v4.2 or arduino-esp32 as of v2.0.0.

#define USE_WIFI
#define USE_CAN
//#define USE_TWAI
#define USE_TWAI
//#define USE_TWAI_ASYNC

// uncomment the line below to have all packets printed to the Serial
Expand Down Expand Up @@ -85,10 +78,6 @@
#define USE_TWAI
#endif // USE_TWAI_ASYNC && !USE_TWAI

#if defined(USE_CAN) && defined(USE_TWAI)
#error USE_CAN and USE_TWAI are mutually exclusive!
#endif

#if defined(FIRMWARE_UPDATE_BOOTLOADER) && !defined(USE_TWAI)
#error FIRMWARE_UPDATE_BOOTLOADER requires USE_TWAI or USE_TWAI_SELECT.
#endif
Expand Down Expand Up @@ -129,7 +118,7 @@ const char *hostname = "esp32mrn";

#endif // USE_WIFI

#if defined(USE_CAN) || defined(USE_TWAI)
#if defined(USE_TWAI)
/// This is the ESP32 pin connected to the SN65HVD23x/MCP2551 R (RX) pin.
/// Recommended pins: 4, 16, 21.
/// Note: Any pin can be used for this other than 6-11 which are connected to
Expand All @@ -146,7 +135,7 @@ constexpr gpio_num_t CAN_RX_PIN = GPIO_NUM_4;
/// the GPIO pin definitions for the outputs.
constexpr gpio_num_t CAN_TX_PIN = GPIO_NUM_5;

#endif // USE_CAN || USE_TWAI
#endif // USE_TWAI

#if defined(FIRMWARE_UPDATE_BOOTLOADER)
// Include the Bootloader HAL implementation for the ESP32. This should only
Expand All @@ -171,9 +160,9 @@ static constexpr openlcb::ConfigDef cfg(0);
Esp32WiFiManager wifi_mgr(ssid, password, openmrn.stack(), cfg.seg().wifi());
#endif // USE_WIFI

#if defined(USE_TWAI) && !defined(USE_CAN)
#if defined(USE_TWAI)
Esp32HardwareTwai twai(CAN_RX_PIN, CAN_TX_PIN);
#endif // USE_TWAI && !USE_CAN
#endif // USE_TWAI

// Declare output pins
// NOTE: pins 6-11 are connected to the onboard flash and can not be used for
Expand Down Expand Up @@ -381,9 +370,9 @@ void setup()
}
#endif // FIRMWARE_UPDATE_BOOTLOADER

#if defined(USE_TWAI) && !defined(USE_CAN)
#if defined(USE_TWAI)
twai.hw_init();
#endif // USE_TWAI && !USE_CAN
#endif // USE_TWAI

check_for_factory_reset();

Expand All @@ -410,15 +399,11 @@ void setup()
openmrn.stack()->print_all_packets();
#endif // PRINT_PACKETS

#if defined(USE_CAN)
// Add the hardware CAN device as a bridge
openmrn.add_can_port(
new Esp32HardwareCan("esp32can", CAN_RX_PIN, CAN_TX_PIN));
#elif defined(USE_TWAI_ASYNC)
#if defined(USE_TWAI_ASYNC)
openmrn.add_can_port_async("/dev/twai/twai0");
#elif defined(USE_TWAI)
openmrn.add_can_port_select("/dev/twai/twai0");
#endif // USE_CAN
#endif // USE_TWAI_ASYNC

openmrn.start_executor_thread();
}
Expand Down
10 changes: 3 additions & 7 deletions arduino/examples/ESP32IOBoard/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "freertos_drivers/esp32/Esp32WiFiConfiguration.hxx"

// catch invalid configuration at compile time
#if !defined(USE_CAN) && !defined(USE_WIFI)
#error "Invalid configuration detected, USE_CAN or USE_WIFI must be defined."
#if !defined(USE_TWAI) && !defined(USE_WIFI)
#error "Invalid configuration detected, USE_TWAI or USE_WIFI must be defined."
#endif

namespace openlcb
Expand All @@ -32,14 +32,10 @@ namespace openlcb
extern const SimpleNodeStaticValues SNIP_STATIC_DATA = {
4,
"OpenMRN",
#if defined(USE_WIFI) && !defined(USE_CAN) && !defined(USE_TWAI)
#if defined(USE_WIFI) && !defined(USE_TWAI)
"Arduino IO Board (WiFi)",
#elif defined(USE_CAN) && !defined(USE_WIFI)
"Arduino IO Board (CAN)",
#elif defined(USE_TWAI) && !defined(USE_WIFI)
"Arduino IO Board (TWAI)",
#elif defined(USE_CAN) && defined(USE_WIFI)
"Arduino IO Board (WiFi/CAN)",
#elif defined(USE_TWAI) && defined(USE_WIFI)
"Arduino IO Board (WiFi/TWAI)",
#else
Expand Down
12 changes: 7 additions & 5 deletions arduino/examples/ESP32S2CanLoadTest/ESP32S2CanLoadTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <Arduino.h>
#include <SPIFFS.h>
#include <esp_spi_flash.h>
#include <esp_private/cache_utils.h>
#include <USB.h>

#include <OpenMRNLite.h>
Expand Down Expand Up @@ -267,13 +268,14 @@ void setup()

// Register hardware timer zero to use a 1Mhz resolution and to count up
// from zero when the timer triggers.
auto timer = timerBegin(0, 80, true);
// Attach our callback function to be called on the timer edge signal.
timerAttachInterrupt(timer, record_cpu_usage, true);
auto timer = timerBegin(80);
// Attach our callback function to be called when the timer is ready to
// fire.
timerAttachInterrupt(timer, &record_cpu_usage);
// Configure the trigger point to be roughly 163 times per second.
timerAlarmWrite(timer, 1000000/163, true);
timerWrite(timer, 1000000/163);
// Enable the timer.
timerAlarmEnable(timer);
timerStart(timer);

// Initialize the SPIFFS filesystem as our persistence layer
if (!SPIFFS.begin())
Expand Down
Loading
Loading