SPI for Teensy 3.6 On-board microSD?

Status
Not open for further replies.

Bill Greiman

Well-known member
It appears that it may be possible to use SPI for the on-board microSD. Is this true?

Unless I can get optimized SDHC transfers to work, SPI may be faster for most users.

Here are some print benchmarks for SDHC and optimized multi-block SPI. I use SPI0 which has a four bytes FIFO so I can't say what the result would be with SPI1.

The test writes 20,000 values to a file using a for loop. Here is the for() and the println statements.
Code:
  for (uint16_t i = 0; i < 20000; i++) {

  // uint16_t println 
  file.println(i);

  // uint32_t println
  file.println(12345678UL + i);

  // float println
  file.println((float)0.01*i);

Here are results for SDHC:
Test of println(uint16_t)
Time 0.29 sec
File size 128.89 KB
Write 442.92 KB/sec

Test of println(uint32_t)
Time 0.41 sec
File size 200.00 KB
Write 485.44 KB/sec

Test of println(float)
Time 0.48 sec
File size 149.00 KB
Write 311.06 KB/sec

Here are results for SPI with optimized multi-block transfers.
Test of println(uint16_t)
Time 0.13 sec
File size 128.89 KB
Write 991.46 KB/sec

Test of println(uint32_t)
Time 0.15 sec
File size 200.00 KB
Write 1351.35 KB/sec

Test of println(float)
Time 0.26 sec
File size 149.00 KB
Write 577.52 KB/sec

SPI is three times faster for large uint32_t numbers. This is because single block writes to modern SD cards are slow.

The optimized SPI version uses multi-block writes so even though there is a single cache block, contiguous writes can use multi-block write.
 
Yes, but currently the PIN-definitions are missing...

A few days ago, i tried to modify the teensy sd-lib - but i stopped working on this, because the pins were missing and i didn't want to add my own definitions for pins.. :)
 
I have not tried using SPI on those pins to write to an SDCard, but I have experimented with those pins to do SPI, to for example write to an ILI9341 display, using an adapter I fabricated.

T3.5-with-display-on-SDCard.jpg
SDCard-Adapters.jpg

As I have mentioned on K66 beta thread: #1251
I have possible Pull requests in Core and SPI to allow you to use these as normal pins, including SPI, Uarts...

The pin table with their possible usages are:
Code:
58	PTE0	ADC1_SE4a	ADC1_SE4a	PTE0		SPI1_PCS1	UART1_TX	SDHC1_D1	TRACE_CLKOUT	I2C1_SDA	RTC_CLKOUT
59	PTE1	ADC1_SE5a	ADC1_SE5a	PTE1/LLWU_P0	SPI1_SOUT	UART1_RX	SDHC0_D0	TRACE_D3	I2C1_SCL	SPI1_SIN
60	PTE2	PTE2/LLWU_P1	ADC1_SE6a	PTE2/LLWU_P1	SPI1_SCK	UART1_CTS_b	SDHC0_DCLK	TRACE_D2		
61	PTE3	ADC1_SE7a	ADC1_SE7a	PTE3		SPI1_SIN	UART1_RTS_b	SDHC0_CMD	TRACE_D1			SPI1_SOUT
62	PTE4	DISABLED			PTE4/LLWU_P2	SPI1_PCS0	UART3_TX	SDHC0_D3	TRACE_D0		
63	PTE5	DISABLED			PTE5		SPI1_PCS2	UART3_RX	SDHC0_D2			FTM3_CH0
So yes they are setup for SPI 1 pins.

Note: Doing some testing on T3.5 board yesterday and found issues about doing DMA SPI on SPI1 and SPI2 on the K64 chips as these chips, the DMA TX channel and DMA RX channel for SPI1 and SPI2 are the same. More comments about it in the K64 Beta Test thread.
 
Kurt, is your adapter-board open source ? I want to order some from OSH.
Do you have eagle-files ?
 
Kurt, is your adapter-board open source ? I want to order some from OSH.
Do you have eagle-files ?

Yep anything I do is open source... But I use diptrace not eagle. Design files and zip file is up at: https://github.com/KurtE/Teensy3.1-Breakout-Boards/tree/master/microsd-Adapter

Warning: Microsd slots I believe will take a card up to about .75mm and I believe that OSH cards are either 1.6mm? So they won't fit. Defragster had some done I believe by either OSHPark or digistump which I believe is about 1.2mm) whic hhe then filed or sanded down until it fit.

Mine I ordered from Seeedstudio and ordered the .6mm thickness. I know there are some others who also do .6 but charge a whole lot more

Kurt
 
I ordered from Digistump - hit one with a file and some sand paper - still a bit high and not yet soldered to - but expect it to work.
 
First pass (maybe last pass)
Here are 3d outputs from diptrace
T3.6-SD-TOP.jpg

T3.6-SD-BOT.jpg

On the top, I show Arduino Pin numbers and on bottom show Port numbers

Again I just did this and have not checked out the gerber files yet, but they are in:

Update: I ordered a set from OSHPARK for $1.65 again remember the .8mm option
 

Attachments

  • microsd-Adapter-2row_Gerber.zip
    6.5 KB · Views: 146
Last edited:
I'd recommend rounded or at least diagonal edges instead of sharp right angle corners for the side that inserts into the SD socket.
 
I'd recommend rounded or at least diagonal edges instead of sharp right angle corners for the side that inserts into the SD socket.
Good idea:
T3.6-SD-TOP.jpg
I also ordered the updated ones where I diagonal edged.. Figured it was worth the $1.65
 

Attachments

  • microsd-Adapter-2row_Gerber.zip
    6.5 KB · Views: 149
Sort of an old thread to resurrect.

But by PMs been asked if I could convert the board to Altium... Not sure if you would gain much. The whole design:
screenshot.jpg

I did try to export the board layout to Eagle file in case that helps....
 
There are lots of microsSD extenders, converters and sniffers that I use to look at signals while debugging. Look for something like this on ebay.

s-l500.jpg

They tend to be about $3.50

I find boards that allow me to probe signals with a scope. Probably not as good as an extender with a cable attached.

Here is a board I bought a couple years ago.
Adapter.jpg
 
Last edited:
I used one of these extenders, Bill is talking about, to try sdio-access to multiple microSD.
while the extenders worked fine, my attempts to have multiple SD cards on the sdio bus failed. only one card was responding correctly and it seems that microSD do not implement the required feature. but using sdio bus for other sdio devives should still be possible.
 
Status
Not open for further replies.
Back
Top