Hello,
I am working with S32K146 and see a issue with UART when we run for long time.
I see the UART ISR running very frequently(System view), and please let me know if I did any mistake in initialization.
Do I need to clear ISR flags in call back function in case Error?
Why the UART ISR running very frequently?
Please give any example code to work with UART using interrupts and call back function.
I have give UART ISR priority is 14. Does bigger number has high priority?
Call back
------------
static void uart_callback(void *driver_state, uart_event_t event, void *user_data)
{
(void) driver_state;
(void) user_data;
if(event == UART_EVENT_RX_FULL){
OS_MAILBOX_Put1(&g_uart_rx_mb, (char*)g_uart_rx_buf);
LPUART_DRV_SetRxBuffer(INST_UART0, g_uart_rx_buf, 1);
}
}
Init
-----------
/*! uart0 configuration structure */
const lpuart_user_config_t uart0_InitConfig0 = {
.transferType = LPUART_USING_INTERRUPTS,
.baudRate = 115200U,
.parityMode = LPUART_PARITY_DISABLED,
.stopBitCount = LPUART_ONE_STOP_BIT,
.bitCountPerChar = LPUART_8_BITS_PER_CHAR,
.rxDMAChannel = 0U,
.txDMAChannel = 0U,
};
typedef enum
{
UART_IRQ_PRIO = 14u,
FLEXCAN_IRQ_PRIO = 10,
SPI2_IRQ_PRIO = 9u,
QCA_IRQ_PRIO = 9u,
FTM_IRQ_PRIO = 8u
} interrupt_priorities_t;
void uart_init()
{
OS_MAILBOX_Create(&g_uart_rx_mb, 1, UART_RX_MB_BUFFER_SIZE, g_uart_rx_mb_buffer);
OS_QUEUE_Create(&g_uart_uds_queue, &g_uart_qu_buffer, sizeof(g_uart_qu_buffer));
OS_MUTEX_Create(&g_uart_tx_mutex);
INT_SYS_SetPriority(s_lpuartRxTxIrqId[INST_UART0], UART_IRQ_PRIO);
LPUART_DRV_Init(INST_UART0, &uart0_State, &uart0_InitConfig0);
LPUART_DRV_InstallRxCallback(INST_UART0, uart_callback, NULL);
debug_log_print(LL_DEV, MOD_UART, "Init OK\n");
}
In task
-------------
rb_init(&g_uart_rx_rb, g_uart_rx_rb_data, UART_RX_RB_SIZE);
status_t rx_status = STATUS_SUCCESS;
do{
OS_Delay(10);
rx_status = LPUART_DRV_ReceiveData(INST_UART0, g_uart_rx_buf, 1);
}while(rx_status != STATUS_SUCCESS);
debug_log_print(LL_DEV, MOD_UART, "RX Receiving Started\n");
while(1)
{
uart_set_diagnosis_mode();
uint32_t bytes_remaining = 0;
status_t s = LPUART_DRV_GetReceiveStatus(INST_UART0, &bytes_remaining);
if(s != STATUS_BUSY){
debug_log_print(LL_ERR, MOD_UART, "RX Failed with code %i\n", s);
s = LPUART_DRV_ReceiveData(INST_UART0, g_uart_rx_buf, 1);
debug_log_print(LL_INFO, MOD_UART, "RX Restarted with code %i\n", s);
}
uint8_t data = 0;
if(OS_MAILBOX_GetTimed1(&g_uart_rx_mb, (char*) &data, UART_RX_IDLE_TO) != 0)
continue;
Thanks,
Sai
@dianabatrlova @Robin_Shen