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

How logging is done in nrf52832 nrf17.0 sdk and nrf5.0 mesh sdk?

Hi,

I want to know how logging is happening in the nrf 17.0 sdk and nrf5.0 mesh sdk is it different in any case in nrf sdk and nrf mesh sdk? As, in infocenter of nordic it is mentioned in logger module post, that we can use RTT or UART for backend logging by just initialising the log_init with intialising the backend function with RTT or UART. 

I have used provisioner example code from nrf5.0 mesh sdk and have done changes regarding getting logs over UART instead of RTT, but i was not able to do so.

I have some points to ask regarding logging:

1) Can we get logs or setup bidirectional communication over UART for nrf52832 development kit? If yes, then how, right now we are getting logs and sending commands using RTT for any existing example code. I have tried certain things as mentioned in some of devzone post and in the logger module section of the nordic infocenter, will attach the changes. 

2)  How should we test the logs over UART instead of RTT using the same USB cable or have to take connections from the UART pins ?

Changes i have done for getting the bidirectional communication via UART i.e, to send and recieve commands from UART as we are doing using RTT as of now. Changes in file "main.c"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"



#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif



#define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
#include "app_uart.h"







/***uart******/
void uart_error_handle(app_uart_evt_t * p_event)
{
    if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_code);
    }
}
           





void uart_event_handle(app_uart_evt_t * p_event)
{
     printf("\r\nUART started uart event handler .\r\n");


}



/**@brief  Function for initializing the UART module.
 */
/**@snippet [UART Initialization] */
static void uart_init(void)
{
    printf("\r\nUART started initialisation .\r\n");
    uint32_t                     err_code;
    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
#if defined (UART_PRESENT)
       // printf("\r\nUART started intialisation if defined.\r\n"); 
        .baud_rate    = NRF_UART_BAUDRATE_115200
#else
        .baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);
    APP_ERROR_CHECK(err_code);
}
/**@snippet [UART Initialization] */





/**@brief Function for initializing the nrf log module.
 */
static void log_init(void)
{
     printf("\r\nUART started loginit initialisation.\r\n");
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}




/**@brief Function for initializing the timer module.
 */
static void timers_init(void)
{
      printf("\r\nUART started timer initialisation.\r\n");
    ret_code_t err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);
}





int main(void)
{
 

     printf("\r\nUART provision started.\r\n");
     // initialize
    //uart_init();
    //log_init();
    uart_init();
    log_init();
    timers_init();
    initialize();
    start();

    for (;;)
    {
        (void)sd_app_evt_wait();
    }
}

In file "sdk_config.h"

// <e> NRFX_UARTE_ENABLED - nrfx_uarte - UARTE peripheral driver
//==========================================================
#ifndef NRFX_UARTE_ENABLED
#define NRFX_UARTE_ENABLED 
#endif
// <o> NRFX_UARTE0_ENABLED - Enable UARTE0 instance
#ifndef NRFX_UARTE0_ENABLED
#define NRFX_UARTE0_ENABLED 0
#endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_HWFC  - Hardware Flow Control

// <0=> Disabled
// <1=> Enabled

#ifndef NRFX_UARTE_DEFAULT_CONFIG_HWFC
#define NRFX_UARTE_DEFAULT_CONFIG_HWFC 0
#endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_PARITY  - Parity

// <0=> Excluded
// <14=> Included

#ifndef NRFX_UARTE_DEFAULT_CONFIG_PARITY
#define NRFX_UARTE_DEFAULT_CONFIG_PARITY 0
#endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate

// <323584=> 1200 baud
// <643072=> 2400 baud
// <1290240=> 4800 baud
// <2576384=> 9600 baud
// <3862528=> 14400 baud
// <5152768=> 19200 baud
// <7716864=> 28800 baud
// <8388608=> 31250 baud
// <10289152=> 38400 baud
// <15007744=> 56000 baud
// <15400960=> 57600 baud
// <20615168=> 76800 baud
// <30801920=> 115200 baud
// <61865984=> 230400 baud
// <67108864=> 250000 baud
// <121634816=> 460800 baud
// <251658240=> 921600 baud
// <268435456=> 1000000 baud

#ifndef NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE
#define NRFX_UARTE_DEFAULT_CONFIG_BAUDRATE 30801920
#endif

// <o> NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority

// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7

#ifndef NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY
#define NRFX_UARTE_DEFAULT_CONFIG_IRQ_PRIORITY 6
#endif

// <e> NRFX_UARTE_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_UARTE_CONFIG_LOG_ENABLED
#define NRFX_UARTE_CONFIG_LOG_ENABLED 0
#endif
// <o> NRFX_UARTE_CONFIG_LOG_LEVEL  - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef NRFX_UARTE_CONFIG_LOG_LEVEL
#define NRFX_UARTE_CONFIG_LOG_LEVEL 3
#endif

// <o> NRFX_UARTE_CONFIG_INFO_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef NRFX_UARTE_CONFIG_INFO_COLOR
#define NRFX_UARTE_CONFIG_INFO_COLOR 0
#endif

// <o> NRFX_UARTE_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef NRFX_UARTE_CONFIG_DEBUG_COLOR
#define NRFX_UARTE_CONFIG_DEBUG_COLOR 0
#endif

// </e>

// </e>

// <e> NRFX_UART_ENABLED - nrfx_uart - UART peripheral driver
//==========================================================
#ifndef NRFX_UART_ENABLED
#define NRFX_UART_ENABLED 0//1
#endif
// <o> NRFX_UART0_ENABLED - Enable UART0 instance
#ifndef NRFX_UART0_ENABLED
#define NRFX_UART0_ENABLED 0
#endif

// <o> NRFX_UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control

// <0=> Disabled
// <1=> Enabled

#ifndef NRFX_UART_DEFAULT_CONFIG_HWFC
#define NRFX_UART_DEFAULT_CONFIG_HWFC 0
#endif

// <o> NRFX_UART_DEFAULT_CONFIG_PARITY  - Parity

// <0=> Excluded
// <14=> Included

#ifndef NRFX_UART_DEFAULT_CONFIG_PARITY
#define NRFX_UART_DEFAULT_CONFIG_PARITY 0
#endif

// <o> NRFX_UART_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate

// <323584=> 1200 baud
// <643072=> 2400 baud
// <1290240=> 4800 baud
// <2576384=> 9600 baud
// <3866624=> 14400 baud
// <5152768=> 19200 baud
// <7729152=> 28800 baud
// <8388608=> 31250 baud
// <10309632=> 38400 baud
// <15007744=> 56000 baud
// <15462400=> 57600 baud
// <20615168=> 76800 baud
// <30924800=> 115200 baud
// <61845504=> 230400 baud
// <67108864=> 250000 baud
// <123695104=> 460800 baud
// <247386112=> 921600 baud
// <268435456=> 1000000 baud

#ifndef NRFX_UART_DEFAULT_CONFIG_BAUDRATE
#define NRFX_UART_DEFAULT_CONFIG_BAUDRATE 30924800
#endif

// <o> NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority

// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7

#ifndef NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY
#define NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
#endif

// <e> NRFX_UART_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_UART_CONFIG_LOG_ENABLED
#define NRFX_UART_CONFIG_LOG_ENABLED 0
#endif
// <o> NRFX_UART_CONFIG_LOG_LEVEL  - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef NRFX_UART_CONFIG_LOG_LEVEL
#define NRFX_UART_CONFIG_LOG_LEVEL 3
#endif

// <o> NRFX_UART_CONFIG_INFO_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef NRFX_UART_CONFIG_INFO_COLOR
#define NRFX_UART_CONFIG_INFO_COLOR 0
#endif

// <o> NRFX_UART_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef NRFX_UART_CONFIG_DEBUG_COLOR
#define NRFX_UART_CONFIG_DEBUG_COLOR 0
#endif




// </e>
#ifndef RETARGET_ENABLED
#define RETARGET_ENABLED 1
#endif
//==========================================================
// <q> APP_FIFO_ENABLED  - app_fifo - Software FIFO implementation
 

#ifndef APP_FIFO_ENABLED
#define APP_FIFO_ENABLED 1
#endif


// <e> APP_UART_ENABLED - app_uart - UART driver
//==========================================================
#ifndef APP_UART_ENABLED
#define APP_UART_ENABLED 1
#endif

