bool MTPD::SendObject() {
uint32_t len = ReadMTPHeader();
while (len)
{
////////////////////////////////////////////////////////////
if(usb_mtp_available()) {
digitalToggleFast(2);
if(fetch_packet(rx_data_buffer)) {
printContainer(); // to switch on set debug to 1 at beginning of file
}
}
bool MTPD::SendObject() {
uint32_t len = ReadMTPHeader();
while (len)
{
receive_buffer();
uint32_t to_copy = data_buffer_->len - data_buffer_->index;
to_copy = min(to_copy, len);
if(!storage_->write((char*)(data_buffer_->buf + data_buffer_->index), to_copy)) return false;
data_buffer_->index += to_copy;
len -= to_copy;
if (data_buffer_->index == data_buffer_->len)
{
usb_free(data_buffer_);
data_buffer_ = NULL;
}
}
storage_->close();
return true;
}
storage_->setFileSize(size
Have a question on how to do something with LittleFS and for that matter probably in general.
In lfs_util.h you can turn on different logging functions. Just cant't do a Serial.printf so how do I set it up to get them turned on.
#define LFS_YES_TRACE
void debug_print(const char *format, ...);
// Macros, may be replaced by system specific wrappers. Arguments to these
// macros must not have side-effects as the macros can be removed for a smaller
// code footprint
// Logging functions
#ifdef LFS_YES_TRACE
#define LFS_TRACE_(fmt, ...) \
debug_print("%s:%d:trace: " fmt "%s\n", __FILE__, __LINE__, __VA_ARGS__)
......
#include <stdarg.h>
extern "C" void debug_print(const char *format, ...)
{
va_list args;
va_start(args, format);
for (; *format != 0; format++) { // no-frills stand-alone printf
if (*format == '%') {
++format;
if (*format == '%') goto out;
if (*format == '-') format++; // ignore size
while (*format >= '0' && *format <= '9') format++; // ignore size
if (*format == 'l') format++; // ignore long
if (*format == '\0') break;
if (*format == 's') { debug_print((char *)va_arg(args, int));
} else if (*format == 'd') { Serial.print(va_arg(args, int));
} else if (*format == 'u') { Serial.print(va_arg(args, unsigned int));
} else if (*format == 'x' || *format == 'X') {Serial.print(va_arg(args, int),HEX);
} else if (*format == 'c' ) { Serial.print((char)va_arg(args, int));
} else if (*format == 'p' ) { Serial.print(va_arg(args, int),HEX);}
} else {
out:
if (*format == '\n') Serial.print('\r');
Serial.print(*format);
}
}
va_end(args);
}
{{0x03, 0x2E, 0xC2}, 24, 64, 256, 1048576, 10, 15}, //Cypress 8Mb FRAM
D:\Users\Merli\Documents\Arduino\LittleFS tests\littlefs_teensy_test3\littlefs_teensy_test3.ino Dec 6 2020 12:03:37
LittleFS Timer Test
Flash ID: 03 2E C2
Flash size is 1.00 Mbyte
attempting to mount existing media
couldn't mount media, attemping to format
attempting to mount freshly formatted media
printDirectory
--------------
Disk Usuage:
Bytes Used: 512, Bytes Total:1048576
Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
printDirectory
--------------
-------------------------------
File1 contents:
-------------------------------
File1 size: 0
-------------------------------
File3 byte conversion test:
-------------------------------
Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
success
2nd Directory contents:
printDirectory
--------------
false, 0.0000000000, 0, 0,
printDirectory
--------------
printDirectory
--------------
test1 /
file1.txt 16
test2 /
file2.txt 16
test3 /
printDirectory
--------------
file20.txt 16
test1 /
file1.txt 16
LittleFS Test
Flash ID: 03 2E C2
Flash size is 1.00 Mbyte
attempting to mount existing media
started
printDirectory
--------------
FILE T4.1-Cardlike.jpg 220021
printDirectory
--------------
FILE mtpindex.dat 0
Disk Usuage:
Bytes Used: 512, Bytes Total:1048576
D:\Users\Merli\Documents\Arduino\LittleFS tests\littlefs_teensy_test3\littlefs_teensy_test3.ino Dec 7 2020 08:45:18
LittleFS Timer Test
Flash ID: 03 2E C2
Flash size is 1.00 Mbyte
attempting to mount existing media
printDirectory
--------------
Disk Usuage:
Bytes Used: 256, Bytes Total:1048576
Using println and printf to printoutput file
opened PRINTOUTPUT1.txt
opened PRINTOUTPUT2.txt
printDirectory
--------------
PRINTOUTPUT1.txt 628
PRINTOUTPUT2.txt 630
-------------------------------
File1 contents:
-------------------------------
File1 size: 628
abcdefghijklmnopqrstuvwxyz
Rec: 0, Float: 26.400000, Int: 98
abcdefghijklmnopqrstuvwxyz
Rec: 1, Float: 27.400000, Int: 99
abcdefghijklmnopqrstuvwxyz
Rec: 2, Float: 28.400000, Int: 100
abcdefghijklmnopqrstuvwxyz
Rec: 3, Float: 29.400000, Int: 101
abcde
ghijklmnopqrstuvwxyz
Rec: 4, Float: 30.400000, Int: 102
abcdefghijklmnopqrstuvwxyz
Rec: 5, Float: 31.400000, Int: 103
abcdefghijklmnopqrstuvwxyz
Rec: 6, Float: 32.400000, Int: 104
abcdefghijklmnopqrstuvwxyz
Rec: 7, Float: 33.400000, Int: 105
abcdefghi
klmnopqrstuvwxyz
Rec: 8, Float: 34.400000, Int: 106
abcdefghijklmnopqrstuvwxyz
Rec: 9, Float: 35.400000, Int: 107
-------------------------------
File3 byte conversion test:
-------------------------------
Data_0: true
Data_1: 1.3574999571
Data_2: 314159
Data_3: 142
19
The Quick Brown Fox
Init Done - array loaded
...... ...... ......
create folder
success
2nd Directory contents:
printDirectory
--------------
PRINTOUTPUT1.txt 628
PRINTOUTPUT2.txt 630
structuredData /
logger.txt 480
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
true, 1.3574999571, 314159, 142, The Quick Brown Fox
printDirectory
--------------
PRINTOUTPUT1.txt 628
PRINTOUTPUT2.txt 630
file1.txt 32
file10.txt 16
file2.txt 32
file20.txt 16
file3.txt 32
file30.txt 16
structuredData /
logger.txt 480
test1 /
test2 /
test3 /
printDirectory
--------------
PRINTOUTPUT1.txt 628
PRINTOUTPUT2.txt 630
file1.txt 32
file10.txt 16
file2.txt 32
file20.txt 16
file3.txt 32
file30.txt 16
structuredData /
logger.txt 480
test1 /
file1.txt 16
test2 /
file2.txt 16
test3 /
file3.txt 16
printDirectory
--------------
PRINTOUTPUT1.txt 628
PRINTOUTPUT2.txt 630
file1.txt 32
file10.txt 16
file2.txt 32
file20.txt 16
file3.txt 32
file30.txt 16
structuredData /
logger.txt 480
test1 /
file1.txt 16
test2 /
file2.txt 16
test3 /
file3.txt 16
Disk Usuage:
Bytes Used: 6272, Bytes Total:1048576
{{0x03, 0x2E, 0xC2}, 24, 256, 256, 1048576, 250, 1200}, //Cypress 8Mb FRAM
#include <LittleFS.h>
#include <SPI.h>
#include <SD.h>
//#define TEST_RAM
//#define TEST_SPI
#define TEST_QSPI
//#define TEST_SDCARD
#ifdef TEST_RAM
LittleFS_RAM myfs;
char buf[200000];
#elif defined(TEST_SPI)
LittleFS_SPIFlash myfs;
#elif defined(TEST_SDCARD)
SDClass myfs;
#else
LittleFS_QSPIFlash myfs;
#endif
void setup() {
#ifdef TEST_SPI
SPI.begin();
#else
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
#endif
while (!Serial && millis() < 5000) ; // wait
Serial.read();
delay(250);
Serial.println("LittleFS Test"); delay(5);
#ifdef TEST_RAM
if (!myfs.begin(buf, sizeof(buf))) {
#elif defined(TEST_SPI)
if (!myfs.begin(6)) {
#elif defined(TEST_SDCARD)
if (!myfs.begin(BUILTIN_SDCARD)) {
#else
if (!myfs.begin()) {
#endif
Serial.println("Error starting LittleFS Disk");
while (1) ;
}
Serial.println("started");
delay(10);
}
uint16_t loop_count = 0;
elapsedMillis em = 0;
uint8_t filename[256] = "test.txt";
uint8_t buffer[8 * 1024];
void loop() {
printDirectory();
Serial.println("Enter file size write size and name to create: ");
while (!Serial.available()) ;
uint32_t file_size = Serial.parseInt();
uint16_t write_size = Serial.parseInt();
uint8_t *psz = filename;
int ch = Serial.read();
while (ch == ' ') ch = Serial.read();
while (ch > ' ') { // not allowing spaces in test.
*psz++ = ch;
ch = Serial.read();
}
if (psz != filename) *psz = 0; // null terminate
if ((write_size > sizeof(buffer)) || (write_size == 0)) write_size = sizeof(buffer);
Serial.printf("Create File:%s size:%u write size:%u\n", filename, file_size, write_size);
elapsedMicros emTotal = 0;
File f = myfs.open(filename, FILE_WRITE);
Serial.println("*** opened ***");
for (uint16_t i = 0; i < write_size; i++) buffer[i] = i & 0xff;
while (file_size) {
elapsedMicros em = 0;
uint16_t output_count = (file_size > write_size) ? write_size : file_size;
uint16_t bytes_output = f.write(buffer, output_count);
if (output_count != output_count)
Serial.printf(" %u - %u - %u\n", output_count, bytes_output, (uint32_t)em);
file_size -= bytes_output;
}
f.close();
Serial.printf("Closed: %u\n", (uint32_t)emTotal);
}
void printDirectory() {
Serial.println("printDirectory\n--------------");
printDirectory(myfs.open("/"), 0);
Serial.println();
}
void printDirectory(File dir, int numTabs) {
//dir.whoami();
while (true) {
static int count = 0;
File entry = dir.openNextFile();
if (! entry) {
// no more files
//Serial.println("**nomorefiles**");
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println(" / ");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}
Enter file size write size and name to create:
Create File:bar.txt size:3355221 write size:8192
*** opened ***
[COLOR="#FF0000"]Closed: 26944362[/COLOR]
printDirectory
--------------
DSC03356.JPG 3355221
DSC03358.JPG 3280204
IMG_1259.jpg 368708
bar.txt 3355221
foo.txt 3355221
Enter file size write size and name to create:
Enter file size write size and name to create:
Create File:bar.txt size:3355221 write size:8192
*** opened ***
[COLOR="#FF0000"]Closed: 41192928[/COLOR]
printDirectory
--------------
DSC03356.JPG 0
DXL-RS485.jpg 20702
IMG_0112-(002).jpg 19576
IMG_0119.jpg 0
IMG_0283.jpg 244650
IMG_0287.jpg 0
IMG_1121.jpg 79375
IMG_1132.jpg 47198
KeDeiTest.jpg 10142
bar.txt 3355221
foo.txt 3695221
phoenix-rotate-RJoy-LR.jpg 0
test.txt 0
usb3-board-back.jpg 47786
Enter file size write size and name to create:
Create File:bar.txt size:3695221 write size:8192
*** opened ***
[COLOR="#FF0000"]Closed: 187088[/COLOR]
printDirectory
--------------
System Volume Information /
IndexerVolumeGuid 76
WPSettings.dat 12
LaikH.JPG 2801
mtpindex.dat 0
test1.txt 21
hallow.JPG 21026
DSC03360.JPG 3161263
DRAKE.JPG 15775
foo.txt 3355221
bar.txt 3695221
Enter file size write size and name to create:
Big write took 77.33 Sec for 8256000 Bytes : file3.size()=8256000
[COLOR="#FF0000"]Big write KBytes per second 106.76 [/COLOR]
Bytes Used: 8335360, Bytes Total:16777216
-------------------------------------------------------------------------------
{{0xEF, 0x40, 0x18}, 24, [COLOR="#FF0000"]256[/COLOR], 4096, 16777216, [COLOR="#FF0000"]2000[/COLOR], 400000}, // Winbond W25Q128JV*IQ/W25Q128FV
Big write took 54.91 Sec for 8280000 Bytes : file3.size()=8280000
[COLOR="#FF0000"]Big write KBytes per second 150.79 [/COLOR]
Bytes Used: 8306688, Bytes Total:16777216
{{0xEF, 0x40, 0x18}, 24, 128, 4096, 16777216, 2000, 400000}, // Winbond W25Q128JV*IQ/W25Q128FV
Big write took 73.69 Sec for 8280000 Bytes : file3.size()=8280000
Big write KBytes per second 112.36
{{0xEF, 0x40, 0x18}, 24, 64, 4096, 16777216, 2000, 400000}, // Winbond W25Q128JV*IQ/W25Q128FV
Big write took 58.11 Sec for 8280000 Bytes : file3.size()=8280000
Big write KBytes per second 142.49
Bytes Used: 8306688, Bytes Total:16777216
{{0xEF, 0x40, 0x18}, 24, 32, 4096, 16777216, 2000, 400000}, // Winbond W25Q128JV*IQ/W25Q128FV
Big write took 60.63 Sec for 8280000 Bytes : file3.size()=8280000
Big write KBytes per second 136.56
Bytes Used: 8306688, Bytes Total:16777216
int LittleFS_SPIFlash::prog(lfs_block_t block, lfs_off_t offset, const void *buf, lfs_size_t size)
{
if (!port) return LFS_ERR_IO;
const uint32_t addr = block * config.block_size + offset;
const uint8_t cmd = (addrbits == 24) ? 0x02 : 0x12; // page program
uint8_t cmdaddr[5];
make_command_and_address(cmdaddr, cmd, addr, addrbits);
//printtbuf(cmdaddr, 1 + (addrbits >> 3));
port->beginTransaction(SPICONFIG);
digitalWrite(pin, LOW);
port->transfer(0x06); // 0x06 = write enable
digitalWrite(pin, HIGH);
delayNanoseconds(250);
digitalWrite(pin, LOW);
port->transfer(cmdaddr, 1 + (addrbits >> 3));
port->transfer(buf, nullptr, size);
digitalWrite(pin, HIGH);
port->endTransaction();
//printtbuf(buf, 20);
return wait(progtime);
}
...
int LittleFS_SPIFlash::wait(uint32_t microseconds)
{
elapsedMicros usec = 0;
while (1) {
port->beginTransaction(SPICONFIG);
digitalWrite(pin, LOW);
uint16_t status = port->transfer16(0x0500); // 0x05 = get status
digitalWrite(pin, HIGH);
port->endTransaction();
if (!(status & 1)) break;
if (usec > microseconds) return LFS_ERR_IO; // timeout
yield();
}
//Serial.printf(" waited %u us\n", (unsigned int)usec);
return 0; // success
}
@mjs513 - Not sure what that change does or should do?
That is, as far as I can tell, the maximum time it can wait for the program time to complete...
.....So if changing that helps. It implies you are now getting timeouts? Not sure if that is good?
if (!(status & 1)) break;
if (usec > microseconds) return LFS_ERR_IO; // timeout
File f = myfs.open(filename, FILE_WRITE);
for (uint16_t i = 0; i < write_size; i++) buffer[i] = i & 0xff;
uint8_t write_counter = 0;
while (file_size) {
uint16_t output_count = (file_size > write_size) ? write_size : file_size;
uint16_t bytes_output = f.write(buffer, output_count);
file_size -= bytes_output;
}
}
f.close();
}
@Paul, @mjs513 and @defragster ... Sorry in advance if some of these are random questions or ...
Having a little fun with the test app, to allow me to type in file name sizes and write sizes...
It is helping me to understand or figure out I don't understand the proper semantics.
Example: Suppose I wish to to write to a file lets say foo.txt and supposed it is 1MB image. And the file may already exist or not exist. What is the best way to do this. Suppose foo.txt exists and is 2mb in size.
a) Suppose the code is something like:
When this code completes the file will now be 3mb in size (It appends)Code:File f = myfs.open(filename, FILE_WRITE); for (uint16_t i = 0; i < write_size; i++) buffer[i] = i & 0xff; uint8_t write_counter = 0; while (file_size) { uint16_t output_count = (file_size > write_size) ? write_size : file_size; uint16_t bytes_output = f.write(buffer, output_count); file_size -= bytes_output; } } f.close(); }
b) Like above, but I replace FILE_WRITE with FILE_WRITE_BEGIN, the file still ends up being 2mb in size with new stuff at start...
c) like b) but just before f.close() I do. f.truncate();
File ends up being 0 length... Defaults to 0 and not relative... (Yep I did this)
d) like b) but put the f.truncate() right after the myfs.open()... This worked and is what currently doing.
d2) could do like c) but instead maybe do: f.truncate(f.position());
I have not tried this, but I would think would work.
But which approach is better. Especially since sometimes through LittleFS other times to SDCards or ...
That is with some filesystems it is beneficial to have the storage preallocated and then fill in the data. Others maybe not? I am guessing maybe not in LittleFS case?
Related question: Suppose with something like MTP, I know the file that I going to write is lets say 3MB in size. Can LittleFS make use of this data.
It does look if I call f.truncate(3000000);
The underlying code will take the current size and if the truncate size is > current size, it will extend the file by writing 0s... My guess is that then if I try to write into this region it won't be able to directly write out the new data. That is will it have to clear out that region first again? If so does it make sense to have some mechanism for caller to FS to give you a hint on what size the file will likely be?
EDIT: I believe SDFat has a method: bool preAllocate(uint64_t length) ...
Probably enough rambling for one message
I ran into the same situation using SdFat with bench.ino. The size of the file was not consistent and could not determine the end of file. It would change. If I am not mistaken file size of the file and EOF should be the same after closing. Maybe I am wrong. This was using preAllocate(). There was unused space after the actual written data that was arbitrary. Using maybe fielded reads with a fixed number of records would not be a problem but let's say a text file without proper end of file marking would be. This what I ran into with bench.ino. The file size was not always reported as 5000000. Sometimes it was less. What should the file size be if the 5000000 is not completely used. The preAllocated size of 5000000 or the actual size of the data written? EOF character or size of data within the file. Truncate(sizeof(dataWitten) )then close?
.
@all - To somewhat answer some of my previous questions, wondering.
Doing something like: f.truncate(5000000);
Will probably not extend the file in a way that makes it good for me to then write new data in that space. What I believe this will do is to extend the file writing 0s from the current EOF to the specified location. And as Erasing sectors and the like writes all 0xff's, I am pretty sure that when we go back out, it will then have to erase these pages again, before writing out the real data.
...
0 dirs with 0 files of Size 0 Bytes
Total 0 files of Size 0 Bytes
Bytes Used: 8192, Bytes Total:16777216
Start Big write of 8364032 Bytes with TRUNCATE ... patience ...
Big write [B]TRUNCATE /0_bigftrunc.txt took 68.27 Sec [/B]for 8364032 Bytes : file3.size()=0
......................................................................................................
Big [B]write /0_bigftrunc.txt took 67.87 Sec for 8361984 Bytes [/B]: file3.size()=8364032
Big write KBytes per second 123.21
Bytes Used: 8388608, Bytes Total:16777216
[ 2.52 M](2.26913 M elap) Awaiting input 0123456789RdchkFqvplmusBbZztyYxf+-? loops left 0 >
Start Big write of 4173824 Bytes with TRUNCATE ... patience ...
Big write [B]TRUNCATE /1_bigftrunc.txt took 33.95 Sec [/B]for 4173824 Bytes : file3.size()=0
..................................................
Big [B]write /1_bigftrunc.txt took 33.29 Sec for 4171776 Bytes[/B] : file3.size()=4173824
Big write KBytes per second 125.32
Bytes Used: 12570624, Bytes Total:16777216
[ 5.77 M](1.12101 M elap) Awaiting input 0123456789RdchkFqvplmusBbZztyYxf+-? loops left 0 > d
printDirectory QSPI_DISK
--------------
FILE 0_bigftrunc.txt 8364032
FILE 1_bigftrunc.txt 4173824
0 dirs with 2 files of Size 12537856 Bytes
Total 2 files of Size 12537856 Bytes
Bytes Used: 12570624, Bytes Total:16777216
...
file3 = [B]myfs.open(myFile, FILE_WRITE);[/B]
} while ( fileID < '4' && file3.size() > 0);
[B]file3.truncate( toWrite );
file3.close();[/B]
timeMe = micros() - timeMe;
Serial.printf( "\nBig write TRUNCATE %s took %5.2f Sec for %lu Bytes : file3.size()=%llu\n", myFile , timeMe / 1000000.0, xx, file3.size() );
memset( someData, fileID, 2048 );
int hh = 0;
timeMe = micros();
[B]file3 = myfs.open(myFile, FILE_WRITE);
file3.seek( 0 );[/B]
while ( toWrite > 2048 && resW > 0 ) {
[B]resW = file3.write( someData , 2048 );[/B]
...
Delete with read verify all #bigfile's
Verify /0_bigftrunc.txt bytes 8361984 : .................................................. GOOD! >> bytes 8361984
Big read&compare KBytes per second 2416.87
Verify /1_bigftrunc.txt bytes 4171776 : .................................................. GOOD! >> bytes 4171776
Big read&compare KBytes per second 2442.15
checkFormat:: Pre-Formatted Blocks Map
checkUsed:: lfs Used Blocks Map: #used is 2 : lfs traverse return 0 (neg on err) [COLOR="#FF0000"][B]// NO LFS DATA USED (except the root 'bits')[/B][/COLOR]
0 0x3 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
320 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
640 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
960 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1280 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1600 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1920 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2240 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2560 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2880 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3200 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3520 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3840 0x0 0x0 0x0 0x0 0x0 0x0 0x0
checkUsed:: lfs Used Blocks Map: #used is 2
lfs Used&Format overlap errs?: {eol}
checkFormat:: lfsUsed = checkused; [COLOR="#FF0000"][B]// ALL media BLOCKS FORMATTED (except the root 'bits')[/B][/COLOR]
0 0xfffffffc 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
320 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
640 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
960 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
1280 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
1600 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
1920 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
2240 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
2560 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
2880 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3200 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3520 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3840 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
Done myfs.checkFormat() in 581803 us.
CheckFormat On:
[ 7.64 M](0.00000 M elap) Awaiting input 0123456789RdchkFqvplmusSBbZztyYxf+-? loops left 0 >
Start Big write of 8364032 Bytes with TRUNCATE ... patience ... [COLOR="#FF0000"][B]// TIMES 15 and 13 seconds NOT 68 and 67 seconds for 8MB write[/B][/COLOR]
Big write [B]TRUNCATE /0_bigftrunc.txt took 15.36 Sec[/B] for 8364032 Bytes : file3.size()=0
......................................................................................................
Big [B]write /0_bigftrunc.txt took 13.70 Sec for 8361984 Bytes[/B] : file3.size()=8361984
Big write KBytes per second 610.30
Bytes Used: 8388608, Bytes Total:16777216
[ 8.27 M](0.48445 M elap) Awaiting input 0123456789RdchkFqvplmusSBbZztyYxf+-? loops left 0 >
checkFormat:: Pre-Formatted Blocks Map
lfschange missed used 2 != 2048
checkUsed:: lfs Used Blocks Map: #used is 2048 : lfs traverse return 0 (neg on err)[COLOR="#FF0000"][B]// HALF LFS DATA USED [/B][/COLOR]
0 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xfffffff 0x0 0x0 0x0
320 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
640 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
960 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1280 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1600 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1920 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2240 0xf0000000 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
2560 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
2880 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3200 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3520 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
3840 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0xffffffff
checkUsed:: lfs Used Blocks Map: #used is 2048
lfs Used&Format overlap errs?: {eol}
checkFormat:: lfsUsed = checkused; [COLOR="#FF0000"][B]// ONLY TWO media BLOCKS FORMATTED [/B][/COLOR]
0 0x0 0x0 0x0 0x0 0x0 0x0 0x30000000 0x0 0x0 0x0
320 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
640 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
960 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1280 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1600 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
1920 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2240 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2560 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
2880 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3200 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3520 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
3840 0x0 0x0 0x0 0x0 0x0 0x0 0x0
Done myfs.checkFormat() in 23205 us.
MTP_test
SDIO Storage 0 254 sdio 264289280 58577408
SD Storage 1 10 sd1 failed or missing
RAM Storage 0 RAM1 1999872 512
RAM Storage 1 RAM2 4000000 512
Program Storage 0 PROGM 983040 8192
RRRRRRRRQSPI Storage 0 QSPI 16777216 8192
SPIFlash Storage 0 3 nand1 failed or missing
SPIFlash Storage 1 4 nand2 failed or missing
SPIFlash Storage 2 5 nand3 failed or missing
SPIFlash Storage 3 6 nand4 8388608 651264
Setup done
MTPD::SendObject: len:69245
EV-At..+..+..+..+..+..+..+..+..+..+..+..+..+..+..+..+RRRRRRRE.+.+.+.+.+.+.+PRPRPRPRPRPRPRP.+RPRPRPRPRPRPRPRPRE.+.+.+.+.+.+.+PRP.+RPRPRPRPRPRPRPRPRPRPRPRPRPRP.+RE.+.+.+.+.+.+.+RWR 8192 8192 48265 0 145050
PRPRPRPRPRPRPRPRPRPRPRPRP.+RPRPRPRE.+.+.+.+.+.+.+PRPRPRPRPRPRP.+RPRPRPRPRPRPRPRPRPRE.+.+.+.+.+.+.+RRWR 8192 8192 40073 8192 [COLOR="#FF0000"]100505[/COLOR]
PRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRPRE.+.+.+.+.+.+.+PRPRPRPRPRPRPRPRP.+RPRPRPRPRPRPRPRE.+.+.+.+.+.+.+RWR 8192 8192 31881 16384 [COLOR="#FF0000"]100800[/COLOR]
PRPRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRE.+.+.+.+.+.+.+PRPRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRE.+.+.+.+.+.+.+RRRWR 8192 8192 23689 24576 [COLOR="#FF0000"]98679[/COLOR]
PRPRPRPRPRPRPRPRPRPRPRPRP.+RPRPRPRE.+.+.+.+.+.+.+PRPRPRPRPRPRP.+RPRPRPRPRPRPRPRPRPRE.+.+.+.+.+.+.+.+RWR 8192 8192 14985 32768 102678
PRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRPRE.+.+.+.+.+.+.+PRPRPRPRPRPRPRP.+RPRPRPRPRPRPRPRPRE.+.+.+.+.+.+.+RRWR 8192 8192 6793 40960 97992
PRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRPRE.+.+.+.+.+.+.+PRPRPRPRPRPRPRPRPRPRPRPRPRPRP.+RPRE.+.+.+.+.+$RWR 8192 8192 0 49152 100044
PRPRPRPRPRPRPRPRPRPRPRPRPRPRPRPREPRPRPRPRPRPRPRPRPRPRPRPRPRPRPRPRERRRRWR 8192 8192 0 57344 95932
PRPRPRPRPRPRPRPRPRPRPRPRPRPRWR 3709 0 65536 5689
PRRPRCL 69245
EV-At..+..+..+..+..+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 60553 0 [COLOR="#FF0000"]2086[/COLOR]
.+.+.+.+....+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 52361 8192 [COLOR="#FF0000"]371[/COLOR]
.+.+.+.+..+..+..+..+..+..+..+..+..+..+..+..+.+WR 8192 8192 43657 16384 [COLOR="#FF0000"]8991[/COLOR]
.+.+.+.+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 35977 24576 373
.+.+.+.+...+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 27785 32768 844
.+.+.+.+....+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 19593 40960 372
.+.+.+.+..+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 11401 49152 381
.+.+.+.+..+..+..+..+..+..+..+..+..+..+..+..+WR 8192 8192 3209 57344 373
.+.+.+.+....+..+..+WR 3709 0 65536 163
CL 69245
@all...
...
So it looks like for every 8KB write I do, it does 16 (Prog calls followed by Read calls) then Erase then repeat ... Looks like on average the Erase calls take > 40ms
Again question is does it always have to do an erase of a block? I just did a full low level format!
...
@KurtE
Know this may sound funny but the default program size is 256bytes for all the flash chips in LittleFS with an erasesize of 4096 bytes respectively yet we are interfacing MTP at 8192bytes since that is essentially what SD cards with FAT is expecting. Wonder if changing some of these settings can be changed.
Is it possible to change the numbers of bytes transferred by MTP to a smaller size like 4096?
storage.addFilesystem(progmfs[ii], lfs_progm_str[ii]);
storage.addFilesystem(progmfs[ii], lfs_progm_str[ii], 4096);