Hello.
I am having an issue when using FATFs with a micro 4gb SDHC card and my K70 tower board.
I wrote a basic test program with the help of Erich's wonderful blog at http://mcuoneclipse.com/2012/07/30/fatfs-with-kinetis/ .
My card is preformatted to FAT32.
My program does the following:
1. ensures that a card is inserted
2. mounts the card
3. opens a file
4. writes a test string
5. closes the file
My issues occurs on the final step, and I have traced it back to the sync function hanging.
(this occurs if sync is called manually, or when it is called from the action of closing the file)
It appears to spin forever in the SD_Wait function called from the disk_ioctl function passing the CTRL_SYNC command.
This indicates that SD->Finished is not being set AND a timeout is not occurring.
If I pull the card and put it in my PC, the file is in the root directory as expected, with the test string.
Any ideas on what may be causing this hang or how to fix it ?
It is reassuring that the files exist correctly on the card, as this should indicate that the rest of the code is working okay.
Thanks,
Chandler
已解决! 转到解答。
Hi Chandler,
I have spotted the missing part: the Timeout component is not called peridically from a 10ms timer interrupt. So I have added a 10 ms timer, and called it from the Events.c:
void TI1_OnInterrupt(void)
{
TMOUT1_AddTick();
}
I have extended the post in FatFs with Kinetis | MCU on Eclipse so it is less likely to be missed.
Attached is the modified project, but I think the change is straigt forward.
If you I agree, I would like to publish that project on mcuoneclipse/Examples at master · ErichStyger/mcuoneclipse · GitHub. That way I can keep it in sync with all the other Embedded Components hosted on GitHub. Let me know if that's ok for you.
Thanks in advance!
Erich
Hi Chandler,
hard to tell without actually debugging it. One thing could be that there is a timeout somewhere (but it should not hang). The thing is that the timing is very different from one SD card to another. You might try with a different SD card.
I see if I can replicate over the week-end what you see. If you can share your project, that would give me a good starting point.
Hi Erich,
Thanks for the quick response!
Code attached.
All I can think is that I am not clocking the timer for my timeout within SD_Wait, resulting in a hang.
Looking at the sync function, specifically the disk_ioctl CTRL_SYNC call, I do not understand what purpose it serves.
The SD->Finished flag will be set and cleared by the disk_write call a few lines above it.
When the disk_ioctl CTRL_SYNC is called, it calls an empty Activate function, then enters SD_Wait.
Since the finished flag is already cleared, SD_Wait will only be able to time out.
Thanks,
Chandler
Hi Chandler,
I have spotted the missing part: the Timeout component is not called peridically from a 10ms timer interrupt. So I have added a 10 ms timer, and called it from the Events.c:
void TI1_OnInterrupt(void)
{
TMOUT1_AddTick();
}
I have extended the post in FatFs with Kinetis | MCU on Eclipse so it is less likely to be missed.
Attached is the modified project, but I think the change is straigt forward.
If you I agree, I would like to publish that project on mcuoneclipse/Examples at master · ErichStyger/mcuoneclipse · GitHub. That way I can keep it in sync with all the other Embedded Components hosted on GitHub. Let me know if that's ok for you.
Thanks in advance!
Erich
Hello Erich,
I have downloaded test for SD card which you have attached. I found that It is for CW 10.3 version. Can same test is avaliable for Keil tool ? Or how can we implement sd card test for keil tool?
My basic application is like this :
> Open file from SD card.
> Read from the file.
> Perform some mathemetical operation.
> Write output in file on SD card.
Any help from you is appreciated.
Thanks,
John.
Hi John,
you could use that project/componets posted here with Keil too (see Using Keil µVision (ARM-MDK) with Processor Expert Driver Suite | MCU on Eclipse). Download the free CodeWarrior version, open that project and copy the components into the DriverSuite. Then you can use it with Keil as outlined in this article.
Thanks Erich!
I figured it was something small like that, but then I was confused since it seemed like the sync was designed to timeout every time.
You are welcome to post that project on Git.
V/R,
Chandler