This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

app_uart_put() before NVIC_SystemReset()

Hi,

I'm trying to send out 3 bytes just before I reset the chip. I am using nRF51, SD 130 1.0 and SDK v10.0.0. UART works well in other parts of code.

My original solution was:

    app_uart_put(0x01);
	app_uart_put(0x02);
	app_uart_put(0x03);
	
	app_uart_flush();	
	NVIC_SystemReset();

but I only see 0x01 sent out. So the reset must be happening too fast. I tried multiple versions of above snippet, trying to send out all bytes before reset, but none works. This one is very hardcore and I really have no explanation why I see only first byte, but not others:

    app_uart_put(0x01);
	nrf_delay_ms(1);
	app_uart_put(0x02);
	nrf_delay_ms(1);
	app_uart_put(0x03);
	nrf_delay_ms(1);
	
	app_uart_flush();
	
	nrf_delay_ms(500);		
	NVIC_SystemReset();

What is happening here? How can I send out three bytes via UART before reset?

Parents
  • I don't think I should get overflow because I am already using app_fifo:

    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())
            {
                // 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(tx_buffer, 1);
            }
        }
    	
        return err_code;
    }
    

    And even with your solution (while) only first byte gets transmitted. I use 115200 baudrate and I tried with longer pauses (5s).

    What did work is to start the timer in-place of NVIC_SystemReset() and then calling reset from there but it seems like an overkill.

Reply
  • I don't think I should get overflow because I am already using app_fifo:

    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())
            {
                // 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(tx_buffer, 1);
            }
        }
    	
        return err_code;
    }
    

    And even with your solution (while) only first byte gets transmitted. I use 115200 baudrate and I tried with longer pauses (5s).

    What did work is to start the timer in-place of NVIC_SystemReset() and then calling reset from there but it seems like an overkill.

Children
No Data
Related