HimaxWiseEyePlus / Seeed_Grove_Vision_AI_Module_V2

https://www.himax.com.tw/products/wiseeye-ai-sensing/wiseeye2-ai-processor/
MIT License
46 stars 23 forks source link

Receive multiple data buffers over UART using interrupts #38

Closed epibaikas closed 4 weeks ago

epibaikas commented 1 month ago

Hi, I am trying to receive data over the UART0 peripheral through interrupts. I am following example 4 (Usage-4) from the hx_drx_uart.h header file.

I would like the uart_dma_rx_cb() interrupt service routine to be triggered every time the rx_buffer becomes full with new data. However, with the example code, the callback function is triggered only the first time that the rx_buffer becomes full. Therefore, I believe that it is necessary to somehow lower the flag that is raised for the interrupt so that the callback may be triggered again.

What changes could I make to accomplisht that?

Here is my current code:

Global variables

uint32_t g_datasize = 0;
volatile  uint8_t rbuffer[8];
DEV_UART_PTR dev_uart_ptr;
DEV_BUFFER rx_buffer;

Main function:

int app_main(void)
{
    printf("Init UART...\r\n");
    // Initialize UART 0
    hx_drv_uart_init(USE_DW_UART_0, HX_UART0_BASE);

    uint32_t data_size = 8;

    memset(rbuffer, 0x00, data_size);
    g_datasize = data_size;
    rx_buffer.buf = (void *)rbuffer;
    rx_buffer.len = g_datasize;

    dev_uart_ptr = hx_drv_uart_get_dev(USE_DW_UART_0);
    dev_uart_ptr->uart_open(UART_BAUDRATE_921600);
    dev_uart_ptr->uart_control(UART_CMD_SET_RXCB,  (UART_CTRL_PARAM)uart_dma_rx_cb);
    dev_uart_ptr->uart_control(UART_CMD_SET_RXINT_BUF, (UART_CTRL_PARAM)&rx_buffer);
    dev_uart_ptr->uart_control(UART_CMD_SET_RXINT, (UART_CTRL_PARAM)1);

    while(1) {
        printf("Hello\r\n");
    };

    return 0;
}

Callback function:

void uart_dma_rx_cb(void)
{
    int i;
    xprintf("Transfer : RX Done\r\n");
    xprintf("Data Received: \r\n");
    for (i = 0; i < g_datasize; i++)
        printf("0x%02x,", rbuffer[i]);
    memset(rbuffer, 0x00, g_datasize);
}

The uart_pinmux_cfg() function that I call from pinmux_init() is:

void uart_pinmux_cfg()
{
   // UART0 pin mux configuration
   hx_drv_scu_set_PB0_pinmux(SCU_PB0_PINMUX_UART0_RX_1, 1);
   hx_drv_scu_set_PB1_pinmux(SCU_PB1_PINMUX_UART0_TX_1, 1);
}
stevehuang82 commented 1 month ago

Hi @epibaikas,

Sorry we didn't explain clearly how to use uart API. After receiving UART data, UART RX should be enabled again to receive incoming data. You can modify the uart_dma_rx_cb() function as follows.

void uart_dma_rx_cb(void)
{
    int i;
    xprintf("Transfer : RX Done\r\n");
    xprintf("Data Received: \r\n");
    for (i = 0; i < g_datasize; i++)
        xprintf("0x%02x,", rbuffer[i]);
    memset(rbuffer, 0x00, g_datasize);
    dev_uart_ptr->uart_control(UART_CMD_SET_RXINT_BUF, (UART_CTRL_PARAM)&rx_buffer);
    dev_uart_ptr->uart_control(UART_CMD_SET_RXINT, (UART_CTRL_PARAM)1);
}