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
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: Teensy 4.0 & 4.1

Post by Mike Teachman » Wed Feb 23, 2022 6:48 pm

16 and 32 bits are supported

User avatar
rdagger
Posts: 143
Joined: Tue Feb 28, 2017 6:16 pm
Contact:

Re: Teensy 4.0 & 4.1

Post by rdagger » Thu Feb 24, 2022 10:16 pm

Does the Teensy firmware support ulab?

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 Feb 25, 2022 6:56 am

No. It is not integrated into the firmware. It shuold be possible to create such an image, but it will most probably never be a standard image.

ryanGT
Posts: 24
Joined: Fri Jan 28, 2022 12:15 am

Re: Teensy 4.0 & 4.1

Post by ryanGT » Sat Mar 12, 2022 8:48 pm

I was able to build micropython with ulab for teensy 4.1 without too much trouble.

alphaFred
Posts: 31
Joined: Wed Apr 15, 2020 6:47 pm

Re: Teensy 4.0 & 4.1

Post by alphaFred » Sat Mar 12, 2022 9:05 pm

Nice. Maybe if you give us some sort of step by step guide we could include it in the documentation at least? @Robert-hh what do you think?

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 » Sun Mar 13, 2022 7:27 am

Sounds good. The Teensy with it's 768kB heap should work well with ulab. The ARCH MIX board with it's 32 MB heap would be even better for large projects.

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 Mar 19, 2022 7:22 pm

[I2s] @miketeachman @rdagger It just noticed, that running the SPI driver without DMA for the SD Card stops the crackling in I2S playback. It works fine for MIMXRT10xx_EVK boards. So there is a kind of interference between DMA used by both the SPI and I2S. With Teensy and SGTL5000 the device locks up after a while. That has to be analyzed further. I do not expect this to be related to the Codec.
edit: The unexpected halt on Teensy disappeared.

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 » Mon Mar 21, 2022 7:34 am

[I2S, SPI] No, the problem is still there. What is the situation:
Non-DMA for SPI does not interfere with I2S. So you have a clear sound. But with MIMXRT105x/106x MCUs, non-Blocking transfer with SPI stalls at higher baud rates. The best I could get with a Teensy 4.x audio shield was about 5 MBaud. For 44.1 Samples/sec stereo this is still fast enough. On a Seeed Arch Mix board with long patch cables to a SD Micro shield it was about 2 MBaud. I did bit get that error with MIMXRT101x/102x boards. When the fault happens, the code simply locks up in an endless loop inside the SPI Library function.

But there is silver lining at the horizon: The problem disappears when using a more recent version of the NXP library. At the moment, the project uses version ~2.6. With version 2.10 the SPI problem is gone. And the driver can be compiled to not stall in such a case, allowing to raise an exception and handle the case in the Python script.
The move to library v2.10 or v2.11 is under construction since a while. The problem with that version: it is not backward compatible. So it's quite bit of work and testing, which is mostly done.

User avatar
Mike Teachman
Posts: 155
Joined: Mon Jun 13, 2016 3:19 pm
Location: Victoria, BC, Canada

Re: Teensy 4.0 & 4.1

Post by Mike Teachman » Wed Mar 23, 2022 2:04 am

Roberthh wrote:
Sat Mar 19, 2022 7:22 pm
That has to be analyzed further. I do not expect this to be related to the Codec.
edit: The unexpected halt on Teensy disappeared.
I would like to try reproducing the problem with a Teensy 4.1, then try to find the root cause. Can you recommend a configuration that is likely to cause the audio distortion? thanks!

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 » Wed Mar 23, 2022 7:05 am

Just connect a SD Micro Card by SPI at pins 10-13 and use that for the file system. The driver is drivers/sdcard/sdcard.py. I use the little script below for mounting. A cs pin has to be provided to the driver, even if the MIMXRT SPI block drives CS itself. The baudrate can be lower, if there are problems.
The SPI driver in machine_spi,c uses BlockingTransfer for short blocks and eDMA for longer blocks. The value for the discrimination is in variable dma_min_size_threshold in line 247. If set to 0, all transfers are eDMA, if set to a high value (e.g. 1 Million), all transfers are BlockingTransfer. For Blocking transfer and SDCard, you have to use alower baudrate, like 5 Mbaud. The SPI driver does not work any more that way with newer versions of the NXP lib. At the moment I prefer use BlockingTransfer only. It's robust, fast and small.

Code: Select all

import os, sdcard, machine

spi = machine.SPI(0) # SPI0 with cs1 used for SDCARD
cs = machine.Pin(10, machine.Pin.OUT, value=1)
sd = sdcard.SDCard(spi, cs, baudrate=20_000_000)
vfs = os.VfsFat(sd)
os.mount(vfs, "/sdcard")
os.chdir("/sdcard")

Post Reply