Threading or RTOS in uPython

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
gwork
Posts: 5
Joined: Sun Dec 09, 2018 3:51 am

Threading or RTOS in uPython

Post by gwork » Sun Dec 09, 2018 4:04 am

Hello,

I am new to micropython, having just loaded it to my STM32F4 Discovery board yesterday. I have been really enjoying using it though, so kudos to all of the community members that have made it as good as it is today.

My current setup for my project is using the STM32 HAL libraries and FreeRTOS to do everything I need - including PWM, periodically reading sensors, serial communication, and Ethernet connection through a SPI adapter. However, with some new team members coming in, we are hoping to make the system more accessible and easy to learn for them by using a language they already know. Up to this point, I think we can do almost everything in micropython that we are currently doing, but I am concerned with the threading part of it. While I found some resources for threading on other boards, including the _thread and uasyncio modules, as well as zephyr RTOS, I haven't found the way to either include these in my project or use them. Running help('modules') doesn't list either _thread or uasyncio in the collection of available modules, and cd into /ports/zephyr and running 'make BOARD=STM32F4DISC' ran into many makefile errors.

So, what are my options here? Do I need to build or install these libraries? (is there a micropip?) Can I continue to use FreeRTOS for threading in my project? (note: I saw some threads on here for 'embedding' micropython as a FreeRTOS task, but I don't want to do that, I want full a uPython coding experience with threading support)

Thanks for the help!

gw

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

Re: Threading or RTOS in uPython

Post by pythoncoder » Sun Dec 09, 2018 6:57 am

I recommend uasyncio unless you really need threading. Reasons why, and a general tutorial on its installation and use, may be found in this repository.
Peter Hinch
Index to my micropython libraries.

gwork
Posts: 5
Joined: Sun Dec 09, 2018 3:51 am

Re: Threading or RTOS in uPython

Post by gwork » Sun Dec 09, 2018 2:05 pm

Thanks for the suggestion. What is the difference between uasyncio and threading? Is uasyncio non-preemptive? If that's the case, it will probably work fine for my usage.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Threading or RTOS in uPython

Post by kevinkk525 » Sun Dec 09, 2018 3:34 pm

uasyncio is cooperative (non-preemptive). I'd recommend reading about asyncio in python first for a general understanding. But you can of course directly look at the tutorial from pythoncoder.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

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

Re: Threading or RTOS in uPython

Post by pythoncoder » Mon Dec 10, 2018 8:03 am

gwork wrote:
Sun Dec 09, 2018 2:05 pm
Thanks for the suggestion. What is the difference between uasyncio and threading? Is uasyncio non-preemptive? If that's the case, it will probably work fine for my usage.
See this doc and this one.
Peter Hinch
Index to my micropython libraries.

Post Reply