One of the cool features of the Teensy 3.6 is that it has an SD card slot. The slot is supported by the SD library which you can get here (add link to github). The ChibiOS demos for Arduino include a chFifoDataLogger program which uses a version of the SDfat library. The logical thing to do is to replace the SDfat library with the new SD library made for the Teensy 3.6.
So that's what I did.
First, I ran the CardInfo Example program from the SD package to be sure I could see my SD card on the Teensy. For the 3.6, I made sure that the chipSelect was set to BUILTIN_SDCARD. The program ran using two different 4Gig cards and a 32Gig card.
Since the SD library works a little differently than the SDfat library, I compared the Datalogger program from the SD package to the chFifoDataLogger program from SDfat in the ChibiOS package and made some appropriate changes. The main changes were:
- SD is instantiated as an object by SD.h
- SD.open returns a File object to read and write to.
- SD.begin must be called with the proper chip select (as described above).
- A fast version if SD is available for the Teensy 3 series, but works for reading only, so I didn't use it.
- Details of the ChibiOS semaphores can be gleaned by looking at utility/chsem.[ch] in the ChibiOS library.
The file t36chFifoDataLogger is the result of my efforts. It needs a bit of clean up, but the code works. In addition to showing how to use the SD library, it also shows how to use ChibiOS semaphores to solve the Reader-Writer problem using an RTOS. More on this later.