The two card are formated as FAT32, I already checked.
It's very complicated to migrate from MQX 4.1.1 to 4.2 due large changes in the bsp, psp and mainly IO libraries (of incompatibilies of both) . Is possible use only MFS of MQX 4.2 into MQX 4.1.1 ?
Let me do a brief of my situation to be clearer:
I have two boards: frdm-k64f and my custom board based on the first. The two boards are running the same source code: MQX_4_1_1_LINUX_GA/mfs/examples/sdcard/demo.c .
In frdm-k64 I don't have any trouble . As Kingston As SanDisk sdcards run normally. But I realized when calling the function: partition_handle = fopen("pm:1", NULL); the Kingston device return a pointer and call _io_mfs_install over partition , but in SanDisk partition_handle variable the value is NULL, then _io_mfs_install is called over sdcard device because is not possible to open as a device block, why?
In my custom board the Kingston sdcard runs normally equal in the frdm-k64. But in SanDisk card after called _io_mfs_install over 'sdcard: ' device I've a error when I try to open the filesystem "a:" calling fopen with "a:" filesystem_handle = fopen("a:', NULL); . This is very strange.
In the last case, fopen returned NULL . Debugging fopen function is the line below:
io_fopen.c
file_ptr->DEV_PTR = dev_ptr;
if (dev_ptr->IO_OPEN != NULL) {
result = (*dev_ptr->IO_OPEN)(file_ptr, (char *)open_type_ptr, (char *)open_mode_ptr);
if (result != MQX_OK) {
_task_set_error(result);
_mem_free(file_ptr);
return(NULL);
} /* Endif */
}
The value of result in this case is: 0x301e , therefore this error is FS_READ_FAULT in MFS filesystem.
Debbuging the MFS library, I discovered that MFS_Open_Device() functiion return FS_READ_FAULT because MFS_Read_device_sectors returned this value.
mfs_rw.c - MFS_Read_device_sectors:
if ( drive_ptr->BLOCK_MODE )
{
shifter = 0;
seek_loc = sector_number;
expect_num = sector_count;
}
else
{
shifter = drive_ptr->SECTOR_POWER;
seek_loc = sector_number << shifter;
expect_num = sector_count << shifter;
}
In this function (MFS_Read_device_sectors) I discovered that my device isn't in a Block Mode , therefore the expect_num variable received the value -4 ( 0xfffffffc ) . Then when the function:
while ( expect_num > 0 && attempts <= max_retries )
{
num = read(drive_ptr->DEV_FILE_PTR, buffer_ptr, expect_num);
#if MQX_USE_IO_OLD
if ( num == IO_ERROR )
#else
if ( num < 0 )
#endif
{
error = MFS_READ_FAULT;
break;
}
else if ( num > 0 )
{
expect_num -= num;
buffer_ptr += num << (drive_ptr->SECTOR_POWER - shifter);
attempts = 0; /* there is a progress, reset attempts counter */
}
attempts++;
}
The num variable in this case is 5 and below , in the same function of MFS MFS_read_device_sectors I've the following:
if ( expect_num > 0 )
{
#if MQX_USE_IO_OLD
error = drive_ptr->DEV_FILE_PTR->ERROR;
#else
error = errno;
#endif
}
if (error == MFS_NO_ERROR && expect_num)
{
/* Ensure that error code is always set if less than requested data was read */
error = MFS_READ_FAULT;
}
if (processed)
*processed = ((sector_count<<shifter) - expect_num) >> shifter;
return error;
And because expect_num is -4 the MFS_READ_FAULT is set and all the errors occours.
What could be the cause of these errors only with SanDisk (kingston works great) in my custom board and why don't occours in frdm-k64f board.
Could be the PCB vias of my custom board? (I did the impedance control of them using the same lenght for all related of sdcard)
And... why only occours when I install the MFS over sdcard instead over the partition? It's very difficult to solve this problem.