Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

+FAT how to create two partitions on SD card

Posted by spikeroot on August 4, 2017

I'm having a hard time figuring out how to do this. Here is my code, could you tell me what is wrong with it? ffconfigMAXPARTITIONS is set to 2, and the 2nd call to FFFormat is only finding 1 partition when it calls FF_PartitionSearch.

~~~ static FFDiskt Disks[ffconfigMAX_PARTITIONS];

static FFIOManagert * CreateIoManager(FFDiskt * pdisk) { FFCreationParameterst xParameters; memset( &xParameters, '0', sizeof( xParameters ) ); xParameters.pxDisk = pdisk; xParameters.pucCacheMemory = NULL; xParameters.ulMemorySize = 1024; xParameters.ulSectorSize = 512; xParameters.fnWriteBlocks = prvFFWrite; xParameters.fnReadBlocks = prvFFRead; xParameters.xBlockDeviceIsReentrant = pdFALSE; if (!xPlusFATMutex) xPlusFATMutex = xSemaphoreCreateRecursiveMutex(); ASSERTANDRETURN(xPlusFATMutex, NULL); xParameters.pvSemaphore = ( void * ) xPlusFATMutex;

FF_Error_t err;
FF_IOManager_t * p_ioman = FF_CreateIOManger( &xParameters, &err );
ASSERT_AND_RETURN(p_ioman, NULL);
if (err != 0) 
{
	ffconfigFREE(p_ioman);
	return NULL;
}
return p_ioman;

}

int FFSDDiskTwoPartitionFormat(void) { for (sizet i = 0; i < ffconfigMAXPARTITIONS; i++) { memset(&Disks[i], 0, sizeof(Disks[i])); Disks[i].ulNumberOfSectors = RTEStorageGetBlockCount(RTESTORAGE_CARD); Disks[i].pxIOManager = CreateIoManager(&Disks[i]); if (!Disks[i].pxIOManager) return -1;

	Disks[i].xStatus.bIsInitialised = pdTRUE;
	Disks[i].xStatus.bPartitionNumber = i;
}

FF_PartitionParameters_t partitions;
memset( &partitions, 0x00, sizeof( partitions ) );
partitions.ulSectorCount = RTE_Storage_GetBlockCount(RTE_STORAGE_CARD);
partitions.ulHiddenSectors = 0;
partitions.ulInterSpace = 0;
partitions.xPrimaryCount = 2; // ????
partitions.eSizeType = eSizeIsPercent;
partitions.xSizes[0] = partitions.xSizes[1] = 50;

FF_Error_t partition_err = FF_Partition(&Disks[0], &partitions);
if (partition_err != FF_ERR_NONE) return -1;

for (size_t i = 0; i < ffconfigMAX_PARTITIONS; i++)
{
	FF_Error_t format_err = FF_Format(&Disks[i], i, pdFALSE, pdFALSE);
	if (format_err != FF_ERR_NONE) return -1;
}

return 0;

}

~~~


+FAT how to create two partitions on SD card

Posted by rtel on August 7, 2017

Is this a different topic to this thread: https://sourceforge.net/p/freertos/discussion/382005/thread/4874bbe8/ ?


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 7, 2017

The topics are indeed quite similar. Before answering, I will try-out the above code on an SD-card


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 7, 2017

PS. please check all return codes from the library calls and it may also useful to define FF_PRINTF, in order to see the internal logging of FreeRTOS+FAT. I'm still playing with it and I'll report later.


+FAT how to create two partitions on SD card

Posted by spikeroot on August 7, 2017

My code is checking all return values. The second call to FF_Format is returning 0x86000010.

I also have FF_PRINTF defined, and here is the output:

