Issue with serial interrupt with FreeRTOS

savindra wrote on Friday, May 13, 2016:

Hello,

I am using renesas RX62N platform.
My application is as below :
I have a task that is running at 50ms and it is sending serial data to a slave device.Slave device is giving response after receiving this serial data. I have setup a interrupt service routine with priority level 5 in renesas platform.
My ISR is receving each byte and putting it into RAM buffer when buffer exceed 21 byte then i am giving a semaphore to my task(50 ms task) to use that buffer data.

Apart from i have two more task and two more pheripheral ISR.
Please help me to know if i am missing anything to configure pheripheral ISR with FreeRTOS.

My code is running for some seconds and after that it is giving below exception:
void Excep_BRK(void){ wait(); }

Below the code:

My ISR :

void MMT_AppCallBack(void)
{
    static signed portBASE_TYPE xHigherPriorityTaskWoken;
    /// Declare error flag
    bool err = true;

    /// Configure the SCI receive interrupt
    err &=    R_SCI_Receive
              (
              2,
              PDL_NO_DATA,
              &gucRxBuffer,
              1,
              MMT_AppCallBack,
              PDL_NO_DATA
              );
			  
	/// Halt in while loop when RPDL errors detecte
    while (!err);
	
			  
	xHigherPriorityTaskWoken = pdFALSE;

    /// Unblock the task by releasing the semaphore
    xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken );
	  
    /// If xHigherPriorityTaskWoken was set to true you
    ///we should yield.  The actual macro used here is
    ///port specific
    portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
			 	
}///end MMT_AppCallBack

My Task:

void vModbusMaster_Task( void *pvParameters )
{
	uint8_t gucTxBuffer[8];
    uint8_t ucSlaveID ;
	uint8_t ucFunctionCode;
	uint16_t usStartAddress;
	uint16_t usRegisterCount;
	uint16_t usQueryCrc;
	uint16_t usCrc;
    uint16_t usResponseCrc;
	
	ucSlaveID = 1;
	ucFunctionCode =4;
	usStartAddress = 1;
	usRegisterCount = 8;
	
	gucTxBuffer[0] = ucSlaveID;
	gucTxBuffer[1] = ucFunctionCode;
	gucTxBuffer[2] = ((usStartAddress >> 8) & 0xFF);
	gucTxBuffer[3] = ((usStartAddress ) & 0xFF);
	gucTxBuffer[4] = ((usRegisterCount >> 8) & 0xFF);
	gucTxBuffer[5] = ((usRegisterCount ) & 0xFF);
		
	( void ) pvParameters;
	portTickType xNextWakeTime;
	/// Initialise xNextWakeTime - this only needs to be done once
	xNextWakeTime = xTaskGetTickCount();
	///intialise modbus master
	MMT_Init();
	
	/// We are using the semaphore for synchronisation so we create a binary
    ///semaphore rather than a mutex.  We must make sure that the interrupt
    ///does not attempt to use the semaphore before it is created.
    xSemaphore = xSemaphoreCreateBinary();

	
	for( ;; )
	{
		
		/// Place this task in the blocked state until it is time to run again 
		///The block state is specified in ticks, the constant used converts ticks to ms
		vTaskDelayUntil( &xNextWakeTime, configMODBUS_MASTER_FREQUENCY_50MS );

		usQueryCrc = MMT_CRC16(gucTxBuffer,6);

		gucTxBuffer[6] = (usQueryCrc & 0xFF);
		gucTxBuffer[7] = ((usQueryCrc >> 8)&0xFF);
					
	    /// Send modbus rtu query
        R_SCI_Send
                 (
                 2,
                 PDL_NO_DATA,
                 gucTxBuffer,
                 8,
                 PDL_NO_FUNC
				 );
                 

       ///  Block waiting for the semaphore to become available
        if( xSemaphoreTake( xSemaphore, 1 / portTICK_RATE_MS ) == pdTRUE )
        {
		///do this work				  			
		}
           

            /// We have finished our task.  Return to the top of the loop where
            ///we will block on the semaphore until it is time to execute
            ///again.  Note when using the semaphore for synchronisation with an
            ///ISR in this manner there is no need to 'give' the semaphore back.
        }	 
			
	}
	
}///end vModbusMaster_Task

rtel wrote on Friday, May 13, 2016:

We can’t comment on chip specifics (reading and writing to the UART), only on the use of FreeRTOS.

The first thing you need to determine is how you are getting into the Excep_BRK(void){ wait(); } statement. Is this a fault exception handler, or an unpopulated interrupt handler.

Which compiler are you using? Have you followed the guidelines on the documentation page (on the FreeRTOS.org website) for your port with regards to writing interrupt service routines?

Have you ensured the priority of the ISR is at or below the configMAX_SYSCALL_INTERRUPT_PRIORITY setting?