Hi everyone,
I'm using the following code to view files from a Teensy 4's SD card into my computer, via USB and MTP. It works great, but for some reason it doesn't show the files' creation or modification date on the file browser. I'm using linux and 'simple-mtfs' or other tools to mount the disk. The code is based on the @WMXZ MTP_t4 library. I suppose there is a problem in the code, because trying with another MTP library available (Kurt) I can see the files' dates. That other library is simpler to implement in code, but unfortunately it doesn't perform as well as the WMXZ for me in other aspects.
Any advice please, if anyone feels like taking a look at the code. It is based (simplified for SDIO only) on an example published with the library, which exhibits the same problem when used as published.
Kind regards,
Domingo
I'm using the following code to view files from a Teensy 4's SD card into my computer, via USB and MTP. It works great, but for some reason it doesn't show the files' creation or modification date on the file browser. I'm using linux and 'simple-mtfs' or other tools to mount the disk. The code is based on the @WMXZ MTP_t4 library. I suppose there is a problem in the code, because trying with another MTP library available (Kurt) I can see the files' dates. That other library is simpler to implement in code, but unfortunately it doesn't perform as well as the WMXZ for me in other aspects.
Any advice please, if anyone feels like taking a look at the code. It is based (simplified for SDIO only) on an example published with the library, which exhibits the same problem when used as published.
Kind regards,
Domingo
Code:
//Uses https://github.com/WMXZ-EU/MTP_t4
#include "SPI.h"
#include "SD.h"
#include "MTP.h"
#define USE_SD 1 // SDFAT based SDIO and SPI
#if USE_EVENTS==1
extern "C" int usb_init_events(void);
#else
int usb_init_events(void) {}
#endif
#if defined(__IMXRT1062__)
// following only as long usb_mtp is not included in cores
#if !__has_include("usb_mtp.h")
#include "usb1_mtp.h"
#endif
#else
#ifndef BUILTIN_SDCARD
#define BUILTIN_SDCARD 254
#endif
void usb_mtp_configure(void) {}
#endif
/**** Start device specific change area ****/
// SDClasses
#if USE_SD==1
// edit SPI to reflect your configuration (following is for T4.1)
#define SD_MOSI 11
#define SD_MISO 12
#define SD_SCK 13
#if defined (BUILTIN_SDCARD)
const char *sd_str[]={"sdio"}; // edit to reflect your configuration
const int cs[] = {BUILTIN_SDCARD,10}; // edit to reflect your configuration
#else
const char *sd_str[]={"sd1"}; // edit to reflect your configuration
const int cs[] = {10}; // edit to reflect your configuration
#endif
const int nsd = sizeof(sd_str)/sizeof(const char *);
SDClass sdx[nsd];
#endif
MTPStorage_SD storage;
MTPD mtpd(&storage);
void storage_configure()
{
// Using SD card for storage
#if USE_SD==1
/* #if defined SD_SCK
SPI.setMOSI(SD_MOSI);
SPI.setMISO(SD_MISO);
SPI.setSCK(SD_SCK);
#endif
*/
for(int ii=0; ii<nsd; ii++)
{
if(cs[ii]<BUILTIN_SDCARD)
{
pinMode(cs[ii],OUTPUT); digitalWriteFast(cs[ii],HIGH);
}
if(!sdx[ii].begin(cs[ii]))
{ Serial.printf("SD/SDIO Storage %d %d %s failed or missing",ii,cs[ii],sd_str[ii]); Serial.println();
}
else
{
storage.addFilesystem(sdx[ii], sd_str[ii]);
uint64_t totalSize = sdx[ii].totalSize();
uint64_t usedSize = sdx[ii].usedSize();
Serial.printf("SDIO Storage %d %d %s ",ii,cs[ii],sd_str[ii]);
Serial.print("; total "); Serial.print(totalSize); Serial.print(" used: "); Serial.println(usedSize);
}
}
#endif
}
void setup()
{
/* while(!Serial);
Serial.println("MTP_test");
*/
#if USE_EVENTS==1
usb_init_events();
#endif
#if !__has_include("usb_mtp.h")
usb_mtp_configure();
#endif
storage_configure();
}
void loop()
{
mtpd.loop();
#if USE_EVENTS==1
if(Serial.available())
{
char ch=Serial.read();
Serial.println(ch);
if(ch=='r')
{
Serial.println("Reset");
mtpd.send_DeviceResetEvent();
}
}
#endif
}