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?

  • 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

  • Hi, Jorgen,

    I tried to use the macro NRF_LOG_DEBUG(...) way, following it, I added include for nrf_log_default_backends.h, nrf_log.h, then added 4 more when compiler complaint can't find, until I realized this way would not work.

    The thing is, the head file I added include also have include other files it self, even after you add all the includes, compiler would still complaint it can't find the file included by the file you have included, you have to change sdk 15 head file to solve that, which is not I want.

    After a glance, I found there's an uart folder in nRF5_SDK_15.0.0_a53641a\components\libraries\, maybe I should try that.

    What do you think?

    Best regards.

  • 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?

Related