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

Thread: HOw can I read/write files on Teensy 3.6's SD card from my PC?

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11

    HOw can I read/write files on Teensy 3.6's SD card from my PC?

    Hi, I've bought over 20 Teensy 3.6s and am planning my next project.

    I need to be able to read and write files that are on my Teensy's SD card using the Teensy's on-board microUSB socket connected to my Windows 10 PC. The sketch running on my Teensy can happily create and read files itself but I want to be able to see them remotely. Is this possible, or do I have to copy them into Teensy RAM and access this remotely instead?

    I thought that selecting USB type: RAW HID might do something but my PC sees nothing. I was hoping to have a USB drive visible from Windows...

    I found an old thread about this but it involved changing hardware config files and looked a bit scary. Isn't there a simple way?

    Many thanks

  2. #2
    You need to change USB type to MTP (EXPERIMENTAL)
    in Teensyduino, and add a few lines of code at the beginning of your sketch.
    If you search PJRC for MTP RESPONDER you will find details.
    There seem to be some caveats, but I find it works quite well in my project.

  3. #3
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    Yeah that's the scary way I referred to...
    So I just tried it.
    1. compiling the blinky example gives:
    Arduino: 1.8.9 (Windows 10), TD: 1.46, Board: "Teensy 3.6, MTP Disk (Experimental), 180 MHz, Faster, US English"

    Build options changed, rebuilding all
    In file included from F:\Documents\Arduino\libraries\MTP-master\examples\MTP_blinky\MTP_blinky.ino:7:0:

    F:\Documents\Arduino\libraries\MTP-master/MTP.h: In member function 'virtual uint32_t MTPStorage_SD::Create(uint32_t, bool, const char*)':

    F:\Documents\Arduino\libraries\MTP-master/MTP.h:375:38: warning: large integer implicitly truncated to unsigned type [-Woverflow]

    OpenFileByIndex(ret, FILE_WRITE);

    ^

    exec: "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/{build.command.linker}": file does not exist
    Error compiling for board Teensy 3.6.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.


    and compiling the sketch I actually want to use - and that normally works perfectly - gives
    Arduino: 1.8.9 (Windows 10), TD: 1.46, Board: "Teensy 3.6, Serial, 180 MHz, Faster, US English"

    exec: "C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/{build.command.linker}": file does not exist
    Error compiling for board Teensy 3.6.

    I followed the instrucions on Github and both boards.txt and platform.txt are where the instructions say they should be. If I revert to my original boards.txt then my program compiles again.

  4. #4
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    With the original boards.txt, the blinky compiles and runs on the Teensy but Windows 10 sees nothing

    Windows device manager finds a new USB Composite DEvice but shows it cannot start. STATUS_DEVICE_DATA_ERROR

  5. #5
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    in mtp.h if I replace

    void OpenFileByIndex(uint32_t i, uint8_t mode = O_RDONLY) {

    with


    void OpenFileByIndex(uint32_t i, oflag_t mode = O_RDONLY) {

    it works and Windows can see my files! Woooooo!

    Now all I've got to do is out the clever MTP stuff in my sketch without breaking it.....not going well so far

  6. #6
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    OK now I've got my sketch to compile but I seem to be stuck in USB: MTP mode which means I can't use the serial port for diagnostics or use Teensy loader to download code without pushing the button on the Teensy. My customers can't get at the button and I can't debug without serial. And customers can't do a firmware update without serial mode. Is there a way round this?

  7. #7
    Yes and no.
    As far as I am aware (I'm just a novice though) You cannot have MTP and Serial. Get MTP in your code and working, then comment out / compile with serial for your continued development with debugging.
    Your customers should not need serial? so obviously you ship with firmware configured for MTP.
    You do not need to press the button to upload firmware even if it is in MTP mode.
    This is how my product/project is set up. I had issues with my data-logging code while running MTP, but solved this by disabling MTP interupts when logging is started and re-eneabling them when logging ends. I do not need to give my customer USB access to the files on the SD card while logging.

  8. #8
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    Thanks Darcy, yes that's the conclusion I'm coming to as well.
    I don't know if something has screwed my Teensy but it won't load any sketches at all now without pressing its button. I've now tried the TyUpdater tool instead and this works fine without the button, and going back to Teensy Uploader works again so I guess it corrected something?

    Is there a way to have the extra code (which is spread between headers, setup and main) easily switchable by having it in a separate file for example, so that adding/removing it is easier?

    Thanks

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,755
    Quote Originally Posted by sw_hunt View Post
    Is there a way to have the extra code (which is spread between headers, setup and main) easily switchable by having it in a separate file for example, so that adding/removing it is easier?
    Yes, there are ways...

    Would they be easier? No, probably not.

  10. #10
    Quote Originally Posted by sw_hunt View Post
    Thanks Darcy, yes that's the conclusion I'm coming to as well.
    I don't know if something has screwed my Teensy but it won't load any sketches at all now without pressing its button. I've now tried the TyUpdater tool instead and this works fine without the button, and going back to Teensy Uploader works again so I guess it corrected something?

    Is there a way to have the extra code (which is spread between headers, setup and main) easily switchable by having it in a separate file for example, so that adding/removing it is easier?

    Thanks
    #define DEBUG


    #ifdef DEBUG
    . Some code here
    #endif

    Comment out the #define DEBUG when compiling for end users.

  11. #11
    Junior Member
    Join Date
    Nov 2018
    Posts
    18
    Maybe not best idea, but a another approach would be to write a PC program that can transfer files trough the usb serial interface to your teensy and vice versa.
    Then you can debug with serial.print, transfer files and upload without using button.

    Best regards
    King of bad solutions

  12. #12
    Junior Member
    Join Date
    Jul 2019
    Location
    United Kingdom
    Posts
    11
    Now I'm able to access filed on my Teensy's SD card from my PC, is there a way I can access them from a Mac? Thanks

  13. #13
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,397
    Quote Originally Posted by Darcy View Post
    Yes and no.
    As far as I am aware (I'm just a novice though) You cannot have MTP and Serial. Get MTP in your code and working, then comment out / compile with serial for your continued development with debugging.
    Only partially correct. when using MTP you get Seremu which simulates Serial over HID. Using Arduino, you have same functionality as with Serial. On Linux, you simply can cat end echo to the HID port. Not sure about HatingDevelopers MAC.

    When replacing the core usb-files with the one provided with MTP, you should even get real Serial (However, not tried myself)

Posting Permissions

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