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

App timer and Disable Softdevice Problems ?

Hi all,

I using nrf52832 and segger IDE

I am trying disable softdevice and enable it while chip running. In my project, I use RTC1 for app timer.

When I disable SD, I will stop app_timer relate to SD follow example ble_app_gzll.

This my code :

static void disable_GATT_table(void)
{
    NRF_LOG_INFO("Disable GATT Table");

    // Stop functions using SoftDevice before disabling Soft Device
    ble_services_stop();
	
	//wdt_stop();

    // Disable the softdevice stack.
    ble_stack_stop();
	NRF_LOG_INFO("Disable SD");
    //check_source_clock();
    // Request Low frequency clock for RTC2
    nrf_drv_clock_lfclk_request(NULL);   
	NRF_LOG_INFO("Request Low frequency clock");
	//check_source_clock();	
}

static void ble_services_stop(void)
{
    uint32_t err_code;

    // Stop any impending connection parameters update.
    err_code = ble_conn_params_stop();
    APP_ERROR_CHECK(err_code);

	//app_timer_stop_all();
    // Stop application timers.
    err_code = app_timer_stop(m_bonding_timeout);
    APP_ERROR_CHECK(err_code);

    err_code = app_timer_stop(m_update_service_id);
    APP_ERROR_CHECK(err_code);
	
}

void uart_start(uart_data_handle_t p_data_handler)
{
    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
    };

    NVIC_ClearPendingIRQ(UART_RX_HANDLE_IRQn);
    NVIC_SetPriority(UART_RX_HANDLE_IRQn, UART_RX_HANDLE_IRQPriority);
    NVIC_EnableIRQ(UART_RX_HANDLE_IRQn);
    
    p_uart_data_handler = p_data_handler;

    fifo_init(&m_transmit_fifo);    
    fifo_init(&m_receive_fifo);

        // Create timers.
    err_code = app_timer_create(&m_wakeup_ecu_timeout,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                wakeup_ecu_timeout);
    APP_ERROR_CHECK(err_code);
    
    err_code = app_timer_create(&m_send_msg_timeout,
                            APP_TIMER_MODE_SINGLE_SHOT,
                            send_msg_timeout);
    APP_ERROR_CHECK(err_code);
#if (defined BONDING_WHEN_START_UP) && (BONDING_WHEN_START_UP == true)    
        // Create timers.
    err_code = app_timer_create(&m_uart_bonding_timeout,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                uart_bonding_timeout);
    APP_ERROR_CHECK(err_code);   
#endif
    app_uart_buffers_t buffers;

    buffers.rx_buf      = rx_buf;
    buffers.rx_buf_size = sizeof (rx_buf);
    buffers.tx_buf      = tx_buf;
    buffers.tx_buf_size = sizeof (tx_buf);
    err_code = app_uart_init(&comm_params, &buffers, uart_event_handle, APP_IRQ_PRIORITY_LOWEST);
    APP_ERROR_CHECK(err_code);

    wakeup_gpio_int_init();
    uart_initialized = true;
}

In uart_start, I created 2 app_timer. If I comment this app_timer. My process dis SD and en SD run normal.

If I don't comment 2 app_timer. I wil have troubles with function 

expired_timers_handler   in  app_timer.c and program will run forever in loop while (mp_timer_id_head != NULL)

If in function ble_services_stop(), I add line : app_timer_stop_all();

I will not encounter this problem with app timer. But I don't want disable all app_timer because I will have app_timer repeat. So I only want disable app_timer relate with SD, after reinit it.

I need 2 app_timer in uart.c . So how I resolve problem with expired_timers_handler  

Thank very much!!!


  • Hi,

    So if I understand you correctly you can run app_timers while softdevice is enabled and disabled, but it's only if app_timer is stopped when softdevice is disabled you have an issue?

    You should call nrf_drv_clock_lfclk_request() after ble_stack_init() to ensure that the clock is kept running after softdevice disable, it's too late to call nrf_drv_clock_lfclk_request() after stack is disabled.

    I can't see from your above code that you have any repeated times though.

    Best regards,
    Kenneth

Related