USB stick larger then 2Gb -> _MAX_SS / USB stick not detected

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,

I can not find a solution to implement usb sticks larger then 2Gb.
If I'm not mistaken I should only have to change the value of _MAX_SS in the file ffconf.h to a bigger sector size.
When doing this the larger usb stick isn't recognised (it is detected). Looking at the value of the sector size it always returns 512bytes. How can I implement larger USB sticks?

Second question some USB sticks aren't detected when plugging them in the relax lite kit. What is the reason of this issue? (USB stick has a 512bytes sector size and works fine on Windows). When plugging them in the usb hoststate doesn't change has this something to do with the type of usb stick?

Regards
Peter Reychler
0 Likes
6 Replies
lock attach
Attachments are accessible only for community members.
Not applicable
Hi Peter,

Can you please update the following file: USBBL001.c. It should solve your issue now. We tested the update on XMC45 CPU board with 8GB Sandisk USB stick and it is working.
Note: Please do not change _MAX_SS in the file ffconf.h file. The sector size should always be 512.

Regards,
Daryl
0 Likes
Not applicable
Hi Daryl,

We have changed the file but:
Writing to a usb stick larger than 2Gb (being formatted with a larger sector size then 512) is working without any problems. We have tried it with a usb stick of 16Gb (sector size 4096).
The problem is reading from the usb stick. This gives all kind of rubish data and isn't correct.

That's why in ff_conf they say you need to change the _MAX_SS. Trying to change that didn't resolve our problem because the program always returns that sector size is 512bytes.
This gives us a second isue if we do not receive the correct sector size we cannot compute the free space on the stick.

Peter
0 Likes
Not applicable
Hi Peter,

I will update you once we are able to replicate this at our side. Hopefully also a solution at the next reply. 🙂

Regards,
Daryl
0 Likes
Not applicable
Hi Peter,

We still have some trouble to arrange for a thumb drive with 4096 sector size. We would like to find out the information on the device that you are using.

Can you assist to do the following:
1. Find the sector size returned from device, put the break point in the code, inside USBBL001.c file.
In function USBBL001_Initialize, after the call to MS_Host_ReadDeviceCapacity() and then check the DiskCapacity.BlockSize.
It should show 4096.
Otherwise it is the issue with the device, which doesn’t return proper sector size on request.

2. Which is the thumb drive that you are using?
To ensure the device is having sector size of 4096, can you check they can do the following from windows command line.
C:\>wmic DISKDRIVE get bytespersector, caption

Look forward to hearing from you.

Regards,
Daryl
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
Hi Daryl,

I've confused the sector size with the disk allocation size.
My stick has a 512 sector size, but when formatting (FAT32) with an Allocation unit size > 512 (needed for sticks larger then 2Gb) we can write to the stick correctly but we cannot read from it.
A stick of 16Gb has an allocation unit size of 4096bytes.

Below some an adapted main.c for the project USBBL001_USBMS001 and a file that you need to put in the root of the usb stick.
The code should read the parameters that are in the LogCfg.txt file, but when looking at the data read for maxNumberOfLogFiles it gives me a number that isn't the correct value.
When putting a 2Gb stick with the same LogCfg.txt in the drive everything is read correctly.
Hope this can simulate our problem



#include
#include "Dave\Generated\src\USBMS001\USB\USB.h"


/*******************************************************************************
** Global Variable Definitions **
*******************************************************************************/
/* File pointer */
FIL fp ;
/* File System Object Structure variable */
FATFS myfsObject ;


/*******************************************************************************
** Private Function Declarations:
*******************************************************************************/

/* Function to demonstrate MassStorageHost */
void FATFS_TestDemo(void);


/*******************************************************************************
** Public Function Definitions **
*******************************************************************************/


struct logfileInfo {
char logDirectory[256];
uint32_t maxNumberOfLogFiles;
uint32_t maxSizeOfLogFiles;
uint8_t numberOfConfigLines;
uint8_t numberOfEventConfigLines;
};

struct logInfo {
uint8_t NodeNr;
uint8_t IDExten;
uint32_t Identifier;
uint32_t IDMask;
uint8_t EventFlag;
};


struct logfileInfo *sLogfileInfo;
//struct logInfo sLogFilters;













