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

nrf_libuarte_async_rx_free ?

Dear Member,

I want to call nrf_libuarte_async_rx_free from another file outside main.c

nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1);

I got  

..\..\..\GPS-Lib\GPS_lib.c(35): error:  #20: identifier "libuarte1" is undefined

I have included 

#include "nrf_libuarte_async.h"

in GPS_lib.c

and

NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 1, 2, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

in main.c ,

How can I rectify it ?

Thanks

  • Hi,

    The NRF_LIBUARTE_ASYNC_DEFINE macro will declare libuarte1 in your main.c file as a static variable, which prevents you from accessing it outside of the file where it is declared (out-of-scope).

    You have some different options to resolve this:

    • Modify the NRF_LIBUARTE_ASYNC_DEFINE macro in nrf_libuarte_async.h to declare the nrf_libuarte_async_t object as non-static, then declare the variable as extern in the file where you want to use it.
    • Declare a pointer to libuarte1 in main.c, and declare the same pointer as extern in the file where you want to use it (see this post).
    • Implement a function in main.c that calls nrf_libuarte_async_rx_free() for you, and declare this function in a header-file (main.h) that you include in the file where you want to use the function.

    Best regards,
    Jørgen

  • Hi Jorgen,

    Thanks for your reply,

    I select option 1,

    So :

     static const nrf_libuarte_async_t _name = {\
                  .p_rx_pool = &CONCAT_2(_name,_rx_pool),\
                  .p_rx_queue =  &CONCAT_2(_name,_rxdata_queue),\
                  /* If p_rtc is not NULL it means that RTC is used for RX timeout */ \
                  .p_rtc = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED), (&CONCAT_2(_name, _rtc)), (NULL)),\
                  /* If p_timer is not NULL it means that RTC is used for RX timeout */ \
                  .p_timer = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED), (&CONCAT_2(_name, _timer)), (NULL)),\
                  /* If p_time and p_rtc is NULL it means that app_timer is used for RX timeout */ \
                  .p_app_timer = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED),\
    	                    (NULL),\
    	                    (_LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),(NULL), \
    	                         (&CONCAT_2(_name,_app_timer)))) \
    	            ),\
                  .p_app_timer_ctrl_blk = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED),\
    	                    (NULL),\
    	                    (_LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),(NULL), \
    	                         (&CONCAT_2(_name,_app_timer_ctrl_blk)))) \
    	            ),\
                  .p_libuarte = &CONCAT_2(_name, _libuarte),\
                  .p_ctrl_blk = &CONCAT_2(_name, ctrl_blk),\
                  .rx_buf_size = _rx_buf_size,\
                  _LIBUARTE_ASYNC_EVAL(\
                      NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),\
                      (.rtc_handler =CONCAT_2(_name, _rtc_handler)),\
                      ()\
                  )\
          };\

    change to :

     const nrf_libuarte_async_t _name = {\
                  .p_rx_pool = &CONCAT_2(_name,_rx_pool),\
                  .p_rx_queue =  &CONCAT_2(_name,_rxdata_queue),\
                  /* If p_rtc is not NULL it means that RTC is used for RX timeout */ \
                  .p_rtc = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED), (&CONCAT_2(_name, _rtc)), (NULL)),\
                  /* If p_timer is not NULL it means that RTC is used for RX timeout */ \
                  .p_timer = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED), (&CONCAT_2(_name, _timer)), (NULL)),\
                  /* If p_time and p_rtc is NULL it means that app_timer is used for RX timeout */ \
                  .p_app_timer = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED),\
    	                    (NULL),\
    	                    (_LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),(NULL), \
    	                         (&CONCAT_2(_name,_app_timer)))) \
    	            ),\
                  .p_app_timer_ctrl_blk = _LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_TIMER, _timer1_idx, _ENABLED),\
    	                    (NULL),\
    	                    (_LIBUARTE_ASYNC_EVAL(NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),(NULL), \
    	                         (&CONCAT_2(_name,_app_timer_ctrl_blk)))) \
    	            ),\
                  .p_libuarte = &CONCAT_2(_name, _libuarte),\
                  .p_ctrl_blk = &CONCAT_2(_name, ctrl_blk),\
                  .rx_buf_size = _rx_buf_size,\
                  _LIBUARTE_ASYNC_EVAL(\
                      NRFX_CONCAT_3(NRFX_RTC, _rtc1_idx, _ENABLED),\
                      (.rtc_handler =CONCAT_2(_name, _rtc_handler)),\
                      ()\
                  )\
          };\

    Then

    extern const nrf_libuarte_async_t libuarte1;

    Guide me, please ? thanks

  • extern const nrf_libuarte_async_t libuarte1; in main.c and

    I call

    nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1); in GPS_lib.c

    Correct me  ? thanks

  • it's working with :

    nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1);   

    but not working with

    nrf_libuarte_async_tx(&libuarte, GPS.rxBuffer, 512);

    I don't understand ? they use the same

    const nrf_libuarte_async_t _name

  • RixtronixLAB said:

    but not working with

    nrf_libuarte_async_tx(&libuarte, GPS.rxBuffer, 512);

    What exactly is not working with this? Do you get compile errors? Errors during run-time? Data not being transmitted correctly?

Related