Using
- nRF5_SDK_15.0.0_a53641a
- gcc-arm-none-eabi-6-2017-q2-update 6.3.1
If I enable APP_TIMER_KEEPS_RTC_ACTIVE in the sdk config, setup the app timer with this:
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
app_timer_cnt_get always returns 0.
If I then start a dummy timer, app_timer_cnt_get works fine.
Here is my example, based off of examples/peripheral/uart.
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf.h"
#include "bsp.h"
#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif
#include "app_timer.h"
#include "nrf_drv_clock.h"
#include "nrf_drv_power.h"
#define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */
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);
}
}
////Dummy timer stuff
//APP_TIMER_DEF(dummy_timer);
//static void dummy_timer_handler(void * p_context) {
// UNUSED_PARAMETER(p_context);
//}
static void timers_init(void) {
ret_code_t ret;
ret = nrf_drv_clock_init();
APP_ERROR_CHECK(ret);
ret = nrf_drv_power_init(NULL);
APP_ERROR_CHECK(ret);
nrf_drv_clock_lfclk_request(NULL);
ret = app_timer_init();
APP_ERROR_CHECK(ret);
//// Create Security Request timer.
//ret = app_timer_create(&dummy_timer,
// APP_TIMER_MODE_REPEATED,
// dummy_timer_handler);
//APP_ERROR_CHECK(ret);
//ret = app_timer_start(dummy_timer, APP_TIMER_TICKS(500), NULL);
//APP_ERROR_CHECK(ret);
}
int main(void) {
uint32_t err_code;
bsp_board_init(BSP_INIT_LEDS);
timers_init();
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED,
false,
#if defined (UART_PRESENT)
NRF_UART_BAUDRATE_115200
#else
NRF_UARTE_BAUDRATE_115200
#endif
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
printf("\r\nUART example started.\r\n");
while (true) {
for (int i = 0; i < LEDS_NUMBER; i++) {
bsp_board_led_invert(i);
nrf_delay_ms(500);
printf("time: %ld\r\n", app_timer_cnt_get());
}
}
}