MTP Responder Contribution

6 mins old when I downloaded. I did AWESOME editing the #defines!

Worked to get SDIO and 12MB RAM2 on first build for this T_4.1

Copied T_4.1 folder to RAM2 and it 'beeped' LONG names and continued!
Code:
DATA:100c(SEND_OBJECT_INFO)l: 224 T:4c : 0 3000 19 3000 0
SendObjectInfo: 3 4 20202040: 0 3000 0 19 3000 0 0 0 0 0 0 0 0 0 0 : esp-psram64_esp-psram64h_datasheet_e2.txt
MTPStorage_SD::Create esp-psram64_esp-psram64h_datasheet_e2.txt failed to create file
RESP:2020(RSP:SPECIFICATION_OF_DESTINATION_UNSUPPORTED)l: 24 T:4c : 3 4 ffffffff
CMD: 100c(SEND_OBJECT_INFO)l: 20 T:4d : 3 4
DATA:100c(SEND_OBJECT_INFO)l: 224 T:4d : 0 3000 1484bb 3000 0
SendObjectInfo: 3 4 20202040: 0 3000 0 1484bb 3000 0 0 0 0 0 0 0 0 0 0 : esp-psram64_esp-psram64h_datasheet_en.pdf
MTPStorage_SD::Create esp-psram64_esp-psram64h_datasheet_en.pdf failed to create file
RESP:2020(RSP:SPECIFICATION_OF_DESTINATION_UNSUPPORTED)l: 24 T:4d : 3 4 ffffffff
CMD: 100c(SEND_OBJECT_INFO)l: 20 T:4e : 3 4
DATA:100c(SEND_OBJECT_INFO)l: 224 T:4e : 0 3000 f000 3000 0
SendObjectInfo: 3 4 20202040: 0 3000 0 f000 3000 0 0 0 0 0 0 0 0 0 0 : esp-psram64_esp-psram64h_datasheet_en.txt
MTPStorage_SD::Create esp-psram64_esp-psram64h_datasheet_en.txt failed to create file
RESP:2020(RSP:SPECIFICATION_OF_DESTINATION_UNSUPPORTED)l: 24 T:4e : 3 4 ffffffff
CMD: 100c(SEND_OBJECT_INFO)l: 20 T:4f : 3 4
DATA:100c(SEND_OBJECT_INFO)l: 238 T:4f : 0 3000 19 3000 0
SendObjectInfo: 3 4 20202040: 0 3000 0 19 3000 0 0 0 0 0 0 0 0 0 0 : esp-psram64_esp-psram64h_datasheet_en_-_Copy.txt
MTPStorage_SD::Create esp-psram64_esp-psram64h_datasheet_en_-_Copy.txt failed to create file
RESP:2020(RSP:SPECIFICATION_OF_DESTINATION_UNSUPPORTED)l: 24 T:4f : 3 4 ffffffff
CMD: 100c(SEND_OBJECT_INFO)l: 20 T:50 : 3 4

Went to SDIO and copied the SAME T_4.1 ... already existed - it did copy and replace with OS dialog - and added the LONG NAME files previous edit prevented!

Renamed sdio\t_4.1 and made another copy and it worked with no issue and the LONG file .txt files open in notepad. As did the original long name : esp-psram64_esp-psram64h_datasheet_en.pdf
 
Just woke up from my nap :) You all been busy.

I downloaded the updated branch and copied @defragsters T4-1 directory to both the SDIO card and NAND 1G.

On the SDIO it copied the the long filename file .txt with no problem, no beeping :). On the NAND it beeped and skipped the long file name .txt file but kept copying the files in the directory without crashing the Teensy :)

Nice job Kurt - a lot more elegant than what I did.
 
Good Morning :)

Here is a supersimple test if the SD-Card is inserted (BUILTIN):
Code:
void setup() { pinMode(46, INPUT_PULLDOWN); }
void loop() { Serial.println(digitalRead(46)); delay(1000);  }

