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

NRF calendar example error with ble_stack_init()

Hello, I am using nrf52840 board and SDK 16.0.0.

I am trying to merge this calendar example (https://github.com/NordicPlayground/nrf5-calendar-example) into ble_app_template project. My main function looks like this.

int main(void)
{   
    bool erase_bonds;
    
    /** Calendar example merging starts from here **/
    uint8_t uart_byte;
    uint32_t year, month, day, hour, minute, second;
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    
    nrf_cal_init();
    nrf_cal_set_callback(calendar_updated, 4);
    uart_init();
    
    /** Ble example code starts from here **/
    // Initialize.
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();

    mac_add_find();

    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();
  

    // Start execution.
    NRF_LOG_INFO("Template example started.");
    application_timers_start();
    advertising_start(erase_bonds);
    
    /** Calendar example **/
    printf("\r\nCalendar demo\r\n\n");
    printf("s - Set time\r\n");
    printf("g - Get time\r\n");
    printf("r - Run continuous time updates\r\n\n");
    /*
    while (true)
    {
        if(app_uart_get(&uart_byte) == NRF_SUCCESS)
        {
            switch(uart_byte)
            {
                case 's':
                    run_time_updates = false;
                
                    year = (uint32_t)uart_get_parameter("Enter year", 1970, 2100);
                    month = (uint32_t)uart_get_parameter("Enter month", 0, 11);
                    day = (uint32_t)uart_get_parameter("Enter day", 1, 31);
                    hour = (uint32_t)uart_get_parameter("Enter hour", 0, 23);
                    minute = (uint32_t)uart_get_parameter("Enter minute", 0, 59);
                    second = (uint32_t)uart_get_parameter("Enter second", 0, 59);
                    
                    nrf_cal_set_time(year, month, day, hour, minute, second);
                    
                    printf("Time set: ");
                    printf("%s", nrf_cal_get_time_string(false));
                    printf("\r\n\n");
                    break;
                
                case 'g':
                    //print_current_time();
                    printf("%s", nrf_cal_get_time_string(false));
                    break;
                
               
            }
        }
    }

    */
  
    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}

Here are the problems.

Problem #1

In the main function, it seems nrf_cal_init() and ble_stack_init() function are not compatible, it always resulted NRF_BREAKPOINT_COND.

static void ble_stack_init(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);  // << Where the error is happening
    ...
}

Problem #2

Also, uart_init() function from the calendar example seems to collide with log_init() function from the ble_app_template example. The error is generated when I debug this function inside the log_init(). I put the comment on the problem line.

void nrf_log_default_backends_init(void)
{
    int32_t backend_id = -1;
    (void)backend_id;
    
    ...
    
#if defined(NRF_LOG_BACKEND_UART_ENABLED) && NRF_LOG_BACKEND_UART_ENABLED
    nrf_log_backend_uart_init();        // << Where the error is happening
    backend_id = nrf_log_backend_add(&uart_log_backend, NRF_LOG_SEVERITY_DEBUG);
    ASSERT(backend_id >= 0);
    nrf_log_backend_enable(&uart_log_backend);
#endif
}

I guess the first problem might be the RTC0 issues by the SoftDevice, but the Problem 2, I don't know whats going on. I appreciate any suggestions and solutions! Thank you

Parents
  • Hi

    Problem 1 is related to RTC0 being used, correct. Change the CAL_RTC defines here to RTC1 or RTC2 to avoid this conflict. 

    Regarding 2 I would try disabling the NRF_LOG_BACKEND_UART_ENABLED in sdk_config.h, and enable the RTT backend instead. 

    Alternatively you have to remove the uart_init call from the nrf_cal code, and possibly also change all the printf calls in the example to use the NRF_LOG.. API instead. 

    Best regards
    Torbjørn

  • Hello Ovrebekk,

    Thanks for you prompt reply. Everything worked like a charm. I changed RTC0 to RTC1. For the problem 2, I rather decided to stick on to the uart, so I disabled RTT instead.

    And, as you might have expected, I brought another questions here :D

    Question

    I am trying to advertise a timestamp. How can I get the sec, minute, hour, .. etc separately? Of course, I could just call the function nrf_cal_get_time_string() (btw how did you link and highlight the function ? i could only link the URL) in the main() and extract each time data from that string. Is there any other way that I can retrieve each sec, mins, hours.. differently?

    struct tm *nrf_cal_get_time(void)
    {
        time_t return_time;
        return_time = m_time + CAL_RTC->COUNTER / 8;
        m_tm_return_time = *localtime(&return_time);
        return &m_tm_return_time;
    }

    I found this, and it seems to contain current time data calculated by RTC.

    printf("%d\r\n", *nrf_cal_get_time());

    I did this in my main function and it gives me 2-digit data, which looks like secs data. I am learning from basics, and I appreciate if you could provide me some help. Thanks always Nordic,

  • Hi

    The nrf_cal_get_time() function returns a pointer to a tm struct, which contains seconds, minutes etc. 

    For a full overview of the fields in the tm struct please have a look here:
    https://pubs.opengroup.org/onlinepubs/007908799/xsh/time.h.html

    Please note that this is all part of the standard time.h C library, so it's not Nordic specific in any way. 

    Best regards
    Torbjørn 

Reply Children
Related