-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
Port Sming to esp32/Arduino #1333
Comments
@avr39-ripe @frankdownunder I would like to hear your comments. |
@slaff : For your first questions : TCP : Due to ESP32 multiprocessor, lwip has specific implementation aspects. Difference between Arduino and Sming is std::function vs delegates. |
@hreintke Last time I peek esp/Arduino it wasn't async by nature, parts of it is, as you mention AsyncTCP + frewnds, but not framework as whole. May be things had been changed since my peek. Sming's strong side is unified mechanism of timer/delegate for ANY aspect of application - either tcp or serial or wifi or whatever.. So I think porting such "whole system with ASYNC in mind" to esp/Arduino worth efforts. |
As much as i like Swing i don't think it will add a lot on top of the really excellent toolchain and libs that come from Espressif. They have done an excellent job on the ESP-IDF (Espressif IoT Development Framework). And a port from sting will loose a lot of the features you get with their lib and api's. You get as much control as you want for low level communication i2C, SPI, Serial .. And on top of all this a very easy to understand and modular make based build system, including a nice extendable menuconfig target. I'm working for a while now withe the Esp-idf toolchain a like it more every day. I will likely spend more time on porting or writing libs on top of the Espressif API's than trying to adopt to the Arduino programming models. |
I do not know how many people develop using sming - is it possible to guess from the download stats? harry-boe points out that the ESP-IDF has some interesting new features. But ESP-IDF is still just a collection of functions; its is not a well-designed set of classes as is Sming. And while it may be good, I nevertheless do not want to rewrite all my Sming code to run for the new platform. So I would suggest our aims for the project should provide an easy migration path for SMING based code and also if possible, SMINGRTOS projects. To do this we should
It will need to be a team effort- there is a lot of effort involved I suspect. Need to canvas support for this amongst the community.
|
i don't agree that the esp-idf is just a collection of functions. If you take a closer look into the components folder if the idf than you will find components for more or less all the low level stuff you ever wanted (from lwip to openssl, JSON to nghhtp ..) not to mention a huge library on examples. However, i'm happy to support porting for the stuff i contributed. Like the SPI, SDCard and testing on some Displays libs. |
Slaf said: "As a start we need someone to try and Migrate the Timing classes to Arduino."
Just getting things to compile was challenging - and I would like to document the changes I needed to make (if such a list has not already been started). I note that the docs say this: @hreintke I agree about std::function, Slaff seems also to agree, I might put my hand up to do that after Easter @hreintke I looked at the Ticker class, IMO it is pretty basic compared to Timer. Do we need both? or do we add functionality to Ticker? I guess if we want to make it easy for Arduino code to build then we want to support Ticker class somehow. I now know much more about the scope of this exercise than before. |
@frankdownunder The ESP32 ticker class will probably get the same options. |
@hreintke OK, I looked at it briefly. Do you think we should encapsulate an instance of Ticker in the new Timer class, inherit from it, replace it entirely, or just get everyone to change their code to use Ticker instead? |
This might be interesting: |
Picking up from #1579 (comment) -
I agree. I wasn't proposing we switch to FreeRTOS, but that we restructure according to the ESP-IDF-style API (or perhaps we should refer to it as the HAL). Many API calls have just been renamed, so I guess all we'd need to do to make a start is to create a |
I would suggest the following restructuring as a start
And so on. Once that is ready and everything is still compiling and working :) you can start abstracting the timer stuff. What do you say? |
Sounds like a plan! We can always revisit but the structure sounds good. Will you take care of the initial restructuring? And I guess (hope) we can continue in develop branch... |
Wonderful!
Honestly your C/C++ skills are way better than mine. Can you try to do the initial restructuring and I will try to help as much as I can?
Yes, this way more people can check if the platform refactoring works as expected. |
OK, I'll work up a PR for the restructuring. Don't be fooled about my C++ abilities - the STL still baffles me! |
We also need to deal with the |
May I suggest we use cmake? I have been working for quite a while on an ESP32 project, and Ive been using the cmake development way of IDF - I think it has clear advantages over makefiles. "The CMake-based build system will become the default build system in ESP-IDF V4.0. The existing GNU Make based build system will be deprecated in ESP-IDF V5.0." https://docs.espressif.com/projects/esp-idf/en/latest/get-started-cmake/ |
I think initially we can continue with Makefiles, but once the code is structured more closely with IDF we should certainly look at migrating to Cmake. The makefiles need simplifying and now is the time to do that. Question: Do we remove 'makefile-project' now? I am happy to upgrade it inline with makefile-rboot (I would pull out common parts anyway) but obviously that would create additional work especially for testing. |
Yes, it's about time we do this. |
cmake will be essential in getting a port to ESP32 done, but cmake has more to offer than just alignment with idf. Speed is one thing - it is very fast. It gets the dependencies right, and it runs on Windows without any Linux layer necessary. Ive seen many posts where a potential Sming user has given up when trying to use Windows. Just my two bobs worth! |
I definitely believe cmake is the way to go. I had had a fully working ESP32 build system and compiled a sample within an hour yesterday. The visual makeconfig is a great improvement. (It is pretty slow under Windows, of course, as everything runs under MinGW.) Having the build environment as a .zip file made installation easy. I also looked at the ESP8266-RTOS which has a similar .zip. I'll have a look at whether this can be used for our purposes. What we want is for Sming projects to build for Esp8266, Esp32 plus Windows and Linux targets, so I'm bearing this in mind whilst working on the initial restructure, which should not affect existing apps in any way. Next step perhaps, for me anyway, is to implement the Windows target which will allow any app to build and run natively under MinGW for debugging, testing and for new users to evaluate. This will involve writing new versions of Sming modules (classes) and/or creating IDF-compatible components to abstract the hardware, where appropriate. I would prefer not to mix platforms within modules (#ifdefs). This should continue to have no effect on building for Esp8266. The 'Timer' abstraction mentioned above would be in there somewhere. I'm very mindful that the ESP32 has considerably more resources available, especially RAM, so we need to be careful of introducing additional overhead if at all possible. Sming has its 'modules', but the lower-level code isn't so well structured so migrating this into IDF-compatible components will help considerably. For example, gdbstub would be a component. This means we can also do direct comparison with/merging of code from the ESP8266-RTOS SDK. So the I note that Espressif's flashing tool supports both ESP32/8266 so that's helpful. OK, so where does that leave us with Cmake? Well, doing it right is a fair bit of work though doesn't need to replace existing makefiles yet, can be added as alternative. Can probably start once we're happy with the initial restructure. Lastly, porting will place additional requirements on users (python + cmake) plus the app. makefile and standard #include will need to change. |
Agreed. Happy to help. |
Not true Mike. You should instead have followed the instructions here https://docs.espressif.com/projects/esp-idf/en/latest/get-started-cmake/windows-setup.html
Im a fan of Linux, but I dislike MSYS2 and MinGW. I need to rebuild my windows machine it got schtumpfred by Windows Update, but last time I had it running, i had native exes with CMake and Ninja in control and I got I get similar performance to Ubuntu. SUPER fast builds. |
@frankdownunder Thanks Frank, I'd missed the CMake build preview. Definitely the way to go. It seems that the ESP32 is getting all the love at the moment, hope we can find a way to do the same for the humble ESP8266. (I still think of the ESP32 as an ESP8266 on steroids.) |
As per discussion #1333. Rearrange files and fix #includes: * Rename `SmingCore` -> `Core` * Rename `SmingCore/Platform` -> `Platform` * Rename `system` -> `System` * Move `Services/libb64` -> `Components` * Move `Services/WebHelpers` -> `Core/Network` * Remove `apptest` * Move Esp8266-specific code: * Move most `Platform` sources -> `Arch/Esp8266/Platform` * Move some `SmingCore` sources -> `Arch/Esp2866/Core` * Rename `compiler` -> `Arch/Esp8266/Compiler` * Rename `tools` -> `Arch/Esp8266/Tools` * Move `SmingCore/Network/rBootHttpUpdate` -> `Arch/Esp2866/Core/Network` * Move `custom_heap` -> `Arch/Esp8266/Components` * Move some of `system` files -> `Arch/Esp8266/Components/esp8266` (reflects IDF layout) * Rename `appinit/user_main.cpp` -> `Arch/Esp8266/Components/esp8266/startup.cpp` * Rename `gdb` -> `Arch/Esp8266/Components/gdbstub` * Rename `appspecific/gdb` -> `Arch/Esp8266/Components/gdbstub/appcode` * Rename `Services/FATFS` -> `Arch/Esp8266/Components/fatfs` * Move `system/include/rboot-integration.h`, `appspecific/rboot/overrides.c` -> `Arch/Esp8266/Components/rboot/appcode` * Rename `Services/SpifFS` -> `Arch/Esp8266/Components/spiffs` * Move `include/user_config.h` -> `Arch/Esp8266/System/include` Makefile revisions * Remove `Makefile-project.mk` * Rename `Makefile-rboot.mk` -> `Makefile-app.mk` * Retain `Makefile-rboot.mk` (redirects to `Makefile-app.mk`) for backward compatibility * Separate common script used by both Sming and App * `build.mk` contains host environment setup * Add directory definitions `ARCH_BASE`, `ARCH_SYS`, `ARCH_CORE`, `ARCH_COMPONENTS` and `ARCH_TOOLS` * `modules.mk` contains rule creation script * Separate-out ESP8266-specific script: * `Arch/*/build.mk` included by `build.mk` file * `Arch/*/sming.mk` included by `Makefile` * `Arch/*/app.mk` included by `Makefile-app.mk` * Change build output directory to `Arch/*/out` * Pull related variable definitions and rules together * Define macros to replace repetitive script: endeavour to name files or directories once only * Ignore errors in all clean operations * Use `TOOLS`, `TOOLS_CLEAN` and `CLEAN` variables containing pre-requisites for `tools`, `tools-clean` and `clean` targets * Simplify user library building by adding to `LIBS`, each library gets an additional shorthand make target e.g. `make axtls`. * Distribute PHONY declarations * Add `decode-stacktrack` rule to application makefile * Add `help` target to extract formatted makefile comments * Add `list-config` target Submodule handling * third-party libraries: `rBoot`, `new-pwm`, `axtls-8266`, `umm_malloc`, `esp-open-lwip`, `lwip2` -> `Arch/Esp8266/Components` * Move `.patch` file into related submodule parent directory * Internal SDK moved into `Components/Sdk` and updated to use unpatched Version 3.0 release * Move remaining `third-party` submodules into `Components` * Revise Makefiles so that only those submodules required for a build are updated/patched and built * Add `SUBMODULES` variable to specify which submodules are required * Use `.submodule` file as consistent pre-requisite for update/patching of all submodules * Make `ARDUINO_LIBRARIES` a public variable to optionally restrict which libraries get loaded and built * Add `submodules` and `submodules-clean` rules to replace `third-party` and `libraries` rules Other * Add `building.md` * Add help documentation to makefiles, with new `help` and `list-config` targets * Update coding style directories and Travis checks * Update Doxygen directories Fixes: * Add `libpwm_open` to `CUSTOM_TARGETS` so it builds with framework Bugs found: * Testing with `ENABLE_CUSTOM_LWIP=0` fails because of static definitions in `mem_manager.h` - also happens with existing build
OK so the appveyor build fails on a missing I've attempted (without success) to track down MinGW 5.3.0 to inspect why this is happening and to find the correct fix. My install is 6.3.0, which as far as I can tell is what chocolatey pulls down. I had a similar issue with Perhaps update the version for appveyor? |
Sounds good to me. Any update that we make to the Windows CI should also be reflected on the docs and the choco packages so that Windows users are able to compile Sming also on their systems. |
It used to succeed on the same code with the same compiler. I guess there is a problem with the includes and not in the compiler version. |
I've haven't risked a choco install on my dev. system yet, but inspecting the scripts looks like the mingw install should be the current one, not the old one provided on appveyor. Needs confirming, of course. |
@slaff So far my work on SHEM is only to get it to build, so no network functionality. I'm happy to to take a look at your Linux code to see how it could be integrated? |
You are reading my mind :). I will try to post the details here later today. |
Here is what I did in order to be able to use LWIP in Sming on Linux.
That produced
After that I used the unix minimal example and based the lwip initialization code on it. You should set the IP that will be used from the app. I couldn't find a way to set it automatically so I had to set it manually. And that IP must be in the same network as the struct netif netif;
/* (manual) host IP configuration */
static ip4_addr_t ipaddr, netmask, gw, dns;
int setup()
{
/* startup defaults (may be overridden by one or more opts) */
IP4_ADDR(&gw, 192, 168, 13, 1);
IP4_ADDR(&ipaddr, 192, 168, 13, 2);
IP4_ADDR(&netmask, 255, 255, 255, 0);
/* use debug flags defined by debug.h */
debug_flags = 0;
#ifdef LWIP_DEBUG_ALL
debug_flags |= (LWIP_DBG_ON | LWIP_DBG_TRACE | LWIP_DBG_STATE |
LWIP_DBG_FRESH | LWIP_DBG_HALT);
#else
debug_flags |= LWIP_DBG_STATE;
#endif
strncpy(ip_str, ip4addr_ntoa(&ipaddr), sizeof(ip_str));
strncpy(nm_str, ip4addr_ntoa(&netmask), sizeof(nm_str));
strncpy(gw_str, ip4addr_ntoa(&gw), sizeof(gw_str));
printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str);
lwip_init(); // <!-- This must be called first before using LWIP
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
netif_set_default(&netif);
netif_set_up(&netif);
#if LWIP_IPV6
netif_create_ip6_linklocal_address(&netif, 1);
#endif
// ...
} In my setup I had a problem with setting up a DNS server that I could not solve. Also I had issues with UDP packets. So those might be connected. // @TODO: DNS resolution is still not working...
// @TODO: IPv4 Packet forwarding is also not working...
IP4_ADDR(&dns, 8, 8, 8, 8);
dns_setserver(0, &dns); Once the setup is done the
My code and setup is not elegant. I just needed to have it running on Linux and was able to achieve this. But that helped me immensely in finding issues with our network code or just testing new code before testing it on the device. Not to mention the advantages of using valgrind and static code analyzers to discover potential problems with the code. |
@slaff Thanks for the info, very helpful. I've got it integrated now so have a play and see what's broken!! Update: Added default DNS server but as you say no response to UDP packets... |
Things are still in flux so shall we work from my |
So far the Host architecture looks very-very promising :) I started from zero and added some notes as a WIKI entry: https://github.com/SmingHub/Sming/wiki/Host-Emulator that will be updated over time. First question - the library code and the application code seems to be optimized and debugging it by default is a bit more inconvenient. Shall I specify a env. variable or would it be better to have the code non-optimized by default for the Host architecture unless SMING_RELEASE is specified? |
@mikee47 The Sming Host Emulator, even at this early stage, is awesome! I played with it yesterday night and it was real fun to use it. Some years ago there was another simulator that I was planning to use as a base for our own https://github.com/afnid/espsim but you did much better. Hints
Something similar can be used also in the simulator because socat can listen on TCP ports and forward them to usb. Check these examples. Suggestions for Improvements
|
@slaff Happy you like it! Thanks for starting the Wiki page. I did have a scan of https://github.com/afnid/espsim before all this but sometimes it's better starting from scratch I think, especially with all the progress made with Esp32/IDF.
If you build with
If
I'll have a look, I guess we want to pull in as much existing Esp8266 code as possible.
Probably implement that in a shell script I guess.
Perhaps a powershell script, once we've sorted out what a 'virtual network' looks like for Windows, possibly some kind of bridged configuration as you suggest. The |
Right. I have added the following to the wiki page: -- cut -- If you plan to use a debugger make sure to set the following environmental variables before compiling the code:
-- cut --
I can provide one. I was able to access my DNS and Internet with packet forwarding. Those additional lines made it work:
|
Further idea comes to my mind: Show the developers how to use terminal multiplexer as tmux or screen and provide in one terminal window a split view with the output from UART 0, UART1 and the simulator itself. |
I have found this on Internet: http://codelectron.com/how-to-setup-virtual-spi-in-linux/. Maybe this can be a good starting point. |
@slaff Thanks for this slaff, an interesting idea but not sure how it would fit. This is quite a complex area so I've opened a separate issue #1710 to discuss further. |
@mikee47 Are you ready to try ESP32 port :)) ? This way we can prove in practise if current structure is good enough to add multiple new architectures. |
Go for it :) |
I guess we could also start looking at building an Esp32 Arch tree, even if it's not functional would give some direction. I have a recurring thought about getting Sming running on bare-bones Esp32, without any freertos. I have yet to use the Esp32 myself, so cannot speak from experience, but the ROM code doesn't seem to be RTOS-dependent. It would be crazy fast :-) |
@mikee47 ESP-IDF v4.0 is officially released (https://github.com/espressif/esp-idf/releases/tag/v4.0). I guess we can start implementing |
@slaff It's in progress, but bored with it. Python build script crashes and takes terminal with it. Tedious.. |
@mikee47 create a PR and put WIP in the name. Let's try together to see if we can advance faster. |
@slaff Not ready for a PR of any kind yet but I've pushed my working branch to I'm keeping notes in the Last time I looked at this when I ran the python builder it just crashes and shuts down the terminal, which kind of makes debugging a little awkward. Also wading through issues with the python builder. P.S. Working with ESP-IDF release 4.1 branch. |
Just pulled a fresh IDF in and re-run install. Previously |
@mikee47 @slaff You may also be interested to know there is a version of Arduino that claims to run with ver 4. Ive been working with 4.0 RC and it went well certainly nothing like you have described. I had 3 problems getting my project to build; almost there. Now I see as of 2 days ago, 4.1 is there so maybe time to give that a go |
This issue is created to collect all tasks needed to create a port of Sming on top of esp32/Arduino.
As mentioned from @avr39-ripe here:
Sming itself can be described as several components which together allow us to develop complete standalone app for esp8266:
The main idea is to use esp32/Arduino as a base that provides us with:
As a start we need someone to try and do the following:
The text was updated successfully, but these errors were encountered: