Hello FreeRToS Community
I am using PSoC 6 (ARM M4 & M0+) micro-controller. I am working with PSoC Creator 4.3.
Can someone shed any light how to add to the FreeRToS+FAT library to the project so I can be able to use it? It is a very urgent matter, so any resources can be helpful.
Hello Richard.
Thanks for your reply. I have checked these links. They are very informative, however, I am currently stuck into adding the FreeRToS+FAT to the Cypress PSoC Creator 4.3 Project, so I can reuse the read/write to the SD blocks. I am connecting the SD cards using SPI.
So if I understand correctly you have the +FAT source files building, and your problem is in writing the media driver (in this case the media is the SD card).
Do you have the SPI bus working correctly outside of FreeRTOS+FAT?
What have you done so far to create the driver? I would recommend looking at other SD card drivers used in FreeRTOS+FAT to see if you can just change the SPI driver.
The FreeRToS+FAT are building without a problem, but this is handled externally. I need add this build to the PSoC Creator itself, so it can detect the library.
Carl, do I understand well that you’ve got your +FAT PSoC-63 working, and that you want to share the first draft to the FreeRTOS community?
I don’t have the hardware to try it out my self, but thank you very much.
If I my ask one thing: would you mind to split up the very long file ff_sddisk.c?
Normally ff_sddisk.c only contains the public functions that are mentioned in common/ff_sddisk.h.
Maybe you could split it up in ff_sddisk.c, sd_spi.c,spi.c, and a crc.c? That would make it much easier to read and to adopt the driver by others. Also it would be nice to put these files together in one folder.
But beside that, you’ve done a great job! I can see that it was a lot of work. SD-cards are not simple, SD/SPI cards are even more difficult to program.
I thought about that. I was trying to stick to the model that I saw in other implementations of ff_sddisk.c. Another consideration: having all the code in a single translation unit allows the compiler to do better inter-procedure optimization resulting in machine code that is faster. (And, many of those little static functions can be inlined by the compiler.) But I agree, it is unwieldy.
PSoC Creator is a strange beast. It uses “virtual folders”:
In PSoC Creator, there are two different types of folders: physical and virtual. Physical folders are created on disk by PSoC Creator as part of creating projects, Components, and devices/families/architectures. Virtual folders do not exist on disk. You can create virtual folders in your workspaces and projects to organize things as you need them, but you will not see those folders using Windows Explorer.*
So, things are nicely organized into folders in the tool, but not on disk. I have tried to fight that, but so far, it is a losing battle.
Fortunately, I was able to build on the work already done by many others. The MBED source code was a great starting point, and of course that builds on work going back to Neil Thiessen / SDFileSystem and many forks since.
Anyway, thanks for your advice. I will see what I can do to clean this up. This is one reason I wanted to share this with the community: to get input on how it can be improved.
I saw in the forum email what you were asking about common/ff_sddisk.h:
Is there a header that declares things like read & write functions?
I assume that you have found it your self: the read and write functions can be declared static. A pointer of both functions is stored in the disk object.
The two access functions have a type declaration in ff_ioman.h:
Yes it should. It has the same layering as the above functions.
Note that FF_FlushCache() is also called internaly in the library at the end of some API’s, notably FF_Close().
Suppose that your device wants to reboot, it is enough to close all file handles that have write permission. FF_SDDiskFlush() doesn’t need to be called.
I’m looking at hooking up an interrupt to the Card Detect switch, and trying to come up with a functional specification. I’m thinking along these lines (pseudo code):
Interrupt_Handler() {
if (pxDisk->xStatus.bIsInitialised) {
if (FF_SDDiskDetect(pxDisk) & !pxDisk->xStatus.bIsMounted)
FF_SDDiskMount(pxDisk);
if (!FF_SDDiskDetect(pxDisk) & pxDisk->xStatus.bIsMounted)
FF_SDDiskUnmount(pxDisk);
}
}
Do I need to worry about FF_FS_Add() & FF_FS_Remove()?
BTW, does FF_SDDiskInit() normally do an implicit mount (if possible)?
How does this (in FreeRTOSFATConfig.h) play into it?
/* Set to 1 if the media is removable (such as a memory card).
Set to 0 if the media is not removable.
When set to 1 all file handles will be "invalidated" if the media is
extracted. If set to 0 then file handles will not be invalidated.
In that case the user will have to confirm that the media is still present
before every access. */
#define ffconfigREMOVABLE_MEDIA 1
How does FreeRTOS + FAT know when the media is extracted?
For now, I decided to only act on card removal, not insertion, with this as the interrupt handler:
if (pxDisk->xStatus.bIsInitialised) {
sd_lock(pSD);
if (!sd_card_detect(pSD)) {
if (pxDisk->xStatus.bIsMounted) {
FF_Invalidate(pxDisk->pxIOManager);
FF_Unmount(pxDisk);
pxDisk->xStatus.bIsMounted = pdFALSE;
if (pxDisk->pxIOManager)
FF_DeleteIOManager(pxDisk->pxIOManager);
sd_deinit(pSD);
pxDisk->xStatus.bIsInitialised = pdFALSE;
}
}
sd_unlock(pSD);
}
Despite this comment in FreeRTOSFATConfig.h:
When set to 1 all file handles will be "invalidated" if the media is
extracted. If set to 0 then file handles will not be invalidated.
In that case the user will have to confirm that the media is still present
before every access. */
#define ffconfigREMOVABLE_MEDIA 1
it seems to be left up to the application to call FF_Invalidate(pxDisk->pxIOManager);
Personally, I like the memory cards to be soldered into the boards. Removable cards cause too many problems with the electrical contacts: think of corrosion and little insects.
But if you have a device with a removable SD-card, I recommend to define ffconfigREMOVABLE_MEDIA and check constantly for the presence of the card.
Removal and insertion will cause an interrupt. Let the interrupt only wake-up a task, and let the task call FF_Invalidate() when necessary.