So, I think there is a way to use that..
I'll try this today.

@Kurt: Good Idea.
 
Good Morning :)

Here is a supersimple test if the SD-Card is inserted (BUILTIN):
Code:
void setup() { pinMode(46, INPUT_PULLDOWN); }
void loop() { Serial.println(digitalRead(46)); delay(1000);  }

So, I think there is a way to use that..
I'll try this today.

@Kurt: Good Idea.

I thought I could simply read the USDHC1_PRES_STATE register.
No... it depends on external pullup/down resistors which we don't have.
Turns out to be a bit more complicated.
 
Hi Frank,

I was playing with some of that a couple of days ago. And and tried looking for changes in the USDHC1_PRES_STATE which I did not see any. But if you first test of simply using digitalRead works, that might get us part way there. That is if we know we have a hardware SD and it fails at startup, we can switch that pin to INPUT_PULLUP and have the loop check for it... And then maybe try adding it to storage...

Again question may be: When should it be added to Storage list? At startup, with type of removable? (Have not looked where to set this or not set this)... Or when we detect it having a card... We can then send a notify of new storage... But not sure if the internals of MTP are setup to add in a new storage, except at startup...

Will look.

@all - I am again thinking of simplify the SendObject code to temporarily remove the more complicated version and see if I can get the simple fill up buffer, write, ... version to work better, at least to error out better.
Not sure if I should start off with removing it or to simply have it all #if out ... Most of it is under #if, but some variables and the like may not be proper... Will try that.

Things I want to check is not sure I put in any timeout stuff in the simple code or I left it calling the get me the next USB packet which may wait forever..
 
Well, this works if you can be sure that there is nothing active on the card:
Code:
static const int _SD_DAT3 = 46;

//Checks if a Card is present:
//- only when it is not in use! - 
bool isSDpresent() {
  
  pinMode(_SD_DAT3, INPUT_PULLDOWN);
  delayMicroseconds(1);
  bool r = digitalReadFast(_SD_DAT3);
  pinMode(_SD_DAT3, INPUT_DISABLE);
  return r;
}



