Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 22 of 22

Thread: SPI for Teensy 3.6 On-board microSD?

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Posts
    298

    SPI for Teensy 3.6 On-board microSD?

    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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,997
    Yes, SPI1 should work. There is no FIFO.

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    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..

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    See this post:

    https://forum.pjrc.com/threads/34808...l=1#post113904

    - might be useful ?

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    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.

    Click image for larger version. 

Name:	T3.5-with-display-on-SDCard.jpg 
Views:	116 
Size:	30.6 KB 
ID:	7994
    Click image for larger version. 

Name:	SDCard-Adapters.jpg 
Views:	262 
Size:	39.9 KB 
ID:	7995

    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.

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    Kurt, is your adapter-board open source ? I want to order some from OSH.
    Do you have eagle-files ?

  7. #7
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    Quote Originally Posted by Frank B View Post
    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-B...icrosd-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

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    Thank you - I ordered a set of 3 from OSH-Park (0.8mm)
    Price is $3.45

  9. #9
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,753
    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.

  10. #10
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    FYI - My first experiments with this are using the micro sd sniffer from sparkfun: https://www.sparkfun.com/products/9419
    They also have Eagle design files up there for it.

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    298
    Quote Originally Posted by KurtE View Post
    FYI - My first experiments with this are using the micro sd sniffer from sparkfun: https://www.sparkfun.com/products/9419
    They also have Eagle design files up there for it.
    Here is a really cheap, $2.17, microSD extension you could hack.

  12. #12
    Quote Originally Posted by Frank B View Post
    Thank you - I ordered a set of 3 from OSH-Park (0.8mm)
    Price is $3.45
    Could you please post a link to OSH-Park for this, if you've already uploaded it to them, so that the rest of us peeps can order them, too?

  13. #13
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    I believe the zip file he used came from my github... https://github.com/KurtE/Teensy3.1-B...icrosd-Adapter
    Up there is the diptrace files as well as the zip file that should work at OSHPark.

    I am thinking of making a 2nd version, that puts everything in two rows and shortens the length some...

    May hack on it later today.

    Kurt

  14. #14
    Quote Originally Posted by KurtE View Post
    I believe the zip file he used came from my github... https://github.com/KurtE/Teensy3.1-B...icrosd-Adapter
    Up there is the diptrace files as well as the zip file that should work at OSHPark.

    I am thinking of making a 2nd version, that puts everything in two rows and shortens the length some...

    May hack on it later today.

    Kurt
    Cool! Keep us posted...

  15. #15
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,230
    Yes, the zipfile works with OSH-Park.
    Remember to order the 0.8mm pcb!

    Well done, Kurt !

  16. #16
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    First pass (maybe last pass)
    Here are 3d outputs from diptrace
    Click image for larger version. 

Name:	T3.6-SD-TOP.jpg 
Views:	89 
Size:	18.9 KB 
ID:	8692

    Click image for larger version. 

Name:	T3.6-SD-BOT.jpg 
Views:	92 
Size:	24.9 KB 
ID:	8693

    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
    Attached Files Attached Files
    Last edited by KurtE; 11-02-2016 at 04:41 PM.

  17. #17
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,753
    That looks good Kurt.

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,997
    I'd recommend rounded or at least diagonal edges instead of sharp right angle corners for the side that inserts into the SD socket.

  19. #19
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    Quote Originally Posted by PaulStoffregen View Post
    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:
    Click image for larger version. 

Name:	T3.6-SD-TOP.jpg 
Views:	116 
Size:	29.6 KB 
ID:	8696
    I also ordered the updated ones where I diagonal edged.. Figured it was worth the $1.65
    Attached Files Attached Files

  20. #20
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,889
    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:
    Click image for larger version. 

Name:	screenshot.jpg 
Views:	7 
Size:	88.4 KB 
ID:	23820

    I did try to export the board layout to Eagle file in case that helps....

  21. #21
    Senior Member
    Join Date
    Nov 2012
    Posts
    298
    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.

    Click image for larger version. 

Name:	s-l500.jpg 
Views:	10 
Size:	22.3 KB 
ID:	23831

    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.
    Click image for larger version. 

Name:	Adapter.jpg 
Views:	9 
Size:	62.2 KB 
ID:	23832
    Last edited by Bill Greiman; 02-24-2021 at 04:01 PM.

  22. #22
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,122
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •