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

UART usage - I cannot see the light in the SDK

In advance I would like to say I’m sorry for the frustration that this message reflects…Event though I have been using the UART for some time, adding more functionality makes me search documentation for a UART description, and this makes me really frustrated.

I have what I think is a relatively simple need, I want to use UART0 and UART1 on a nRF32840 (both for some RS485 communication).

 

I do not care if it is NRF_DRV, NRFX or APP layer, anything that can be made to work will do!

 

Originally, I thought that selecting between NRF or NRFX was simple; documents suggest that NRF is legacy and I should use the "new" NRFX layer.

So selecting NRFX_UART_ENABLE would be logical and then including nrfx_uart.c driver file.....

But nothing is that simple with this SDK.... there always seems to be a mess of dependencies between configuration macros and files you need to include. and absolutely nothing that documents it (except heavy reading of header files of course ;-). I would love to see. “If you want this layer, tick this in SDK config and include ….”)

Well initial suggestion as above for NRFX just creates a bunch of errors…. so what is the combination needed...

It seems I can choose between using:

1 nrf_drv_uart

2 nrfx_uart

3 nrfx_uarte

4 app_uart

Can anyone suggest settings that will make just one of these options work, it would be highly appreciated and hopefully spare me a lot of testing and experimentation.

What I’m looking for what is a combination of what should be in SDK Config for

NRFX_UARTE section

NRFX_UART section

NRF_DRV (UART_ENABLED) section

APP_UART_ENABLED (+APP_FIFO_ENABLED) section

And any other sections that have dependencies!

I want to be able to call ???_init, send one or more bytes and receive bytes one by one

Parents
  • A small story... how to get UART working or not working. (before this one day just fumbling around trying to figure out what to do).

    As UARTE is the only method that seems to support both uarts I start by this
    In the sdk config:
    Enable the following
    NRFX_UARTE_ENABLED
    NRFX_UARTE0_ENABLED
    NRFX_UARTE1_ENABLED
    No other uart related sections enabled

    Include nrfx_uart.c in the build

    With this setup nrfx_uarte_init() is undefined!

    This is related to the check of NRFX_UARTE_ENABLED in nrfx_uarte.c line 43.
    As there is only one include file (nrfx.h) before the check, I walk backwards to see what is missing as NRFX_UARTE_ENABLED is set in the sdk_config.h file.
    It seems that nrfx.h includes nrfx_config.h and this does include sdk_config.h so it should be fine, but....
    There is a single #undef of NRFX_UARTE_ENABLED, but it does not seem to be hit, so i cannot directly see the reason.

    So I contine (trial and error)

    Maybe try do include the driver layer by

    Enable UART_ENABLED in sdk config.

    Ok that worked, at least reduced number of errors, but undefinded nrf_drv_... and nrfx_uart_... functions...

    Conclusiong I have to include both legacy and nrfx layer driver files (nrf_drv_uart.c and nrfx_uart.c) also in the project to remove linker error!

    OK, that was it.... not I can compile and link.

    Running is a different issue, I get a application error when initializing the second UART.

    Seems that there is an internal structure m_cb[] where there is only one instance (m_cb[0]). This seems to come from the definition NRFX_UARTE_ENABLED_COUNT.
    But the code for defining it this seems OK, so why do I see a wrong definition. Include file order, what???
    This could be the same as above where something also was wrong with NRFX_UARTE_ENABLED...

    In the file /nrfx/legacy/apply_old_config.h there is a redefinition of NRFX_UARTE1_ENABLED that seems to be depending on both UART1_ENABLED and UART_EASY_DMA_SUPPORT,
    so I'm trying to figure what this requires!
    Aaaahhh error on my side or.., I did not see the UART1_ENABLED when I earlier enabled UART_ENABLED to make it compiler. Why do I at all have to define these myself as I have already enabled using NRFX_UARTE defines?

    That helped, I am able to compile.

    And both init functions succeed. Now on with the usage!

    Now investigating how to use the nrfx_uarte API functions. Transmitting seems straight forward as using nrfx_uarte_tx() should be fine.
    Receiving seems to require more.
    As most protocols and in many situations, I do not know how many characters I expect to received but would like to process them as they come in.
    I do not mind that a few are buffered up, actually the best would be to process mainly on a "gab" detection and a timer.

    I can call nrfx_uarte_rx() with a single byte buffer but does not seem efficient.

    Investigating further....

Reply
  • A small story... how to get UART working or not working. (before this one day just fumbling around trying to figure out what to do).

    As UARTE is the only method that seems to support both uarts I start by this
    In the sdk config:
    Enable the following
    NRFX_UARTE_ENABLED
    NRFX_UARTE0_ENABLED
    NRFX_UARTE1_ENABLED
    No other uart related sections enabled

    Include nrfx_uart.c in the build

    With this setup nrfx_uarte_init() is undefined!

    This is related to the check of NRFX_UARTE_ENABLED in nrfx_uarte.c line 43.
    As there is only one include file (nrfx.h) before the check, I walk backwards to see what is missing as NRFX_UARTE_ENABLED is set in the sdk_config.h file.
    It seems that nrfx.h includes nrfx_config.h and this does include sdk_config.h so it should be fine, but....
    There is a single #undef of NRFX_UARTE_ENABLED, but it does not seem to be hit, so i cannot directly see the reason.

    So I contine (trial and error)

    Maybe try do include the driver layer by

    Enable UART_ENABLED in sdk config.

    Ok that worked, at least reduced number of errors, but undefinded nrf_drv_... and nrfx_uart_... functions...

    Conclusiong I have to include both legacy and nrfx layer driver files (nrf_drv_uart.c and nrfx_uart.c) also in the project to remove linker error!

    OK, that was it.... not I can compile and link.

    Running is a different issue, I get a application error when initializing the second UART.

    Seems that there is an internal structure m_cb[] where there is only one instance (m_cb[0]). This seems to come from the definition NRFX_UARTE_ENABLED_COUNT.
    But the code for defining it this seems OK, so why do I see a wrong definition. Include file order, what???
    This could be the same as above where something also was wrong with NRFX_UARTE_ENABLED...

    In the file /nrfx/legacy/apply_old_config.h there is a redefinition of NRFX_UARTE1_ENABLED that seems to be depending on both UART1_ENABLED and UART_EASY_DMA_SUPPORT,
    so I'm trying to figure what this requires!
    Aaaahhh error on my side or.., I did not see the UART1_ENABLED when I earlier enabled UART_ENABLED to make it compiler. Why do I at all have to define these myself as I have already enabled using NRFX_UARTE defines?

    That helped, I am able to compile.

    And both init functions succeed. Now on with the usage!

    Now investigating how to use the nrfx_uarte API functions. Transmitting seems straight forward as using nrfx_uarte_tx() should be fine.
    Receiving seems to require more.
    As most protocols and in many situations, I do not know how many characters I expect to received but would like to process them as they come in.
    I do not mind that a few are buffered up, actually the best would be to process mainly on a "gab" detection and a timer.

    I can call nrfx_uarte_rx() with a single byte buffer but does not seem efficient.

    Investigating further....

Children
No Data
Related