cancel
Showing results for 
Search instead for 
Did you mean: 

How to get defines in (*.C) recognized in *.h when MX places defines in the *.c rather than the *.h.

BEppe.1
Associate II

I have a program which uses interrupts, but these are in a separate *_it.c file and not in the main.c. So given that MX places all defines, queue, thread, etc in the main.c rather than the main.h how am I supposed to give another file visibility to the item(s)?

I already made the drastic mistake of setting up the *.h file with the information from the *.C, but on the next "Generate Code" everything I did is gone then recognition of the items are gone and I'm back to square 1.

I have setup a queue and in the interrupt plan on sending a message via the queue to the main task. I hate to make everything global so all the files can see them, but I'm at the point where this is the only option I see to get this task done. Since the Queue is only visible to the main.c the queue will not work in the interrupt file. :(

Any suggestions would be appreciated.

void EXTI1_IRQHandler(void)
{
  /* USER CODE BEGIN EXTI1_IRQn 0 */
	SystemQueue_t	SystemQueue;
 
	SystemQueue.Message = eMsgBumperFront; <- Error given the file cannot see the typedef enum in the  main.c file
	SystemQueue.Data1 = NULL;
	SystemQueue.Data2 = NULL;
	
	/* Post the byte. */
  xQueueSendFromISR( SystemQueueHandle, ( void * ) &SystemQueue, ( TickType_t ) 10 );
	                ^ the handle for the queue as well
  /* USER CODE END EXTI1_IRQn 0 */
  HAL_GPIO_EXTI_IRQHandler(BUMPER_FRONT_IN_Pin);
  /* USER CODE BEGIN EXTI1_IRQn 1 */
 
  /* USER CODE END EXTI1_IRQn 1 */
}

1 REPLY 1
TDK
Guru

Declare them as extern in the file you want to use them in, or in a header file that it includes. There should be a user code section at the top to do so which will remain unchanged on regenerating the code.

If you feel a post has answered your question, please click "Accept as Solution".