void setup()
{
  while (!Serial) {;} 
  
  
  //Wait for SD Card insertion:  
  while (!isSDpresent()) {
    Serial.println("No SD Card inserted...");
    delay(1000);
  }


  
  Serial.print("Initializing SD card...");
  if (!SD.begin(BUILTIN_SDCARD)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");



....
However, if the card was (or is) in use, you cant just change the pinmode - at least it needs a check added wether there is datatransfer active (DMA? Buffer?)
This does not leave many options. There may be transfers running in an interrupt (Audio...)
The controllers Card detection can't be used, because of missing external connections (switch or resistors)
I think it would be possible to check the pinmode after an error - But I think this needs changes to SDFAT (?!?)
But what if, If there is _no_error - because there is no file access, currently? (it can come only a few clock cycles later, in the next audio interrupt or whatever..)
 
Card removed: Maybe this way ?
Code:
SD error -> try to re-init (call begin() again) 
 -> success: Ok, card is inserted and works again
 -> failure: Use pinMode method. 
   -> card inserted yes: Huston...problem here
   -> No. Reset SDHC controller, poll pin DAT3 somewhere until a card is present, call begin()
if a transfer is running in a interrupt, this works, too (if SDFAT stores the error somewhere..and we can ask it)
If no tranfer is running: We can't detect this and must wait ... there will be an error sooner or later - but is this a problem? Not sure? what do you think?

What happens with MTP if the audio-waveplayer (or similar) is running? Was this tested?
 
Hi Frank,

It will be interesting to try some of the stuff with MTP to know that a card is inserted and maybe add to MTP... Also I can imagine if I ever finish my Well monitor program,
maybe I might have it sending log files to onboard chips, and if I plug in SD, maybe it would want to know that and copy the log files to the SD card. ;)

As for MTP with Audio... Not sure I have not done much with Audio in awhile.
 
I just pushed up a change that disables the Send object with yield call back code and always uses the code that is close to the code in current release.

I did however add code into there which times out after half second of waiting for the next USB packet. I do get a my debug message output, but windows is still not recovering...

Looking for maybe a sledgehammer approach.
 
I just pushed up a change that disables the Send object with yield call back code and always uses the code that is close to the code in current release.

I did however add code into there which times out after half second of waiting for the next USB packet. I do get a my debug message output, but windows is still not recovering...

Looking for maybe a sledgehammer approach.

Afternoon all
Just gave the update a try.

Seems to working successfully on the NANDs chips and the 25Q128JV NOR Flash. Was able to transfer @defragsters T4-1 directory - it still successfully skips that long filename txt file and keeps going. Was able to open and read documents without a problem.

The strange issue with the 25Q512 NOR Flash still exists. And still can't seem to copy large files to the 8Mbyte FLASH chip.
 
Afternoon all
Just gave the update a try.
...

The strange issue with the 25Q512 NOR Flash still exists. And still can't seem to copy large files to the 8Mbyte FLASH chip.

Just back to see there is an update...

@mjs513- does the 8MB flash work if it is LLformatted "F" or fully formatUnused 'f' first in LFS? Is the little 8MB Flash on the PropShield as SPI?
 
Not sure why mtp-test is giving this?
Code:
T:\TEMP\arduino_build_mtp-test.ino\sketch\mtp-test.ino.cpp.o: In function `setup':
T:\tCode\libraries\MTP_t4-MEM_send_object_large\examples\mtp-test/mtp-test.ino:323: undefined reference to `MTPD::addSendObjectBuffer(char*, unsigned long)'
collect2.exe: error: ld returned 1 exit status

Did this:
Code:
#if 0
  if (!send_object_buffer) {
    send_object_buffer_size = SEND_BUFFER_SIZE_DMAMEM;
    send_object_buffer = (char*)malloc(send_object_buffer_size);
  }
  if (send_object_buffer) mtpd.addSendObjectBuffer(send_object_buffer, send_object_buffer_size);
#endif
 
Sorry I meant to mention, I put it under ifdef as well
Code:
#ifdef MTP_SEND_OBJECT_YIELD
#ifdef ARDUINO_TEENSY41
  if (external_psram_size) {
    send_object_buffer_size = SEND_BUFFER_SIZE_EXTMEM;
    send_object_buffer = (char*)extmem_malloc(send_object_buffer_size);
  }
#endif
  if (!send_object_buffer) {
    send_object_buffer_size = SEND_BUFFER_SIZE_DMAMEM;
    send_object_buffer = (char*)malloc(send_object_buffer_size);
  }
  if (send_object_buffer) mtpd.addSendObjectBuffer(send_object_buffer, send_object_buffer_size);
#endif
 
Back on T_4.1 with PJRC memory test board - asked this before...

Not understanding why : const char *lfs_spi_str[]={"nand1","nand2","nand3","nand4"}; // edit to reflect your configuration

Only showing : "nand3","nand4"

Where are "nand1","nand2"?

wht?
Code:
SPIFlash Storage 0 3 nand1 failed or missing
SPIFlash Storage 1 4 nand2 failed or missing
 
Last edited:
Ok you lost me. NANDs are only on 3 and 4 (2g 1G respectfully). 5 and 6 are the 25q512 NOR flash chips.

You can really name to your preference :)
 
So #3 and #4 are : NAND 1Gb on #3, 2GB on #4
> Do they not auto detect/select as NAND? But the FS name strings say "nand#" ??? LFSIntegrity has flags - but not showing in mtp-test?
> The working #5,6 are NOR's - but the 'disk name is NAND???

