Using SDXC/exFAT with Teensy 4.0 (SDIO)

Sunday, December 13, 2020

Teensy 4.0

t f B! P L

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.
SDIO-related pins
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.

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 pitch difference, although not the most elegant solution, I forcefully connected the 1.0mm pitch to the 1.1mm pitch pads. Since the microSD card has 8 pins, when centered, the 0.1mm pitch difference per pin accumulates to a 0.35mm offset at the edge pins. Depending on the pad width, soldering is still possible with some effort.
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
Pros
  • 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.
Cons
  • Card insertion and removal requires clearance behind the Teensy 4.0 board, or the card must be installed permanently once assembled.
The size is excellent, but the difficulty or inability to insert and remove the microSD card in a normal manner is a significant drawback.

[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
Pros
  • Any card slot connector can be used, including standard locking microSD card slots.
  • Greater flexibility in microSD card slot placement.
Cons
  • 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
When formatting microSD cards, it is recommended to use the SD Memory Card Formatter from the SD Association rather than the OS built-in formatting tools.

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\.

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
In the bench project, set SD_FAT_TYPE to 3 at the beginning of bench.ino to handle exFAT formatted cards:
// 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 3
Both 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)

About Me

My photo
Electronics, programming & audio

Featured Post

Synchronizing Radio-Controlled Clocks with Raspberry Pi Pico W (JJY Standard Radio Wave Emulator)

As a Raspberry Pi Pico W application, I built a JJY emulator for radio-controlled clocks (for time synchronization) with minimal peripheral...

QooQ