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

Is there an easy way to do printf by UART in mesh sdk 2.2?

I tried to use the code from nRF5_SDK_15.0.0_a53641a, but the compiler keep complaining can't find head files ( seems not possible without  changing sdk 15 files )

So, Is there an easy way?

Parents
  • Hi,

    The easy way is to use the files from SDK 15.x.0 in your project. Did you include the path to the header files in your project?

    Which exact errors are you getting when compiling?

    Best regards,
    Jørgen

  • There is a lot of dependencies in the NRF_LOG module. If you only need simple UART, I would recommend using the app_uart library that you found. You can use the UART example as a reference when adding the library to your application.

  • Hi, Jorgen,

    I tried your way but it's still complicate to solve the dependencies without changing the head files..

    So I made it simpler, as below:

    config part:

    void uarte_config(NRF_UARTE_Type * p_uarte,
    nrfx_uarte_config_t const * p_config)
    {
    if (p_config->pseltxd != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_pin_set(p_config->pseltxd);
    nrf_gpio_cfg_output(p_config->pseltxd);
    }
    if (p_config->pselrxd != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
    }

    nrf_uarte_baudrate_set(p_uarte, p_config->baudrate);
    nrf_uarte_configure(p_uarte, p_config->parity, p_config->hwfc);
    nrf_uarte_txrx_pins_set(p_uarte, p_config->pseltxd, p_config->pselrxd);
    if (p_config->hwfc == NRF_UARTE_HWFC_ENABLED)
    {
    if (p_config->pselcts != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_cfg_input(p_config->pselcts, NRF_GPIO_PIN_NOPULL);
    }
    if (p_config->pselrts != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_pin_set(p_config->pselrts);
    nrf_gpio_cfg_output(p_config->pselrts);
    }
    nrf_uarte_hwfc_pins_set(p_uarte, p_config->pselrts, p_config->pselcts);
    }
    /*
    nrf_uarte_int_enable(p_uarte, UARTE_INT_MASK);
    NVIC_SetPriority(UARTE0_UART0_IRQn, p_config->interrupt_priority);
    NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
    NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    */
    nrf_uarte_enable(p_uarte);
    }

    action part:

    void uarte_tx(NRF_UARTE_Type * p_reg, uint8_t * p_data, size_t len)
    {
    p_reg->TXD.PTR = (uint32_t)p_data;
    p_reg->TXD.MAXCNT = len;
    p_reg->TASKS_STARTTX = 0x1UL;
    }

    I don't want to use interrupts by now so that part is commented,  Looks good, but it don't work..

    Anything I missed?

  • Hi, awneil,

    here's the code:

    void uarte_config(NRF_UARTE_Type * p_uarte,
    nrfx_uarte_config_t const * p_config)
    {
    if (p_config->pseltxd != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_pin_set(p_config->pseltxd);
    nrf_gpio_cfg_output(p_config->pseltxd);
    }
    if (p_config->pselrxd != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_cfg_input(p_config->pselrxd, NRF_GPIO_PIN_NOPULL);
    }
    
    nrf_uarte_baudrate_set(p_uarte, p_config->baudrate);
    nrf_uarte_configure(p_uarte, p_config->parity, p_config->hwfc);
    nrf_uarte_txrx_pins_set(p_uarte, p_config->pseltxd, p_config->pselrxd);
    if (p_config->hwfc == NRF_UARTE_HWFC_ENABLED)
    {
    if (p_config->pselcts != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_cfg_input(p_config->pselcts, NRF_GPIO_PIN_NOPULL);
    }
    if (p_config->pselrts != NRF_UARTE_PSEL_DISCONNECTED)
    {
    nrf_gpio_pin_set(p_config->pselrts);
    nrf_gpio_cfg_output(p_config->pselrts);
    }
    nrf_uarte_hwfc_pins_set(p_uarte, p_config->pselrts, p_config->pselcts);
    }
    /*
    nrf_uarte_int_enable(p_uarte, UARTE_INT_MASK);
    NVIC_SetPriority(UARTE0_UART0_IRQn, p_config->interrupt_priority);
    NVIC_ClearPendingIRQ(UARTE0_UART0_IRQn);
    NVIC_EnableIRQ(UARTE0_UART0_IRQn);
    */
    nrf_uarte_enable(p_uarte);
    }
    
    void uarte_tx(NRF_UARTE_Type * p_reg, uint8_t * p_data, size_t len)
    {
    p_reg->TXD.PTR = (uint32_t)p_data;
    p_reg->TXD.MAXCNT = len;
    p_reg->TASKS_STARTTX = 0x1UL;
    }

  • By the way, here's the config I used:

    #define NRF_UARTE_DEFAULT_CONFIG                                             \
    {                                                                            \
        .pseltxd            = TX_PIN_NUMBER,                                     \
        .pselrxd            = NRF_UART_PSEL_DISCONNECTED,                        \
        .pselcts            = NRF_UART_PSEL_DISCONNECTED,                        \
        .pselrts            = NRF_UART_PSEL_DISCONNECTED,                        \
        .p_context          = NULL,                                              \
        .hwfc               = (nrf_uart_hwfc_t)UART_DEFAULT_CONFIG_HWFC,         \
        .parity             = (nrf_uart_parity_t)UART_DEFAULT_CONFIG_PARITY,     \
        .baudrate           = NRF_UART_BAUDRATE_115200,                          \
        .interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY,                  \
    }

Reply
  • By the way, here's the config I used:

    #define NRF_UARTE_DEFAULT_CONFIG                                             \
    {                                                                            \
        .pseltxd            = TX_PIN_NUMBER,                                     \
        .pselrxd            = NRF_UART_PSEL_DISCONNECTED,                        \
        .pselcts            = NRF_UART_PSEL_DISCONNECTED,                        \
        .pselrts            = NRF_UART_PSEL_DISCONNECTED,                        \
        .p_context          = NULL,                                              \
        .hwfc               = (nrf_uart_hwfc_t)UART_DEFAULT_CONFIG_HWFC,         \
        .parity             = (nrf_uart_parity_t)UART_DEFAULT_CONFIG_PARITY,     \
        .baudrate           = NRF_UART_BAUDRATE_115200,                          \
        .interrupt_priority = UART_DEFAULT_CONFIG_IRQ_PRIORITY,                  \
    }

Children
No Data
Related