cancel
Showing results for 
Search instead for 
Did you mean: 

Static C functions called from a thread in azrtos

matt-crc
Senior

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); }
View more

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

1 ACCEPTED SOLUTION

Accepted Solutions
matt-crc
Senior

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.

View solution in original post

2 REPLIES 2
matt-crc
Senior

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.

You shouldn't have to do that.

Try using the option to have CubeMX generate the initialisation functions in separate files:

AndrewNeil_0-1740567680031.png

That way, the initialisation functions will not be static.

 

Note that there's also an option to have CubeMX not generate a call to the initialisation function - so that you can call it yourself wherever & whenever you like:

AndrewNeil_1-1740567856178.png

 

PS:

There's also an option to make the functions static or not:

AndrewNeil_0-1740568494061.png

(this seems to be ignored when generating separate files)