Пример #1
0
/**@brief Function for UART initialization.
 */
static uint32_t uart_init(app_uart_stream_comm_params_t * p_comm_params)
{
    if (p_comm_params->baud_rate > UART_BAUD_RATE_115200)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;

    config.pselrxd = p_comm_params->rx_pin_no;
    config.pseltxd = p_comm_params->tx_pin_no;
    config.baudrate = (nrf_uart_baudrate_t) m_baud_rates[p_comm_params->baud_rate];
    config.hwfc = NRF_UART_HWFC_DISABLED;
    config.parity = NRF_UART_PARITY_EXCLUDED;

    nrf_drv_uart_uninit();
    uint32_t err_code = nrf_drv_uart_init(&config, NULL);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }
    nrf_drv_uart_rx_enable();

    m_iterations_next_byte_max = m_iteration[p_comm_params->baud_rate];

    return NRF_SUCCESS;
}
Пример #2
0
uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
                       app_uart_buffers_t           * p_buffers,
                       app_uart_event_handler_t       event_handler,
                       app_irq_priority_t             irq_priority)
{
    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = (nrf_uart_baudrate_t)p_comm_params->baud_rate;
    config.hwfc = (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
    config.interrupt_priority = irq_priority;
    config.parity = p_comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
    config.pselcts = p_comm_params->cts_pin_no;
    config.pselrts = p_comm_params->rts_pin_no;
    config.pselrxd = p_comm_params->rx_pin_no;
    config.pseltxd = p_comm_params->tx_pin_no;

    m_event_handler = event_handler;

    rx_done = false;

    uint32_t err_code = nrf_drv_uart_init(&app_uart_inst, &config, uart_event_handler);
    VERIFY_SUCCESS(err_code);

    // Turn on receiver if RX pin is connected
    if (p_comm_params->rx_pin_no != UART_PIN_DISCONNECTED)
    {
        return nrf_drv_uart_rx(&app_uart_inst, rx_buffer,1);
    }
    else
    {
        return NRF_SUCCESS;
    }
}
Пример #3
0
uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
                       app_uart_buffers_t           * p_buffers,
                       app_uart_event_handler_t       event_handler,
                       app_irq_priority_t             irq_priority)
{
    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = (nrf_uart_baudrate_t)p_comm_params->baud_rate;
    config.hwfc = (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
    config.interrupt_priority = irq_priority;
    config.parity = p_comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
    config.pselcts = p_comm_params->cts_pin_no;
    config.pselrts = p_comm_params->rts_pin_no;
    config.pselrxd = p_comm_params->rx_pin_no;
    config.pseltxd = p_comm_params->tx_pin_no;

    m_event_handler = event_handler;

    rx_done = false;

    if (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_LOW_POWER)
    {
        return NRF_ERROR_NOT_SUPPORTED;
    }

    uint32_t err_code = nrf_drv_uart_init(&config, uart_event_handler);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    nrf_drv_uart_rx_enable();
    return nrf_drv_uart_rx(rx_buffer,1);
}
Пример #4
0
uint32_t ser_phy_hci_slip_open(ser_phy_hci_slip_event_handler_t events_handler)
{
    uint32_t err_code;

    if (events_handler == NULL)
    {
        return NRF_ERROR_NULL;
    }

    // Check if function was not called before.
    if (m_ser_phy_hci_slip_event_handler != NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    m_ser_phy_hci_slip_event_handler = events_handler;

    err_code = nrf_drv_uart_init(&m_uart, &m_uart_config, uart_event_handler);
    if (err_code != NRF_SUCCESS)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    ser_phy_hci_slip_reset();

    APP_ERROR_CHECK(nrf_drv_uart_rx(&m_uart, m_rx_buf, 1));

    return NRF_SUCCESS;
}
Пример #5
0
uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
                             app_uart_buffers_t *     p_buffers,
                             app_uart_event_handler_t event_handler,
                             app_irq_priority_t       irq_priority)
{
    uint32_t err_code;

    m_event_handler = event_handler;

    if (p_buffers == NULL)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    // Configure buffer RX buffer.
    err_code = app_fifo_init(&m_rx_fifo, p_buffers->rx_buf, p_buffers->rx_buf_size);
    VERIFY_SUCCESS(err_code);

    // Configure buffer TX buffer.
    err_code = app_fifo_init(&m_tx_fifo, p_buffers->tx_buf, p_buffers->tx_buf_size);
    VERIFY_SUCCESS(err_code);

    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = (nrf_uart_baudrate_t)p_comm_params->baud_rate;
    config.hwfc = (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
    config.interrupt_priority = irq_priority;
    config.parity = p_comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
    config.pselcts = p_comm_params->cts_pin_no;
    config.pselrts = p_comm_params->rts_pin_no;
    config.pselrxd = p_comm_params->rx_pin_no;
    config.pseltxd = p_comm_params->tx_pin_no;

    err_code = nrf_drv_uart_init(&app_uart_inst, &config, uart_event_handler);
    VERIFY_SUCCESS(err_code);
    m_rx_ovf = false;

    // Turn on receiver if RX pin is connected
    if (p_comm_params->rx_pin_no != UART_PIN_DISCONNECTED)
    {
#ifdef UARTE_PRESENT
        if (!config.use_easy_dma)
#endif
        {
            nrf_drv_uart_rx_enable(&app_uart_inst);
        }

        return nrf_drv_uart_rx(&app_uart_inst, rx_buffer,1);
    }
    else
    {
        return NRF_SUCCESS;
    }
}
Пример #6
0
/**
 * Initialize the RS232 port.
 *
 */
void
uart0_init(unsigned long ubr)
{
  nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
  ret_code_t retcode = nrf_drv_uart_init(&config, uart_event_handler);
  APP_ERROR_CHECK(retcode);

  ringbuf_init(&txbuf, txbuf_data, sizeof(txbuf_data));

  nrf_drv_uart_rx_enable();
  nrf_drv_uart_rx(rx_buffer, 1);
}
Пример #7
0
static void uart_init(bool async_mode)
{
    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.pseltxd  = NRF_LOG_BACKEND_UART_TX_PIN;
    config.pselrxd  = NRF_UART_PSEL_DISCONNECTED;
    config.pselcts  = NRF_UART_PSEL_DISCONNECTED;
    config.pselrts  = NRF_UART_PSEL_DISCONNECTED;
    config.baudrate = (nrf_uart_baudrate_t)NRF_LOG_BACKEND_UART_BAUDRATE;
    ret_code_t err_code = nrf_drv_uart_init(&m_uart, &config, async_mode ? uart_evt_handler : NULL);
    APP_ERROR_CHECK(err_code);

    m_async_mode = async_mode;
}
uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
                             app_uart_buffers_t *     p_buffers,
                             app_uart_event_handler_t event_handler,
                             app_irq_priority_t       irq_priority)
{
    uint32_t err_code;

    m_event_handler = event_handler;

    if (p_buffers == NULL)
    {
        return NRF_ERROR_INVALID_PARAM;
    }

    // Configure buffer RX buffer.
    err_code = app_fifo_init(&m_rx_fifo, p_buffers->rx_buf, p_buffers->rx_buf_size);
    if (err_code != NRF_SUCCESS)
    {
        // Propagate error code.
        return err_code;
    }

    // Configure buffer TX buffer.
    err_code = app_fifo_init(&m_tx_fifo, p_buffers->tx_buf, p_buffers->tx_buf_size);
    if (err_code != NRF_SUCCESS)
    {
        // Propagate error code.
        return err_code;
    }

    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = (nrf_uart_baudrate_t)p_comm_params->baud_rate;
    config.hwfc = (p_comm_params->flow_control == APP_UART_FLOW_CONTROL_DISABLED) ?
            NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
    config.interrupt_priority = irq_priority;
    config.parity = p_comm_params->use_parity ? NRF_UART_PARITY_INCLUDED : NRF_UART_PARITY_EXCLUDED;
    config.pselcts = p_comm_params->cts_pin_no;
    config.pselrts = p_comm_params->rts_pin_no;
    config.pselrxd = p_comm_params->rx_pin_no;
    config.pseltxd = p_comm_params->tx_pin_no;

    err_code = nrf_drv_uart_init(&config, uart_event_handler);

    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    nrf_drv_uart_rx_enable();
    return nrf_drv_uart_rx(rx_buffer,1);
}
Пример #9
0
/*====================================================================================================*/
void Serial_Config( void )
{
  nrf_drv_uart_config_t uart_init_struct = {0};

  uart_init_struct.pseltxd            = UART0_CONFIG_PSEL_TXD;
  uart_init_struct.pselrxd            = UART0_CONFIG_PSEL_RXD;
  uart_init_struct.pselcts            = UART0_CONFIG_PSEL_CTS;
  uart_init_struct.pselrts            = UART0_CONFIG_PSEL_RTS;
  uart_init_struct.p_context          = NULL;
  uart_init_struct.hwfc               = UART0_CONFIG_HWFC;
  uart_init_struct.parity             = UART0_CONFIG_PARITY;
  uart_init_struct.baudrate           = UART0_CONFIG_BAUDRATE;
  uart_init_struct.interrupt_priority = UART0_CONFIG_IRQ_PRIORITY;
//  uart_init_struct.use_easy_dma       = UART0_CONFIG_USE_EASY_DMA;
  nrf_drv_uart_init(&uart_init_struct, NULL);
}
Пример #10
0
uint32_t serial_dfu_transport_init(void)
{
    uint32_t err_code;

    leds_init();

    m_dfu.slip.p_buffer         = m_dfu.recv_buffer;
    m_dfu.slip.current_index    = 0;
    m_dfu.slip.buffer_len       = sizeof(m_dfu.recv_buffer);
    m_dfu.slip.state            = SLIP_STATE_DECODING;

    nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;

    uart_config.pseltxd            = TX_PIN_NUMBER;
    uart_config.pselrxd            = RX_PIN_NUMBER;
    uart_config.pselcts            = CTS_PIN_NUMBER;
    uart_config.pselrts            = RTS_PIN_NUMBER;
    uart_config.hwfc               = NRF_UART_HWFC_ENABLED;
    uart_config.p_context          = &m_dfu;


    nrf_drv_uart_t instance =  NRF_DRV_UART_INSTANCE(0);
    memcpy(&m_dfu.uart_instance, &instance, sizeof(instance));

    err_code =  nrf_drv_uart_init(&m_dfu.uart_instance,
                                  &uart_config,
                                  uart_event_handler);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("Failed initializing uart\n");
        return err_code;
    }

    nrf_drv_uart_rx_enable(&m_dfu.uart_instance);

    err_code = nrf_drv_uart_rx(&m_dfu.uart_instance, &m_dfu.uart_buffer, 1);
    if (err_code != NRF_SUCCESS)
    {
        NRF_LOG_ERROR("Failed initializing rx\n");
    }

    NRF_LOG_DEBUG("UART initialized\n");

    return err_code;
}
Пример #11
0
uint8_t QS_onStartup(void const *arg) {
    static uint8_t qsBuf[512]; /* buffer for Quantum Spy */

    (void)arg; /* avoid the "unused parameter" compiler warning */
    QS_initBuf(qsBuf, sizeof(qsBuf));

    //QS_tickTime_ = Timer1_period; /* to start the timestamp at zero */

    nrf_drv_uart_config_t config = NRF_DRV_UART_DEFAULT_CONFIG;
    config.baudrate = NRF_UART_BAUDRATE_1000000;
    uint32_t err_code = nrf_drv_uart_init(&config, uart_event_handler);
    APP_ERROR_CHECK(err_code);

    /* setup the QS filters... */
    QS_FILTER_ON(TRACE_SDK_EVT);
    QS_FILTER_ON(TRACE_ADV_EVT);
    QS_FILTER_ON(TRACE_BLE_EVT);
    QS_FILTER_ON(TRACE_DM_EVT);
    QS_FILTER_ON(TRACE_PEER_EVT);
    QS_FILTER_ON(TRACE_SEC_EVT);
    QS_FILTER_ON(TRACE_ANCS_EVT);

    return (uint8_t)1; /* return success */
}
Пример #12
0
/**
 *  @brief Initialise serial port
 */
void debug_init()
{
    /* Initialise debugging port */
    nrf_drv_uart_config_t uartconfig = NRF_DRV_UART_DEFAULT_CONFIG;
    nrf_drv_uart_init(&uartconfig, NULL);
}
Пример #13
0
void uart_init()
{
    uint32_t errCode;
    errCode = nrf_drv_uart_init(NULL, NULL);
    APP_ERROR_CHECK(errCode);
}