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

[WIP] ESP32: ESP-IDF v4.x support #377

Closed
wants to merge 52 commits into from
Closed

[WIP] ESP32: ESP-IDF v4.x support #377

wants to merge 52 commits into from

Conversation

atanisoft
Copy link
Collaborator

@atanisoft atanisoft commented Mar 23, 2020

This PR enables compilation of OpenMRN/OpenMRNLite in an ESP-IDF v4.x env. This will also include ESP32-S2 support (new single core modules to replace ESP8266).

Also fixes #256.

IDF v4 has reworked the VFS layer in a breaking manner to IDF v3.x, specifically in the start_select and end_select VFS methods. The semaphore that IDF VFS passes to the esp_start_select API is now a structure containing extra metadata about the semaphore (LwIP or FreeRTOS owned). With this new data structure it is not necessary to obtain and trigger the LwIP semaphore directly.

Also added documentation for methods which were missing it and the cxx license comment copied from hxx file.
@atanisoft
Copy link
Collaborator Author

IDF v4 uses cmake to build, I have a CMakeFiles.txt that I can include that will build the required files that show up in OpenMRNLite with bare IDF and IDF+Arduino. I wasn't sure how we would want to package that though.

@atanisoft atanisoft changed the title ESP-IDF v4 support ESP32: ESP-IDF v4 support Mar 23, 2020
@atanisoft atanisoft changed the title ESP32: ESP-IDF v4 support [WIP] ESP32: ESP-IDF v4 support Mar 23, 2020
@atanisoft
Copy link
Collaborator Author

@balazsracz I've tagged it as WIP in the title for now, I don't expect any additional work on this outside of the HW Can driver and ESP-IDF example(s) which I don't think would fit under the Arduino directory. Where should I create the ESP-IDF example app, perhaps under applications?

@@ -34,7 +34,8 @@

#include "DeviceBuffer.hxx"

#ifndef ARDUINO
#include "openmrn_features.h"
#if OPENMRN_FEATURE_DEVTAB
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifdef ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done either way, I modeled this one after other feature flag usages since they are bool in nature. If you prefer ifdef I'll change it over.

My only concern on this change is for the STM32 Arduino port since it should also not include this functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balazsracz looking at the usage of FEATURE_* in the codebase there seems to be a mix of #if and #ifdef. Which would you prefer, I can update this one or send in a PR with mass cleanup for consistency of others.

This uses only ESP-IDF functions rather than using the Arduino API. It also exposes pull-down support for input pins that is not currently available in the Arduino APIs.
… header only exists in that arch.

Adding CONFIG_IDF_TARGET_ESP32 to selection of HASSERT/DIE implementation and missing doc comments for HASSERT/DIE where needed
…customizations for esp32.

On the esp32 the default stack size is now 3kb after seeing LwIP instability due to free low stack during accept. The ESP32 also does not see to have capacity for five pending sockets concurrently, reduced to three for ESP32 only.

Added support for named socket listener threads for the envs with multiple listeners.
…n operating at a remote location without the normal SSID being available. This is also useful when operating as WIFI_MODE_APSTA with the SoftAP being available for reconfiguration or general runtime usage.
@atanisoft atanisoft changed the title [WIP] ESP32: ESP-IDF v4 support [WIP] ESP32: ESP-IDF v4.x support May 28, 2020
The ESP32-S2 is a single core version of the ESP32 designed as a replacement for the ESP8266.

Key differences between ESP32 and ESP32-S2:
1. BLE, Ethernet, Hall Sensor support has been removed.
2. SRAM reduced from 520kb to 320kb.
3. ROM reduced from 448kb to 128kb.
4. Single CPU core.
5. 43 usable IO pins vs 34 IO pins.

The CAN driver is currently not supported on the ESP32-S2 but a variant of it will be available in ESP-IDF v4.2 (required for ESP32-S2 use anyway).
…th Arduino defines (annoying namespace pollution by arduino)
… rather than __FreeRTOS__.

Removed non-compiling code in os_thread_create_helper relating to static task allocation (newly enabled in arduino-esp32:esp32s2)
…most functionality for IDF v3.x.

IDF v4.0 introduced a new esp_event library to replace the event_loop system that was previously used for propagating WiFi events and event_loop was deprecated but still functional. In IDF v4.1 the event_loop code was made optional and is not included by default (arduino-esp32 is not including it in version 2.0 which will be coming soon).

Removed non-managed WiFi since it doesn't make as much sense as originally.

Removed the event callback support since it was never released in OpenMRNLite and will not compile in arduino-esp32 v2.0. The replacement is to hook into the esp_event system directly for the required events.
…c_exchange_1, since this is a required feature for OpenMRN provided an implementation based on the Cortex-M0 implementation with adjustments for Xtensa ASM.
This example provides 16 outputs and 15 (or 16) inputs. Two pins are reserved for the TWAI (CAN) interface which will be available in the near future.
…address since IDF passes it in host order and ipv4_to_string() expects it in network order.
esp32_network_up_callback_t : called when STA or AP interface is "UP" with IP assigned.
esp32_network_down_callback_t : called when STA or AP is down (IP lost, interface down, etc)
esp32_network_init_callback_t : called when STA has been started and connection process begins. For AP this is not called.

Callbacks are scheduled via the executor to offload them from the esp_event loop.
MultiConfiguredPC allows dynamic adjustment of pins to be input or output. If a pin that is input only is attempted to be reconfigured as output it will result in an error being asserted.

On the ESP32 pins from 0..33 are suitable for outputs. Note that pins 6-11 and 24 are not usable.

On the ESP32-S2 pins from 0..45 are suitable for outputs. Note that pins 22-24 and 26-32 are not usable.
Without unmounting the second call to SPIFFS.begin() will be a no-op.
…ype cast was incorrect resulting in invalid IP address being reported.

Added log output for mDNS publish failure.
This is needed for the S2 to allow logging to both UART (stderr/stdout) and USB CDC.
… to INPUT_OUTPUT.

* Adding output toggle() method which sets the output state to the opposite of the current state.
* Added GPIO 19 and 20 usage note for ESP32-S2 (USB)
* Added built-in pull-up/down resistor value (45kohm)
Starting with ESP-IDF v4.2 the CAN peripheral has been renamed to TWAI. The current CAN adapter has a few issues (like #238) and now generates compilation warnings for the old CAN driver code.

This new driver replicates the ESP-IDF TWAI driver HAL layer in an ESP-IDF verison neutral manner and exposes the TWAI peripheral via a select() aware VFS endpoint.

The Esp32LoadTest.ino is able to process in excess of 1800 frames per second with minimal dropped frames (one or two per 100k received).

More refinement may be necessary for the ESP32-S2.
1. Add support for WiFi TX power configuration.
2. Add support for disabling uplink creation (useful when operating in CAN only mode).
3. Switch to use SimpleCanStack::start_tcp_hub_server().
4. Restrict "hub" mode to ESP32 only since ESP32-S2 has limited memory available (except WROVER variants with PSRAM).
5. Cache all config inside apply_configuration() callback
@atanisoft atanisoft closed this Nov 23, 2020
@atanisoft atanisoft deleted the md-espidf branch November 23, 2020 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add const for listener_stack_size in socket_listener.cxx
2 participants