Hello ,
I just got an assert() error with my project (which use KL17Z256 with KSDKv2 and FreeRTOS).
I need to deal with a GSM module. LPUART0 peripheral is used for this task.
And sometime, an assert() error occurred and the __assert_func() reported me this message in my terminal :
ASSERT ERROR " ev == 0 ": file "../drivers/fsl_lpuart_freertos.c" Line "278" function name "LPUART_RTOS_Receive"
The " ev " pointed by assert seem to be the returned value of xEventGroupClearBits() where the event bit RTOS_UART_COMPLET is cleared before doing a non blocking receive transfer (see code at the end, line 41). Also, jumping into the assert function loop the MCU forever (see code below).
#elif(defined(__GNUC__))
void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
{
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func);
for (;;)
{
__asm("bkpt #0");
}
}
#endif
#endif
*assert function loop forever the MCU when occurred
I commented the assert function in fsl_freertos_lpuart.c file and it solved the problem but I believe this asserting have its own reason to be there. So maybe I should not do that.... (?)
So the questions are :
- Why asserting occurred during LPUART_RTOS_Receive() ?
- Why the return value of xEventGroupClearBits() should never be equal to zeros in this case ?
int LPUART_RTOS_Receive(lpuart_rtos_handle_t *handle, uint8_t *buffer, uint32_t length, size_t *received)
{
EventBits_t ev;
size_t n = 0;
int retval = kStatus_Success;
if (NULL == handle->base)
{
return kStatus_Fail;
}
if (0 == length)
{
if (received != NULL)
{
*received = n;
}
return 0;
}
if (NULL == buffer)
{
return kStatus_InvalidArgument;
}
if (pdFALSE == xSemaphoreTake(handle->rx_sem, portMAX_DELAY))
{
return kStatus_Fail;
}
handle->rx_xfer.data = buffer;
handle->rx_xfer.dataSize = (uint32_t)length;
ev = xEventGroupClearBits(handle->rx_event, RTOS_UART_COMPLETE);
assert(ev == 0);
LPUART_TransferReceiveNonBlocking(handle->base, handle->t_state, &handle->rx_xfer, &n);
if (n < length)
{
ev = xEventGroupWaitBits(handle->rx_event, RTOS_UART_COMPLETE, pdTRUE, pdFALSE, portMAX_DELAY);
if (ev & RTOS_UART_COMPLETE)
{
n = length;
}
else
{
retval = kStatus_Fail;
}
}
if (pdFALSE == xSemaphoreGive(handle->rx_sem))
{
retval = kStatus_Fail;
}
if (received != NULL)
{
*received = n;
}
return retval;
}