Device reset happening and i can't able to upload the code

Hello,

In my project i am using  nrf52840 with my custom board and to upload the code through NRF_CONNECT application with soft device its uploading properly but with  segger emmbedded its giving some error like this .please have look and let me know what is the problem.

after this i have add DEBUG in preprocessor definition and i got this

thank you.

  • Hello,

    thanks for the reply simonr, i will try and let know the status.

    thank you.

  • Hello Simonr,

    I have gone through the UART driver and it's not easy as i thought in the driver they mentioned the implementation flow but i am not able to implement the exact. so i have seen some other ways in the forum it's self and i have got this but still  i couldn't 

    The app_uart libraries were developed when there only existed one UART on the nRF5 series. Now we have two, so it is pretty hardcoded to only use one. 

    If you look at uart_init() -> APP_UART_FIFO_INIT() -> app_uart_init() -> nrf_drv_uart_init(), you can see that the first input parameter in nrf_drv_uart_init() is the uart instance. 

    Depending on how you want your application to work, I suggest that you (either way) add an input parameter from APP_UART_FIFO_INIT() containing the instance, so that you can call it twice, once with each instance. Then, in addition, you may want to add another instance of the fifo buffers, m_rx_fifo and m_tx_fifo in app_uart_fifo.c.

    Whether you want a separate uart_event_handler() in app_uart_fifo.c is up to you. It may be easier to use two different handlers for each of the UART instances. The callback itself doesn't contain information on what UART instance that triggered. Another option is to add a custom pointer with a parameter in the context pointer used in nrf_drv_uart_init():

    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;
        config.p_context = custom_pointer;              // THIS ONE
    
        err_code = nrf_drv_uart_init(&app_uart_inst, &config, uart_event_handler);
        VERIFY_SUCCESS(err_code);

    Whatever you pass into this p_context pointer will be present in the callback (p_context)

    static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)

    Alternatively, you can use the nrf_drv_uart_init directly from your application, and skip the app_uart_fifo library.

    so can you please try for 2 UART and send me the implementation code since i new to nordic so i need your help.

    thank you.

  • Hi

    You're getting close I think. As my colleague Edvin says in the ticket you refer to, the instance is set by the &app_uart_inst as an input parameter in the nrf_drv_uart_init(), so you need to change this slightly, so you add an input parameter from the APP_UART_FIFO_INIT() containing the instance you want to use. The instances need to be defined in your sdk_config.h as something like APP_UART0_DRIVER_INSTANCE and APP_UART1_DRIVER_INSTANCE.

    Let me know what issues you have implementing this and I'll guide you through it.

    Best regards,

    Simon

  • Hello Simonr,

    thanks for your support, As you said i have changed  APP_UART0_DRIVER_INSTANCE and APP_UART1_DRIVER_INSTANCE. in sdk_config.h file and aftrer this the config.h file look like this.

    after this i have build my ble_uart then i got new error like this,

    then again i have changed the passing INSTANCE to UART0 and UART1 and then app_uart_fifo.c look like this,

    and for next compile i have got app_uart_instance errors so i have changed to uart0 and uart1 in all functions then the app_fifo.c look like this 

    #include "sdk_common.h"
    #if NRF_MODULE_ENABLED(APP_UART)
    #include "app_uart.h"
    #include "app_fifo.h"
    #include "nrf_drv_uart.h"
    #include "nrf_assert.h"
    
    //// HERE I HAVE CHENAGED TO UART0 AND UART1 ///////////////////////////////////////////
    static nrf_drv_uart_t app_uart0_inst = NRF_DRV_UART_INSTANCE(APP_UART0_DRIVER_INSTANCE);
    static nrf_drv_uart_t app_uart1_inst = NRF_DRV_UART_INSTANCE(APP_UART1_DRIVER_INSTANCE);
    
    
    static __INLINE uint32_t fifo_length(app_fifo_t * const fifo)
    {
      uint32_t tmp = fifo->read_pos;
      return fifo->write_pos - tmp;
    }
    
    #define FIFO_LENGTH(F) fifo_length(&F)              /**< Macro to calculate length of a FIFO. */
    
    
    static app_uart_event_handler_t   m_event_handler;            /**< Event handler function. */
    static uint8_t tx_buffer[1];
    static uint8_t rx_buffer[1];
    static bool m_rx_ovf;
    
    static app_fifo_t                  m_rx_fifo;                               /**< RX FIFO buffer for storing data received on the UART until the application fetches them using app_uart_get(). */
    static app_fifo_t                  m_tx_fifo;                               /**< TX FIFO buffer for storing data to be transmitted on the UART when TXD is ready. Data is put to the buffer on using app_uart_put(). */
    
    static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
    {
        app_uart_evt_t app_uart_event;
        uint32_t err_code;
    
        switch (p_event->type)
        {
            case NRF_DRV_UART_EVT_RX_DONE:
                // If 0, then this is a RXTO event with no new bytes.
                if(p_event->data.rxtx.bytes == 0)
                {
                   // A new start RX is needed to continue to receive data
                   (void)nrf_drv_uart_rx(&app_uart0_inst, rx_buffer, 1);
                    (void)nrf_drv_uart_rx(&app_uart1_inst, rx_buffer, 1);
                   break;
                   break;
                }
    
                // Write received byte to FIFO.
                err_code = app_fifo_put(&m_rx_fifo, p_event->data.rxtx.p_data[0]);
                if (err_code != NRF_SUCCESS)
                {
                    app_uart_event.evt_type          = APP_UART_FIFO_ERROR;
                    app_uart_event.data.error_code   = err_code;
                    m_event_handler(&app_uart_event);
                }
                // Notify that there are data available.
                else if (FIFO_LENGTH(m_rx_fifo) != 0)
                {
                    app_uart_event.evt_type = APP_UART_DATA_READY;
                    m_event_handler(&app_uart_event);
                }
    
                // Start new RX if size in buffer.
                if (FIFO_LENGTH(m_rx_fifo) <= m_rx_fifo.buf_size_mask)
                {
                    (void)nrf_drv_uart_rx(&app_uart0_inst, rx_buffer, 1);
                    (void)nrf_drv_uart_rx(&app_uart1_inst, rx_buffer, 1);
                }
                else
                {
                    // Overflow in RX FIFO.
                    m_rx_ovf = true;
                }
    
                break;
    
            case NRF_DRV_UART_EVT_ERROR:
                app_uart_event.evt_type                 = APP_UART_COMMUNICATION_ERROR;
                app_uart_event.data.error_communication = p_event->data.error.error_mask;
                (void)nrf_drv_uart_rx(&app_uart0_inst, rx_buffer, 1);
                 (void)nrf_drv_uart_rx(&app_uart1_inst, rx_buffer, 1);
                m_event_handler(&app_uart_event);
                break;
    
            case NRF_DRV_UART_EVT_TX_DONE:
                // Get next byte from FIFO.
                if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
                {
                    (void)nrf_drv_uart_tx(&app_uart0_inst, tx_buffer, 1);
                     (void)nrf_drv_uart_tx(&app_uart1_inst, tx_buffer, 1);
                }
                else
                {
                    // Last byte from FIFO transmitted, notify the application.
                    app_uart_event.evt_type = APP_UART_TX_EMPTY;
                    m_event_handler(&app_uart_event);
                }
                break;
    
            default:
                break;
        }
    }
    
    
    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_uart0_inst, &config, uart_event_handler);
        VERIFY_SUCCESS(err_code);
        err_code = nrf_drv_uart_init(&app_uart1_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)
        {
            return nrf_drv_uart_rx(&app_uart0_inst, rx_buffer,1);
            return nrf_drv_uart_rx(&app_uart1_inst, rx_buffer,1);
        }
        else
        {
            return NRF_SUCCESS;
        }
    }
    
    uint32_t app_uart_flush(void)
    {
        uint32_t err_code;
    
        err_code = app_fifo_flush(&m_rx_fifo);
        VERIFY_SUCCESS(err_code);
    
        err_code = app_fifo_flush(&m_tx_fifo);
        VERIFY_SUCCESS(err_code);
    
        return NRF_SUCCESS;
    }
    
    
    uint32_t app_uart_get(uint8_t * p_byte)
    {
        ASSERT(p_byte);
        bool rx_ovf = m_rx_ovf;
    
        ret_code_t err_code =  app_fifo_get(&m_rx_fifo, p_byte);
    
        // If FIFO was full new request to receive one byte was not scheduled. Must be done here.
        if (rx_ovf)
        {
            m_rx_ovf = false;
            uint32_t uart_err_code1 = nrf_drv_uart_rx(&app_uart0_inst, rx_buffer, 1);
            uint32_t uart_err_code2 = nrf_drv_uart_rx(&app_uart1_inst, rx_buffer, 1);
    
            // RX resume should never fail.
            APP_ERROR_CHECK(uart_err_code1);
            APP_ERROR_CHECK(uart_err_code2);
        }
    
        return err_code;
    }
    
    
    uint32_t app_uart_put(uint8_t byte)
    {
        uint32_t err_code;
        err_code = app_fifo_put(&m_tx_fifo, byte);
        if (err_code == NRF_SUCCESS)
        {
            // The new byte has been added to FIFO. It will be picked up from there
            // (in 'uart_event_handler') when all preceding bytes are transmitted.
            // But if UART is not transmitting anything at the moment, we must start
            // a new transmission here.
            if (!nrf_drv_uart_tx_in_progress(&app_uart0_inst))
            {
                // This operation should be almost always successful, since we've
                // just added a byte to FIFO, but if some bigger delay occurred
                // (some heavy interrupt handler routine has been executed) since
                // that time, FIFO might be empty already.
                if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
                {
                    err_code = nrf_drv_uart_tx(&app_uart0_inst, tx_buffer, 1);
                }
            }
    
    
              if (!nrf_drv_uart_tx_in_progress(&app_uart1_inst))
            {
                // This operation should be almost always successful, since we've
                // just added a byte to FIFO, but if some bigger delay occurred
                // (some heavy interrupt handler routine has been executed) since
                // that time, FIFO might be empty already.
                if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS)
                {
                    err_code = nrf_drv_uart_tx(&app_uart1_inst, tx_buffer, 1);
                }
            }
        }
        return err_code;
    }
    
    
    uint32_t app_uart_close(void)
    {
        nrf_drv_uart_uninit(&app_uart0_inst);
        nrf_drv_uart_uninit(&app_uart1_inst);
        return NRF_SUCCESS;
    }
    #endif //NRF_MODULE_ENABLED(APP_UART)
    

    then in next compilation i got this error in nrfx_uarte.h and its look like this

    So from here onwards i don't know how to take it forward or is there any wrong that which i have followed the steps to resolving the errors, so please let me know and assist me for further steps.

    thank you. 

  • Hi

    Can you copy the build log output you see in SEGGER and upload it here as a snippet? From the first few lines we won't be able to see what the error is.

    Best regards,

    Simon

Related