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); }
/**@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; }
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; } }
/** * 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); }
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); }
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; }