I did some tests here using C:\Freescale\Freescale_MQX_4_1_1\mfs\examples\sdcard with MQX 4.1.1 and my k64 custom board ( I already make my own board based on frdm-k64f) and realized the error below only using a different brand of SD card of 2 GB, for example, using kingston brand the problem doesn't occours, but using sandisk brand there is this problem when opening filesystem:
/* Open file system */
filesystem_handle = fopen(filesystem_name, NULL);
error_code = ferror(filesystem_handle);
if (error_code == MFS_NOT_A_DOS_DISK)
{
pDEBUG("NOT A DOS DISK! You must format to continue.\n");
}
else if (error_code != MFS_NO_ERROR)
{
pDEBUG("Error opening filesystem:%d - %s\n", error_code, MFS_Error_text((uint32_t)error_code));
return 1;
}
The error code returned when I'm opening the filesystem is equal -1. After this error occours, there is no more possible to use SD card (inclusive using kingston brand) to record data. There is necessary restart MFS stack (restarting MQX).
I believe that there is a problem in the moment of open the filesystem after partition manager is installed sucessfully. Starnge is occours only using sandisk brand.
I already retested with another sdcard card units and the problem is the same with SANDISK.
I already checked with SD Insight app on Android to verify if this San Disk Card is fake, but it isn't. It work ok on a PC.
The strange is that in frdm-k64f work as Kingston as Sandisk brands, but in my custom board, works only with Kingston. Why.?
Message was edited by: Thiago Wiezbicki This post : https://community.freescale.com/message/576728#576728 say that can be the signal strength problem, dos anybody agree? Can I decrease the clock?
Using two sdcards, I already tested in PC and they're original and working.
Using sdcard.c example with a Kingston SD I see:
shell>
shell> Installing MFS over partition...
SD card installed to a:
shell>
And all work fine, I can read and write. But,
Using a sdcard.c example with a SAnDisk card:
shell>
shell>
shell> Installing MFS over SD card driver...
Error opening filesystem: UNKNOWN ERROR !!!
shell>
And when I push the SanDisk card card:
Error uninstalling filesystem.
SD card uninstalled.
I can't read and write,;.
Now When I try to use the Kingston card again, the MFS broke and show the same error:
shell> Installing MFS over SD card driver...
Error initializing MFS: UNKNOWN ERROR !!!
Does anybody have any idea about this problem? I believe that the SanDisk card operate in a different way. Maybe the clock of the ESDHC channel is high.
Can I decrease this clock?
Hello thiagow,
I tested the sdcard example located at the path: C:\Freescale\Freescale_MQX_4_2\mfs\examples
I tested using MQX4.2 and the TWR-K64 board without issues. I tried with the below sdcards:
Panasonic 64MB
Panasonic 1GB
Kingston 8GB
Maxell 8GB
SanDisk 4GB
SanDisk 4GB
Adata 8GB
There are some changes between MQX4.1.1 and MQX4.2. Could you please try using MQX 4.2 version??
MFS supports FAT12, FAT16, and FAT32 file systems, so cloud you please double check if the disks have a different file system or if it is unformatted?
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
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.
Hi,
Based on the new information that you provide in your last post, seems clearly that you are having hardware issues, since you didn´t had the problem with FDRM-K64F board but your custom board it is having this peculiar situation, so my advise it is to review and measure the following:
a) Voltage Level of all pads related to the SD need to be at 3.3 +-0.3v
b) Frequency Operation, in this case review if your oscillator or crystal it is having JITTER! which affects the Swing of the SD Cards Signal providing delays in the response and causing errors.
c) Layout. Check if the layout design of the SD Card it is not affected by another EMC devices like microphones, motor, inductors you know any magnetic or electric field that may causing parasite currents affecting the delays.
It would be great to see and compare the signals from the FRDM and the Custom board with the same Card to see what efect it is causing the hardware problem.
Hope this helps!
Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Is it possible decrease the SDHC clock to workaround this probably PCB layout problem?
Hi Thiagow,
In the BSP under Peripheral_IO_Drivers->sdcard->sdcard_esdhc is file sdcard_esdhc.c .
Around line 265 the following code is present:
_io_sdcard_esdhc_r2_format(command.RESPONSE, csd);
sdcard_ptr->NUM_BLOCKS = _io_sdcard_csd_capacity(csd);
param = _io_sdcard_csd_baudrate(csd);
/* Get maximal baudrate for card setup */
if (ESDHC_OK != ioctl (sdcard_ptr->COM_DEVICE, IO_IOCTL_ESDHC_GET_BAUDRATE_MAX, &baudrate))
{
return FALSE;
}
//baudrate = 10000000;
if (param > baudrate)
{
param = baudrate;
}
if (ESDHC_OK != ioctl (sdcard_ptr->COM_DEVICE, IO_IOCTL_ESDHC_SET_BAUDRATE, ¶m))
{
return FALSE;
}
Where you see //baudrate = 10000000; you can uncomment and set to desired baud rate to see if slower clock helps.
Regards,
David
To tests. I changed to baudrate = 10000000, baudrate = 1000000, baudrate = 100000, baudrate = 10000, baudrate = 1000, baudrate = 100 .
I have the same symptom, using MQX 4.2 with KSDK 1.3 now, to test.
I see with kingston using the sdcard demo:
shell> Installing MFS over partition...
shell>
shell> dir
LOG_TMP.DAT 272 01-29-2016 16:31:50 A LOG_TMP.DAT
LOG201~1.CSV 621 01-29-2016 16:31:50 A LOG2016-01-29.csv
shell>
shell>
shell> SD card uninstalled.
And with Sandisk:
shell> Installing MFS over SD card driver...
Error while opening a:\ (UNKNOWN ERROR !!!)Demo start
It's strange because this is in low, very low frequency, the oscillator jitter or pcb layout problems couldn't affect the sdhc working.
When I see the function _pmgr_get_part_info() that calls read() , the last returns 6 , and internal _nio_read() instead returning 0x200 bytes read, returns 0xffffffff and the error occours again.
I already checked my oscillator and I don't have a crystal jitter.
I believe that I don't have a PCB layout problem too. It is very difficult to solve this problem.
Hi Soledad,
I agree with you, but its strange the problem occurs only determinate brand of SD Cards, following my tests:
a) My voltage it's ok, its 3.33 V without ripple.
b) About the frequency, I believe that decreasing the frequency from 25 MHz to 400 kHz could solve the problem with SanDisk brand, I did the code changes below, but without working in lower frequencies with Sandisk (Kingston, workds normally with this frequency):
esdhc.h
/* in esdhc.h */
/* ESDHC standard baud rates */
/* #define ESDHC_DEFAULT_BAUDRATE (25000000) */
#define ESDHC_DEFAULT_BAUDRATE (400000)
#define ESDHC_INIT_BAUDRATE (400000)
init_esdhc.c
const ESDHC_INIT_STRUCT _bsp_esdhc0_init = {
0, /* ESDHC device number */
400000,
BSP_SYSTEM_CLOCK /* ESDHC clock source */
};
I believe that decreasing the frequency from 25 MHz to 400 kHz could solve the problem (but didn't solve), do you agree?
For the PCB layout I did the impedance control fo the CLK, CMD, DAT0, DAT1, DAT2 and DAT3 making the trails with the same width the difference between frdm-k64 is that my custom board the trails is longer.
Is there any way to do a work around? MFS can operate using SPI or SDHC instead esdhc?
c) Following the signals of frdm-k64f and my custom board operating with default configuration at 25 MHz. This signals is the frdm-k64f with the SanDisk card and my custom board with the Kingston card. If I try to use my custom board with SanDisk card the clock signal dies.
FRDM-k64F - SDHC_CLK SIGNAL
CUSTOM Board - SDHC_CLK Signal
FRDM-K64F - DAT0 SIGNAL
CUSTOM BOARD - DAT0 SIGNAL
FRMDM-K64F - DAT1 SIGNAL
CUSTOM BOARD - DAT1 SIGNAL
FRDM-K64F - DAT2 SIGNAL
CUSTOM BOARD - DAT2 SIGNAL
FRDM-K64F - DAT3 SIGNAL
CUSTOM BOARD - DAT3 SIGNAL
FRDM-K64F CMD SIGNAL
CUSTOM BOARD - CMD SIGNAL
Do you have any suggestion?