#if  APP_UART_ENABLED
// <o> APP_UART_DRIVER_INSTANCE  - UART instance used
 
// <0=> 0 

#ifndef APP_UART_DRIVER_INSTANCE
#define APP_UART_DRIVER_INSTANCE 0
#endif

#endif //APP_UART_ENABLED

// <e> UART_ENABLED - nrf_drv_uart - UART/UARTE peripheral driver - legacy layer
//==========================================================
#ifndef UART_ENABLED
#define UART_ENABLED 1
#endif


#if  UART_ENABLED
// <o> UART_DEFAULT_CONFIG_HWFC  - Hardware Flow Control

// <0=> Disabled
// <1=> Enabled

#ifndef UART_DEFAULT_CONFIG_HWFC
#define UART_DEFAULT_CONFIG_HWFC 0
#endif

// <o> UART_DEFAULT_CONFIG_PARITY  - Parity

// <0=> Excluded
// <14=> Included

#ifndef UART_DEFAULT_CONFIG_PARITY
#define UART_DEFAULT_CONFIG_PARITY 0
#endif

// <o> UART_DEFAULT_CONFIG_BAUDRATE  - Default Baudrate

// <323584=> 1200 baud
// <643072=> 2400 baud
// <1290240=> 4800 baud
// <2576384=> 9600 baud
// <3862528=> 14400 baud
// <5152768=> 19200 baud
// <7716864=> 28800 baud
// <10289152=> 38400 baud
// <15400960=> 57600 baud
// <20615168=> 76800 baud
// <30801920=> 115200 baud
// <61865984=> 230400 baud
// <67108864=> 250000 baud
// <121634816=> 460800 baud
// <251658240=> 921600 baud
// <268435456=> 1000000 baud

#ifndef UART_DEFAULT_CONFIG_BAUDRATE
#define UART_DEFAULT_CONFIG_BAUDRATE 30801920
#endif

// <o> UART_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority


// <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// <0=> 0 (highest)
// <1=> 1
// <2=> 2
// <3=> 3
// <4=> 4
// <5=> 5
// <6=> 6
// <7=> 7

#ifndef UART_DEFAULT_CONFIG_IRQ_PRIORITY
#define UART_DEFAULT_CONFIG_IRQ_PRIORITY 6
#endif

// <q> UART_EASY_DMA_SUPPORT  - Driver supporting EasyDMA


#ifndef UART_EASY_DMA_SUPPORT
#define UART_EASY_DMA_SUPPORT 1
#endif

// <q> UART_LEGACY_SUPPORT  - Driver supporting Legacy mode


#ifndef UART_LEGACY_SUPPORT
#define UART_LEGACY_SUPPORT 0//1
#endif

#endif //UART_ENABLED


// <e> UART0_ENABLED - Enable UART0 instance
//==========================================================
#ifndef UART0_ENABLED
#define UART0_ENABLED 1
#endif
// <q> UART0_CONFIG_USE_EASY_DMA  - Default setting for using EasyDMA


#ifndef UART0_CONFIG_USE_EASY_DMA
#define UART0_CONFIG_USE_EASY_DMA 1
#endif

// </e>




// </h>
//==========================================================

// <h> nRF_Log

//==========================================================
// <e> NRF_LOG_BACKEND_UART_ENABLED - nrf_log_backend_rtt - Log UART backend
//==========================================================
#ifndef NRF_LOG_BACKEND_UART_ENABLED
#define NRF_LOG_BACKEND_UART_ENABLED 0
#endif




//==========================================================
// <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
//==========================================================
#ifndef NRF_LOG_BACKEND_RTT_ENABLED
#define NRF_LOG_BACKEND_RTT_ENABLED 1
#endif



// <o> NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. 
// <i> Size of the buffer is a trade-off between RAM usage and processing.
// <i> if buffer is smaller then strings will often be fragmented.
// <i> It is recommended to use size which will fit typical log and only the
// <i> longer one will be fragmented.

#ifndef NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE
#define NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE 64
#endif

// <o> NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS - Period before retrying writing to RTT 
#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS
#define NRF_LOG_BACKEND_RTT_TX_RETRY_DELAY_MS 1
#endif

// <o> NRF_LOG_BACKEND_RTT_TX_RETRY_CNT - Writing to RTT retries. 
// <i> If RTT fails to accept any new data after retries
// <i> module assumes that host is not active and on next
// <i> request it will perform only one write attempt.
// <i> On successful writing, module assumes that host is active
// <i> and scheme with retry is applied again.

#ifndef NRF_LOG_BACKEND_RTT_TX_RETRY_CNT
#define NRF_LOG_BACKEND_RTT_TX_RETRY_CNT 3
#endif

// </e>

// <e> NRF_LOG_ENABLED - nrf_log - Logger
//==========================================================
#ifndef NRF_LOG_ENABLED
#define NRF_LOG_ENABLED 1//0
#endif
// <h> Log message pool - Configuration of log message pool



// <e> UART_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef UART_CONFIG_LOG_ENABLED
#define UART_CONFIG_LOG_ENABLED 0
#endif
// <o> UART_CONFIG_LOG_LEVEL  - Default Severity level

// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug

#ifndef UART_CONFIG_LOG_LEVEL
#define UART_CONFIG_LOG_LEVEL 3
#endif

// <o> UART_CONFIG_INFO_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef UART_CONFIG_INFO_COLOR
#define UART_CONFIG_INFO_COLOR 0
#endif

// <o> UART_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.

// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White

#ifndef UART_CONFIG_DEBUG_COLOR
#define UART_CONFIG_DEBUG_COLOR 0
#endif




Is it the way we should proceed with it. If not, then please suggest me how to achieve this, if yes, then how to test as i am not able to achieve by these changes.

Thanks & Regards,

Ela

