Teensy 4.0 & 4.1

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Teensy 4.0

Post by jimmo » Tue Apr 21, 2020 11:37 am

There's a PR in progress that adds the beginning of support for machine.Pin

I'm surprised by those results too, my memory is is that ESP32 and Pyboard have similar-ish performance numbers and the simple tests I did with Teensy showed that the perf scaled roughly with CPU speed compared to the Pyboard (so I would expect to see significantly higher performance on the Teensy compared to ESP32).

Would be good to replicate with MP on both devices. I've been meaning to test out the PR described above so might be a good opportunity to do this.

User avatar
rcolistete
Posts: 352
Joined: Thu Dec 31, 2015 3:12 pm
Location: Brazil
Contact:

Re: Teensy 4.0

Post by rcolistete » Tue Jun 02, 2020 2:42 pm

Teensy 4.1 was released in May 11th 2020 :
Image
Teensy 4.1 Released
US$26.85 at PJRC official store
basically a Teensy 4.0 with Teensy 3.6 format, i. e., more pins, uSD, more possible expansions :
- same MCU NXP i.MX RT1062 from Teensy 4.0, which already was a super-microcontroller;
- 8 MB of internal flash memory flash instead of 2 MB;
- uSD;
- more pins compatible with breadboard, 48 in Teensy 4.1 x 26 in Teensy 4.0;
- pins for Ethernet 10 / 100 Mbits;
- pins fora USB host;
- pads in the back side to solder up to 2 IC's : 8MB PSRAM or 16MB flash. It allows some combinations : 8 MB PSRAM, 16 MB flash, 8 MB PSRAM + 16 MB flash, 8+8=16 MB PSRAM.

There is already CircuitPython support for Teensy 4.1, with some new features implemented , see this post at PJRC forum :
- more internal flash memory (7MB in Teensy 4.1 x 1 MB in Teensy 4.0) visible as file system;
- more exposed pins;
- the microSD can work with the Adafruit_CircuitPython_SD library.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).

Cami
Posts: 1
Joined: Wed Feb 10, 2021 8:16 am

Re: Teensy 4.0 & 4.1

Post by Cami » Wed Feb 10, 2021 8:21 am

Hi There

This looks really interesting!
Are there any updates to the support of Teensy 4.0 for Micropython?

All the best
Cami

User avatar
RobH
Posts: 91
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: Teensy 4.0 & 4.1

Post by RobH » Fri Jun 04, 2021 10:10 am

I just discovered the existence of Teensy40 and Teensy41 boards in the Micropython repository. A make of the firmware for my Teensy40 succeeded and after I loaded the resulting firmware.hex file with the Teensy loader a virtual serial port appeared (ttyACM0). From a serial terminal program I see the Python 'command prompt'. An os.listdir() statement returns an empty list: [], so it looks like there is a file system present.
But I do not see an USB-stick like interface as with PyBoard. So I do not understand how to copy a file to the Teensy. Rshell ffor example doesn't accept '/flash' as copy-destination.
Any suggestions how to get Python scripts to the Teensy?
Rob.

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

Re: Teensy 4.0 & 4.1

Post by Roberthh » Fri Jun 04, 2021 11:04 am

alphaFred and me started to revive support for the MIMXRT MCU's, which is used in Teensy 4.0 and 4.1. We made some progress, but there is still a huge amount of work ahead, and that will take some time. The state we are in now is somewhat usable. It has a file system now, Pin, ADC, SoftI2C, SoftSPI, Onewire, most python features, and a PR for UART support is also made. Since the Teensy 4.1 has a Ethernet transceiver, Ethernet support should be added sometime. I hope someone else chimes in for that. The MCU is pretty complex.

About your question:

The file system is mounted at "/", not "/Flash". I use mpremote to copy in files, like

mpremote a0 cp <filename> :<filename>

The Teensy loader has the bad habit of destroying the file system on firmware load. So every time you load a new firmware you have to update the files again. I made a little shell script dong that for my purpose. You may as well copy file you use often to the modules directory, which will embed them as frozen bytecode. There is plenty of space available for frozen bytecode.

User avatar
RobH
Posts: 91
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: Teensy 4.0 & 4.1

Post by RobH » Fri Jun 04, 2021 12:18 pm

Thanks Robert! I'll see if I can get things working despite the (hopefully temporary) limitations...
Success with the developments.
Rob.

User avatar
RobH
Posts: 91
Joined: Fri Mar 23, 2018 3:37 pm
Location: Netherlands
Contact:

Re: Teensy 4.0 & 4.1

Post by RobH » Fri Jun 04, 2021 7:02 pm

It took some time to become familiar with mpremote, but I managed to transfer some scripts to my Teensy40.
Since I have now a working Micropython on the Teensy I was curious about its performance compared to what I experienced with Circuitpython (see my entry of 21 April 2020 in this Forum).
So I repeated my measurements with 'pystone_lowmem.py (1.2)', this time with the ESP32 and the Teensy both loaded with Micropython firmware 1.15-186. Results:

Code: Select all

 ESP32     1231 pystones / second
 Teensy40  3782  pystornes / second
This shows a lot better performance of the Teensy with Micropython than with Circuitpython.
It is also much closer to what I would expect of the difference between ESP32 and Teensy.

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

Re: Teensy 4.0 & 4.1

Post by Roberthh » Sat Jun 05, 2021 6:03 am

Just two comments:
Since you build the firmware yourself, you can simply use "make deploy" to start the firmware download process.

And you can also mount the file system at /Flash by changing the mount instructions in modules/_boot.py, e.g. to:

Code: Select all

# _boot.py
# Try to mount the filesystem, and format the flash if it doesn't exist.
# Note: the flash requires the programming size to be aligned to 256 bytes.

import os
import mimxrt

bdev = mimxrt.Flash()

try:
    vfs = os.VfsLfs2(bdev, progsize=256)
except:
    os.VfsLfs2.mkfs(bdev, progsize=256)
    vfs = os.VfsLfs2(bdev, progsize=256)
os.mount(vfs, "/Flash")
os.chdir("/Flash")
You have to change sys.path then ass well, easiest done in main.py.

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

Re: Teensy 4.0 & 4.1

Post by pythoncoder » Sat Jun 05, 2021 7:46 am

RobH wrote:
Fri Jun 04, 2021 7:02 pm
It took some time to become familiar with mpremote, but I managed to transfer some scripts to my Teensy40...
Have you tried the mount feature? This is very powerful. I am currently developing a large application written as a Python package, and have done this without transferring a single file to the target hardware. I navigate to the project root on my PC and issue

Code: Select all

mpremote mount .
This gives me a REPL where I can issue

Code: Select all

>>> import ugui.demos.test
and the code runs. I could plug in a different target, e.g. replace an RP2 with an ESP32, and repeat. All without affecting or worrying about their filesystems. This strikes me as awesome.
Peter Hinch
Index to my micropython libraries.

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

Re: Teensy 4.0 & 4.1

Post by Roberthh » Sat Jun 05, 2021 9:11 am

Thank you for reminding, Peter: this is indeed extremely helpful and makes mounting the boards file system to the PC unnecessary. As long as I used that, I wrecked my board's file system several times, even when taking care to "sync & wait" every after each file transfer.

Post Reply