Hi,
I am working with GPS module and Freertos. The microcontroller is STM32F4 and I have done the configuration using CubeMX software for freertos.
The GPS outputs NMEA sentences for every 1 sec on UART3 and I have written my routine in ISR that receives the continuous stream of characters.
I have start character $ and end character \n. I am looking for this sentence.
$GPGGA,080339.00,1732.61630,N,07821.15740,E,2,08,1.65,584.6,M,-73.8,M,0000*74
I am storing this sentence into a buffer. My task is to send this buffer from ISR to task using Queue.
How to do this exactly.
How to allocate size for queue.
Queue01Handle = xQueueCreate(1,100); /* Create a queue */
How much size I have to create for my message as I will get GPS data for every one second of different size.
$GPGGA,080339.00,1732.61630,N,07821.15740,E,2,08,1.65,584.6,M,-73.8,M,0000*74
This is my ISR Routine
void HAL_UART_RxCpltCallback(UART_HandleTypeDef huart)
{
/ Prevent unused argument(s) compilation warning */
UNUSED(huart);
/*Process the UART */
/*
Clear the pending interrupt
*/
int txStatus = 0;
char *pGpsSentence;
BaseType_t xHigherPriorityTaskWoken;
switch((uint32_t)huart->Instance)
{
case (uint32_t)USART2 :
break;
case (uint32_t)USART3 :
if(GpsUart.RxCount >= 1024)//Overflow judgment
{
GpsUart.RxCount = 0;
memset(GpsUart.RxBuffer,0x00,sizeof(GpsUart.RxBuffer));
HAL_UART_Transmit(&huartSerial, (uint8_t *)&cAlmStr, sizeof(cAlmStr),0xFFFF);
}
else
{
switch(GpsUart.RxFrameState)
{
case UART_FRAME_IDLE :
pGpsSentence = (char *)&GpsUart.RxBuffer;
memset(GpsUart.RxBuffer,0x00,sizeof(GpsUart.RxBuffer));
if((GpsUart.RxByte == GpsUart.RxStartByte1) || (GpsUart.RxByte == GpsUart.RxStartByte2))
{
GpsUart.RxCount = 0;
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsUart.RxByte;
GpsUart.RxFrameState = UART_FRAME_START;
}
else
{
GpsUart.RxFrameState = UART_FRAME_START;
}
break;
case UART_FRAME_START :
if((GpsUart.RxByte == GpsUart.RxEndByte1) || (GpsUart.RxByte == GpsUart.RxEndByte2))
{
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsUart.RxByte;
GpsUart.RxFrameState = UART_FRAME_READY;
txStatus = xQueueSendFromISR(Queue01Handle, &pGpsSentence, &xHigherPriorityTaskWoken);
if (0 == txStatus)
{
}
else
{
// portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);
}
}
else
{
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsUart.RxByte;
}
break;
default :
GpsUart.RxFrameState = UART_FRAME_IDLE;
break;
}
}
}
HAL_UART_Receive_IT(&huartGps, (uint8_t *)&GpsUart.RxByte, 1); //Restart receive interrupt
}
This is my receiver task
void Receiver1_Task(void argument)
{
/ USER CODE BEGIN Receiver1_Task */
BaseType_t xHigherPriorityTaskWoken;
char *pGpsRxSentence ;
int RxStatus = 0;
pGpsRxSentence = NULL;
/* Infinite loop */
for(;;)
{
if(pdTRUE == xQueueReceiveFromISR(Queue01Handle,&pGpsRxSentence,&xHigherPriorityTaskWoken))
{
// osMutexWait(Mutex01_PrintfHandle,1000);
// printf("%s\r\n",pGpsRxSentence);
// osMutexRelease(Mutex01_PrintfHandle);
}
else
{
/* osMutexWait(Mutex01_PrintfHandle,1000);
printf("No data\r\n ");
osMutexRelease(Mutex01_PrintfHandle); */
}
/*GpsSync();*/
osDelay(1);
}
/* USER CODE END Receiver1_Task */
}
But when I run this I am going to Hard fault handler.