Doubts in UARTE configuration

Dear Nordic fellows,

I have a NRF52832 and I want to configure the UARTE peripheral driver in not blocking mode. I want to try and exploit the double buffered DMA. I'm using nRF5_SDK17.1.0

I read the documentation but find it sparse.

This is part of my code:

#define BLE_UARTE_RXD_BUFF_SIZE 22

static nrfx_uarte_t uarteInstance;
static uint8_t bleUarteDriverRxBuff[BLE_UARTE_RXD_BUFF_SIZE] = {0};
static uint8_t bleUarteDriverSecondaryRxBuff[BLE_UARTE_RXD_BUFF_SIZE] = {
    0};

static uint8_t bleUarteRxBuff[BLE_UARTE_RX_BUFF_SIZE] = {0};
static uint16_t bleUarteRxBuffWrIdx = 0;

void ble_uarte_init(const nrfx_uarte_event_handler_t event_handler)
{
    nrfx_err_t errorCode;

    uarteInstance = (nrfx_uarte_t)NRFX_UARTE_INSTANCE(0);

    const nrfx_uarte_config_t configUarte = {BLE_UARTE_TXD_PIN_NUMBER,
                                             BLE_UARTE_RXD_PIN_NUMBER,
                                             BLE_UARTE_CTS_PIN_NUMBER,
                                             BLE_UARTE_RTS_PIN_NUMBER,
                                             NULL,
                                             BLE_UARTE_HWFC,
                                             BLE_UARTE_PARITY,
                                             BLE_UARTE_BAUDRATE,
                                             BLE_UARTE_IRQ_PRIORITY};

    errorCode = nrfx_uarte_init(&uarteInstance, &configUarte, event_handler);
    APP_ERROR_CHECK(errorCode);

    /* Set main buffer */
    nrfx_uarte_rx(&uarteInstance, bleUarteDriverRxBuff, BLE_UARTE_RXD_BUFF_SIZE);
    APP_ERROR_CHECK(errorCode);

    /* Set secondary buffer */
    nrfx_uarte_rx(&uarteInstance, bleUarteDriverSecondaryRxBuff, BLE_UARTE_RXD_BUFF_SIZE);
    APP_ERROR_CHECK(errorCode);
}

uint32_t ble_uarte_get(nrfx_uarte_event_t *pUarteEvt)
{
    nrfx_err_t errorCode = NRF_SUCCESS;

    if (pUarteEvt->data.rxtx.bytes)
    {
        memcpy(&bleUarteRxBuff[bleUarteRxBuffWrIdx], pUarteEvt->data.rxtx.p_data, BLE_UARTE_RXD_BUFF_SIZE);

        bleUarteRxBuffWrIdx = bleUarteRxBuffWrIdx + 22;

        if (bleUarteRxBuffWrIdx == BLE_UARTE_RX_BUFF_SIZE)
        {
            bleUarteRxBuffWrIdx = 0;
        }
    }
    else
    {
        errorCode = NRF_ERROR_NOT_FOUND;
    }
    return errorCode;
}

void ble_uarte_event_handler(nrfx_uarte_event_t const *pUarteEvt, void *pContext)
{
    switch (pUarteEvt->type)
    {
    case NRFX_UARTE_EVT_RX_DONE:
        if (ble_uarte_get(pUarteEvt) == NRF_SUCCESS)
        {
            test_send_eco();
        }

        // Call to nrfx_uarte_rx(...)??

        break;

    case NRFX_UARTE_EVT_TX_DONE:
        break;

    case NRFX_UARTE_EVT_ERROR:
        APP_ERROR_HANDLER(pUarteEvt->data.error);
        break;

    default:
        break;
    }
}

Q1. The third parameter of nrfx_uarte_rx(...) is the length of the buffer I want to set? (Line 31)

Q2. Is it necessary to call nrfx_uarte_rx(...) after processing every 22 bytes received ? If so, with which parameters? One for main and one for secondary buffer? (Line 71)

Q3. The correct way to process the received that is to read pUarteEvt->data.rxtx.p_data when received an NRFX_UARTE_EVT_RX_DONE event? (Line 45)

If you have any further pointers or could clarify the usage of double buffering on RX transfers that would be great!

Thanks in advance,

Fernando.

Parents Reply Children
No Data
Related