Okay - so they were not coded ... so here it is ... ugly?
Code:
MTP_test
sd_addFilesystem: 0 20003190 sdio 0
SDIO Storage 0 254 sdio 31963742208 196542464
SD Storage 1 10 sd1 failed or missing
sd_addFilesystem: 1 20003b08 RAM1 0
RAM Storage 0 RAM1 199936 512
sd_addFilesystem: 2 20003bd0 RAM2 0
RAM Storage 1 RAM2 3999744 4096
sd_addFilesystem: 3 20003c98 QSPI 1
QSPI Storage 0 QSPI 16777216 7585792
Flash ID: EF AA 21
Flash size is 125.50 Mbyte
Device ID: 0xEFAA21
[B]sd_addFilesystem: 4 20002dd0 nand1 1
SPIFlash NAND Storage 0 3 nand1 131596288 21233664
[/B]Flash ID: EF AA 22
Flash size is 253.00 Mbyte
Device ID: 0xEFAA22
[B]sd_addFilesystem: 5 20002ec0 nand2 1
SPIFlash NAND Storage 1 4 nand2 265289728 32112640
[/B]sd_addFilesystem: 6 200064b0 nand3 1
[B]SPIFlash Storage 2 5 nand3 67108864 3035136
sd_addFilesystem: 7 20006588 nand4 1
SPIFlash Storage 3 6 nand4 67108864 8192
[/B]

Then I try to copy T_4.1 onto All four SPI NAND/NOR (where NAND3/4 are 64MB SPI NOR's::
Except NAND3 is not presented in Explorer at some point?
mtp_test_most.png
Recompiled and they were all there until putting T_4.1 on the one missing before - then another goes away?
was it this?:
Code:
SendObjectInfo: 8 84 200040e0: 0 3000 0 e2e75 3000 0 0 0 0 0 0 0 0 0 0 : AN12253.pdf
RESP:2001(RSP:OK)l: 24 T:28a : 8 54 55
CMD: 100d(SEND_OBJECT)l: 12 T:28b
MTPD::SendObject: len:929397
MTPD::SendObject *** USB Read Timeout *** # USB Packets: 468 avg ms: 0 max: 1
>>>Total Time: 3603436
RESP:2007(RSP:INCOMPLETE_TRANSFER)l: 12 T:28b
It starts like this:
mtp_test_all.png
On restart only that one file 234KB of 907 KB is in the folder for nand4
Looking at nand3 that went away before it has 4 PDF's with the 4th being partial "NXP_i2c_UM10204.pdf" 1.23MB of 1.33MB.

Given - this hack to use same CS and Name arrays:
Code:
#if USE_LFS_SPI==1
LittleFS_SPIFlash [B]spifs[/B][nfs_spi];
LittleFS_SPINAND [B]nspifs[/B][nfs_spi];
#endif

This checks for NOR use and failing that asks if it is NAND:
Code:
    #if USE_LFS_SPI==1
    for(int ii=0; ii<nfs_spi;ii++)
    {
      if(![B]spifs[/B][ii].begin(lfs_cs[ii])) // FAILS NOR try NAND
      { 
        if(![B]nspifs[/B][ii].begin(lfs_cs[ii]))
        {
          Serial.printf("SPIFlash Storage %d %d %s failed or missing",ii,lfs_cs[ii],lfs_spi_str[ii]); Serial.println();
        }
        else
        {
          storage.addFilesystem(nspifs[ii], lfs_spi_str[ii], true);
          uint64_t totalSize = nspifs[ii].totalSize();
          uint64_t usedSize  = nspifs[ii].usedSize();
          Serial.printf("SPIFlash NAND Storage %d %d %s ",ii,lfs_cs[ii],lfs_spi_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
        }
      }
      else
      {
        storage.addFilesystem(spifs[ii], lfs_spi_str[ii], true);
        uint64_t totalSize = spifs[ii].totalSize();
        uint64_t usedSize  = spifs[ii].usedSize();
        Serial.printf("SPIFlash Storage %d %d %s ",ii,lfs_cs[ii],lfs_spi_str[ii]); Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);
      }
    }
    #endif
 
Ok you lost me. NANDs are only on 3 and 4 (2g 1G respectfully). 5 and 6 are the 25q512 NOR flash chips.

You can really name to your preference :)

