Teensyduino File System Integration, including MTP and MSC

Got to the bottom of my MicroMod problem. Turns out the M.2 socket is defecting, pin 13 isn't connected! Just running the LED blink, the blue LED on MicroMod blinks, but no connection to pin 13 on the carrier board. Swapping to another carrier works fine.

Missed that :( ... so close ...

I continuity checked the board SPI pins to themselves (side to the socket rows) - and ran blink after I put DVM away and said I should check that ... but another set of chores were at hand ...

Got new iron with 6 tips - will go put a green wire from the DISPLAY SCK to 13 and confirm.

@Mike - as noted MTP_test was not the only test done. The integrity was the LittleFS - not mtp ...
 
Got to the bottom of my MicroMod problem. Turns out the M.2 socket is defecting, pin 13 isn't connected! Just running the LED blink, the blue LED on MicroMod blinks, but no connection to pin 13 on the carrier board. Swapping to another carrier works fine.

That's strange. I am using the PJRC carrier without a problem - I did remove the display though just didn't like the backlit on :)
 
Missed that :( ... so close ...

I continuity checked the board SPI pins to themselves (side to the socket rows) - and ran blink after I put DVM away and said I should check that ... but another set of chores were at hand ...

Got new iron with 6 tips - will go put a green wire from the DISPLAY SCK to 13 and confirm.

@Mike - as noted MTP_test was not the only test done. The integrity was the LittleFS - not mtp ...

This is what I am seeing with LittleFS_MRAMSPI integrity sketch on startup
Code:
C:\Users\Merli\AppData\Local\Temp\arduino_modified_sketch_77878\MRAMSPI.ino Dec 13 2021 18:18:00
LittleFS Test : File Integrity
attempting to mount existing media
printDirectory FRAM_DISK
--------------

 0 dirs with 0 files of Size 0 Bytes
 Total 0 files of Size 0 Bytes
Bytes Used: 256, Bytes Total:131072
Did change pin numbers of course. Think the problem with yours maybe the pin 13 issue but mine seems to be working.
 
I think (hope) the pin 13 problem was isolated to just 1 bad M.2 socket. At first had a hard time believing this was the issue, but easy to confirm with tests. Hopefully none of the other M.2 sockets I used have any issues on a pin.

mm.jpg
 
Pin 13 wired SCK from display header to side rail SCK and MRAM works:
Code:
 0 dirs with 17 files of Size 55728 Bytes
 Total 17 files of Size 55728 Bytes
Bytes Used: 64896, Bytes Total:131072

And over to mtp-test.ino - still fails - need second wire to the shield headers it seems.
 
I think (hope) the pin 13 problem was isolated to just 1 bad M.2 socket. At first had a hard time believing this was the issue, but easy to confirm with tests. Hopefully none of the other M.2 sockets I used have any issues on a pin.

Paul - the SPI display worked ... it uses same SCK/pin13 signal?

I wired one over and SPI MRAM LittleFS integrity works.
 
Saw some oddity with other SFUN made carriers as posted weeks back. Seemed reseating the MCU Module made a diff here?
 
Paul - I assume you are not talking about your breakout board that I believe uses SDIO.. Or was this specific to one board?

Running into issue with SD.mediaPresent() on T3.6 (and think 3.5...)

Thought it was with my code, so I switch branch back to the master (Juse_...)
Code:
#include <SD.h>
#if defined(ARDUINO_TEENSY41)
static const uint8_t _SD_DAT3 = 46;
#elif defined(ARDUINO_TEENSY40) || defined(ARDUINO_TEENSY_MICROMOD)
static const uint8_t _SD_DAT3 = 38;
#elif defined(ARDUINO_TEENSY35) || defined(ARDUINO_TEENSY36)
static const uint8_t _SD_DAT3 = 62;
#endif

bool media_present = false;

void setup() {
  while (!Serial) ;
  Serial.println("Test Media Present");
  media_present = SD.begin(BUILTIN_SDCARD);
  Serial.printf("\n$$$Media Present: %u\n", media_present);
  print_sd_regs();

#if 0
  if (!sd_inserted) {
    SDHC_PROCTL |= SDHC_PROCTL_D3CD | SDHC_PROCTL_CDSS | SDHC_PROCTL_CDTL;
    SDHC_IRQSTATEN |= SDHC_IRQSTATEN_CINTSEN;
    //PORTE_PCR4
  }
#endif
}

void print_sd_regs() {
  Serial.printf("\tDSADDR:%x", SDHC_DSADDR);
  Serial.printf("\tBLKATTR:%x", SDHC_BLKATTR);
  Serial.printf("\tCMDARG:%x", SDHC_CMDARG);
  Serial.printf("\tXFERTYP:%x\n", SDHC_XFERTYP);
  Serial.printf("\tCMDRSP0:%x", SDHC_CMDRSP0);
  Serial.printf("\tCMDRSP1:%x", SDHC_CMDRSP1);
  Serial.printf("\tCMDRSP2:%x", SDHC_CMDRSP2);
  Serial.printf("\tCMDRSP3:%x\n", SDHC_CMDRSP3);
  Serial.printf("\tDATPORT:%x", SDHC_DATPORT);
  Serial.printf("\tPRSSTAT:%x", SDHC_PRSSTAT);
  Serial.printf("\tPROCTL:%x", SDHC_PROCTL);
  Serial.printf("\tSYSCTL:%x\n", SDHC_SYSCTL);
  Serial.printf("\tIRQSTAT:%x", SDHC_IRQSTAT);
  Serial.printf("\tIRQSTATEN:%x", SDHC_IRQSTATEN);
  Serial.printf("\tIRQSIGEN:%x", SDHC_IRQSIGEN);
  Serial.printf("\tAC12ERR:%x\n", SDHC_AC12ERR);
  Serial.printf("\tHTCAPBLT:%x\n", SDHC_HTCAPBLT);
  Serial.printf("\tFEVT:%x", SDHC_FEVT);
  Serial.printf("\tADMAES:%x", SDHC_ADMAES);
  Serial.printf("\tADSADDR:%x", SDHC_ADSADDR);
  Serial.printf("\tVENDOR:%x\n", SDHC_VENDOR);
  Serial.printf("\tMMCBOOT:%x", SDHC_MMCBOOT);
  Serial.printf("\tHOSTVER:%x\n", SDHC_HOSTVER);

  Serial.printf("PORTE_PCR0-5: %x", PORTE_PCR0); // SDHC_D1
  Serial.printf(" %x", PORTE_PCR1); // SDHC_D0
  Serial.printf(" %x", PORTE_PCR2); // SDHC_CLK
  Serial.printf(" %x", PORTE_PCR3); // SDHC_CMD
  Serial.printf(" %x", PORTE_PCR4); // SDHC_D3
  Serial.printf(" %x\n", PORTE_PCR5); // SDHC_D2

}

void loop() {
  if (Serial.available()) {
    while (Serial.read() != -1) ;
    Serial.println("Paused");
    while (Serial.read() == -1) ;
    while (Serial.read() != -1) ;
  }
  //Serial.println(digitalReadFast(_SD_DAT3), DEC);
  elapsedMicros em;
  bool cur_media_present = SD.mediaPresent();
  Serial.printf("New: %u Prev: %u em:%u\n", cur_media_present, media_present, (uint32_t)em);
  if (cur_media_present != media_present) {
    media_present = cur_media_present;
    print_sd_regs();
  }
  delay(1000);
}
Sorry some of this could be removed... been through a few iterations...

When I started off with SD plugged in, the mediaPresent code will alternate saying yes no yes no yes no...
Code:
Test Media Present

$$$Media Present: 1
	DSADDR:200307b8	BLKATTR:fffe0200	CMDARG:2000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:30101225	CMDRSP2:55534430	CMDRSP3:ad4c53
	DATPORT:209076eb	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
New: 0 Prev: 1 em:1000004
	DSADDR:200307bc	BLKATTR:fffe0200	CMDARG:b3680000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:30101225	CMDRSP2:55534430	CMDRSP3:ad4c53
	DATPORT:209076eb	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
New: 1 Prev: 0 em:8625
	DSADDR:20030768	BLKATTR:fffe0200	CMDARG:2000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:30101225	CMDRSP2:55534430	CMDRSP3:ad4c53
	DATPORT:209076eb	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
New: 0 Prev: 1 em:1000004
	DSADDR:2003076c	BLKATTR:fffe0200	CMDARG:b3680000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:30101225	CMDRSP2:55534430	CMDRSP3:ad4c53
	DATPORT:209076eb	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443

I was seeing this in the MTP code I am experimenting with as well.

But in the MTP code if the code then does something with the SD like listing files or something than I think settled to say it was there...

Investigating stilll..
 
Last edited:
Or was this specific to one board?

Yup, just 1 specific carrier board.

Normally I would never suspect the M.2 socket which visually looks normal. But ultimately that's what it turned out to be. The defective pin contacts the top side of the MicroMod board, and that carrier has nearby 14 pin sockets that obstruct the view into the M.2 socket opening, so hard to know what really happened. Maybe I damaged it somehow.

Swapping for another carrier board fixed everything. In the end, it was just a "simple" problem of a defective M.2 socket.
 
Paul, Glad that was all it was...

Now for SD stuff...

I extended the sketch slightly to when I can pause the output by entering something in the serial terminal... If it is an l or L it will do a structured list of files on the SD.

When this happens, then after the list, the status stuff works...

Code:
Test Media Present

$$$Media Present: 1
	DSADDR:200305b8	BLKATTR:fffe0200	CMDARG:10000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Card->status: 0
New: 0 Prev: 1 em:1000013
	DSADDR:200305bc	BLKATTR:fffe0200	CMDARG:aaaa0000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
New: 1 Prev: 0 em:21929
	DSADDR:20030568	BLKATTR:fffe0200	CMDARG:10000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Card->status: 0
New: 0 Prev: 1 em:1000011
	DSADDR:2003056c	BLKATTR:fffe0200	CMDARG:aaaa0000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
New: 1 Prev: 0 em:21432
	DSADDR:20030568	BLKATTR:fffe0200	CMDARG:10000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Card->status: 0
New: 0 Prev: 1 em:1000013
	DSADDR:2003056c	BLKATTR:fffe0200	CMDARG:aaaa0000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Paused
New: 1 Prev: 0 em:22056
	DSADDR:20030568	BLKATTR:fffe0200	CMDARG:10000	XFERTYP:123a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008a	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Directory
---------
System Volume Information/
  WPSettings.dat                      12
  IndexerVolumeGuid                   76
Logic+Setup+2.3.39-master.xxx         162667688
sixaxispairtoolsetup-0.3.1.xxx        26917168
SDTEST4.mp3                           3135327
256K.OPU                              7670125
SDTEST1.mp3                           2791046
SDTEST2.mp3                           2962926
SDTEST3.mp3                           2079162
T1_1024.FLA                           9802802
T1_128.FLA                            11126659
T1_2048.FLA                           9725417
T1_256.FLA                            10415954
T1_512.FLA                            10007370
mtpindex.dat                          0
2001/
  calculations.wav                    426300
  completed.wav                       276460
  dangerous_to_remain.wav             372892
  enough_info.wav                     513388
  functional.wav                      237356
  one_moment.wav                      202236
  operational.wav                     772140
  stop.wav                            200844
sorry_dave.wav                        791164
Candyman.aac                          3177823
Audacity/
  Away_in_a_Manger.mp3                2014737
  Dont_Rain_on_My_Parade.mp3          3943937
  Take_My_Breathe_Away.mp3            5740819
  Welcome_Christmas.mp3               2985790
zarathustra.mp3                       489461
top_gun.flac                          30401785

	DSADDR:2003216c	BLKATTR:ffff0200	CMDARG:0	XFERTYP:cdb0032
	CMDRSP0:b00	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:650041	PRSSTAT:ff8800f8	PROCTL:22	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
PORTE_PCR0-5: 443 443 440 443 443 443
Card->status: 900
New: 1 Prev: 1 em:15
Card->status: 900
New: 1 Prev: 1 em:15
Card->status: 900
New: 1 Prev: 1 em:14
Paused
Before this happened card->status() was returning 0 after this 900...

Now to see what status does. Note I printed all of the registers before and after...
 

Attachments

  • zzz-211213a.zip
    1.5 KB · Views: 38
Yup, just 1 specific carrier board.

Normally I would never suspect the M.2 socket which visually looks normal. But ultimately that's what it turned out to be. The defective pin contacts the top side of the MicroMod board, and that carrier has nearby 14 pin sockets that obstruct the view into the M.2 socket opening, so hard to know what really happened. Maybe I damaged it somehow.

Swapping for another carrier board fixed everything. In the end, it was just a "simple" problem of a defective M.2 socket.

I can't confirm now that I soldered a wire on under side from TFT SCK to side rail SCK - but FRAM now works on SPI - and it did not work before.

Did just confirm that that edge SCK is common to the 'shield' header SCK. Had to edit the mtp-test.ino to allow for SPI inclusion and now can see 3 of the 4 FLASH on the 4x Flash board.

With other edits on the PJRC MMod breakout I see:
Code:
Dump Storage list(5)
store:0 storage:10001 name:sdio fs:2000c938
store:1 storage:20001 name:PROGM fs:2000c810
store:2 storage:30001 name:sflash5 fs:2000d490
store:3 storage:40001 name:sflash6 fs:2000d56c
STORE:4 storage:50001 name:WINBOND1G fs:2000c3c4

Not sure where the 2G SPI NAND is?

And the 1G showing 106MB free of 125MB - but giving up showing the files through Windows even though it has tons of 'integrity' files.
 
KurtE said:
Now for SD stuff...

I extended the sketch slightly to when I can pause the output by entering something in the serial terminal... If it is an l or L it will do a structured list of files on the SD.

When this happens, then after the list, the status stuff works...
Maybe there is an extra SD Card CMDXX that needs to be issued to say ok I am here. But this works too
Code:
  bool cur_media_present = SD.mediaPresent();
  if(!cur_media_present) {
    Serial.printf("New: %u Prev: %u em:%u\n", cur_media_present, media_present, (uint32_t)em);
    if (cur_media_present != media_present) {
      media_present = cur_media_present;
      print_sd_regs();
    }
  } else {
    printDirectory(&SD);
    list_files = false;    
    print_sd_regs();
  }
 
Tim - might be something with your configuration - not sure your copy of mtp_test or mtp_test_integrity has Fram configured

Here is my latest incarnation of mtp_test_integrity - note I haven't updated to your latest changes to bigfileverify yet

I had not been trying to get Fram on MTP - but back to this mtp-test-integrity I did get it working:
Code:
Dump Storage list(6)
store:0 storage:10001 name:sdio fs:2000ca14
store:1 storage:20001 name:PROGM fs:2000c810
store:2 storage:30001 name:sflash5 fs:2000d3b4
store:3 storage:40001 name:sflash6 fs:2000d490
[U]store:4 storage:50001 name:WINBOND1G fs:2000c3c4[/U]
[B]store:5 storage:60001 name:Fram8 fs:2000c8dc[/B]

And again 1G NAND fails to get DIR data to Windows and 2G NAND : SPIFlash NAND Storage 1 4 WINBOND2G failed or missing.

<edit>: had some good Hard Fails - with restarts before setup or loop() could print - turned on FRAM without noting the CS section - duplicated the 3,4,5 with overlap and mine is handwired to 8.
> of course I may be missing other WIP/github edits ...
 
I committed a similar speedup for program memory.

https://github.com/PaulStoffregen/LittleFS/commit/2a5ca2e89f95fd0a0da3c7925008f038758301e1

It requires this update in the core library

https://github.com/PaulStoffregen/cores/commit/3c442f9c67ee785ddad921ff5d0a3ebe5a9682ca

Here is a benchmark program

Code:
#include <LittleFS.h>
#include <Entropy.h>
#include <FastCRC.h>

LittleFS_Program myfs;
FastCRC32 CRC32;

void setup() {
  Entropy.Initialize();
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("LittleFS Sustained Write Speed Test");
  if (!myfs.begin(1200000)) {
    Serial.printf("Error starting %s\n", "SPI FLASH");
    while (1) ; // stop here
  }
  Serial.printf("Volume size %d MByte\n", myfs.totalSize() / 1048576);
}

uint64_t total_bytes_written = 0;

void loop() {
  const uint8_t c = 0x5A;
  unsigned long buf[1024];
  File myfile = myfs.open("WriteSpeedTest.bin", FILE_WRITE_BEGIN);
  if (myfile) {
    const int num_write = 64;
    Serial.printf("Writing %d byte file... ", num_write * 4096);
    randomSeed(Entropy.random());
    uint32_t crc_wr = CRC32.crc32(&c, 1);
    uint32_t cycles = ARM_DWT_CYCCNT; // don't use elapsedMillis
    for (int n=0; n < num_write; n++) {
      for (int i=0; i<1024; i++) buf[i] = random();
      myfile.write(buf, 4096);
      crc_wr = CRC32.crc32_upd((uint8_t *)buf, 4096);
    }
    myfile.close();
    cycles = ARM_DWT_CYCCNT - cycles;
    unsigned int ms = cycles / (F_CPU / 1000);
    total_bytes_written = total_bytes_written + num_write * 4096;
    Serial.printf(" %d ms, bandwidth = %d bytes/sec", ms, num_write * 4096 * 1000 / ms);
    //Serial.printf(" CRC = %08X\n", crc_wr);

    myfile = myfs.open("WriteSpeedTest.bin");
    if (myfile) {
      const int num_read = 64;
      uint32_t crc_rd = CRC32.crc32(&c, 1);
      for (int n=0; n < num_read; n++) {
        myfile.read(buf, 4096);
        crc_rd = CRC32.crc32_upd((uint8_t *)buf, 4096);
      }
      myfile.close();
      //Serial.printf(" CRC = %08X\n", crc_rd);
      if (crc_rd != crc_wr) Serial.print("\nCRC ERROR\n");
    }
    myfs.remove("WriteSpeedTest.bin");
  }
  Serial.println();
  delay(2000);
  /* Do not write forever, possibly reducing the chip's lifespan */
  if (total_bytes_written >= myfs.totalSize() * 100) {
    Serial.println("End test, entire flash has been written 100 times");
    while (1) ; // stop here
  }
}
 
I committed a similar speedup for program memory.

https://github.com/PaulStoffregen/LittleFS/commit/2a5ca2e89f95fd0a0da3c7925008f038758301e1

It requires this update in the core library

https://github.com/PaulStoffregen/cores/commit/3c442f9c67ee785ddad921ff5d0a3ebe5a9682ca

Here is a benchmark program

...

Updated and Integrity on LFS_PROG at MMod 14MB - did this with some loops that worked in between - and a formatUnused:
Code:
Start Big write of 6795264 Bytes..................................................................................
Big write /0_bigfile.txt took 11.44 Sec for 6793216 Bytes : file3.size()=6793216
	Big write KBytes per second 593.75 

	Verify /0_bigfile.txt bytes 6793216 : ..................................................	GOOD! >>  bytes 6793216
	Big read&compare KBytes per second 3023.96

Trying the benchmark next ...

Code:
LittleFS Sustained Write Speed Test
Volume size 1 MByte
Writing 262144 byte file...  1233 ms, bandwidth = 212606 bytes/sec
Writing 262144 byte file...  1268 ms, bandwidth = 206738 bytes/sec
Writing 262144 byte file...  1229 ms, bandwidth = 213298 bytes/sec
Writing 262144 byte file...  1210 ms, bandwidth = 216647 bytes/sec
Writing 262144 byte file...  1264 ms, bandwidth = 207392 bytes/sec
 
Oppps - returned to Littlefs/integrity/prog.ino:
Code:
 2 dirs with 5 files of Size 6718320 Bytes
 Total 14 files of Size 6771720 Bytes
Bytes Used: 14680064, Bytes Total:14680064


	WARNING: DISK FULL >>>>>  Bytes Used: 14680064, Bytes Total:14680064

[  1.98 M](0.00268 M elap) Awaiting input 0123456789RdDwcghkFqvplmusSBbyYxfan+-? loops left 0 >
Walk all Files verify Read Size:	
0
 File Size Error:: 0_bigfile.txt found 6694913 Bytes for Size 6694912 
	D1 ABCDE
	D2 ABCE
ABCD	1 Errors found

Bytes Used: 14680064, Bytes Total:14680064

Paul seems there is a detection problem on image change ...

Benchmark code ran and 1.2MB image overlayed the 14MB - then the 14MB image came back???

'q'uick format didn't fix it
'F'ull low level format did though

<edit> smaller image overwrites the end of the prior image - going back to larger image is unaware of the overwritten blocks - but the last 1200000 bytes of the 14 MB image were trashed.
> not much to do about it - unless it were to be detected and the mount forced a full format - or refuse to mount ?
 
Last edited:
I had not been trying to get Fram on MTP - but back to this mtp-test-integrity I did get it working:
Code:
Dump Storage list(6)
store:0 storage:10001 name:sdio fs:2000ca14
store:1 storage:20001 name:PROGM fs:2000c810
store:2 storage:30001 name:sflash5 fs:2000d3b4
store:3 storage:40001 name:sflash6 fs:2000d490
[U]store:4 storage:50001 name:WINBOND1G fs:2000c3c4[/U]
[B]store:5 storage:60001 name:Fram8 fs:2000c8dc[/B]

And again 1G NAND fails to get DIR data to Windows and 2G NAND : SPIFlash NAND Storage 1 4 WINBOND2G failed or missing.

<edit>: had some good Hard Fails - with restarts before setup or loop() could print - turned on FRAM without noting the CS section - duplicated the 3,4,5 with overlap and mine is handwired to 8.
> of course I may be missing other WIP/github edits ...

Not sure maybe try to give a quick format since we went to 64k block erases may help. Here is mine on a micromod:
Capture.PNG
1G Dir
Code:
 Space Used = 93061120
Filesystem Size = 131596288
Directory
---------
DS4.pcapng                            182852
LargeIndexedTestfileOrig1.txt         22015988
Picture1.png                          1037815
SDTEST1.wav                           16788062
SDTEST2.wav                           16426210
SDTEST3.wav                           13617870
SDTEST4.wav                           17173664
calculations.wav                      426812
completed.wav                         276972
dangerous_to_remain.wav               373404
datalog.txt                           1187
enough_info.wav                       513900
functional.wav                        237868
odd1.wav                              553516
one_moment.wav                        202748
operational.wav                       772652
sorry_dave.wav                        791676
stop.wav                              201356
and on the 2G
Code:
 Space Used = 70516736
Filesystem Size = 265289728
Directory
---------
2001/
  calculations.wav                    426300
  completed.wav                       276460
  dangerous_to_remain.wav             372892
  enough_info.wav                     513388
  functional.wav                      237356
  one_moment.wav                      202236
  operational.wav                     772140
  sorry_dave.wav                      791164
  stop.wav                            200844
Audacity/
  Away_in_a_Manger.mp3                2014737
  Dont_Rain_on_My_Parade.mp3          3944449
  Take_My_Breathe_Away.mp3            5740819
  Welcome_Christmas.mp3               2985790
Candyman.aac                          3177823
Dont Rain on My Parade.mp3            3944449
FLAC/
  T1_1024.FLA                         9802802
  T1_128.FLA                          11126659
  T1_256.FLA                          10415954
  T1_512.FLA                          10007370
mtpindex.dat                          500
odd1.mp3                              46888
odd1.wav                              553004
zarathustra.mp3                       489461
 

Just tried the benchmark on the Micromod:
Code:
LittleFS Sustained Write Speed Test
Volume size 1 MByte
Writing 262144 byte file...  1701 ms, bandwidth = 154111 bytes/sec
Writing 262144 byte file...  1737 ms, bandwidth = 150917 bytes/sec
Writing 262144 byte file...  1724 ms, bandwidth = 152055 bytes/sec
Writing 262144 byte file...  1712 ms, bandwidth = 153121 bytes/sec
Writing 262144 byte file...  1729 ms, bandwidth = 151615 bytes/sec
Writing 262144 byte file...  1734 ms, bandwidth = 151178 bytes/sec
Writing 262144 byte file...  1741 ms, bandwidth = 150570 bytes/sec
Writing 262144 byte file...  1705 ms, bandwidth = 153750 bytes/sec
Writing 262144 byte file...  1736 ms, bandwidth = 151004 bytes/sec
Writing 262144 byte file...  1718 ms, bandwidth = 152586 bytes/sec
Writing 262144 byte file...  1722 ms, bandwidth = 152232 bytes/sec
Writing 262144 byte file...  1744 ms, bandwidth = 150311 bytes/sec
Writing 262144 byte file...  1770 ms, bandwidth = 148103 bytes/sec
Writing 262144 byte file...  1734 ms, bandwidth = 151178 bytes/sec
Writing 262144 byte file...  1750 ms, bandwidth = 149796 bytes/sec
Writing 262144 byte file...  1750 ms, bandwidth = 149796 bytes/sec
Writing 262144 byte file...  1747 ms, bandwidth = 150053 bytes/sec
Writing 262144 byte file...  1755 ms, bandwidth = 149369 bytes/sec
Writing 262144 byte file...  1796 ms, bandwidth = 145959 bytes/sec
Writing 262144 byte file...  1743 ms, bandwidth = 150398 bytes/sec
Writing 262144 byte file...  1784 ms, bandwidth = 146941 bytes/sec
Writing 262144 byte file...  1745 ms, bandwidth = 150225 bytes/sec
 
Not sure maybe try to give a quick format since we went to 64k block erases may help. Here is mine on a micromod:
...

Worked w 2Gb NAND CS==4 on LFS_integrity - came up with expected data. Did a FULL FORMAT and ran it there okay.
Doing the same while in that sketch to 1Gb CS==3, the one that failed to get dir data to Windows

And back to mtp-test - all seems well - drive list and windows drive read:
Code:
Dump Storage list(8)
STORE:0 storage:10001 name:sdio fs:2000cbac
store:1 storage:20001 name:RAM1 fs:2000c9b8
store:2 storage:30001 name:RAM2 fs:2000ca84
store:3 storage:40001 name:PROGM fs:2000c814
store:4 storage:50001 name:sflash5 fs:2000d704
store:5 storage:60001 name:sflash6 fs:2000d7e0
store:6 storage:70001 name:WINBOND1G fs:2000c3c8
store:7 storage:80001 name:WINBOND2G fs:2000c4bc
 
Looks like things are going well!

With T3.x SD Insertion issue, wondering if I should simply find work around or try to resolve. Work around is probably once I detect a disk is in there, do something with it before we call it again to say are you still there...

Right now just trying to understand, Added more debug output to CardCommand in SdioTeensy.cpp
Code:
...
  SDHC_XFERTYP = xfertyp;
  if (waitTimeout(isBusyCommandComplete)) {
    Serial.printf("  >>>> Failed isBusyCommandComplete(%x) <<<<\n", SDHC_IRQSTAT);

    return false;  // Caller will set errorCode.
  }

Code:
$$$SdioCard::status()
CardCommand(d1a0000 aaaa0000)
  >> after 1
  >>>> Failed isBusyCommandComplete(0) <<<<
Card->status: 0
New: 0 Prev: 1 em:1000039
	DSADDR:200305bc	BLKATTR:fffe0200	CMDARG:aaaa0000	XFERTYP:d3a0032
	CMDRSP0:900	CMDRSP1:388071a4	CMDRSP2:53483132	CMDRSP3:35344
	DATPORT:ffffffff	PRSSTAT:ff88008b	PROCTL:10022	SYSCTL:e0038
	IRQSTAT:0	IRQSTATEN:117f000b	IRQSIGEN:0	AC12ERR:0
	HTCAPBLT:7f30000
	FEVT:0	ADMAES:0	ADSADDR:0	VENDOR:1
	MMCBOOT:0	HOSTVER:1201
So failing with irq status = 0...
 
Morning all

Was doing a bit more testing this morning with the teensy micromod board with the following configuration:
Code:
Dump Storage list(7)
store:0 storage:10001 name:sdio fs:2000d138
store:1 storage:20001 name:PROGM fs:2000d010
store:2 storage:30001 name:sflash5 fs:2000dad8
store:3 storage:40001 name:sflash6 fs:2000dbb8
store:4 storage:50001 name:WINBOND1G fs:2000cbc4
store:5 storage:60001 name:WINBOND2G fs:2000ccb8
store:6 storage:70001 name:MSC0-exFAT-SSD fs:2000ab70
Tested the SDIO again and behaves the same way as the SDIO on the T4.1.
The SSD is a 500GB Crucial SSD formatted as a GPT with single exFAT partition. Was able to do a quick format from MTP and transfer a whole directory without MTP complaining
Code:
Storage Index 6 Name: MSC0-exFAT-SSD Selected

 Space Used = 511705088
Filesystem Size = 500080574464
Directory
---------
2001/
  calculations.wav                    426300
  completed.wav                       276460
  dangerous_to_remain.wav             372892
  enough_info.wav                     513388
  functional.wav                      237356
  one_moment.wav                      202236
  operational.wav                     772140
  sorry_dave.wav                      791164
  stop.wav                            200844
Audacity/
  Away_in_a_Manger.mp3                2014737
  Dont_Rain_on_My_Parade.mp3          3944449
  Take_My_Breathe_Away.mp3            5740819
  Welcome_Christmas.mp3               2985790
FLAC/
  T1_1024.FLA                         9802802
  T1_128.FLA                          11126659
  T1_256.FLA                          10415954
  T1_512.FLA                          10007370
Candyman.aac                          3177823
Dont Rain on My Parade.mp3            3944449
odd1.mp3                              46888
odd1.wav                              553004
zarathustra.mp3                       489461
 
Also did some more testing on the T4.1 and found 1 more thing needing fixing. There seems to be one issue that remains. On SDIO, sflash5/6 (going to guess other NOR Flash SPI chips as well) if you open a couple of txt files and try to delete them you can't and it hangs MTP. USB/NAND/QSPI/SD10 works great.
 
Looks like things are going well!

With T3.x SD Insertion issue, wondering if I should simply find work around or try to resolve. Work around is probably once I detect a disk is in there, do something with it before we call it again to say are you still there...

Right now just trying to understand, Added more debug output to CardCommand in SdioTeensy.cpp
...
Follow on: now before setting the xfertyp I print out:
Code:
  if (xfertyp == CMD13_XFERTYP)Serial.printf("    >>$$ %x %x\n", SDHC_XFERTYP, SDHC_PRSSTAT);
  SDHC_XFERTYP = xfertyp;

Failure case I see:
Code:
CardCommand(d1a0000 aaaa0000)
  >> after 1
    >>$$ 123a0032 ff88008a
  >>>> Failed isBusyCommandComplete(0) <<<<

Success I see:
Code:
CardCommand(d1a0000 aaaa0000)
  >> after 1
    >>$$ d1a0000 ff8800f8
  >> after 2
Card->status: 900
My guess is: >>$$ 123a0032 ff88008a
Is the interesting thing: It has on the CDIHB bit in failure...(Command Inhibit Dat)

This status bit is generated if either the DLA or the RTA is set to 1. If this bit is 0, it indicates that the
SDHC can issue the next SD/MMC Command. Commands with a busy signal belong to CDIHB, for
example, R1b, R5b type. Except in the case when the command busy is finished, changing from 1 to 0
generates a transfer complete interrupt in the Interrupt Status register

Lots of TLAs ;)
 
