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

Confusion between drv_inst_idx and inst_idx in UART?

I'm trying to enable the UART module. The function calls follow:

    nrf_init -> nrf_drv_uart_init -> nrfx_uart_init

Here we see that nrfx_uart_init() is called with

    result = nrfx_uart_init(&p_instance->uart, │ rx_secondary_buffer_length = 0,
      (nrfx_uart_config_t const *)&config, │ tx_counter = 0,
      event_handler ? uart_evt_handler : NULL);

With nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0); Note that in this macro inst_idx is set to 0. However, later on this field is not used, but uart->drv_inst_idx.

In nrfx_uart_init the id for p_instance->drv_inst_idx is not 0 however.

    uart_control_block_t * p_cb = &m_cb[p_instance->drv_inst_idx];

This means that not m_cb[0] is used, but something irrelevant (it's here a CONCAT3 resulting in NRFX_UART0_INST_IDX). Is it not the idea to use?

    uart_control_block_t * p_cb = &m_cb[*(int*)p_config->p_context];

Why else is inst_idx first placed into the p_context field?

Parents
  • Hi,

    drv_inst_idx should always be zero on the 52832 because there's only one UART. The index tells the driver which control block element (see uart_control_block_t) and what registers to use. The driver is written this way so it can support multiple UART instances on other HW like the 52840.

    Can you clarify what you mean by this : "Why else is inst_idx first placed into the p_context field"? p_context is a member of the control block structure, and is not related to the index value.

  • Turned out that I had the following p_instance.

    (gdb) print *p_instance

    Reading 20 bytes @ address 0x20002444
    $2 = {
      inst_idx = 0 '\000',
      uarte = {
        p_reg = 0x40002000,
        drv_inst_idx = 0 '\000'
      },
      uart = {
        p_reg = 0x38521 <__gnu_cxx::__verbose_terminate_handler()>,
        drv_inst_idx = 49 '1'
      }
    }

    Apparently both UARTE and UART were enabled from two different config files. Removing UARTE and it works perfectly. Thanks!

Reply
  • Turned out that I had the following p_instance.

    (gdb) print *p_instance

    Reading 20 bytes @ address 0x20002444
    $2 = {
      inst_idx = 0 '\000',
      uarte = {
        p_reg = 0x40002000,
        drv_inst_idx = 0 '\000'
      },
      uart = {
        p_reg = 0x38521 <__gnu_cxx::__verbose_terminate_handler()>,
        drv_inst_idx = 49 '1'
      }
    }

    Apparently both UARTE and UART were enabled from two different config files. Removing UARTE and it works perfectly. Thanks!

Children
No Data
Related