I did not refresh to see this reply before making the post where NAND support was added. What was weird was calling them NAND and not mounting NAND but only NOR? Made it seem like NAND should automagically work - when it does not :(

If the strings weren't CONST I could EDIT NOR_/NAND when mounted - but I decided it was ugly enough already. But doing it right would duplicate all the NOR stuff for NAND and be more confusing to get the code compiled?
 
@defragster

Will take a look at your new sketch and see how it works.

Then I try to copy T_4.1 onto All four SPI NAND/NOR (where NAND3/4 are 64MB SPI NOR's::
Except NAND3 is not presented in Explorer at some point?
Click image for larger version.

Name: mtp_test_most.png
Views: 1
Size: 15.6 KB
ID: 23666
Recompiled and they were all there until putting T_4.1 on the one missing before - then another goes away?
was it this?:
Code:
SendObjectInfo: 8 84 200040e0: 0 3000 0 e2e75 3000 0 0 0 0 0 0 0 0 0 0 : AN12253.pdf
RESP:2001(RSP:OK)l: 24 T:28a : 8 54 55
CMD: 100d(SEND_OBJECT)l: 12 T:28b
MTPD::SendObject: len:929397
MTPD::SendObject *** USB Read Timeout *** # USB Packets: 468 avg ms: 0 max: 1
>>>Total Time: 3603436
RESP:2007(RSP:INCOMPLETE_TRANSFER)l: 12 T:28b
It starts like this:
Click image for larger version.

Name: mtp_test_all.png

On restart only that one file 234KB of 907 KB is in the folder for nand4
That is pretty much what I saw when I did the same test in copying over your T4.1 directory to the 64MB Flash.
 
Morning all,

@defragster will take a look.

Note: my version which I did not push up yet has:
Code:
#if USE_LFS_SPI==1
                            const char *lfs_spi_str[]={"sflash5","sflash6","prop"}; // edit to reflect your configuration
                            const int lfs_cs[] = {5,6, 7}; // edit to reflect your configuration
                            const int nfs_spi = sizeof(lfs_spi_str)/sizeof(const char *);

                            LittleFS_SPIFlash spifs[nfs_spi];
#endif
#if USE_LFS_NAND == 1
                            const char *nspi_str[]={"WINBOND1G", "WINBOND2G"};     // edit to reflect your configuration
                            const int nspi_cs[] = {3,4}; // edit to reflect your configuration
                            const int nspi_nsd = sizeof(nspi_cs)/sizeof(int);
                            LittleFS_SPINAND nspifs[nspi_nsd]; // needs to be declared if LittleFS is used in storage.h
#endif

So mine comes up like:
screenshot.jpg

The other changes I have in it is to also check for the LFS_NAND and of course add them, plus I have the hacked code that again checks this list if the user chooses the format command on windows, to route it through to call the quick format of LittleFS. Again I still don't have any support in to format SD cards... Nor anyway yet to choose the slower full format. Trying to see if there is way to specify that on Windows side.

Will push up my changes, once I check that I don't have some other screwy things still in here, like my earlier looking at if the SDIO was not present, could I detect when it was...
 
@all - On trying to recover from a send object timeout... So far I have tried a couple of things including:

a) return a couple of different response codes, before windows has given me the chime that says we are toast.... Does not appear to help.
b) Try to send a couple of different Events back to the host. like: if you type in r<cr> into terminal window it tries to do a reset (@WMXZ added this earlier). Did not help, may it again sooner.
c) Event CancelTransaction - Tried sending this when detected a timeout, did not help. But may verify I am sending back the transaction ID...

Now looking to see if we available a USB Sledgehammer? That is, is there a simple way to force the host to do a reset of their connection. Would not be ideal, but better than having to reset the whole teensy...
 
Back
Top