2025-02-25 5:11 PM
Hello,
I'm using AzRTOS with threadX and FileX. I have a thread with msg_queue that monitors the SD_Detect pin. The code works properly, I detect the card insertion/removal process. The problem is I need to re-initialize the SDMCC hardware so it can read the parameters off the SD card before I can mount the media. I tried calling MX_SDMMC1_SD_Init() which is defined in the main.c file, but the compiler says MX_SDMMC1_SD_Init is an undefined reference.
app_filex.c has an include "main.h" at the beginning.
in "main.h" I defined the routine:
/* USER CODE BEGIN EFP */
void GetDateTime(void);
static void MX_SDMMC1_SD_Init(void);
/* USER CODE END EFP */
in app_filex.c:
/* check if we received the correct event message */
syslog(SYSLOG_NOTIF, "SD Card received queued event");
if (r_msg == CARD_STATUS_CHANGED) {
r_msg = 0; /* reset the status */
/* for debouncing purpose we wait a bit till it settles down */
tx_thread_sleep(TX_TIMER_TICKS_PER_SECOND / 1);
if (SD_IsDetected(FX_STM32_SD_INSTANCE) == HAL_OK) {
/* We have a valid SD insertion event, start processing.. */
syslog(SYSLOG_NOTIF, "SD Card Inserted");
last_status = CARD_STATUS_CONNECTED; /* Update last known status */
MX_SDMMC1_SD_Init(); /* re-initialize SD card - get params from card */
if (media_status == MEDIA_CLOSED) {
sd_status = fx_media_open(&sdio_disk, FX_SD_VOLUME_NAME,
fx_stm32_sd_driver, (VOID *)FX_NULL,
(VOID *) fx_sd_media_memory, sizeof(fx_sd_media_memory));
if (sd_status != FX_SUCCESS) { /* Check the media open sd_status */
syslog(SYSLOG_CRITICAL,"SD Card Unable to open media [0x04x]", sd_status);
//Error_Handler(); /* Create error, call error handler. */
}
media_status = MEDIA_OPENED;
}
break;
} else {
syslog(SYSLOG_NOTIF,"SD Card Removed\r\n");
last_status = CARD_STATUS_DISCONNECTED; /* Update last known status */
media_status = MEDIA_CLOSED; /* force media closed */
}
} else {
syslog(SYSLOG_CRITICAL,"SD Card unknown event received [0x08lx]", r_msg);
}
There is something I'm not understanding with static routines. Can they be called from Threads? Why isn't the compiler finding this routine?
thanks
Matthew
Solved! Go to Solution.
2025-02-25 6:24 PM
The static function limits the scope of the function. Since this static function is auto generated by CubeMX, i had to create a separate function.
void SD_Init() {
MX_SDMMC1_SD_Init();
}
not an elegant solution, but it works with CubeMX code.
2025-02-25 6:24 PM
The static function limits the scope of the function. Since this static function is auto generated by CubeMX, i had to create a separate function.
void SD_Init() {
MX_SDMMC1_SD_Init();
}
not an elegant solution, but it works with CubeMX code.