Creating and Adding several partitions to the file sytem in FreeRTOS

Hello All,
I am working with freertos and I am trying to add to the file system several partitions inside a pxDisk (SD card) with different names.

I have partititioned the pxDisk in two partitions, after that I format and mount each partition without problem, but when using FF_FS_Add, I don’t have any way to select the partition to Add.
I have used the ‘active partition field’ pxDisk->xStatus.bPartitionNumber = partno;
For example:
pxDisk->xStatus.bPartitionNumber = 0
FF_FS_Add( pcName0, pxDisk );
pxDisk->xStatus.bPartitionNumber = 1
FF_FS_Add( pcName1, pxDisk );
However when I ulse FTP to check the filesystem it seems that both names ‘pcname0’ and ‘pcname1’ points to the same filesystem.

How can I use FF_FS_Add() with two partitions inside the same media pxDisk?
If I use two different pxDisk structures, there is some example where different pxDisk structures point to the same SD card ? how to do the partition in such case ? only with in one pxDisk structure?

I am using FreeRTOS V9.0.0,

Many thanks in advance for the help!!

Hi @przrtos
Welcome to FreeRTOS Community Forums !
The issue might be reusing the same pxDisk pointer and expect FF_FS_Add() to distinguish partitions.

You can try creating two FF_Disk_t structures -one per partition-even if they share the same physical media.

FF_Disk_t *pxDisk0 = FF_SDDiskInit( /* your SD driver init */ );
FF_Disk_t *pxDisk1 = FF_SDDiskInit( /* reinit for 2nd partition */ );

pxDisk0->xStatus.bPartitionNumber = 0;
FF_FS_Add( pcName0, pxDisk0 );

pxDisk1->xStatus.bPartitionNumber = 1;
FF_FS_Add( pcName1, pxDisk1 );

Hi karahulx,
Many thanks for you response,
If my SD driver has no partition and I want to create two partitions, must I use FF_Partition( pxDisk, &xPartition ); and FF_Format( pxDisk, partnumber, pdFALSE, pdFALSE ); in both pxDisk0 and pxDisk1 ? or only in one of them ?

I mean for example to do the following:

FF_Disk_t pxDisk0 = FF_SDDiskInit( / your SD driver init */ );
FF_Disk_t pxDisk1 = FF_SDDiskInit( / reinit for 2nd partition */ );

FF_Partition( pxDisk0, &xPartition ); /* in xPartition 2 partitions are configured for Partitioning */

FF_Format( pxDisk0, 0, pdFALSE, pdFALSE );
FF_Format( pxDisk0, 1, pdFALSE, pdFALSE );

pxDisk0->xStatus.bPartitionNumber = 0;
FF_FS_Add( pcName0, pxDisk0 );

pxDisk1->xStatus.bPartitionNumber = 1;
FF_FS_Add( pcName1, pxDisk1 );

Many thanks

FF_Partition() writes to sector 0 (MBR) . Formatting writes to a specific partition region - this can be done by reusing the same disk handle with the right partition number.
You must not run FF_Partition() more than once unless you intend to destroy the partition table again.

1 Like

Ok, thanks,
Should I mount partitions separately from different disks?

FF_Disk_t pxDisk0 = FF_SDDiskInit( / your SD driver init */ );
FF_Disk_t pxDisk1 = FF_SDDiskInit( / reinit for 2nd partition */ );

FF_Partition( pxDisk0, &xPartition ); /* in xPartition 2 partitions are configured for Partitioning */

FF_Format( pxDisk0, 0, pdFALSE, pdFALSE );
FF_Format( pxDisk0, 1, pdFALSE, pdFALSE );

pxDisk0->xStatus.bPartitionNumber = 0;
FF_Mount( pxDisk0, pxDisk0->xStatus.bPartitionNumber );
FF_FS_Add( pcName0, pxDisk0 );

pxDisk1->xStatus.bPartitionNumber = 1;
FF_Mount( pxDisk0, pxDisk1->xStatus.bPartitionNumber );
FF_FS_Add( pcName1, pxDisk1 );

FF_Mount()must be called per FF_Disk_t, using the partition number set in that disk.
So when try to setup the second partition on the second disk structure , you should call FF_Mount() on pxDisk1

FF_Mount( pxDisk1, pxDisk1->xStatus.bPartitionNumber );