cancel
Showing results for 
Search instead for 
Did you mean: 

Use UART DMA with X-CUBE-CELLULAR

SL61
Associate II

Hi everyone,

I am using X-CUBE-CELLULAR v6.0 and would like to use DMA on UART to replace the original interrupt receiving method.

The original method is calling IPC_RXFIFO_writeCharacter() in HAL_UART_RxCpltCallback() and notify upper layer when an end of message is received.

Seems I need to modify the functions above and the codes below in ATCoreTaskBody() to receive a block of UART bytes and parse them in ATCoreTaskBody()

      if (msg == (SIG_IPC_MSG))
      {
        /* retrieve message from IPC */
        if (IPC_receive(&ipcHandleTab, &msgFromIPC) == IPC_ERROR)
        {
          TRACE_DBG("IPC receive error")
          ATParser_abort_request(&at_context);
          TRACE_DBG("**** Sema Released on error 1 *****")
          (void) rtosalSemaphoreRelease(s_WaitAnswer_SemaphoreId);
          /* skip this loop iteration */
          continue;
        }
 
        /* one message has been read */
        IRQ_DISABLE();
        MsgReceived--;
        IRQ_ENABLE();
 
        /* Parse the response */
#if (USE_PARSING_MUTEX == 1)
        (void)rtosalMutexAcquire(ATCore_ParsingMutexHandle, RTOSAL_WAIT_FOREVER);
#endif /* USE_PARSING_MUTEX == 1 */
        action = ATParser_parse_rsp(&at_context, &msgFromIPC);
#if (USE_PARSING_MUTEX == 1)
        (void)rtosalMutexRelease(ATCore_ParsingMutexHandle);
#endif /* USE_PARSING_MUTEX == 1 */
 
        /* analyze the response (check data mode flag) */
        action = analyze_action_result(action);
 
        /* add this action to action flags only if this kind of action will be treated later */
        if ((action == ATACTION_RSP_FRC_END)
            || (action == ATACTION_RSP_FRC_CONTINUE)
            || (action == ATACTION_RSP_ERROR))
        {
          at_context.action_flags |= action;
          TRACE_DBG("add action 0x%x (flags=0x%x)", action, at_context.action_flags)
        }
        if (action == ATACTION_RSP_ERROR)
        {
          TRACE_ERR("AT_sendcmd error")
          ATParser_abort_request(&at_context);
          TRACE_DBG("**** Sema Released on error 2 *****")
          (void) rtosalSemaphoreRelease(s_WaitAnswer_SemaphoreId);
          continue;
        }
 
        /* check if this is an URC to forward */
        if (action == ATACTION_RSP_URC_FORWARDED)
        {
          /* notify user with callback */
          if (register_URC_callback != NULL)
          {
            /* get URC response buffer */
            do
            {
              (void) memset((void *) urc_buf, 0, ATCMD_MAX_BUF_SIZE);
              retUrc = ATParser_get_urc(&at_context, urc_buf);
              if ((retUrc == ATSTATUS_OK) || (retUrc == ATSTATUS_OK_PENDING_URC))
              {
                /* call the URC callback */
                (* register_URC_callback)(urc_buf);
              }
            } while (retUrc == ATSTATUS_OK_PENDING_URC);
          }
        }
        else if ((action == ATACTION_RSP_FRC_CONTINUE) ||
                 (action == ATACTION_RSP_FRC_END) ||
                 (action == ATACTION_RSP_ERROR))
        {
          TRACE_DBG("**** Sema released *****")
          (void) rtosalSemaphoreRelease(s_WaitAnswer_SemaphoreId);
        }
        else
        {
          /* nothing to do */
        }
      }

Any suggestion is welcome.

Best,

Sean

0 REPLIES 0