Access to two partition of SD card

Hi. I make two partitions for an sd card (16 GB sd to two of 8 GB). I just can READ and WRITE on partition 1. How can I READ/WRITE on partition 2?
this code:

//#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(3)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

//////////////////////////////////////////////////////////
This is the Serial output of my sd card partitions and info: (sdfat-Adafruit Fork -> sdinfo)
///////////////////////////////////////////////////////////
Card type: SDHC
sdSpecVer: 5.00
HighSpeedMode: false

Manufacturer ID: 0X3
OEM ID: SD
Product: SC16G
Revision: 8.0
Serial number: 0X2D0F10FC
Manufacturing date: 11/2017

cardSize: 15931.54 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
dataAfterErase: zeros

OCR: 0XC0FF8000

SD Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
1,0X0,0X20,0X21,0X0,0XC,0XFE,0XE9,0X95,2048,14745600
2,0X0,0XFE,0XEA,0X95,0XC,0XFE,0XFF,0XFF,14747648,16365568
3,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0
4,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0X0,0,0

Scanning FAT, please wait.

Volume is FAT32
sectorsPerCluster: 8
fatStartSector: 6078
dataStartSector: 34816
clusterCount: 1839104
freeClusterCount: 1839099

Support for Multiple Partitions · Issue #69 · greiman/SdFat-beta · GitHub

greiman commented on Feb 21, 2021

SD cards are not designed for multiple partitions and the SD association specifies that a card shall have only one partition. The structure of a card's flash, buffers, and algorithms depends on not just one partition but the location of file system structures and cluster sizes.

1 Like

I can use both partitions simultaneously. (figure) I used seeeduino xiao and Adafruit tinyusb library -> Mass storag -> msc_sdfat. it works in windows perfectly. but I can't access or READ/WRITE files at the second partition.

Windows is somewhat more sophisticated than the SD-Fat library code used with Arduino. What Bill Greiman likely meant in his GitHub statement, I'll rephrase here: The SD Association did not make a specification for multiple partitions on SD-cards, so the SD library for Arduino does not support more than one (1) primary partition.
I suspect Ladyada @Adafruit and her coders probably wrote their SD Arduino library to mimic what Bill did.

With the massive size SD-Cards recently coming on to marketplace, the SD Association may well take up the multi-partion question in a working committee.
SD Association | The SD Association (sdcard.org)

Building an Arduino library to support multi-partition SD cards would be futile until a spec was officially released. Life has a way of advising one that just because something is possible does not imply that the something should be done.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.