As previously introduced, one of the key features of the Teensy 4.0 board is its SDIO interface support. In the Teensy 4 series, Teensy 4.1 has also been released with a built-in microSD card slot, but the board size is larger. The compact size of the Teensy 4.0 is a compelling advantage, so this article reports on methods to connect a microSD card to the Teensy 4.0, including trial and error. Access tests with large-capacity SDXC cards formatted with exFAT are also covered.
SDIO Interface
On microcontroller boards, SPI is the common interface for SD cards, but the Teensy 4.0 supports a 4-bit SDIO interface. The SDIO-related pins are provided as surface-mount pads on the back of the Teensy 4.0.
These pads were originally designed for mounting a flex cable connector for the Teensy 4.0 Breakout Board, and the pins are arranged in the same order as the microSD card pinout.
![]() |
| SDIO-related pins |
Connecting a microSD Card Connector
When connecting a microSD card slot without using the Breakout Board, two issues need to be addressed:- The pin pitch on the Teensy 4.0 side is 1.0mm, while the microSD card pin pitch is 1.1mm.
- If you try to place the microSD card slot directly on the pads with matching pin orientation, the card insertion opening faces inward on the Teensy 4.0 board.
For the orientation issue, I tried the following two methods [A] and [B]:
[A] Using a Hinge-Type microSD Card Connector
Instead of a standard locking microSD card connector, a hinge-type connector with an opening top is used:https://www.marutsu.co.jp/GoodsListNavi.jsp?path=&q=DM3CS
The non-pin areas of the microSD card were insulated with polyimide tape before soldering. Since the connector tends to float, the legs were fixed with epoxy. This connector allows card insertion and removal even when the card opening faces inward.
![]() |
| Hinge-type microSD card connector implementation |
- The microSD card can be attached without compromising the Teensy 4.0 board size.
- The wiring between the Teensy 4.0 board and microSD card terminals is minimized.
- Card insertion and removal requires clearance behind the Teensy 4.0 board, or the card must be installed permanently once assembled.
[B] Using a Flex Connector and Cable
To use a standard locking microSD card connector, the pins are routed out via a flex cable to connect the microSD card connector. On the Teensy 4.0 side, you can either attach a 1.0mm pitch flex connector or directly solder the flex cable. The pitch difference must be handled at the junction between the 1.1mm pitch microSD card connector and the 1.0mm pitch flex cable. In this case, a 10-pin flex cable and connector were used since 8-pin versions were not available.![]() |
| Connection using flex cable |
- Any card slot connector can be used, including standard locking microSD card slots.
- Greater flexibility in microSD card slot placement.
- Increased part count and assembly effort.
- Additional space is required for the microSD card connector separate from the Teensy 4.0 board.
[C] Other Methods
Various other connection methods are reported at the following URL:https://forum.pjrc.com/threads/58126-Optimal-microSD-pins-on-the-Teensy-4-0
Using an SD card adapter is a quick and easy method that works with commonly available parts.
SDXC Card exFAT Testing
When using SDXC cards of 64GB or larger, the file system will inevitably be exFAT. (There is a workaround of force-formatting to FAT32 using tools.) As a library supporting exFAT, the SdFat library (beta version) supports both exFAT and SDIO connection for the Teensy series. Here, I introduce the access test method using the SdFat beta version.Cards Used for Testing
The cards used for testing are listed below:- SanDisk microSDXC Ultra A1 64GB (UHS-I Speed Class 1)
- SanDisk microSDXC Ultra A1 512GB (UHS-I Speed Class 1)
- SanDisk microSDXC Extreme A2 1TB (UHS-I Speed Class 3)
![]() |
| Cards used for testing |
Downloading SdFat Beta
First, download the SdFat beta version from:https://github.com/greiman/SdFat-beta
For use in the Arduino environment, place it as a folder named SdFat under C:\Users\%username%\Documents\Arduino\libraries\.
In the bench project, set SD_FAT_TYPE to 3 at the beginning of bench.ino to handle exFAT formatted cards:
Test Projects
The following projects are used for card recognition and access speed verification:- Card recognition — examples/SdInfo project
- Access speed benchmark — examples/bench project
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h, // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT. // #define SD_FAT_TYPE 0 #define SD_FAT_TYPE 3Both projects are compiled in the Arduino environment, and operation is verified via the serial monitor.
For reference, the log from running the SdInfo project with the 64GB card is shown below:
=================================== SdFat version: 2.0.3-beta.1 ... (same as original) ===================================
Troubleshooting: Adjusting Drive Strength
If card recognition or access tests fail or intermittently fail, in my experience all issues were resolved by adjusting the SDIO pin drive strength. Specifically, modify the following section (around line 300) in SdioTeensy.cpp within the SdFat library's src/SdCard/ directory: const uint32_t CLOCK_MASK = IOMUXC_SW_PAD_CTL_PAD_PKE |
#if defined(ARDUINO_TEENSY41)
IOMUXC_SW_PAD_CTL_PAD_DSE(1) |
#else // defined(ARDUINO_TEENSY41)
IOMUXC_SW_PAD_CTL_PAD_DSE(4) | ///// WHG (try values like 1 or 2 here)
#endif // defined(ARDUINO_TEENSY41)
IOMUXC_SW_PAD_CTL_PAD_SPEED(2);
This section sets the drive strength for the SDIO clock and 4-bit data line IOs.
For the Teensy 4.0, drive strength 4 is set presumably for the Breakout Board, but with the connection methods described above (especially [A]), the drive strength was too high and caused access failures with certain card types. Setting it to drive strength 1 or 2 (equivalent to Teensy 4.1) resulted in stable operation. Although I haven't tested different Speed Classes of the same capacity, it appears that higher SDXC Speed Classes require more careful drive strength settings. (The 512GB Speed Class 1 card works with DSE=4, but the 1TB Speed Class 3 card produces errors.)Bench Project Results
Finally, here are the bench project results. The microSD wiring methods used were [A] and [B], with drive strength DSE values of [A]: 1 and [B]: 2. The flex cable length for [B] was approximately 5cm. While not reaching the full performance of UHS-I Speed Class 1 or 3, the access speed is approximately 5 times faster compared to SPI connection.================================ [A] IOMUXC_SW_PAD_CTL_PAD_DSE = 1 ... (same as original)





No comments:
Post a Comment