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
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Teensy 4.0 & 4.1

Post by Roberthh » Sat Feb 19, 2022 5:34 pm

Which SDCard.py do you use? The old one sets SPI speed back to 1.3MHz. There is an updated one now in the repository, where you can define in the constructor of the SDCard the final baudrate.
See: https://github.com/micropython/micropyt ... ers/sdcard

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

Re: Teensy 4.0 & 4.1

Post by rdagger » Sat Feb 19, 2022 5:58 pm

Roberthh wrote:
Sat Feb 19, 2022 5:34 pm
Which SDCard.py do you use? The old one sets SPI speed back to 1.3MHz. There is an updated one now in the repository, where you can define in the constructor of the SDCard the final baudrate.
See: https://github.com/micropython/micropyt ... ers/sdcard
Great suggestion! I tried the new SDCard.py with a Class 4 SD card and the recording took 16 seconds and sounds much better although still choppy. I think if I go pick up a class 10 it might work.

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 Feb 19, 2022 7:10 pm

One question: Is your sgtl5000 repository up-to-date. I plan to extend the driver to sample rates <32000.

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

Re: Teensy 4.0 & 4.1

Post by rdagger » Sat Feb 19, 2022 8:40 pm

Roberthh wrote:
Sat Feb 19, 2022 7:10 pm
One question: Is your sgtl5000 repository up-to-date. I plan to extend the driver to sample rates <32000.
I just pushed my latest version to GitHub.

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 Feb 19, 2022 8:50 pm

Thanks. I have a version here now which allows more freedom in sample rate setting: https://github.com/robert-hh/micropython-sgtl5000

For sample rates < 32000, you have to use PWM to create the mclk. The I2S module must be configured not to provide the MCLK. You can set the PWM for a 10MHz clock like:

from machine import PWM
mclk=PWM(23, 10_000_000)
codec = CODEC(0x0A, i2c, mclk=10_000_000, mclk_mode=3, sample_rate=16000)

Tested with 16000, 22050, 32000, 44100, Mono and Stereo. There is a hiccup yet. It starts well only after power-on-reset. After soft-reset, the configuration is not reset well. t.b.d.

Maybe mlkc=xx should be renamed to mclk_freq=xxx

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

Re: Teensy 4.0 & 4.1

Post by rdagger » Sat Feb 19, 2022 10:12 pm

Roberthh wrote:
Sat Feb 19, 2022 8:50 pm
Thanks. I have a version here now which allows more freedom in sample rate setting: https://github.com/robert-hh/micropython-sgtl5000

For sample rates < 32000, you have to use PWM to create the mclk. The I2S module must be configured not to provide the MCLK. You can set the PWM for a 10MHz clock like:

from machine import PWM
mclk=PWM(23, 10_000_000)
codec = CODEC(0x0A, i2c, mclk=10_000_000, mclk_mode=3, sample_rate=16000)

Tested with 16000, 22050, 32000, 44100, Mono and Stereo. There is a hiccup yet. It starts well only after power-on-reset. After soft-reset, the configuration is not reset well. t.b.d.

Maybe mlkc=xx should be renamed to mclk_freq=xxx
That's very cool! I had initially tried using PLL with an ESP32 and a PWM MCLK but I couldn't get it to work. The mclk and fs arguments are left over from this failed attempt and aren't currently used in my codes so you can change them as you deem best.
Please let me know when you think your version is ready to be merged.

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 Feb 20, 2022 8:06 am

Just a hint: There is a driver for the SGTL5000 codec by NXP themselves at https://github.com/NXPmicro/mcux-sdk/tr ... c/sgtl5000. They have also the WM8960 driver there, which I translated into Python.
Some good hints can be taken from their driver, except for dealing with the PLL, which is not used.

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

Re: Teensy 4.0 & 4.1

Post by rdagger » Mon Feb 21, 2022 9:21 pm

Roberthh wrote:
Sat Feb 19, 2022 5:34 pm
Which SDCard.py do you use? The old one sets SPI speed back to 1.3MHz. There is an updated one now in the repository, where you can define in the constructor of the SDCard the final baudrate.
See: https://github.com/micropython/micropyt ... ers/sdcard
fyi: I switched to a class 10 SD card and the recording works using the Teensy Audio adapter SD slot!

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 Feb 23, 2022 7:26 am

@rdagger: I made another PR to the SGTL5000 driver. There was a little 1 bit fix to make, since the sound at low sample rates like 8000 was blurred. Now it's only muffled, which is to be expected at SR 8000.

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

Re: Teensy 4.0 & 4.1

Post by rdagger » Wed Feb 23, 2022 6:25 pm

Is 8-bit recording supported? I tried setting the I2S bits to 8 and got the following error:
ValueError: invalid bits

Post Reply