init of one UARTE OK but subsequent UARTE failing in slightly modified example in .../examples/libuarte/main.c

Hi
We'll be adding to a design that uses libuarte/UART0.     I've tested/run the example code and it's fine.  Changing/swapping
index from UARTE0 or 1 works fine as does reassigning TxD/RxD pins from 8 & 6 to others.

So I just made some minor changes and first decided to instantiate both UARTEs, and just to see a test string on both UARTE
outputs.    sdk_config.h  turned on UARTE1   .    Complies w GCC /burns fine.    Runs up to "Here #1" and stops.

[I do not have a debugger setup yet just  JLinkRTTView for logging debug printfs for "Hello #n" progress stamps.]

Are there some configuration options I'm missing/need correction,  esp in  NRF_LIBUARTE_ASYNC_DEFINE(...)    ??
Anything else I can check?

Shouldn't be any resource constraints otherwise.   I'd like to see both UARTEx's  emit something ....   and yes, HWFC
is of course disabled.  Both ports used/configured singly (i.e, commenting out init/usage of the other port) work 100%.


Thanks
Bill
San Jose

--------------------------------------------------------------------------------------------------

Key excerpts:

#include xxxxx  ec.
....

.....
NRF_LIBUARTE_ASYNC_DEFINE(libuarte1,   0,  0, 0,  NRF_LIBUARTE_PERIPHERAL_NOT_USED, 128, 3);
NRF_LIBUARTE_ASYNC_DEFINE(libuarte2,   1,  0, 0,  NRF_LIBUARTE_PERIPHERAL_NOT_USED, 128, 3);
.....

/// two separate copies uart_handler1(), uart_handler2()   - noninterfering w each other, etc

main()

      /// same intro setup (clockcs, etc) as orig code....

       nrf_libuarte_async_config_t nrf_libuarte_async_config[] = {
          // UARTE0
        { .tx_pin = TX_PIN_NUMBER,      // == 0,6
          .rx_pin = RX_PIN_NUMBER,     // == 0,8
          .baudrate = NRF_UARTE_BAUDRATE_115200,
          .parity = NRF_UARTE_PARITY_EXCLUDED,
          .hwfc = NRF_UARTE_HWFC_DISABLED,
          .timeout_us = 100,
          .int_prio = APP_IRQ_PRIORITY_LOW
     },
           // UARTE1
       {  .tx_pin = SER_CON_TX_PIN,     // == 1,13
          .rx_pin = SER_CON_RX_PIN,     // == 1,14
          .baudrate = NRF_UARTE_BAUDRATE_115200,
         .parity = NRF_UARTE_PARITY_EXCLUDED,
         .hwfc = NRF_UARTE_HWFC_DISABLED,
         .timeout_us = 100,
         .int_prio = APP_IRQ_PRIORITY_LOW
         }
       };

 

         dprintf(0,"Here 0\n");

         err_code = nrf_libuarte_async_init(&libuarte1, &nrf_libuarte_async_config[0], uart_event_handler1, (void *)&libuarte1);
         APP_ERROR_CHECK(err_code);
         nrf_delay_ms(25);

         dprintf(0,"Here 1\n");

         err_code = nrf_libuarte_async_init(&libuarte2, &nrf_libuarte_async_config[1], uart_event_handler2, (void *)&libuarte2);
         APP_ERROR_CHECK(err_code);
         nrf_delay_ms(25);

         dprintf(0,"Here 2\n");

         nrf_libuarte_async_enable(&libuarte1);
         nrf_delay_ms(25);

         dprintf(0,"Here 3\n");

         nrf_libuarte_async_enable(&libuarte2);
         nrf_delay_ms(25);

         dprintf(0,"Here 4\n");

         err_code = nrf_libuarte_async_tx(&libuarte1, text, text_size);
         APP_ERROR_CHECK(err_code);
         nrf_delay_ms(500);

         err_code = nrf_libuarte_async_tx(&libuarte2, text, text_size);
         APP_ERROR_CHECK(err_code);
         nrf_delay_ms(500);

         dprintf(0,"Here 5\n");
         .
         .
         .
         .

Parents
  • Hi Edvin..

    Update...

    With config as
        ... 
      NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 128, 4);
      NRF_LIBUARTE_ASYNC_DEFINE(libuarte2, 1, 0, 1, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 128, 4);
        ...

    or even
       ...
       NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 0, 0, 0, n1, 128, 4);
       NRF_LIBUARTE_ASYNC_DEFINE(libuarte2, 1, 0, 1, n2, 128, 4);

    where n=0, 2 etc and same or different....


    We also need necessary elevating of config structure's   .int_prio   field   to   APP_IRQ_PRIORITY_MID     (i.e,,.   >  ..._LOW).


    So we are now progressing thru codeflow to
     
          nrf_libuarte_async_init(...)  lines 530-533
                |
                |
                +---> nrf_libuarte_drv_init(...)  lines 493-496, with NRF_ERR_INTERNAL via call to   
                                                      nrfx_timer_init(&p_libuarte->timer,
                                                                      &tmr_config, tmr_evt_handler);



    Helping me understand basic config in the ..._DEFINE setup  for two UARTEs without conflict of associated elements/assets/timers
    might be helpful


    Thx
    Bill


  • It looks like the libuarte library is really not made to handle two instances at once efficiently, because they require one timer and one rtc each.

    This worked for me:

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

    It means that libuarte1 is using UARTE instance nr. 0, timer 0 and RTC0,

    then libuarte2 is using UARTE instance nr.1, timer1 and RTC2. 

    I tried to set it up with RTC1, but since app_timer is enabled in the libuarte project, it wouldn't let me.use RTC1 as this is used by the app_timer.

    Remember to enable TIMER1 and RTC2 in sdk_config.h.

    Now again, do you really need to use libuarte? The other UART implementations require less resources. If you intend to use the softdevice and app_timer in your application, then this will not work, because you don't have two spare RTCs. The softdevice uses RTC0 and the app_timer uses RTC1, leaving you with RTC2.

    In case you just used libuarte because it was the first thing you came across, I suggest you look into the UART implementation from ble_app_uart, and try to get that up and running with two instances.

    Best regards,

    Edvin

Reply
  • It looks like the libuarte library is really not made to handle two instances at once efficiently, because they require one timer and one rtc each.

    This worked for me:

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

    It means that libuarte1 is using UARTE instance nr. 0, timer 0 and RTC0,

    then libuarte2 is using UARTE instance nr.1, timer1 and RTC2. 

    I tried to set it up with RTC1, but since app_timer is enabled in the libuarte project, it wouldn't let me.use RTC1 as this is used by the app_timer.

    Remember to enable TIMER1 and RTC2 in sdk_config.h.

    Now again, do you really need to use libuarte? The other UART implementations require less resources. If you intend to use the softdevice and app_timer in your application, then this will not work, because you don't have two spare RTCs. The softdevice uses RTC0 and the app_timer uses RTC1, leaving you with RTC2.

    In case you just used libuarte because it was the first thing you came across, I suggest you look into the UART implementation from ble_app_uart, and try to get that up and running with two instances.

    Best regards,

    Edvin

Children
No Data
Related