FFFormat: Secs 124868608 Rsvd 32 Hidden 0 Root 0 Data 124868576 FFFormat: SecCluster 64 DatSec 124838016 DataClus 1950594 ulClusterBeginLBA 30592 FFFormat: Clearing entire FAT (2 x 15240 sectors): FFFormat: Clearing done FFFormat: Clearing root directory at 00007780: 64 sectors FFPart: no partitions, try as PBR FFPart: no partitions, try as PBR FFPart: no partitions, try as PBR prvDetermineFatType: firstWord 0000FFF8


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 7, 2017

I'm working on it, about one hour to go :-)


+FAT how to create two partitions on SD card

Posted by spikeroot on August 7, 2017

Thanks! Appreciate your responsive support on this forum.


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 7, 2017

Hi Michael, the biggest problem with your code was this line:

~~~ partitions.ulHiddenSectors = 0; ~~~

As a consequence, the boot sector 0 got overwritten while formatting partition 0. The meaning of partitions.ulHiddenSectors is: the offset where the BPR ( Partition Boot Record ) shall be stored.

I will add a configASSERT(), to flag this off in future releases.

There were some other issues, like not settings the signature:

~~~ pxDisks[ i ]->ulSignature = sdSIGNATURE; ~~~

As multiple partitions are rarely used, the documentation about this feature is maybe not optimal. We're sorry about this.

Here below you find an attachment called format_partitions.c that I used for testing.

Please tell us how it goes. Thanks, Hein

Attachments

format_partitions.c (4104 bytes)

+FAT how to create two partitions on SD card

Posted by heinbali01 on August 7, 2017

Another thing that I changed was:

~~~ - xParameters.ulMemorySize = 1024; + xParameters.ulMemorySize = 3072; // 1024; ~~~

This is the amount of cache memory per I/O handler. Recently there was a question about the "optimal" size of this cache memory. I found that at most 9 sector buffers were being used simultaneously in a busy application:

https://sourceforge.net/p/freertos/discussion/382005/thread/ea301981/?limit=250#3a53

So this would be safer:

~~~ xParameters.ulMemorySize = 9 * 512; ~~~

If you have a single task that makes use of FreeRTOS+FAT, the size of the caching memory may be less.


+FAT how to create two partitions on SD card

Posted by spikeroot on August 9, 2017

I've incorporated your suggestions and am now successfully partitioning my SD card. But now my problem is that Windows won't read the second partition. I can see it through the disk management console, but I can't actually access it. Apparently (and I wish I'd known this before) Windows just doesn't recognize multiple partitions on a removable drive. I found a couple workarounds that involved installing a hacked-together driver to make windows see it as a non-removable drive, but only ended up causing Windows to run its "Repair Windows" utility upon restarting and re-install the old driver.

Do you have any other suggestions for accessing the second partition?

Link to my original question about being able to access all partitions: https://sourceforge.net/p/freertos/discussion/382005/thread/4874bbe8/


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 9, 2017

Do you have any other suggestions for accessing the second partition?

Yes I do, use Linux :-)

I just checked my SD-card under ubuntu. It shows the two partitions created by FreeRTOS+FAT. I see their contents and I can write to them.

Also running the file check program showed success:

~~~ root@myubuntu:~# fsck.vfat /dev/sdb1 fsck.fat 3.0.28 (2015-05-16) /dev/sdb1: 6 files, 6/123381 clusters root@myubuntu:~# fsck.vfat /dev/sdb2 fsck.fat 3.0.28 (2015-05-16) /dev/sdb2: 3 files, 3/123381 clusters ~~~

My W10 only sees a single partition.


+FAT how to create two partitions on SD card

Posted by heinbali01 on August 9, 2017

My W10 only sees a single partition.

With W10, of course I mean Windows-10.

Also when I try to (re-)format the SD-card it will only see the first partition, i.e. it only sees 50% of the actual disk size.


+FAT how to create two partitions on SD card

Posted by spikeroot on August 9, 2017

Linux might be an option if I were the user of my product. Unfortunately, I need to make it work for Windows users.

My original question was whether I'd be able to access all partitions from Windows. Apparently the answer should have been "no." I understand now that this limitation is inherent in Windows.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner