This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM2434: uart RX is not working in callback mode

Part Number: AM2434

I am trying to send the 8bytes of data using terminal to AM243x, so i configured UART1 read using callback function. When I try to send data every 20ms no bytes received, and no callback function triggered checked using the print statement inside callback function.  I have attached the files for your referenceappUart.c appTask.c  But when i config blocking mode i could see the data received.
I am using ethernet adapter demo sdk 9.2.00.24
In EI_APP_TASK_main uart init is invoked. in appuart.c EI_APP_UART_rx_task used for rx task and Uart_PCB_Rx_callback function used for rx callback.
using A12 /B12 for uart configimage.png 

  • and no callback function triggered checked using the print statement inside callback function. 

    Are you using DebugP_log statements inside ISR? If yes, DebugP_log statements does not work within ISR context.

    Regards,

    Tushar

  • I have removed debug log in ISR and used separate print function by enabling flag in ISR. But I see only first time data bytes were received after that no data received. any wrong in the re arming?

  • I have removed debug log in ISR and used separate print function by enabling flag in ISR. But I see only first time data bytes were received after that no data received

    This is correct approach. Can you please share the code where you are performing the UART send and receive functionality?

    Regards,

    Tushar

  • here is the TX from another MCU(Renesas)


    void main(void)
    {
    uint8_t data_transmit[8]={0xAA,0x55,0x11,0x01,0x53,0x22,0x44,0x48};
    R_Config_SCI5_Create();
    R_Config_SCI5_Start();

    while (1)
    {
    R_Config_SCI5_Serial_Send(data_transmit, 8);

    R_BSP_SoftwareDelay(400, BSP_DELAY_MILLISECS);
    }
    }

    receiver function

    1) added new struct for my appl uart (uartRxTi)
    typedef struct APP_SParams
    {
    APP_SApplication_t application;
    APP_SHwal_t hwal;
    APP_SLwip_t lwip;
    APP_SCip_t cip;
    APP_SAdapter_t adapter;
    EI_APP_NV_SInit_t nv; /* Initialization parameters of non-volatile memory */
    EI_APP_UART_SInit_t uart; /* Initialization parameters of UART */
    EI_APP_UART_SInit_t uartRxTi; /* Initialization parameters of rx-Ti UART */
    EI_APP_LED_SInit_t led; /* Initialization parameters of LED's */
    EI_APP_CFG_SInit_t config; /* Initialization parameters of non-volatile configuration data */
    CUST_DRIVERS_SInit_t customDrivers;
    APP_SAcd_t acd;

    #if (defined CPU_LOAD_MONITOR) && (1==CPU_LOAD_MONITOR) || ((defined UART_CPU_LOAD_MONITOR) && (UART_CPU_LOAD_MONITOR==1))
    CMN_CPU_API_SParams_t cpuLoad;
    #endif
    #if (defined CPU_LOAD_MONITOR) && (1==CPU_LOAD_MONITOR)
    APP_WEBSRV_SParams_t webServer;
    #endif

    }APP_SParams_t;


    2)invoked both uarts in void EI_APP_TASK_main(void* pvTaskArg_p)

    void EI_APP_TASK_main(void* pvTaskArg_p)
    {
    uint32_t err = OSAL_NO_ERROR;
    int16_t resetServiceFlag = 0;

    APP_SInstance_t* pAppInstance = (APP_SInstance_t*) pvTaskArg_p;


    CMN_BOARD_init();

    if(EI_APP_MUTEX_eERR_NOERROR != EI_APP_Mutex_init())
    {
    //Fatal error
    return;
    }

    CUST_DRIVERS_init(&pAppInstance->config.customDrivers);

    EI_APP_UART_init(&pAppInstance->config.uart);
    EI_APP_UART_init(&pAppInstance->config.uartRxTi);

    3) here is the modified EI_APP_Uart and EI_APP_UART_init definition

    typedef struct EI_APP_Uart {
    UART_Handle handle;
    uint32_t instance;
    void* uartTaskHandle;
    char aOutStream[APP_UART_BUFFER_SIZE];
    UART_Transaction transaction;
    void* uartSignal;
    uint32_t uartWritePos;
    uint32_t uartReadPos;
    bool isInitialized;

    /* --- ADD: RX support for PCB UART(1) --- */
    uint8_t rxByte[8]; /* persistent 1-byte RX buffer */
    UART_Transaction rxTransaction; /* persistent RX transaction */
    uint8_t aInStream[APP_UART_BUFFER_SIZE]; /* RX store */
    uint32_t rxWritePos;
    uint32_t rxReadPos;

    } EI_APP_Uart_t;

    uint32_t EI_APP_UART_init(const EI_APP_UART_SInit_t* pParams)
    {
    uint32_t result = OSAL_GENERAL_ERROR;
    uint32_t idx = pParams->uartInst;
    if(idx < APP_UART_MAX_INSTANCES && FALSE == EI_APP_uart_s[idx].isInitialized)
    {
    EI_APP_uart_s[idx].instance = idx;
    if(idx == UART_PCB_INSTANCE)
    {
    g_uartPcb = &EI_APP_uart_s[idx];
    }
    else if(idx == UART_DBG_INSTANCE)
    {
    g_uartDbg = &EI_APP_uart_s[idx];
    }
    DebugP_log("UART INIT idx=%d\r\n", idx);
    EI_APP_uart_s[idx].handle = EI_APP_UART_getHandle(idx);
    char signalName[16];
    snprintf(signalName, sizeof(signalName), "uartSignal_%u", idx);
    EI_APP_uart_s[idx].uartSignal = OSAL_createSignal(signalName);
    EI_APP_uart_s[idx].uartWritePos = 0;
    EI_APP_uart_s[idx].uartReadPos = 0;
    if((NULL == EI_APP_uart_s[idx].handle) || (NULL == EI_APP_uart_s[idx].uartSignal))
    {
    result = OSAL_UART_DRV_HANDLE_INVALID;
    goto laError;
    }
    char taskName[16];
    snprintf(taskName, sizeof(taskName), "uart_task_%u", idx);
    // Start TX/print task for all instances
    EI_APP_uart_s[idx].uartTaskHandle = OSAL_SCHED_startTask(
    EI_APP_UART_task,
    (void *)&EI_APP_uart_s[idx],
    pParams->taskPrio,
    NULL,
    APP_UART_TASK_STACK_SIZE,
    OSAL_OS_START_TASK_FLG_NONE,
    taskName);

    if (idx == 1U)
    {
    char rxTaskName[20];
    snprintf(rxTaskName, sizeof(rxTaskName), "uart_rx_task_%u", idx);

    OSAL_SCHED_startTask(
    EI_APP_UART_rx_task,
    (void *)&EI_APP_uart_s[idx],
    pParams->taskPrio,
    NULL,
    APP_UART_TASK_STACK_SIZE,
    OSAL_OS_START_TASK_FLG_NONE,
    rxTaskName);
    }

    if(NULL == EI_APP_uart_s[idx].uartTaskHandle)
    {
    result = OSAL_GENERAL_ERROR;
    goto laError;
    }

    EI_APP_uart_s[idx].isInitialized = TRUE;

    /* --- ADD: RX init ONLY for PCB UART instance 1 --- */
    if (idx == 1U) {
    EI_APP_uart_s[idx].rxWritePos = 0U;
    EI_APP_uart_s[idx].rxReadPos = 0U;
    memset(EI_APP_uart_s[idx].aInStream, 0, sizeof(EI_APP_uart_s[idx].aInStream));

    UART_Transaction_init(&EI_APP_uart_s[idx].rxTransaction);
    EI_APP_uart_s[idx].rxTransaction.buf = &EI_APP_uart_s[idx].rxByte[0]; /* 1-byte persistent buffer */
    EI_APP_uart_s[idx].rxTransaction.count = 8U; /* Partial mode: per byte */
    EI_APP_uart_s[idx].rxTransaction.args = NULL;
    EI_APP_uart_s[idx].rxTransaction.timeout = SystemP_WAIT_FOREVER; /* harmless in callback mode */
    int32_t u_status =UART_read(EI_APP_uart_s[idx].handle, &EI_APP_uart_s[idx].rxTransaction);
    DebugP_log("status=%d count=%u\r\n",
    u_status,
    EI_APP_uart_s[idx].rxTransaction.count);
    }

    result = OSAL_NO_ERROR;
    }

    laError:
    return result;
    }

    4) here is the rx task EI_APP_UART_rx_task

    static void EI_APP_UART_rx_task(void *arg)
    {

    while (1)
    {
    EI_APP_UART_parse_rx();
    static uint32_t lastCbCount = 0;

    if(lastCbCount != g_cbCount)
    {
    DebugP_log("CB Count=%u Fail=%u\r\n",
    g_cbCount,
    g_rearmFail);

    lastCbCount = g_cbCount;
    }
    if(callback_fired==1)
    {
    DebugP_log("callback fired");
    callback_fired =0;
    }
    OSAL_SCHED_yield();

    }

    }

    5) here is the rx callback

    void Uart_PCB_Rx_callback(UART_Handle handle, UART_Transaction *t)
    {
    EI_APP_Uart_t *u = &EI_APP_uart_s[1];
    if (!u->isInitialized)
    {
    return;}

    if (t->status == UART_TRANSFER_STATUS_SUCCESS && t->count > 0U)
    {
    uint8_t *src = (uint8_t *)t->buf;
    DebugP_log("Callback fired: %d bytes\r\n", t->count);
    for (uint32_t i = 0; i < t->count; i++)
    {
    uint32_t next = (u->rxWritePos + 1U) % APP_UART_BUFFER_SIZE;

    if (next != u->rxReadPos)
    {
    u->aInStream[u->rxWritePos] = src[i];
    u->rxWritePos = next;
    }
    else
    {
    break; // overflow
    }
    }
    }

    // White check mark RESTART RX HERE ONLY
    UART_Transaction_init(t);
    t->buf = &u->rxByte[0];
    t->count = 1;
    t->timeout = SystemP_WAIT_FOREVER;
    (void)UART_read(handle, t);
    }

  • Are you using UART with DMA enabled? Please note there was an Jira filed for similar issue. Please refer https://sir.ext.ti.com/jira/browse/EXT_SITMPUSW-116 

    Regards,

    Tushar

  • No I am not using DMA .

  • Hi,

    I reviewed the above code and it looks like you are calling the UART_read() from the callback itself. This is not recommended and is not supposed to work.

    Regards,

    Tushar