bool ReadConfigurationFile(char* configFileName)
{
FRESULT dResult;
bool retVal = true;
uint8_t configLineNumber;
char configLine[256];
char *pToken;

// Check if configfilename is configured
if (configFileName == NULL) return 0;

f_chdrive(0);
dResult = f_mount(0, &myfsObject);

if (dResult == FR_OK)
{
dResult = f_open(&fp, configFileName, FA_OPEN_EXISTING | FA_READ);
if(dResult == FR_OK)
{
if(f_gets(configLine, sizeof(configLine), &fp) !=NULL)
{

// First row, info about:
// -> logDirectory
// -> Max number of logfiles
// -> Max size of logfiles
// -> Number of configlines
pToken = strtok(configLine, ";");
if (pToken != NULL)
strcpy(sLogfileInfo->logDirectory, pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogfileInfo->maxNumberOfLogFiles = atoi(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogfileInfo->maxSizeOfLogFiles = atol(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogfileInfo->numberOfConfigLines = atoi(pToken);

sLogfileInfo->numberOfEventConfigLines = 0;

// Continue processing lines (logFilters)
// -> Extended or not
// -> Identifier
// -> Mask
// -> Flag to force saving the file
configLineNumber = 0;
//sLogFilters = new logInfo[sLogfileInfo->numberOfConfigLines];
struct logInfo *sLogFilters[sLogfileInfo->numberOfConfigLines];

while((f_gets(configLine, sizeof(configLine), &fp) != NULL) &&
(configLineNumber < sLogfileInfo->numberOfConfigLines))
{
pToken = strtok(configLine, ";");
if (pToken != NULL)
sLogFilters[configLineNumber]->NodeNr = atoi(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogFilters[configLineNumber]->IDExten = atoi(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogFilters[configLineNumber]->Identifier = atol(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
sLogFilters[configLineNumber]->IDMask = atol(pToken);

pToken = strtok(NULL, ";");
if (pToken != NULL)
{
sLogFilters[configLineNumber]->EventFlag = atoi(pToken);
if (sLogFilters[configLineNumber]->EventFlag > 0)
sLogfileInfo->numberOfEventConfigLines++;
}

configLineNumber++;
}

struct logInfo *sLogEventFilters[sLogfileInfo->numberOfEventConfigLines];
for(uint8_t i = 0, j =0; i < sLogfileInfo->numberOfConfigLines; i++)
{
if (sLogFilters->EventFlag > 0)
{
memcpy(&sLogEventFilters, &sLogFilters, sizeof(sLogFilters));
j++;
}
}

}
}
}
else retVal = false;
dResult = f_close(&fp);

return retVal;
}



bool gelezen = false;










/**
* Main program entry point. This routine configures the hardware required by
* the application, then enters a loop to run the application tasks in sequence.
*/
int main(void)
{
/* USB host status */
uint8_t USBHostState;

/* Set the USB host status to "Wait for Device" */
USB_SetHostState(HOST_STATE_WaitForDevice);

/* DAVE Initialization */
DAVE_Init();

/* Initializes the USB core driver. */
USBBL001_Init();

/* Infinite loop */
while (1)
{
/* Get the USB Host status. */
USB_GetHostState(&USBHostState);

/* To Enumerate the attached device. */
USBBL001_Process();

if(USBHostState == HOST_STATE_Configured)
{

/* Call MassStorageHost demo function */
gelezen = ReadConfigurationFile("LogCfg.txt");
FATFS_TestDemo();

while(USBHostState == HOST_STATE_Configured)
{
USB_USBTask(); // Keep calling this function for USB management
USB_GetHostState(&USBHostState); // Get the USB Host status.
USBBL001_Process(); // To Enumerate the attached device.
}

}

/* Keep calling this function for USB management */
USB_USBTask();
}
}



/**
* Demo Application selects the drive 1 for USB. It creates demo directory & demo
* file and performs basic read, write and close operations on created file.
*/
void FATFS_TestDemo(void)
{
volatile uint8_t DResult;

/* Set drv to 1 for USB */
f_chdrive(1);

/* Mount USB device */
DResult = f_mount(1, &myfsObject);


/* Make directory */
DResult = f_mkdir("ABSTEP");

if ((DResult == FR_OK) || (DResult == FR_EXIST))
{
/*Directory already exists!!*/
}

/* Create File */
DResult = f_open( &fp, "ABSTEP/readme.txt", (FA_CREATE_NEW | FA_WRITE | FA_READ));
if (DResult == FR_OK)
{
f_printf( &fp,"Hello World");
}
else if (DResult == FR_EXIST )
{
/* File already exists!! */
}

/* Close File */
DResult = f_close(&fp);
}



0 Likes
Not applicable
Hi Peter,

We checked with a 8GB thumb drive (Sandisk cruzer blade) and formatted it with disk allocation size of 4096 and 16KB.
The data can be written and read properly.

Next, we checked on a 32GB thumb drive (HP) by writing the same content (from LofCfg.txt). We were able to read back the proper data.
The only point that we noticed is that Windows did not allow us to format the 32GB thumb drive with disk allocation size of 4096. It should be >=8192.
By default the disk allocation size is 16KB, for both 8GB and 32 GB thumb drives.

Can you try to format the thumb drive with a disk allocation size of 16KB, which is default from windows.
Hopefully this can help solve your issue.

Regards,
Daryl
0 Likes