Parents
  • Hi,

    I want to know how logging is happening in the nrf 17.0 sdk and nrf5.0 mesh sdk is it different in any case in nrf sdk and nrf mesh sdk?

    The difference in the two SDKs in regards to logging is that logging via UART isn't enabled. This is possible to implement yourself. 

    1) Can we get logs or setup bidirectional communication over UART for nrf52832 development kit? If yes, then how, right now we are getting logs and sending commands using RTT for any existing example code. I have tried certain things as mentioned in some of devzone post and in the logger module section of the nordic infocenter, will attach the changes. 

    Maybe this can help you, there is also an example attached.

    2)  How should we test the logs over UART instead of RTT using the same USB cable or have to take connections from the UART pins ?

    Are you using a DK? If so, the UART pins are internally connected to the on-board debugger and you can connect it to a PC via a USB cable. It will be available as normal COM port.

  • Hi Mttrinh,

    I have implemented in the same way as mentioned in the example, but getting lot of errors and not able to build the project, can you help me with this. And how shall i test this example code, i do not want to use on board debugger and USB cable i want to use the UART pins to test uart data.

    I am attaching the error i am getting:

    Building 'provisioner_nrf52832_xxAA_s132_7.2.0' from solution 'provisioner_nrf52832_xxAA_s132_7.2.0' in configuration 'Debug'
      Compiling 'main.c'
      Compiling 'provisioner_helper.c'
      Compiling 'node_setup.c'
      Compiling 'rtt_input.c'
      Compiling 'simple_hal.c'
      Compiling 'mesh_adv.c'
      Compiling 'nrf_mesh_weak.c'
      Compiling 'ble_softdevice_support.c'
      Compiling 'app_error_weak.c'
      Compiling 'assertion_handler_weak.c'
      Compiling 'nrf_log_default_backends.c'
      Compiling 'retarget.c'
      Compiling 'nrf_log_frontend.c'
      Compiling 'app_uart_fifo.c'
      Compiling 'nrf_log_str_formatter.c'
      Compiling 'nrf_memobj.c'
      Compiling 'nrf_log_backend_rtt.c'
      Compiling 'nrf_log_backend_serial.c'
      Compiling 'nrf_balloc.c'
      Compiling 'nrf_ringbuf.c'
      Compiling 'nrf_fprintf.c'
      Compiling 'nrf_drv_uart.c'
      Compiling 'app_fifo.c'
      Compiling 'internal_event.c'
      Compiling 'nrf_mesh_configure.c'
      Compiling 'aes.c'
      Compiling 'msg_cache.c'
      Compiling 'transport.c'
      Compiling 'packet_buffer.c'
      Compiling 'event.c'
      Compiling 'flash_manager_defrag.c'
      Compiling 'fifo.c'
      Compiling 'nrf_flash.c'
      Compiling 'net_state.c'
      Compiling 'mesh_flash.c'
      Compiling 'nrf_mesh_utils.c'
      Compiling 'nrf_mesh.c'
      Compiling 'queue.c'
      Compiling 'hal.c'
      Compiling 'aes_cmac.c'
      Compiling 'timer_scheduler.c'
      Compiling 'long_timer.c'
      Compiling 'timer.c'
      Compiling 'rand.c'
      Compiling 'nrf_mesh_opt.c'
      Compiling 'mesh_opt.c'
      Compiling 'timeslot.c'
      Compiling 'timeslot_timer.c'
      Compiling 'bearer_event.c'
      Compiling 'enc.c'
      Compiling 'net_packet.c'
      Compiling 'network.c'
      Compiling 'msqueue.c'
      Compiling 'nrf_mesh_keygen.c'
      Compiling 'cache.c'
      Compiling 'log.c'
      Compiling 'list.c'
      Compiling 'flash_manager.c'
      Compiling 'ccm_soft.c'
      Compiling 'toolchain.c'
      Compiling 'replay_cache.c'
      Compiling 'beacon.c'
      Compiling 'core_tx.c'
      Compiling 'flash_manager_internal.c'
      Compiling 'heartbeat.c'
      Compiling 'mesh_config.c'
      Compiling 'net_beacon.c'
      Compiling 'fsm.c'
      Compiling 'mesh_config_backend.c'
      Compiling 'lpn.c'
      Compiling 'mesh_config_flashman_glue.c'
      Compiling 'core_tx_lpn.c'
      Compiling 'mesh_lpn_subman.c'
      Compiling 'core_tx_local.c'
      Compiling 'emergency_cache.c'
      Compiling 'mesh_mem_stdlib.c'
      Compiling 'core_tx_adv.c'
      Assembling 'thumb_crt0.s'
      Compiling 'mesh_stack.c'
      Compiling 'access_publish.c'
      Compiling 'access_publish_retransmission.c'
      Compiling 'access.c'
      Compiling 'access_reliable.c'
      Compiling 'device_state_manager.c'
      Compiling 'ad_listener.c'
      Compiling 'ad_type_filter.c'
      Compiling 'adv_packet_filter.c'
      Compiling 'advertiser.c'
      Compiling 'bearer_handler.c'
      Compiling 'broadcast.c'
      Compiling 'gap_address_filter.c'
      Compiling 'filter_engine.c'
      Compiling 'radio_config.c'
      Compiling 'rssi_filter.c'
      Compiling 'scanner.c'
      Compiling 'mesh_pa_lna.c'
      Compiling 'SEGGER_RTT.c'
      Compiling 'SEGGER_RTT_printf.c'
      Compiling 'uECC.c'
      Compiling 'nrfx_gpiote.c'
      Compiling 'ble_advdata.c'
      Compiling 'app_util_platform.c'
      Compiling 'nrf_section_iter.c'
      Compiling 'nrf_sdh_soc.c'
      Compiling 'nrf_sdh.c'
        #warning Please select NRF_CLOCK_LF_ACCURACY_500_PPM when using NRF_CLOCK_LF_SRC_RC [-Wcpp]
      Compiling 'nrf_sdh_ble.c'
      Compiling 'ble_conn_params.c'
      Compiling 'nrf_atomic.c'
      Compiling 'ble_srv_common.c'
      Compiling 'system_nrf52.c'
      Compiling 'app_error.c'
      Assembling 'ses_startup_nrf52.s'
      Compiling 'app_error_handler_gcc.c'
      Compiling 'prov_provisioner.c'
      Assembling 'ses_startup_nrf_common.s'
      Compiling 'nrf_mesh_prov.c'
      Compiling 'provisioning.c'
      Compiling 'prov_beacon.c'
      Compiling 'prov_utils.c'
      Compiling 'prov_bearer_adv.c'
      Compiling 'config_client.c'
      Compiling 'composition_data.c'
      Compiling 'config_server.c'
      Compiling 'packed_index_list.c'
      Compiling 'health_server.c'
      Compiling 'health_client.c'
      Compiling 'app_timer_mesh.c'
      Compiling 'app_timer_workaround.c'
      Compiling 'nrf_fprintf_format.c'
      Generating linker script 'provisioner_nrf52832_xxAA_s132_7.2.0.ld'
      Linking provisioner_nrf52832_xxAA_s132_7.2.0.elf
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_rx':
        undefined reference to `nrfx_uarte_rx'
        /home/ekta/Desktop/8_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/integration/nrfx/legacy/nrf_drv_uart.h:569: undefined reference to `nrfx_uarte_rx'
        /home/ekta/Desktop/8_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/integration/nrfx/legacy/nrf_drv_uart.h:569: undefined reference to `nrfx_uarte_rx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx':
        undefined reference to `nrfx_uarte_tx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_rx':
        undefined reference to `nrfx_uarte_rx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx_in_progress':
        undefined reference to `nrfx_uarte_tx_in_progress'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx':
        undefined reference to `nrfx_uarte_tx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/nrf_drv_uart.o: in function `nrf_drv_uart_init':
        undefined reference to `nrfx_uarte_init'
    Build failed

    Attaching the main.c file 

     

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "nrf_delay.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh.h"
    #include "nrf_mesh_events.h"
    #include "nrf_mesh_assert.h"
    #include "access_config.h"
    #include "device_state_manager.h"
    #include "mesh_stack.h"
    #include "net_state.h"
    #include "mesh_opt_provisioner.h"
    #include "mesh_config_entry.h"
    #include "mesh_opt.h"
    
    /* Provisioning and configuration */
    #include "provisioner_helper.h"
    #include "node_setup.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "config_client.h"
    #include "config_server.h"
    #include "health_client.h"
    
    /* Logging and RTT */
    #include "rtt_input.h"
    #include "log.h"
    
    #include"nrf_log_ctrl.h"
    #include "nrf_uart.h"
    #include "app_uart.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    //#include "nrf_log_backend_interface.h"
    
    
    /* Example specific includes */
    #include "example_network_config.h"
    #include "nrf_mesh_config_examples.h"
    #include "ble_softdevice_support.h"
    #include "example_common.h"
    
    /*****************************************************************************
     * Definitions
     *****************************************************************************/
    #define APP_PROVISIONING_LED            BSP_LED_0
    #define APP_CONFIGURATION_LED           BSP_LED_1
    
    
    
    
    
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #include "app_uart.h"
    #include "nrf_uart.h"
    static bool m_device_provisioned;
    
    /*****************************************************************************
     * Forward declaration of static functions
     *****************************************************************************/
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry);
    static void provisioner_deleter(mesh_config_entry_id_t id);
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event);
    static void app_config_successful_cb(void);
    static void app_config_failed_cb(void);
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt);
    
    static void app_start(void);
    
    
    /*****************************************************************************
     * Static variables
     *****************************************************************************/
    /* Required for the provisioner helper module */
    static network_dsm_handles_data_volatile_t m_dev_handles;
    
    static network_stats_data_stored_t m_nw_state;
    static bool m_node_prov_setup_started;
    static nrf_mesh_evt_handler_t m_mesh_core_event_handler = { .evt_cb = app_mesh_core_event_cb };
    
    NRF_MESH_STATIC_ASSERT(MESH_OPT_FIRST_FREE_ID <= MESH_APP_FILE_ID);
    MESH_CONFIG_FILE(m_provisioner_file, MESH_APP_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    MESH_CONFIG_ENTRY(provisioner,
                      PROVISIONER_ENTRY_ID,
                      1,
                      sizeof(network_stats_data_stored_t),
                      provisioner_setter,
                      provisioner_getter,
                      provisioner_deleter,
                      false);
    
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner setter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nsds = (network_stats_data_stored_t *) p_entry;
        memcpy(&m_nw_state, p_nsds, sizeof(network_stats_data_stored_t));
    
        return NRF_SUCCESS;
    }
    
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner getter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nw_state = (network_stats_data_stored_t *) p_entry;
        memcpy(p_nw_state, &m_nw_state, sizeof(m_nw_state));
    }
    
    static void provisioner_deleter(mesh_config_entry_id_t id)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner deleter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        /* Clear and set default values. */
        memset(&m_nw_state, 0x00, sizeof(m_nw_state));
    }
    
    static void provisioner_store(void)
    {
        mesh_config_entry_id_t id = PROVISIONER_ENTRY_ID;
    
        NRF_MESH_ERROR_CHECK(mesh_config_entry_set(id, &m_nw_state));
    }
    
    static void provisioner_invalidate(void)
    {
        /* Stop scanner. */
        prov_helper_scan_stop();
        /* Delete all old values and remove from mesh config. */
        (void)mesh_config_entry_delete(PROVISIONER_ENTRY_ID);
    }
    
    /*****************************************************************************/
    
    static void app_data_store_cb(void)
    {
        provisioner_store();
    }
    
    /*****************************************************************************/
    /**** Configuration process related callbacks ****/
    
    static void app_config_successful_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u successful\n", m_nw_state.configured_devices);
    
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    
        m_nw_state.configured_devices++;
        provisioner_store();
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    }
    
    static void app_config_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u failed.\n", m_nw_state.configured_devices);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to retry configuration.\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 2 to start provisioning new nodes.\n");
        m_node_prov_setup_started = false;
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
    }
    
    static void app_prov_success_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning successful\n");
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
        hal_led_pin_set(APP_CONFIGURATION_LED, 1);
    
        provisioner_store();
    }
    
    static void app_prov_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning failed. Press Button 1 to retry.\n");
    
        m_node_prov_setup_started = false;
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
    }
    
    
    /*****************************************************************************/
    /**** Model related callbacks ****/
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event)
    {
        switch (p_event->type)
        {
            case HEALTH_CLIENT_EVT_TYPE_CURRENT_STATUS_RECEIVED:
                __LOG(LOG_SRC_APP,
                      LOG_LEVEL_INFO,
                      "Node 0x%04x alive with %u active fault(s), RSSI: %d\n",
                      p_event->p_meta_data->src.value,
                      p_event->data.fault_status.fault_array_length,
                      ((p_event->p_meta_data->p_core_metadata->source == NRF_MESH_RX_SOURCE_SCANNER)
                           ? p_event->p_meta_data->p_core_metadata->params.scanner.rssi
                           : 0));
                break;
            default:
                break;
        }
    }
    
    static void app_config_server_event_cb(const config_server_evt_t * p_evt)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "config_server Event %d.\n", p_evt->type);
    
        if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
        {
            /* This should never return */
            hal_device_reset(0);
        }
    }
    
    static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
    {
        /* USER_NOTE: Do additional processing of config client events here if required */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
    
        /* Pass events to the node setup helper module for further processing */
        node_setup_config_client_event_process(event_type, p_event, length);
    }
    
    
    static void provisioning_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Start provisioning procedure ...\n");
    
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    }
    
    static void provisioning_resume(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                m_nw_state.provisioned_devices--;
                provisioning_start();
                m_node_prov_setup_started = true;
            }
        }
    }
    
    /** Check if all devices have been provisioned. If not, provision remaining devices.
     *  Check if all devices have been configured. If not, start configuring them.
     */
    static void check_network_state(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured, start node setup procedure. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                /* Execute configuration */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for provisioned node to be configured ...\n");
    
                node_setup_start(m_nw_state.last_device_address, PROVISIONER_RETRY_COUNT,
                                m_nw_state.appkey, APPKEY_INDEX, NETKEY_INDEX, m_nw_state.current_uri);
    
                hal_led_pin_set(APP_CONFIGURATION_LED, 1);
            }
            else
            {
                provisioning_start();
            }
    
            m_node_prov_setup_started = true;
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for previous procedure to finish ...\n");
        }
    }
    
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt)
    {
        /* USER_NOTE: User can insert mesh core event processing here */
        switch(p_evt->type)
        {
            /* Start user application specific functions only when stack is enabled */
            case NRF_MESH_EVT_ENABLED:
                __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Mesh evt: NRF_MESH_EVT_ENABLED\n");
    #if (PERSISTENT_STORAGE)
                /* Mesh stack initialization has been completed */
                app_start();
    #endif
                break;
    
            case NRF_MESH_EVT_CONFIG_LOAD_FAILURE:
                if (p_evt->params.config_load_failure.id.file == MESH_APP_FILE_ID)
                {
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Persistent provisioner data was corrupted. Set default values. \n");
                    /* Clear and set default values. */
                    memset(&m_nw_state, 0x00, sizeof(m_nw_state));
                }
                break;
    
            default:
                break;
        }
    }
    
    /* Binds the local models correctly with the desired keys */
    void app_default_models_bind_setup(void)
    {
        /* Bind health client to App key, and configure publication key */
        ERROR_CHECK(access_model_application_bind(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
        ERROR_CHECK(access_model_publish_application_set(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
    
        /* Bind self-config server to the self device key */
        ERROR_CHECK(config_server_bind(m_dev_handles.m_self_devkey_handle));
    }
    
    static void node_reset(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset  -----\n");
    
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
        /* This function may return if there are ongoing flash operations. */
        mesh_stack_device_reset();
    }
    
    #if NRF_MESH_LOG_ENABLE
    static const char m_usage_string[] =
        "\n"
        "\t\t--------------------------------------------------------------------------------\n"
        "\t\t Button/RTT 1) Initiate provisioning and configuration of unprovisioned devices.\n"
        "\t\t Button/RTT 4) Clear all the states to reset the node.\n"
        "\t\t--------------------------------------------------------------------------------\n";
    #endif
    
    static void button_event_handler(uint32_t button_number)
    {
        /* Increase button number because the buttons on the board is marked with 1 to 4 */
        button_number++;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            case 1:
            {
                /* Check if all devices have been provisioned or not */
                check_network_state();
                break;
            }
    
            case 2:
            {
                provisioning_resume();
                break;
            }
    
            /* Initiate node reset */
            case 4:
            {
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
    
            default:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
                break;
        }
    }
    
    static void app_rtt_input_handler(int key)
    {
        if (key >= '1' && key <= '4')
        {
            uint32_t button_number = key - '1';
            button_event_handler(button_number);
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
        }
    }
    
    void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
        m_dev_handles.m_netkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_appkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_self_devkey_handle = DSM_HANDLE_INVALID;
    
        /* This app requires following models :
         * config client : To be able to configure other devices
         * health client : To be able to interact with other health servers */
        ERROR_CHECK(config_client_init(app_config_client_event_cb));
        ERROR_CHECK(health_client_init(&m_dev_handles.m_health_client_instance, 0, app_health_event_cb));
    }
    
    static void mesh_init(void)
    {
        bool device_provisioned;
        mesh_stack_init_params_t init_params =
        {
            .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
            .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
            .models.models_init_cb   = models_init_cb,
            .models.config_server_cb = app_config_server_event_cb
        };
    
        nrf_mesh_evt_handler_add(&m_mesh_core_event_handler);
        uint32_t status = mesh_stack_init(&init_params, &device_provisioned);
        switch (status)
        {
            case NRF_ERROR_INVALID_DATA:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Data in the persistent memory was corrupted.\n");
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reboot device before starting of the provisioning process.\n");
                break;
            case NRF_SUCCESS:
                break;
            default:
                ERROR_CHECK(status);
        }
    
        if (status == NRF_SUCCESS)
        {
            /* Initialize the provisioner */
            mesh_provisioner_init_params_t m_prov_helper_init_info =
            {
                .p_dev_data = &m_dev_handles,
                .p_nw_data = &m_nw_state,
                .netkey_idx = NETKEY_INDEX,
                .attention_duration_s = ATTENTION_DURATION_S,
                .p_data_store_cb  = app_data_store_cb,
                .p_prov_success_cb = app_prov_success_cb,
                .p_prov_failed_cb = app_prov_failed_cb
            };
            prov_helper_init(&m_prov_helper_init_info);
    
            if (!device_provisioned)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setup defaults: Adding keys, addresses, and bindings \n");
    
                prov_helper_provision_self();
                app_default_models_bind_setup();
                app_data_store_cb();
            }
            else
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Restored: Handles \n");
                prov_helper_device_handles_load();
            }
    
            node_setup_cb_set(app_config_successful_cb, app_config_failed_cb);
        }
    }
    
    
    
    
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
     printf("\r\nUART started uart event handler.\r\n");
    
    }
    
    
    
    /**@brief  Function for initializing the UART module.
     */
    /**@snippet [UART Initialization] */
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
      APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    /**@snippet [UART Initialization] */
    
    
    
    
    
    
    
    
    static void initialize(void)
    {
          uart_init();
       
       // __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_FRIEND, LOG_LEVEL_DBG1, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Static Provisioner Demo -----\n");
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
        mesh_init();
        node_setup_uri_check();
    }
    
    static void app_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Starting application ...\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioned Nodes: %d, Configured Nodes: %d\n",
              m_nw_state.provisioned_devices, m_nw_state.configured_devices);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Dev key ", m_nw_state.self_devkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Net key ", m_nw_state.netkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "App key ", m_nw_state.appkey, NRF_MESH_KEY_SIZE);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to start provisioning and configuration process. \n");
    }
    
    static void start(void)
    {
        rtt_input_enable(app_rtt_input_handler, RTT_INPUT_POLL_PERIOD_MS);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "<start> \n");
    
        ERROR_CHECK(mesh_stack_start());
    
    #if (!PERSISTENT_STORAGE)
        app_start();
    #endif
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
    
        hal_led_mask_set(HAL_LED_MASK, LED_MASK_STATE_OFF);
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
    }
    
    
    
    /**@brief Function for initializing the nrf log module.
     */
     #if 0
    static void log1_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    #endif
    
    
    
    
    
    
    
    
    #if 0
    void my_uart_callback(nrfx_uarte_event_t const * p_event,
                          void *                     p_context)
    {
        //TODO: Handle 'p_event'
    }
    #endif
    
    int main(void)
    {
        
    
       // nrfx_uarte_t m_uart = NRFX_UARTE_INSTANCE(0); 
        //nrfx_uarte_config_t m_uart_config = NRFX_UARTE_DEFAULT_CONFIG;
        
       // nrfx_uarte_init(&m_uart, &m_uart_config, my_uart_callback);
    
    
    
        // uart_init();
         //log1_init();
    
     //   ret_code_t err_code = NRF_LOG_INIT(NULL);
      //  APP_ERROR_CHECK(err_code);
    
        // NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        initialize();
        start();
    
        for (;;)
        {
            (void)sd_app_evt_wait();
        }
    }
    

    Attaching the log.c file

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdarg.h>
    #include <stdint.h>
    #include <nrf_error.h>
    #include "log.h"
    #if defined(HOST)
    #include <stdio.h>
    #endif
    #include <stdio.h>
    #if NRF_MESH_LOG_ENABLE
    
    const char * g_log_hex_digits = "0123456789ABCDEF";
    
    uint32_t       g_log_dbg_msk = LOG_MSK_DEFAULT;
    int32_t        g_log_dbg_lvl = LOG_LEVEL_DEFAULT;
    log_callback_t m_log_callback = LOG_CALLBACK_DEFAULT;
    
    #if (LOG_ENABLE_RTT && !defined(HOST))
    #include <SEGGER_RTT.h>
    
    /* For some reason, this function, while not static, is not included in the RTT header files. */
    int SEGGER_RTT_vprintf(unsigned, const char *, va_list *);
    
    void log_callback_rtt(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
    
       /* SEGGER_RTT_printf(0, "<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        SEGGER_RTT_vprintf(0, format, &arguments);*/
        printf( "<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        (void)vprintf(format, arguments);
    
    }
    
    void log_callback_logview(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        SEGGER_RTT_printf(0, "%u;%u;%s;%u;", dbg_level, timestamp, p_filename, line);
        SEGGER_RTT_vprintf(0, format, &arguments);
        SEGGER_RTT_Write(0, "$", 1);
    }
    
    #endif
    
    #if defined(HOST) /* For unit tests and host builds */
    void log_callback_stdout(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        printf("<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        (void) vprintf(format, arguments);
    }
    #endif
    
    void log_init(uint32_t mask, uint32_t level, log_callback_t callback)
    {
        g_log_dbg_msk = mask;
        g_log_dbg_lvl = level;
    
        m_log_callback = callback;
    }
    
    void log_set_callback(log_callback_t callback)
    {
        m_log_callback = callback;
    }
    
    void log_printf(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, ...)
    {
        va_list arguments; /*lint -save -esym(530,arguments) Symbol arguments not initialized. */
        va_start(arguments, format);
        log_vprintf(dbg_level, p_filename, line, timestamp, format, arguments);
        va_end(arguments); /*lint -restore */
    }
    
    void log_vprintf(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        if (m_log_callback != NULL)
        {
            m_log_callback(dbg_level, p_filename, line, timestamp, format, arguments);
        }
    }
    
    #endif
    

    Used the same sdk_config.h file. I have done these changes in provisioner example code of nrf 5.0 mesh sdk.

    Please can you just help me in achieving this. I want to use UART logging in the provisioner example code of nrf 5.0 mesh. Can you please provide me the code changes for the provisioner project so that i can able to build it and test it.

    Thank you so much

    Ela

Reply
  • Hi Mttrinh,

    I have implemented in the same way as mentioned in the example, but getting lot of errors and not able to build the project, can you help me with this. And how shall i test this example code, i do not want to use on board debugger and USB cable i want to use the UART pins to test uart data.

    I am attaching the error i am getting:

    Building 'provisioner_nrf52832_xxAA_s132_7.2.0' from solution 'provisioner_nrf52832_xxAA_s132_7.2.0' in configuration 'Debug'
      Compiling 'main.c'
      Compiling 'provisioner_helper.c'
      Compiling 'node_setup.c'
      Compiling 'rtt_input.c'
      Compiling 'simple_hal.c'
      Compiling 'mesh_adv.c'
      Compiling 'nrf_mesh_weak.c'
      Compiling 'ble_softdevice_support.c'
      Compiling 'app_error_weak.c'
      Compiling 'assertion_handler_weak.c'
      Compiling 'nrf_log_default_backends.c'
      Compiling 'retarget.c'
      Compiling 'nrf_log_frontend.c'
      Compiling 'app_uart_fifo.c'
      Compiling 'nrf_log_str_formatter.c'
      Compiling 'nrf_memobj.c'
      Compiling 'nrf_log_backend_rtt.c'
      Compiling 'nrf_log_backend_serial.c'
      Compiling 'nrf_balloc.c'
      Compiling 'nrf_ringbuf.c'
      Compiling 'nrf_fprintf.c'
      Compiling 'nrf_drv_uart.c'
      Compiling 'app_fifo.c'
      Compiling 'internal_event.c'
      Compiling 'nrf_mesh_configure.c'
      Compiling 'aes.c'
      Compiling 'msg_cache.c'
      Compiling 'transport.c'
      Compiling 'packet_buffer.c'
      Compiling 'event.c'
      Compiling 'flash_manager_defrag.c'
      Compiling 'fifo.c'
      Compiling 'nrf_flash.c'
      Compiling 'net_state.c'
      Compiling 'mesh_flash.c'
      Compiling 'nrf_mesh_utils.c'
      Compiling 'nrf_mesh.c'
      Compiling 'queue.c'
      Compiling 'hal.c'
      Compiling 'aes_cmac.c'
      Compiling 'timer_scheduler.c'
      Compiling 'long_timer.c'
      Compiling 'timer.c'
      Compiling 'rand.c'
      Compiling 'nrf_mesh_opt.c'
      Compiling 'mesh_opt.c'
      Compiling 'timeslot.c'
      Compiling 'timeslot_timer.c'
      Compiling 'bearer_event.c'
      Compiling 'enc.c'
      Compiling 'net_packet.c'
      Compiling 'network.c'
      Compiling 'msqueue.c'
      Compiling 'nrf_mesh_keygen.c'
      Compiling 'cache.c'
      Compiling 'log.c'
      Compiling 'list.c'
      Compiling 'flash_manager.c'
      Compiling 'ccm_soft.c'
      Compiling 'toolchain.c'
      Compiling 'replay_cache.c'
      Compiling 'beacon.c'
      Compiling 'core_tx.c'
      Compiling 'flash_manager_internal.c'
      Compiling 'heartbeat.c'
      Compiling 'mesh_config.c'
      Compiling 'net_beacon.c'
      Compiling 'fsm.c'
      Compiling 'mesh_config_backend.c'
      Compiling 'lpn.c'
      Compiling 'mesh_config_flashman_glue.c'
      Compiling 'core_tx_lpn.c'
      Compiling 'mesh_lpn_subman.c'
      Compiling 'core_tx_local.c'
      Compiling 'emergency_cache.c'
      Compiling 'mesh_mem_stdlib.c'
      Compiling 'core_tx_adv.c'
      Assembling 'thumb_crt0.s'
      Compiling 'mesh_stack.c'
      Compiling 'access_publish.c'
      Compiling 'access_publish_retransmission.c'
      Compiling 'access.c'
      Compiling 'access_reliable.c'
      Compiling 'device_state_manager.c'
      Compiling 'ad_listener.c'
      Compiling 'ad_type_filter.c'
      Compiling 'adv_packet_filter.c'
      Compiling 'advertiser.c'
      Compiling 'bearer_handler.c'
      Compiling 'broadcast.c'
      Compiling 'gap_address_filter.c'
      Compiling 'filter_engine.c'
      Compiling 'radio_config.c'
      Compiling 'rssi_filter.c'
      Compiling 'scanner.c'
      Compiling 'mesh_pa_lna.c'
      Compiling 'SEGGER_RTT.c'
      Compiling 'SEGGER_RTT_printf.c'
      Compiling 'uECC.c'
      Compiling 'nrfx_gpiote.c'
      Compiling 'ble_advdata.c'
      Compiling 'app_util_platform.c'
      Compiling 'nrf_section_iter.c'
      Compiling 'nrf_sdh_soc.c'
      Compiling 'nrf_sdh.c'
        #warning Please select NRF_CLOCK_LF_ACCURACY_500_PPM when using NRF_CLOCK_LF_SRC_RC [-Wcpp]
      Compiling 'nrf_sdh_ble.c'
      Compiling 'ble_conn_params.c'
      Compiling 'nrf_atomic.c'
      Compiling 'ble_srv_common.c'
      Compiling 'system_nrf52.c'
      Compiling 'app_error.c'
      Assembling 'ses_startup_nrf52.s'
      Compiling 'app_error_handler_gcc.c'
      Compiling 'prov_provisioner.c'
      Assembling 'ses_startup_nrf_common.s'
      Compiling 'nrf_mesh_prov.c'
      Compiling 'provisioning.c'
      Compiling 'prov_beacon.c'
      Compiling 'prov_utils.c'
      Compiling 'prov_bearer_adv.c'
      Compiling 'config_client.c'
      Compiling 'composition_data.c'
      Compiling 'config_server.c'
      Compiling 'packed_index_list.c'
      Compiling 'health_server.c'
      Compiling 'health_client.c'
      Compiling 'app_timer_mesh.c'
      Compiling 'app_timer_workaround.c'
      Compiling 'nrf_fprintf_format.c'
      Generating linker script 'provisioner_nrf52832_xxAA_s132_7.2.0.ld'
      Linking provisioner_nrf52832_xxAA_s132_7.2.0.elf
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_rx':
        undefined reference to `nrfx_uarte_rx'
        /home/ekta/Desktop/8_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/integration/nrfx/legacy/nrf_drv_uart.h:569: undefined reference to `nrfx_uarte_rx'
        /home/ekta/Desktop/8_feb_21/SmartProducts/Firmware/3rdParty/nRF5/nRF5SDK/integration/nrfx/legacy/nrf_drv_uart.h:569: undefined reference to `nrfx_uarte_rx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx':
        undefined reference to `nrfx_uarte_tx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_rx':
        undefined reference to `nrfx_uarte_rx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx_in_progress':
        undefined reference to `nrfx_uarte_tx_in_progress'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/app_uart_fifo.o: in function `nrf_drv_uart_tx':
        undefined reference to `nrfx_uarte_tx'
        build/provisioner_nrf52832_xxAA_s132_7.2.0_Debug/obj/nrf_drv_uart.o: in function `nrf_drv_uart_init':
        undefined reference to `nrfx_uarte_init'
    Build failed

    Attaching the main.c file 

     

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdint.h>
    #include <string.h>
    
    /* HAL */
    #include "boards.h"
    #include "nrf_delay.h"
    #include "simple_hal.h"
    #include "app_timer.h"
    
    /* Core */
    #include "nrf_mesh.h"
    #include "nrf_mesh_events.h"
    #include "nrf_mesh_assert.h"
    #include "access_config.h"
    #include "device_state_manager.h"
    #include "mesh_stack.h"
    #include "net_state.h"
    #include "mesh_opt_provisioner.h"
    #include "mesh_config_entry.h"
    #include "mesh_opt.h"
    
    /* Provisioning and configuration */
    #include "provisioner_helper.h"
    #include "node_setup.h"
    #include "mesh_app_utils.h"
    
    /* Models */
    #include "config_client.h"
    #include "config_server.h"
    #include "health_client.h"
    
    /* Logging and RTT */
    #include "rtt_input.h"
    #include "log.h"
    
    #include"nrf_log_ctrl.h"
    #include "nrf_uart.h"
    #include "app_uart.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    //#include "nrf_log_backend_interface.h"
    
    
    /* Example specific includes */
    #include "example_network_config.h"
    #include "nrf_mesh_config_examples.h"
    #include "ble_softdevice_support.h"
    #include "example_common.h"
    
    /*****************************************************************************
     * Definitions
     *****************************************************************************/
    #define APP_PROVISIONING_LED            BSP_LED_0
    #define APP_CONFIGURATION_LED           BSP_LED_1
    
    
    
    
    
    #define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE                256                                         /**< UART RX buffer size. */
    #include "app_uart.h"
    #include "nrf_uart.h"
    static bool m_device_provisioned;
    
    /*****************************************************************************
     * Forward declaration of static functions
     *****************************************************************************/
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry);
    static void provisioner_deleter(mesh_config_entry_id_t id);
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event);
    static void app_config_successful_cb(void);
    static void app_config_failed_cb(void);
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt);
    
    static void app_start(void);
    
    
    /*****************************************************************************
     * Static variables
     *****************************************************************************/
    /* Required for the provisioner helper module */
    static network_dsm_handles_data_volatile_t m_dev_handles;
    
    static network_stats_data_stored_t m_nw_state;
    static bool m_node_prov_setup_started;
    static nrf_mesh_evt_handler_t m_mesh_core_event_handler = { .evt_cb = app_mesh_core_event_cb };
    
    NRF_MESH_STATIC_ASSERT(MESH_OPT_FIRST_FREE_ID <= MESH_APP_FILE_ID);
    MESH_CONFIG_FILE(m_provisioner_file, MESH_APP_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    MESH_CONFIG_ENTRY(provisioner,
                      PROVISIONER_ENTRY_ID,
                      1,
                      sizeof(network_stats_data_stored_t),
                      provisioner_setter,
                      provisioner_getter,
                      provisioner_deleter,
                      false);
    
    static uint32_t provisioner_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner setter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nsds = (network_stats_data_stored_t *) p_entry;
        memcpy(&m_nw_state, p_nsds, sizeof(network_stats_data_stored_t));
    
        return NRF_SUCCESS;
    }
    
    static void provisioner_getter(mesh_config_entry_id_t id, void * p_entry)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner getter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        network_stats_data_stored_t * p_nw_state = (network_stats_data_stored_t *) p_entry;
        memcpy(p_nw_state, &m_nw_state, sizeof(m_nw_state));
    }
    
    static void provisioner_deleter(mesh_config_entry_id_t id)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Provisioner deleter ...\n");
        NRF_MESH_ASSERT_DEBUG(PROVISIONER_RECORD == id.record);
    
        /* Clear and set default values. */
        memset(&m_nw_state, 0x00, sizeof(m_nw_state));
    }
    
    static void provisioner_store(void)
    {
        mesh_config_entry_id_t id = PROVISIONER_ENTRY_ID;
    
        NRF_MESH_ERROR_CHECK(mesh_config_entry_set(id, &m_nw_state));
    }
    
    static void provisioner_invalidate(void)
    {
        /* Stop scanner. */
        prov_helper_scan_stop();
        /* Delete all old values and remove from mesh config. */
        (void)mesh_config_entry_delete(PROVISIONER_ENTRY_ID);
    }
    
    /*****************************************************************************/
    
    static void app_data_store_cb(void)
    {
        provisioner_store();
    }
    
    /*****************************************************************************/
    /**** Configuration process related callbacks ****/
    
    static void app_config_successful_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u successful\n", m_nw_state.configured_devices);
    
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    
        m_nw_state.configured_devices++;
        provisioner_store();
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    }
    
    static void app_config_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Configuration of device %u failed.\n", m_nw_state.configured_devices);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to retry configuration.\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 2 to start provisioning new nodes.\n");
        m_node_prov_setup_started = false;
        hal_led_pin_set(APP_CONFIGURATION_LED, 0);
    }
    
    static void app_prov_success_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning successful\n");
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
        hal_led_pin_set(APP_CONFIGURATION_LED, 1);
    
        provisioner_store();
    }
    
    static void app_prov_failed_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioning failed. Press Button 1 to retry.\n");
    
        m_node_prov_setup_started = false;
    
        hal_led_pin_set(APP_PROVISIONING_LED, 0);
    }
    
    
    /*****************************************************************************/
    /**** Model related callbacks ****/
    static void app_health_event_cb(const health_client_t * p_client, const health_client_evt_t * p_event)
    {
        switch (p_event->type)
        {
            case HEALTH_CLIENT_EVT_TYPE_CURRENT_STATUS_RECEIVED:
                __LOG(LOG_SRC_APP,
                      LOG_LEVEL_INFO,
                      "Node 0x%04x alive with %u active fault(s), RSSI: %d\n",
                      p_event->p_meta_data->src.value,
                      p_event->data.fault_status.fault_array_length,
                      ((p_event->p_meta_data->p_core_metadata->source == NRF_MESH_RX_SOURCE_SCANNER)
                           ? p_event->p_meta_data->p_core_metadata->params.scanner.rssi
                           : 0));
                break;
            default:
                break;
        }
    }
    
    static void app_config_server_event_cb(const config_server_evt_t * p_evt)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "config_server Event %d.\n", p_evt->type);
    
        if (p_evt->type == CONFIG_SERVER_EVT_NODE_RESET)
        {
            /* This should never return */
            hal_device_reset(0);
        }
    }
    
    static void app_config_client_event_cb(config_client_event_type_t event_type, const config_client_event_t * p_event, uint16_t length)
    {
        /* USER_NOTE: Do additional processing of config client events here if required */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config client event\n");
    
        /* Pass events to the node setup helper module for further processing */
        node_setup_config_client_event_process(event_type, p_event, length);
    }
    
    
    static void provisioning_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Start provisioning procedure ...\n");
    
        prov_helper_provision_next_device();
        prov_helper_scan_start();
    
        hal_led_pin_set(APP_PROVISIONING_LED, 1);
    }
    
    static void provisioning_resume(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                m_nw_state.provisioned_devices--;
                provisioning_start();
                m_node_prov_setup_started = true;
            }
        }
    }
    
    /** Check if all devices have been provisioned. If not, provision remaining devices.
     *  Check if all devices have been configured. If not, start configuring them.
     */
    static void check_network_state(void)
    {
        if (!m_node_prov_setup_started)
        {
            /* If previously provisioned device is not configured, start node setup procedure. */
            if (m_nw_state.configured_devices < m_nw_state.provisioned_devices)
            {
                /* Execute configuration */
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for provisioned node to be configured ...\n");
    
                node_setup_start(m_nw_state.last_device_address, PROVISIONER_RETRY_COUNT,
                                m_nw_state.appkey, APPKEY_INDEX, NETKEY_INDEX, m_nw_state.current_uri);
    
                hal_led_pin_set(APP_CONFIGURATION_LED, 1);
            }
            else
            {
                provisioning_start();
            }
    
            m_node_prov_setup_started = true;
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Waiting for previous procedure to finish ...\n");
        }
    }
    
    static void app_mesh_core_event_cb (const nrf_mesh_evt_t * p_evt)
    {
        /* USER_NOTE: User can insert mesh core event processing here */
        switch(p_evt->type)
        {
            /* Start user application specific functions only when stack is enabled */
            case NRF_MESH_EVT_ENABLED:
                __LOG(LOG_SRC_APP, LOG_LEVEL_DBG1, "Mesh evt: NRF_MESH_EVT_ENABLED\n");
    #if (PERSISTENT_STORAGE)
                /* Mesh stack initialization has been completed */
                app_start();
    #endif
                break;
    
            case NRF_MESH_EVT_CONFIG_LOAD_FAILURE:
                if (p_evt->params.config_load_failure.id.file == MESH_APP_FILE_ID)
                {
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Persistent provisioner data was corrupted. Set default values. \n");
                    /* Clear and set default values. */
                    memset(&m_nw_state, 0x00, sizeof(m_nw_state));
                }
                break;
    
            default:
                break;
        }
    }
    
    /* Binds the local models correctly with the desired keys */
    void app_default_models_bind_setup(void)
    {
        /* Bind health client to App key, and configure publication key */
        ERROR_CHECK(access_model_application_bind(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
        ERROR_CHECK(access_model_publish_application_set(m_dev_handles.m_health_client_instance.model_handle, m_dev_handles.m_appkey_handle));
    
        /* Bind self-config server to the self device key */
        ERROR_CHECK(config_server_bind(m_dev_handles.m_self_devkey_handle));
    }
    
    static void node_reset(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- Node reset  -----\n");
    
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_RESET);
        /* This function may return if there are ongoing flash operations. */
        mesh_stack_device_reset();
    }
    
    #if NRF_MESH_LOG_ENABLE
    static const char m_usage_string[] =
        "\n"
        "\t\t--------------------------------------------------------------------------------\n"
        "\t\t Button/RTT 1) Initiate provisioning and configuration of unprovisioned devices.\n"
        "\t\t Button/RTT 4) Clear all the states to reset the node.\n"
        "\t\t--------------------------------------------------------------------------------\n";
    #endif
    
    static void button_event_handler(uint32_t button_number)
    {
        /* Increase button number because the buttons on the board is marked with 1 to 4 */
        button_number++;
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Button %u pressed\n", button_number);
        switch (button_number)
        {
            case 1:
            {
                /* Check if all devices have been provisioned or not */
                check_network_state();
                break;
            }
    
            case 2:
            {
                provisioning_resume();
                break;
            }
    
            /* Initiate node reset */
            case 4:
            {
                if (mesh_stack_is_device_provisioned())
                {
                    /* Clear all the states to reset the node. */
                    provisioner_invalidate();
                    mesh_stack_config_clear();
                }
                node_reset();
                break;
            }
    
            default:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
                break;
        }
    }
    
    static void app_rtt_input_handler(int key)
    {
        if (key >= '1' && key <= '4')
        {
            uint32_t button_number = key - '1';
            button_event_handler(button_number);
        }
        else
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
        }
    }
    
    void models_init_cb(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing and adding models\n");
        m_dev_handles.m_netkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_appkey_handle = DSM_HANDLE_INVALID;
        m_dev_handles.m_self_devkey_handle = DSM_HANDLE_INVALID;
    
        /* This app requires following models :
         * config client : To be able to configure other devices
         * health client : To be able to interact with other health servers */
        ERROR_CHECK(config_client_init(app_config_client_event_cb));
        ERROR_CHECK(health_client_init(&m_dev_handles.m_health_client_instance, 0, app_health_event_cb));
    }
    
    static void mesh_init(void)
    {
        bool device_provisioned;
        mesh_stack_init_params_t init_params =
        {
            .core.irq_priority       = NRF_MESH_IRQ_PRIORITY_LOWEST,
            .core.lfclksrc           = DEV_BOARD_LF_CLK_CFG,
            .models.models_init_cb   = models_init_cb,
            .models.config_server_cb = app_config_server_event_cb
        };
    
        nrf_mesh_evt_handler_add(&m_mesh_core_event_handler);
        uint32_t status = mesh_stack_init(&init_params, &device_provisioned);
        switch (status)
        {
            case NRF_ERROR_INVALID_DATA:
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Data in the persistent memory was corrupted.\n");
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reboot device before starting of the provisioning process.\n");
                break;
            case NRF_SUCCESS:
                break;
            default:
                ERROR_CHECK(status);
        }
    
        if (status == NRF_SUCCESS)
        {
            /* Initialize the provisioner */
            mesh_provisioner_init_params_t m_prov_helper_init_info =
            {
                .p_dev_data = &m_dev_handles,
                .p_nw_data = &m_nw_state,
                .netkey_idx = NETKEY_INDEX,
                .attention_duration_s = ATTENTION_DURATION_S,
                .p_data_store_cb  = app_data_store_cb,
                .p_prov_success_cb = app_prov_success_cb,
                .p_prov_failed_cb = app_prov_failed_cb
            };
            prov_helper_init(&m_prov_helper_init_info);
    
            if (!device_provisioned)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Setup defaults: Adding keys, addresses, and bindings \n");
    
                prov_helper_provision_self();
                app_default_models_bind_setup();
                app_data_store_cb();
            }
            else
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Restored: Handles \n");
                prov_helper_device_handles_load();
            }
    
            node_setup_cb_set(app_config_successful_cb, app_config_failed_cb);
        }
    }
    
    
    
    
    
    void uart_event_handle(app_uart_evt_t * p_event)
    {
     printf("\r\nUART started uart event handler.\r\n");
    
    }
    
    
    
    /**@brief  Function for initializing the UART module.
     */
    /**@snippet [UART Initialization] */
    static void uart_init(void)
    {
        uint32_t                     err_code;
        app_uart_comm_params_t const comm_params =
        {
            .rx_pin_no    = RX_PIN_NUMBER,
            .tx_pin_no    = TX_PIN_NUMBER,
            .rts_pin_no   = RTS_PIN_NUMBER,
            .cts_pin_no   = CTS_PIN_NUMBER,
            .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
            .use_parity   = false,
    #if defined (UART_PRESENT)
            .baud_rate    = NRF_UART_BAUDRATE_115200
    #else
            .baud_rate    = NRF_UARTE_BAUDRATE_115200
    #endif
        };
    
      APP_UART_FIFO_INIT(&comm_params,
                           UART_RX_BUF_SIZE,
                           UART_TX_BUF_SIZE,
                           uart_event_handle,
                           APP_IRQ_PRIORITY_LOWEST,
                           err_code);
        APP_ERROR_CHECK(err_code);
    }
    /**@snippet [UART Initialization] */
    
    
    
    
    
    
    
    
    static void initialize(void)
    {
          uart_init();
       
       // __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
        __LOG_INIT(LOG_SRC_APP | LOG_SRC_FRIEND, LOG_LEVEL_DBG1, log_callback_rtt);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Static Provisioner Demo -----\n");
    
        ERROR_CHECK(app_timer_init());
        hal_leds_init();
    
    #if BUTTON_BOARD
        ERROR_CHECK(hal_buttons_init(button_event_handler));
    #endif
    
        ble_stack_init();
        mesh_init();
        node_setup_uri_check();
    }
    
    static void app_start(void)
    {
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Starting application ...\n");
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Provisioned Nodes: %d, Configured Nodes: %d\n",
              m_nw_state.provisioned_devices, m_nw_state.configured_devices);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Dev key ", m_nw_state.self_devkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "Net key ", m_nw_state.netkey, NRF_MESH_KEY_SIZE);
        __LOG_XB(LOG_SRC_APP, LOG_LEVEL_INFO, "App key ", m_nw_state.appkey, NRF_MESH_KEY_SIZE);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Press Button/RTT 1 to start provisioning and configuration process. \n");
    }
    
    static void start(void)
    {
        rtt_input_enable(app_rtt_input_handler, RTT_INPUT_POLL_PERIOD_MS);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "<start> \n");
    
        ERROR_CHECK(mesh_stack_start());
    
    #if (!PERSISTENT_STORAGE)
        app_start();
    #endif
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, m_usage_string);
    
        hal_led_mask_set(HAL_LED_MASK, LED_MASK_STATE_OFF);
        hal_led_blink_ms(HAL_LED_MASK, LED_BLINK_INTERVAL_MS, LED_BLINK_CNT_START);
    }
    
    
    
    /**@brief Function for initializing the nrf log module.
     */
     #if 0
    static void log1_init(void)
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    #endif
    
    
    
    
    
    
    
    
    #if 0
    void my_uart_callback(nrfx_uarte_event_t const * p_event,
                          void *                     p_context)
    {
        //TODO: Handle 'p_event'
    }
    #endif
    
    int main(void)
    {
        
    
       // nrfx_uarte_t m_uart = NRFX_UARTE_INSTANCE(0); 
        //nrfx_uarte_config_t m_uart_config = NRFX_UARTE_DEFAULT_CONFIG;
        
       // nrfx_uarte_init(&m_uart, &m_uart_config, my_uart_callback);
    
    
    
        // uart_init();
         //log1_init();
    
     //   ret_code_t err_code = NRF_LOG_INIT(NULL);
      //  APP_ERROR_CHECK(err_code);
    
        // NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        initialize();
        start();
    
        for (;;)
        {
            (void)sd_app_evt_wait();
        }
    }
    

    Attaching the log.c file

    /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     * list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <stdarg.h>
    #include <stdint.h>
    #include <nrf_error.h>
    #include "log.h"
    #if defined(HOST)
    #include <stdio.h>
    #endif
    #include <stdio.h>
    #if NRF_MESH_LOG_ENABLE
    
    const char * g_log_hex_digits = "0123456789ABCDEF";
    
    uint32_t       g_log_dbg_msk = LOG_MSK_DEFAULT;
    int32_t        g_log_dbg_lvl = LOG_LEVEL_DEFAULT;
    log_callback_t m_log_callback = LOG_CALLBACK_DEFAULT;
    
    #if (LOG_ENABLE_RTT && !defined(HOST))
    #include <SEGGER_RTT.h>
    
    /* For some reason, this function, while not static, is not included in the RTT header files. */
    int SEGGER_RTT_vprintf(unsigned, const char *, va_list *);
    
    void log_callback_rtt(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
    
       /* SEGGER_RTT_printf(0, "<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        SEGGER_RTT_vprintf(0, format, &arguments);*/
        printf( "<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        (void)vprintf(format, arguments);
    
    }
    
    void log_callback_logview(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        SEGGER_RTT_printf(0, "%u;%u;%s;%u;", dbg_level, timestamp, p_filename, line);
        SEGGER_RTT_vprintf(0, format, &arguments);
        SEGGER_RTT_Write(0, "$", 1);
    }
    
    #endif
    
    #if defined(HOST) /* For unit tests and host builds */
    void log_callback_stdout(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        printf("<t: %10u>, %s, %4d, ",timestamp, p_filename, line);
        (void) vprintf(format, arguments);
    }
    #endif
    
    void log_init(uint32_t mask, uint32_t level, log_callback_t callback)
    {
        g_log_dbg_msk = mask;
        g_log_dbg_lvl = level;
    
        m_log_callback = callback;
    }
    
    void log_set_callback(log_callback_t callback)
    {
        m_log_callback = callback;
    }
    
    void log_printf(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, ...)
    {
        va_list arguments; /*lint -save -esym(530,arguments) Symbol arguments not initialized. */
        va_start(arguments, format);
        log_vprintf(dbg_level, p_filename, line, timestamp, format, arguments);
        va_end(arguments); /*lint -restore */
    }
    
    void log_vprintf(uint32_t dbg_level, const char * p_filename, uint16_t line,
        uint32_t timestamp, const char * format, va_list arguments)
    {
        if (m_log_callback != NULL)
        {
            m_log_callback(dbg_level, p_filename, line, timestamp, format, arguments);
        }
    }
    
    #endif
    

    Used the same sdk_config.h file. I have done these changes in provisioner example code of nrf 5.0 mesh sdk.

    Please can you just help me in achieving this. I want to use UART logging in the provisioner example code of nrf 5.0 mesh. Can you please provide me the code changes for the provisioner project so that i can able to build it and test it.

    Thank you so much

    Ela

Children
No Data
Related