RP2040 pico can read LittleFS files but unable to create or write to files

I have trouble creating or writing to files on my pico and rp2040. i am able to start littleFS and read files i uploaded but when i try to create or write to exiting files, it wont work.

my platformio.ini

platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower
upload_protocol = picotool
upload_port = D:
lib_archive = no
board_build.filesystem_size = 0.2m
build_flags = 

Here is sample code that complies fine and if I have an existing file it reads it fine but it wont work for creating / writing to files. I tried w+ mode, different file names, directories also and same issue.

I get: Problem on create file!

Any ideas?

  //  LittleFS.remove(F("/testCreate.txt"));

  File testFile = LittleFS.open(F("/testCreate.txt"), "w");
  if (testFile){
    Serial.println("Write file content!");
    testFile.print("Here is the test text");
    Serial.println("Problem on create file!");
  testFile = LittleFS.open(F("/testCreate.txt"), "r");
  if (testFile){
    Serial.println("Read file content!");
     * File derivate from Stream so you can use all Stream method
     * readBytes, findUntil, parseInt, println etc
    Serial.println("Problem on read file!");

I also tried this and it fails. I can only get r read mode to work if I upload the file manually through tool :frowning:

   fs = LittleFS.open("/sample.json", "w+");
    delay(50); // wait a bit for write to complete

    if (fs.print("Hello") > 0)
        Serial.println("sample written. now will try to read...");
        Serial.println("Problem on create file!");
    delay(50); // wait .5 sec for write to complete
  1. Make sure your platform is up-to-date. Do so e.g. by opening a CLI and executing pio pkg update -g -p raspberrypi
  2. Increase the filesystem size to say 1.0m and upload arduino-pico/libraries/LittleFS/examples/SpeedTest/SpeedTest.ino at master · earlephilhower/arduino-pico · GitHub as the sketch. Does it report a write speed?

Thank you so much. I updated platformio and recompiled my sketch and no change. Then I tried the speed test sketch and increased the size to 1.0m and the speedtest worked.

I went back to my sketch and rebuilt the file system image and uploaded my files and all of a sudden my sketch started working. Not sure why. Perhaps I just had a corrupted file image or something formatting did got it working. Will later try a new board and double check.

Thanks for the tip on the speedtest. That’s helpful!