Multithreading on Teensy 3.2?

I am new to Teensy, and started with a 3.2 board, thinking it should offer similar capabilities of STM32 Nucleo-L476 as they are both facilitating the Cortex M4.
The divide however seems to be large?

On STM32 I am used to using the HAL library, where it is easy to connect to peripherals and also getting callbacks that will run in independent threads.
Unfortunately I am not able to find out how to do that with the Teensy 3.2, so if someone could please tell me to find such info?

In short, I have a main loop that continuously makes decisions dependent on the values from various sensors (temperature, humidity, Hall, light, etc.), and adjust various timer's PWM duty cycles.
Those sensors may be read during the main loop, but also on external interrupts that calls independent functions.
Then, I use a UART Rx/Tx to access a running system, and this is also interrupt driven executing in its own threads.

As all Nucleo boards I have seen are rather large in physical size, I found the Teensy 3.2, which is impressively compact in size, and I thought it would be rather similar to the Nucleo to program.

Multi-thread wise it seems not so?
Can anyone please tell me where to look?
 
There is a multi threading library posted somewhere here on the forum if you really want to go down that route.
 
I did look into the "Teensy 3.x multithreading library first release", but it seems very raw and I would prefer not to have to debug that as well as my own code.

What other route would you advice?

If I only have one thread, I have to serially poll my sensors and then do my decisions on their values, and adjust my PWM timers, controlling whatever devices I have, and always in the same order.

Is that how the Arduino platform is normally expected to be used?
 
Is that how the Arduino platform is normally expected to be used?
Standard Arduino is coming from 8 bit controllers, where multithreading is a large overhead. So you can't expect that everything is based on multithreading by default.

The multi threading library is included in the Teensy software. Look under "Teensy Threads" in the library folder. Just look at the examples.

Maybe this is helpful, too
https://www.pjrc.com/teensy/td_timing_elaspedMillis.html
https://www.pjrc.com/teensy/td_timing_IntervalTimer.html
https://forum.pjrc.com/threads/44723-Arduino-Events
 
Thank you for the links, I will look into those.

I didn't know Arduino from before, but searched for smaller sized boards with Cortex M4 MPU, and when also seeing the Teensy 4.0 with a 600MHz Cortex M7, I would expect the software to have moved on significantly since 8 bit controllers.
 
Moving on significantly since 8 bit controllers is unfortunately often inhibited from the well-meant but inefficient intention to maintain backward compatibility.
 
Yes, a pity.
I started programming in 1981 and has been around since the Z80, and I wouldn't attempt to make software for the newest CPUs backward compatible, which would just underline 'backward'.
Moving on and cutting old stuff is what Major revision numbers are for, isn't it?
 
Indeed the main focus has been compatibility with Arduino and the large ecosystem of Arduino libraries and examples.
 
What other route would you advice?
I decided, instead of full-blown multithreading, to exploit the Arm multi-priority interrupt system.
As my sensor systems lead to a data driven interrupt based processing chain, a lot of work is done in parallel. high speed DMA based acquisition, low-speed (I2C type) data capture and very low priority data archiving (done when no interrupts are served).
 
I guess the simplest - as begin - is the intervaltimer.
You might look at the NVIC macros (NVIC_ENABLE_IRQ etc), vector table, attachInterrupt, pin irqs and software triggered interrupts (every interrupt can be triggered by software)
For the details, the referencs manual is useful, and a look at the core (search for NVIC and _VectorsRam[] <- vector table in RAM)

Should be all pretty similiar to the STM as both run with ARM-Cortex - the syntax is different, that's all.
Somebody ported RTOS - I don't remember who it was.

And take a look at the Teensy 4 (600MHz, overclock to 1GHz (needs cooling), much RAM and Flash), same size as the Teensy 3.2
 
Thank you Frank, I'll have a look.

I didn't get a reference manual as I just bought the Teensy 3.2 barebones for testing and seeing how easy it is to port my code from using STM32 HAL on Nucleo boards.
The reason 3.2 looks interesting (for me now) is that it can handle high currents, up to 250mA, but the 4.0 will get my attention later, if I can make an acceptable environment for it.
Or I might go for a Rasperry Pi to do complex things, and then Teensy to do the peripheral stuff.

On MCU level, I come from using STM32 CubeMX that takes a load off you, doing all the nitty gritty stuff, so you can concentrate on what you want to do in your code.
Even on a Nucleo F031K6 with just 4KB RAM and 32KB Flash, you can do some pretty advanced stuff.
Right now I need something more though, which is why I am looking for a Cortex M4.
 
Indeed the main focus has been compatibility with Arduino and the large ecosystem of Arduino libraries and examples.

On one end I agree with that. Yet as you continue to develop with faster and faster processors it starts to become a major hinderance.
Imagine your PC that could only run arduino. No multitasking. It would be just a total waste.
With the ARM Cortex-M7 processor at 600 MHz, I cannot see why anyone would not be using threading with that. Even the ESP32 has freeRTOS.
 
"Even the ESP32 has freeRTOS."

An ESP32-WROOM-32D also has dual-core CPU at 240MHz, 520KB RAM, 448KB ROM for the program, an external 4MB Flash chip, WiFi and Bluetooth, all mounted in one module.
All for just EUR 3.5, so what's not to like?
 
Sample Code for interrupt-based acquisition

I decided, instead of full-blown multithreading, to exploit the Arm multi-priority interrupt system.
As my sensor systems lead to a data driven interrupt based processing chain, a lot of work is done in parallel. high speed DMA based acquisition, low-speed (I2C type) data capture and very low priority data archiving (done when no interrupts are served).

I have a very similar setup that I am trying to implement. Was also considering multithreading but I faced some difficulties, and I can see that the interrupt-based approach is reasonable. I am trying to read from 4 I2C sensors with DMA acquisition and data archiving. I am new to this, so I am wondering of you could share codes from you project that could be of help for me to follow through! Thanks!
 
FreeRtos is not multithreaded not concurrently. It can not process two threads at the same time so I don't see all the hype in this over glorified OS. Really look forward to all your guys hard work. Thank you so much.
 
Back
Top