esp32 ulp programming

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Thu Mar 15, 2018 3:34 pm

tele_player wrote:If you’re on a linux or other Unix-like system, you can write a shell script to wrap bin/esp32ulp-elf-nm and handle the redirection into a file.
I'm trying to make a python wrapper for the ulp code, thanks, this gave me the idea to use python.
ESP_igrr wrote:Since Arduino for esp32 already depends on Python, this might be an option for you:
https://github.com/ThomasWaldmann/py-esp32-ulp
(still WIP but simple programs can already be compiled).
I was going the python route when I saw your message so thanks for sharing that with me, it helps a lot. I'm not going to do are the parsing of the actual assembly code in python but will use it to wrap up all the shell commands that build and link the ulp code. One thing I did just find out is Arduino ide doesn't handle .s extension to files so I have to find a way to tell if the code is written for the ulp or the xtensa processors in .S files. Also I would eventually like to have this work on (MAC OS, WINDOWS, LINUX) but can I expect them to all have python installed?

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Thu Mar 22, 2018 11:58 pm

Just a follow-up to this thread, I am successfully loading the ulp binary blob into the final elf and running a test sketch using the ulp to increment a global variable. Looks like I can use .s extension for ulp assembly and .S for xtensa assembly and have a python script do the heavy lifting of creating an ulp binary blob to embed into larger elf. I'm trying my hardest to keep the functionality of how you write code for the ulp the same as you would do with esp-idf environment, but there are few snags I need to figure out.

First being on how Arduino compiles code makes it difficult for the sketch to see any global variables defined in the assembly because the Arduino ide doesn't have a platform.txt hook before Arduino detects libraries. The way esp-idf does it is it creates a header file that gives your c, c++ code an externed variables that links to the assembly global variables. What happens is Arduino detects all the libraries and sketch ino files before I can compile the ulp code and create that header file. What works is to have the user create that header file manually in the ide and define the externed global variables that they want to access in their sketch. This is the only way I can think of so far, not to bad though I think?

I am in the process of moving but once I get chance I'll post a how-to for MacOS and possibly linux and upload the files to my github account.

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Wed Mar 28, 2018 4:58 pm

I got the files uploaded to github with a little how-to as the readme. If anyone tries this out let me know any problems you have with compiling a project here or in the github repository.

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Fri Apr 13, 2018 3:06 pm

I have recently added support for multiple ulp assembly files and hopefully window and linux support but those need to be tested by someone that has those OS's.

timpur
Posts: 3
Joined: Fri Jun 08, 2018 12:43 pm

Re: esp32 ulp programming

Postby timpur » Fri Jun 08, 2018 11:34 pm

Hey, sorry random question, just wondering if anyone knows why Programming the ULP using macros became legacy. I was kinda thinking it was an easy and effective way with out the need of additional build tools.

Trying to program the ULP using ESP32 Arduino and cant figure out the "proper" way yet, but macros work for now ....

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: esp32 ulp programming

Postby ESP_igrr » Sat Jun 09, 2018 12:28 pm

We're not planning to remove ULP macros, but examples will be written using ULP binutils support. Also some instructions might be missing from the ULP macros header file.

FYI there's also a ULP assembler written in Python for micropython project. It might be easier to integrate into Arduino.

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Sun Jun 10, 2018 5:30 pm

timpur wrote: Hey, sorry random question, just wondering if anyone knows why Programming the ULP using macros became legacy. I was kinda thinking it was an easy and effective way with out the need of additional build tools.

Trying to program the ULP using ESP32 Arduino and cant figure out the "proper" way yet, but macros work for now ....
I think once you try to program a more complicated program you will find the MACROS quite limiting and difficult to use. Look at the ulp assembly examples and imagine trying that with the MACROS.
ESP_igrr wrote: FYI there's also a ULP assembler written in Python for micropython project. It might be easier to integrate into Arduino.
Wouldn't this require using micro-python instead of Arduino? How would that help if someone wants to use Arduino? Also as far as I have seen the micro-python ULP support is currently only for simple programs and it is stated they try to compile code similar to binutils AS but not exactly. This is awesome for micropython but not sure how that helps with someone wanting to use Arduino. This is why I created this fix for Arduino ulp assembly programing. I wish it could be done easier to install and welcome any ideas people have to make it better. Maybe you guys could integrate it into the forthcoming Arduino esp32 install?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: esp32 ulp programming

Postby ESP_igrr » Mon Jun 11, 2018 4:47 am

Wouldn't this require using micro-python instead of Arduino?
If it doesn't yet run under CPython, i think it would not be too hard to make it run there. Most of the implementation seems to be pretty standard python3, as far as i can tell.
Sorry that I didn't add a link in my previous comment: https://github.com/ThomasWaldmann/py-esp32-ulp

duffster
Posts: 16
Joined: Sun Mar 04, 2018 2:17 am

Re: esp32 ulp programming

Postby duffster » Mon Jun 11, 2018 5:48 pm

ESP_igrr wrote: If it doesn't yet run under CPython, i think it would not be too hard to make it run there. Most of the implementation seems to be pretty standard python3, as far as i can tell.
Sorry that I didn't add a link in my previous comment: https://github.com/ThomasWaldmann/py-esp32-ulp
From what I read, CPython is just the python Interpreter written in C, it doesn't compile C code from python scripts, though I guess there is Cython. How would CPython integrate into a Arduino environment? Not trying to argue with you but I really don't see how this would be any easier or would even work without some major changes to the Arduino IDE using esp32? For example, even if you do get the ulp binary blob from Waldman's python script you still have to combine it with the users compiled code and link it all together, that would still require changing how esp32 Arduino recipes compile users code. I do admit that Thomas Waldmans micro python ulp implementation is a much higher feet of innovation than mine but its geared for micro python not Arduino.

timpur
Posts: 3
Joined: Fri Jun 08, 2018 12:43 pm

Re: esp32 ulp programming

Postby timpur » Tue Jun 12, 2018 10:17 pm

Yes, i think your right, it does become complex and confusing quick using macros, but for now the only way i can find that works easy with arduino. Might create an issue on the arduino thread about this.

Thanks guys :)

Who is online

Users browsing this forum: No registered users and 35 guests