Board: FRDM-K66F. SDK: 2.11.0 (541 2022-01-14)
I'm using the SD library to read and write files to an SD card.
I'm using "baremetal" instead of an RTOS; I mention this because the definition for KOSA_StatusIdle says:
KOSA_StatusIdle = MAKE_STATUS(kStatusGroup_OSA, 3), /*!< Used for bare metal only, the wait object is not ready and timeout still not occur */
My program is trying to f_opendir(), after verifying that the card exists, successful calls to f_mount(), and f_chdrive(), and it's hanging in this function:
status_t SDMMC_OSAEventWait(void *eventHandle, uint32_t eventType, uint32_t timeoutMilliseconds, uint32_t *event)
{
assert(eventHandle != NULL);
osa_status_t status = KOSA_StatusError;
#if defined(SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE) && SDMMC_OSA_POLLING_EVENT_BY_SEMPHORE
while (true)
{
status = OSA_SemaphoreWait(&(((sdmmc_osa_event_t *)eventHandle)->handle), timeoutMilliseconds);
if (KOSA_StatusTimeout == status)
{
break;
}
if (KOSA_StatusSuccess == status)
{
(void)SDMMC_OSAEventGet(eventHandle, eventType, event);
if ((*event & eventType) != 0U)
{
return kStatus_Success;
}
}
}
#endif
return kStatus_Fail;
}
This while() loop never exits because "timeoutMilliseconds" never decreases - the value passed in is a define: SDMMCHOST_TRANSFER_COMPLETE_TIMEOUT, rather than a variable - which might eventually lead to a time out, and the loop condition doesn't check for KOSA_StatusIdle. Before the point at which the program hangs, the semaphore is evidently properly created and removed: I've followed the semaphore value as it's increased and decreased in the Expression panel. However, at some point, OSA_SemaphorePost() is no longer called, so semCount isn't increased, and OSA_SemaphoreWait() just keeps returning KOSA_StatusIdle.
Here's the call stack when it's stuck in this loop:
Thread #1 57005 (Suspended : Breakpoint)
OSA_SemaphoreWait() at fsl_os_abstraction_bm.c:584 0x616e
SDMMC_OSAEventWait() at fsl_sdmmc_osa.c:69 0x3268
SDMMCHOST_TransferFunction() at fsl_sdmmc_host.c:299 0x8524
SD_SendScr() at fsl_sd.c:814 0x16e0
sdcard_init() at fsl_sd.c:2,033 0x2cbe
SD_CardInit() at fsl_sd.c:2,085 0x2d96
SD_Init() at fsl_sd.c:2,268 0x307a
sd_disk_initialize() at fsl_sd_disk.c:145 0x374c
disk_initialize() at diskio.c:117 0x87ba
mount_volume() at ff.c:3,376 0x3c02
f_opendir() at ff.c:4,544 0x953c
prepareSDForWrite() at MK66F18_Van_Gizmo_v02.c:340 0xa9a
measureAccelerometer() at MK66F18_Van_Gizmo_v02.c:353 0xaee
main() at MK66F18_Van_Gizmo_v02.c:416 0xc8c
How can I get either the timeout value to decrease, while time is physically passing, or get the semaphore count increased so the loop continues to work properly until f_opendir() completes?
Also, here's a shot of the g_sd variable, at the time it enters the endless loop: