Taking advantage of the second core

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
binux
Posts: 17
Joined: Tue Jul 25, 2017 10:35 am

Taking advantage of the second core

Post by binux » Mon Aug 28, 2017 7:53 pm

Hello again,

I have another question about the ESP32 chip. When you buy the chip you're told that it uses dual-core. And Espressif says if you use their FreeRTOS tasks are equally split between both cores while memory is shared. But they also state, that if you want you can "pin" one task to one core. Now my question is. As you might know from my older posts, I have a quiet expensive display routine which is called every 33ms. This seems to heavily influence my TCP connection because it's done with a Timer and interrupts the active data-transfer. This in conclusion leads to longer response times in my TCP connection. Now my question is, does Micropython support pinning let's say the display routine to core 1 and the TCP communication to core 2?

Also I see that the @Micropython.Native is not yet supported on the ESP32. Does anyone know if Viper would work?

Thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Taking advantage of the second core

Post by pythoncoder » Tue Aug 29, 2017 5:21 am

Given that Viper is an optimised version of Native, I think the answer is probably no.
Peter Hinch
Index to my micropython libraries.

binux
Posts: 17
Joined: Tue Jul 25, 2017 10:35 am

Re: Taking advantage of the second core

Post by binux » Tue Aug 29, 2017 6:48 am

pythoncoder wrote:Given that Viper is an optimised version of Native, I think the answer is probably no.
That's a pitty, but I guess it will somewhen be ported to the 32. Regarding my first question, do you think there's a way?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Taking advantage of the second core

Post by Roberthh » Tue Aug 29, 2017 12:32 pm

As far as I understand, the pycom.io port, being based on a RTOS, uses both cores. But I might be wrong. Their firmware for WiPy runs aon any ESP32 board. It has some other properties, like smaller heap space, and a slightly different set of modules, but beside that it works. Just for curiosity, I installed it for instance on an sparkfun ESP32 thing and a Wemos Lolin 32.

binux
Posts: 17
Joined: Tue Jul 25, 2017 10:35 am

Re: Taking advantage of the second core

Post by binux » Tue Aug 29, 2017 1:07 pm

Roberthh wrote:As far as I understand, the pycom.io port, being based on a RTOS, uses both cores. But I might be wrong. Their firmware for WiPy runs aon any ESP32 board. It has some other properties, like smaller heap space, and a slightly different set of modules, but beside that it works. Just for curiosity, I installed it for instance on an sparkfun ESP32 thing and a Wemos Lolin 32.
That's what I heared too. Actually in the beginning I used a Wipy 2 which is basically the same chip. But sadly they have no proper NeoPixel support and modules like the WiFi do not work reliably. At least for me.
That's why my question aimed more into a hint on how I can make this functionality myself by adding the needed C modules into my esp-32 fork. But the documentation about this is very thin.
Especially because I want to basically run my python module with the xTaskCreatePinnedToCore function. Is this even possible?

loboris
Posts: 344
Joined: Fri Oct 02, 2015 6:19 pm

Re: Taking advantage of the second core

Post by loboris » Wed Aug 30, 2017 7:26 am

Pycom's MicroPython port uses only 1 core ("#define CONFIG_FREERTOS_UNICORE 1" in sdkconfig.h).

You may want to check my MicroPython port which uses native ESP32 esp-idf build system and runs on both cores without problem. MicroPython task is by default pinned to App core.
I've also made some changes to the _thread module, threaded MicroPython modules works quite reliable. Threads are acctualy separate tasks created with xTaskCreatePinnedToCore. At the moment they have to run on the same core as the main MicroPython task, but I'm investigating the possibility to run it on different core.
There are also the complete mqtt and telnet modules written completely in C running in separate tasks (not yet in repository, will be pushed in a day or two).
NeoPixel module is based on ESP32 RMT peripheral and works without problem.
In spite its name the port runs also on modules without psRAM (at the moment even better).
GitHub
Forum

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Taking advantage of the second core

Post by Roberthh » Wed Aug 30, 2017 8:19 am

This is truly an interesting branch, and I wonder if and how this eventually can be merged again with the micropython.org branch. As time goes by and you are developing new properties at high speed, maybe that is as hypothetic as Daniel and Damien's claim to merge back the Pycom.io and micropython.org trees.

binux
Posts: 17
Joined: Tue Jul 25, 2017 10:35 am

Re: Taking advantage of the second core

Post by binux » Wed Aug 30, 2017 8:41 am

loboris wrote:Pycom's MicroPython port uses only 1 core ("#define CONFIG_FREERTOS_UNICORE 1" in sdkconfig.h).

You may want to check my MicroPython port which uses native ESP32 esp-idf build system and runs on both cores without problem. MicroPython task is by default pinned to App core.
I've also made some changes to the _thread module, threaded MicroPython modules works quite reliable. Threads are acctualy separate tasks created with xTaskCreatePinnedToCore. At the moment they have to run on the same core as the main MicroPython task, but I'm investigating the possibility to run it on different core.
There are also the complete mqtt and telnet modules written completely in C running in separate tasks (not yet in repository, will be pushed in a day or two).
NeoPixel module is based on ESP32 RMT peripheral and works without problem.
In spite its name the port runs also on modules without psRAM (at the moment even better).
GitHub
Forum
Indeed this branch looks very interesting. I will definitely try it out. It also looks like you tried to simplify the build process which is a cool thing that I was having on my list as well. For me it would be a breeze to have the wifi related tasks running on the second core. Eg. they should then not block my RTOS timer. This one is halted while a wifi scan is performed. How close to reality is this idea?

paynecs
Posts: 1
Joined: Tue Jun 05, 2018 2:39 pm

Re: Taking advantage of the second core

Post by paynecs » Thu Sep 06, 2018 2:35 pm

Hi Loboris,

Did you make any progress with this?:

"At the moment they have to run on the same core as the main MicroPython task, but I'm investigating the possibility to run it on different core."

It would be very valuable to be able to run different tasks and/or threads on specific cores.

Many thanks,

Colin

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Taking advantage of the second core

Post by pythoncoder » Fri Sep 07, 2018 9:11 am

I suggest you post queries on the Loboris port on its forum.
Peter Hinch
Index to my micropython libraries.

Post Reply