Adding an 2nd UART to the BLE UART example

I'm trying to get a second UART to work on my nRF52833. Following the advice of this post, I've tried merging the libuart example into the BLE peripheral example. I've added what seem to be the necessary drivers and libraries the the BLE example and relevant configs from the sdk_config.h file. My code errors and then goes to a system reset. This happens on line 779 in main(), which his: ret_code_t err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, libuart_event_handler, (void *)&libuarte); and this goes to line 105 in nrfx_timer.c, which is:
nrfx_timer_init(...)
{
...........
   uint8_t i;
    for (i = 0; i < p_instance->cc_channel_count; ++i)
    {
        nrf_timer_event_clear(p_instance->p_reg,
                              nrf_timer_compare_event_get(i));
    }
...........
}

Could you please provide me with some advice. It might be one of the setting in the config file or initializing a peripheral wrongly. I'm woring on a custom PCB, using soft device s140 and the Keil IDE. Thank you.

ble_uart_libuart_merge.7z

Parents
  • I am not able to compile your code to be able check why it resets. Combing two samples is time consuming process in terms of finding out what configs and resources you need to enable and disable.

    7> Compiling ‘utf.c’
    10> Compiling ‘ble_nus.c’
    11> In file included from ../../../../../../components/libraries/util/sdk_common.h:61,
    11>                  from ../../../../../../components/ble/common/ble_advdata.h:56,
    11>                  from E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:60:
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:28: error: 'NRF_LIBUARTE_DRV_UARTE1' undeclared here (not in a function); did you mean 'NRF_LIBUARTE_DRV_H'?
    11> ../../../../../../components/libraries/util/app_util.h:242:62: note: in definition of macro '_SELECT_ASSERT_FUNC'
    11> ../../../../../../components/libraries/util/app_util.h:258:25: note: in expansion of macro 'STATIC_ASSERT_MSG'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:5: note: in expansion of macro 'STATIC_ASSERT'
    11> ../../../../../../components/libraries/util/nordic_common.h:116:31: note: in expansion of macro 'CONCAT_2_'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:19: note: in expansion of macro 'CONCAT_2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:242:7: note: in expansion of macro 'NRF_LIBUARTE_DRV_DEFINE'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:28: error: expression in static assertion is not an integer
    11> ../../../../../../components/libraries/util/app_util.h:242:62: note: in definition of macro '_SELECT_ASSERT_FUNC'
    11> ../../../../../../components/libraries/util/app_util.h:258:25: note: in expansion of macro 'STATIC_ASSERT_MSG'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:5: note: in expansion of macro 'STATIC_ASSERT'
    11> ../../../../../../components/libraries/util/nordic_common.h:116:31: note: in expansion of macro 'CONCAT_2_'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:176:19: note: in expansion of macro 'CONCAT_2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:242:7: note: in expansion of macro 'NRF_LIBUARTE_DRV_DEFINE'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    11> ../../../../../../components/libraries/util/app_util.h:220:41: error: static assertion failed: "Timer instance not enabled"
    11> ../../../../../../components/libraries/util/app_util.h:242:62: note: in definition of macro '_SELECT_ASSERT_FUNC'
    11> ../../../../../../components/libraries/util/app_util.h:258:25: note: in expansion of macro 'STATIC_ASSERT_MSG'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:177:5: note: in expansion of macro 'STATIC_ASSERT'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:242:7: note: in expansion of macro 'NRF_LIBUARTE_DRV_DEFINE'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    19> Compiling ‘nrf_sdh.c’
    20> Compiling ‘nrf_sdh_ble.c’
    1> Compiling ‘nrf_sdh_soc.c’
    11> In file included from ../../../../../../modules/nrfx/nrfx.h:45,
    11>                  from ../../../../../../modules/nrfx/hal/nrf_gpio.h:44,
    11>                  from ../../../../../../components/boards/boards.h:43,
    11>                  from ../../../../../../components/libraries/bsp/bsp.h:58,
    11>                  from ../../../../../../components/libraries/bsp/bsp_btn_ble.h:60,
    11>                  from E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:72:
    11> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:72:39: error: 'NRFX_TIMER0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TIMER_INSTANCE'?
    11> ../../../../../../modules/nrfx/drivers/nrfx_common.h:113:37: note: in definition of macro 'NRFX_CONCAT_3_'
    11> ../../../../../../modules/nrfx/drivers/include/nrfx_timer.h:72:25: note: in expansion of macro 'NRFX_CONCAT_3'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_drv.h:181:18: note: in expansion of macro 'NRFX_TIMER_INSTANCE'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:242:7: note: in expansion of macro 'NRF_LIBUARTE_DRV_DEFINE'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    11> In file included from E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:82:
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:280:28: warning: initialization of 'void **' from incompatible pointer type 'app_timer_t * const*' [-Wincompatible-pointer-types]
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:183:39: note: in definition of macro 'LIBUARTE_ASYNC_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:210:5: note: in expansion of macro '__LIBUARTE_ASYNC_ARG_2_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:205:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:202:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL1'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:277:30: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:186:65: note: in expansion of macro 'LIBUARTE_ASYNC_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:210:5: note: in expansion of macro '__LIBUARTE_ASYNC_ARG_2_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:205:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:202:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL1'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:279:23: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:280:28: note: (near initialization for 'libuarte.p_app_timer')
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:183:39: note: in definition of macro 'LIBUARTE_ASYNC_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:210:5: note: in expansion of macro '__LIBUARTE_ASYNC_ARG_2_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:205:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:202:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL1'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:277:30: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:186:65: note: in expansion of macro 'LIBUARTE_ASYNC_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:210:5: note: in expansion of macro '__LIBUARTE_ASYNC_ARG_2_DEBRACKET'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:205:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL2'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:202:5: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL1'
    11> ../../../../../../components/libraries/libuarte/nrf_libuarte_async.h:279:23: note: in expansion of macro '_LIBUARTE_ASYNC_EVAL'
    11> E:\Downloads\customer_cases\nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\main.c:702:1: note: in expansion of macro 'NRF_LIBUARTE_ASYNC_DEFINE'
    Build failed
    

    Can you please give me a project I am able to compile?
    I was testing ble_app_uart example from your attached compressed folder. \nRF5_SDK_17.1.0_ddde560\examples\ble_peripheral\ble_app_uart\

  • I have rebuilt the same code and it compiles with 0 errors and 5 warnings. These warnings are from variables not being used, which are test variables I put into the code.

    Rebuild started: Project: ble_app_uart_pca10100_s140
    *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'C:\Keil_v5\ARM\ARM_Compiler_5.06u7\Bin'
    Rebuild target 'nrf52833_xxaa'
    compiling utf.c...
    compiling ble_advdata.c...

    .........................

    ..\..\..\..\..\..\components\libraries\libuarte\nrf_libuarte_async.c: 5 warnings, 0 errors
    compiling nrf_queue.c...
    compiling SEGGER_RTT_Syscalls_KEIL.c...
    compiling nrf_log_backend_serial.c...
    compiling nrf_libuarte_drv.c...
    compiling nrf_log_default_backends.c...
    compiling nrf_log_backend_rtt.c...
    compiling nrf_log_str_formatter.c...
    compiling nrf_log_frontend.c...
    assembling arm_startup_nrf52833.s...
    compiling SEGGER_RTT.c...
    compiling SEGGER_RTT_printf.c...
    compiling nrf_sdh.c...
    compiling nrf_sdh_soc.c...
    compiling nrf_sdh_ble.c...
    compiling system_nrf52.c...
    linking...
    Program Size: Code=40300 RO-data=4108 RW-data=592 ZI-data=7664  
    FromELF: creating hex file...
    ".\_build\nrf52833_xxaa.axf" - 0 Error(s), 5 Warning(s).
    Build Time Elapsed:  00:00:32

    I will retry porting/merging the code, so that it is in its simplest form.

  • Not at my end.
    I had to add nrfx_ppi.c and nrfx_timer.c to the project to make it compile.

    I see that after running your code on the board, there is an assert in nrfx_timer.c:72 where the code checks that you are not using NRF_TIMER0 for initializing the UARTE.

    So in the main.c:702, changing the NRF_LIBUARTE_ASYNC_DEFINE to use TIMER2 instead of TIMER0 and enabling TIMER2_ENABLED and NRFX_TIMER2_ENABLED in sdk_config.h fixes the assert in your code.

Reply
  • Not at my end.
    I had to add nrfx_ppi.c and nrfx_timer.c to the project to make it compile.

    I see that after running your code on the board, there is an assert in nrfx_timer.c:72 where the code checks that you are not using NRF_TIMER0 for initializing the UARTE.

    So in the main.c:702, changing the NRF_LIBUARTE_ASYNC_DEFINE to use TIMER2 instead of TIMER0 and enabling TIMER2_ENABLED and NRFX_TIMER2_ENABLED in sdk_config.h fixes the assert in your code.

Children
Related