This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Part Number: CC3220
I utilized the example fatsd in the CC3220 SDK to interface with a FAT formatted SD card. I did not see an example of determining that the SD card is inserted.
Is there a way to determine that an SD card is inserted while only using the 3 pins provided for SDHost in the TI Pin Mux Tool?
Hi Michael,
Thanks for that information! I'm well aware of the SD card detection pin, unfortunately in the project I am working on we are very much pin constrained. I was asking what would be the best means of polling the SD card interface in the case of only having the SD host pins (i.e. no SD card detection GPIO)?
Looking at the source code in the fatsd example I did not see a means for detecting the SD card is available without the detection pin.
--Ryan
Thanks Michael,
I originally assumed that functionality. Unfortunately I do not see that with the SDFatFS_open() function. When running my driver with the following code:
static int32_t THRD_MountSD(void) { if (true == gbIsMounted) { return ERROR_SD_CARD_ALREADY_MOUNTED; } gFatFSHandle = SDFatFS_open(Board_SD_CARD, FAT_FS_DRIVE_NUM); if (NULL == gFatFSHandle) { return ERROR_SD_CARD_FAILED_TO_MOUNT; } gbIsMounted = true; return ERROR_OK; }
gFatFSHandle is non-NULL when there is no SD card present in the socket. Why do you think that the driver is not returning NULL when there is no SD card present?
I am using:
I think I may have found why the function does not return NULL. The call of f_mount() in SDFatFS.c looks like this:
SDFatFS_Handle SDFatFS_open(uint_least8_t idx, uint_least8_t drive) { uintptr_t key; DRESULT dresult; FRESULT fresult; TCHAR path[3]; SDFatFS_Handle handle = NULL; SDFatFS_Object *obj; /* Verify driver index and state */ if (isInitialized && (idx < SDFatFS_count)) { /* Get handle for this driver instance */ handle = (SDFatFS_Handle)&(SDFatFS_config[idx]); obj = handle->object; /* Determine if the device was already opened */ key = HwiP_disable(); if (obj->driveNum != DRIVE_NOT_MOUNTED) { HwiP_restore(key); DebugP_log1("SDFatFS Drive %d already in use!", obj->driveNum); handle = NULL; } else { obj->driveNum = drive; /* Open SD Driver */ obj->sdHandle = SD_open(idx, NULL); HwiP_restore(key); if (obj->sdHandle == NULL) { obj->driveNum = DRIVE_NOT_MOUNTED; /* Error occurred in lower level driver */ handle = NULL; } else { /* Register FATFS Functions */ dresult = disk_register(obj->driveNum, SDFatFS_diskInitialize, SDFatFS_diskStatus, SDFatFS_diskRead, SDFatFS_diskWrite, SDFatFS_diskIOctrl); /* Check for drive errors */ if (dresult != RES_OK) { DebugP_log0("SDFatFS: Disk functions not registered"); SDFatFS_close(handle); handle = NULL; } else { /* Construct base directory path */ path[0] = (TCHAR)'0' + obj->driveNum; path[1] = (TCHAR)':'; path[2] = (TCHAR)'\0'; /* * Register the filesystem with FatFs. This operation does * not access the SDCard yet. */ fresult = f_mount(&(obj->filesystem), path, 0); if (fresult != FR_OK) { DebugP_log1("SDFatFS: Drive %d not mounted", obj->driveNum); SDFatFS_close(handle); handle = NULL; } else { /* * Store the new sdfatfs handle for the input drive * number */ sdFatFSHandles[obj->driveNum] = handle; DebugP_log0("SDFatFS: opened"); } } } } } return (handle); }
The opt parameter being passed into f_mount() is 0. This specifies to not mount the SD card immediately. Is this the expected outcome?
--Ryan
Hi Ryan,
Good catch with the SD card driver. It looks like on the CC3220 the driver will not attempt to mount the SD card immediately. In order to get the desired behavior I described in my previous post, you'll need to make some slight tweaks to the SDFatFs driver. Specifically, you'll want to change the code around the f_mount() call in SdFatFS_open() so that it not only attempts to mount the card immediately, but also speculatively saves the current SD card handle to the global sfFatFSHandles object so that the fatfs library has the correct pointers to the hardware peripheral functions needed. Please modify SDFatFs.c like so:
sdFatFSHandles[obj->driveNum] = handle; fresult = f_mount(&(obj->filesystem), path, 1); if (fresult != FR_OK) { DebugP_log1("SDFatFS: Drive %d not mounted", obj->driveNum); sdFatFSHandles[obj->driveNum] = NULL; SDFatFS_close(handle); handle = NULL; }
That should get the behavior you want when you poll with SDFatFS_open(). Let me know if that doesn't work or you need more help.
Regards,
Michael