Update from previous:

Found an interesting method in SdioTeensy.cpp

Code:
//------------------------------------------------------------------------------
static bool transferStop() {
  // This fix allows CDIHB to be cleared in Tennsy 3.x without a reset.

And there is a method in the interface to call it:
Code:
bool SdioCard::writeStop() {
  return transferStop();

So Hacked up hacked up test sketch like:
Code:
  while (!Serial) ;
  Serial.println("Test Media Present");
  media_present = SD.begin(BUILTIN_SDCARD);
  Serial.printf("\n$$$Media Present: %u\n", media_present);
  print_sd_regs();

  if (media_present) {
    SdCard *card = SD.sdfs.card();
    if (card->writeStop()) {
      Serial.println("Try to clear out busy");
    }
  }
And now the Media insertion/removal appears to be working on T3.6...

Not sure of best place to do this? In real code.

There are calls to it and the read version inside of SdioCard::syncDevice

EDIT: Should have noted the last command that had turned on the bit: CardCommand(123a0032 10000): ff8800f8

which is probably: const uint32_t CMD18_PGM_XFERTYP = SDHC_XFERTYP_CMDINX(CMD18) | CMD_RESP_R1 |
DATA_READ_MULTI_PGM;

Which is used in: bool SdioCard::readStart(uint32_t sector)
which is used in SdioCard::readSector

like:
Code:
    if (m_curState != READ_STATE || sector != m_curSector) {
      if (!syncDevice()) {
        return false;
      }
      if (!readStart(sector)) {
        return false;
      }
So actually wondering if the mediaPresent function should call syncDevice? maybe if it fails when it calls status and has a value 0...
Will try that...
 
Last edited:
Here is a version of the mediaPresent that I think works for 3.6...
Code:
bool SDClass::mediaPresent()
{
	//Serial.print("mediaPresent: ");
	bool ret;
	SdCard *card = sdfs.card();
	if (card) {
		if (cardPreviouslyPresent) {
			#ifdef BUILTIN_SDCARD
			#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
			card->syncDevice();
			#endif  // defined(__MK64FX512__) || defined(__MK66FX1M0__)
			uint32_t s = card->status();
			Serial.printf("Card->status: %x\n", s);
			#else
			const uint32_t s = 0xFFFFFFFF;
			#endif
			if (s == 0xFFFFFFFF) {
				// SPI doesn't have 32 bit status, read CID register
				cid_t cid;
				ret = card->readCID(&cid);
				//Serial.print(ret ? "CID=ok" : "CID=unreadable");
			} else if (s == 0) {
				// assume zero status means card removed
				// bits 12:9 are card state, which should
				// normally be 101 = data transfer mode
				//Serial.print("status=offline");
				ret = false;
			} else {
				//Serial.print("status=present");
				ret = true;
			}
		} else {
			// TODO: need a quick test, only call begin if likely present
			ret = sdfs.restart();
			//Serial.print(ret ? "begin ok" : "begin nope");
		}
	} else {
		//Serial.print("no card");
		ret = false;
	}
	//Serial.println();
	cardPreviouslyPresent = ret;
	return ret;
}
The important part is the #if defined for the MK...

I also pushed up the MTP test sketch I put calls into this for...

I have not done anything with the performance issues with T4 yet...
Right now on T3.6 the elapsedMicros when installed shows about 20
When not in, about 1780...

Edit: Also runs on T3.5
 
Last edited:
Back
Top