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

ERROR Multiple definition of `RTC1_IRQHandler' using FreeRTOS

Hi, 

I am getting this compilation error when trying to use RTC1 in my program. I am already using RTC2 for a different function with no problems and I need two RTC timers.

Is the RTC1 already being used by FreeRTOS or any other module?

#include "board_basic.h"
#include "nrf52.h"
#include "boards.h"
#include "nrf_delay.h"
#include "nrf_drv_rtc.h"
#include "nrf_rtc.h"
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#include "semphr.h"
#include <stdio.h>
#include "sensor.h"
#include "itracker.h"
#include "nrf_log.h"
#include "nrf_drv_gpiote.h"

/**
 * @brief RTC instance number 
 *
 */
#define PERIODIC_RTC_BOX 1

/**
 * @brief RTC compare channel used
 *
 */
#define PERIODIC_RTC_BOX_CC 0
/**
 * @brief Number of RTC ticks between interrupts
 */
#define PERIODIC_RTC_BOX_US   20000000ULL			
#define PERIODIC_RTC_BOX_TICKS  (RTC_US_TO_TICKS(PERIODIC_RTC_BOX_US, RTC_DEFAULT_CONFIG_FREQUENCY))
/**
 * @brief RTC configuration
 */
static nrf_drv_rtc_config_t const m_rtc_config = NRF_DRV_RTC_DEFAULT_CONFIG;
/**
 * @brief RTC instance
 *
 * Instance of the RTC used for led blinking
 */
static nrf_drv_rtc_t const m_rtc = NRF_DRV_RTC_INSTANCE(PERIODIC_RTC_BOX);

/**
 * @brief Semaphore set in opt3001 interrupt event
 */
static SemaphoreHandle_t box_opened_semaphore = NULL;

static void periodic_rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    	NRF_LOG_DEBUG("Send data RTC handler");
    BaseType_t yield_req = pdFALSE;
	BaseType_t ret_val;
    ret_code_t err_code;
    err_code = nrf_drv_rtc_cc_set(
        &m_rtc,
        PERIODIC_RTC_BOX_CC,
        (nrf_rtc_cc_get(m_rtc.p_reg, PERIODIC_RTC_BOX_CC) + PERIODIC_RTC_BOX_TICKS) & RTC_COUNTER_COUNTER_Msk,
        true);
    APP_ERROR_CHECK(err_code);

   /* The returned value may be safely ignored, if error is returned it only means that
    * the semaphore is already given (raised). */
   UNUSED_VARIABLE(xSemaphoreGiveFromISR(box_opened_semaphore, &yield_req));
   // Request a context switch (switch to other task). Interrupt safe verison of taskYIELD()
   portYIELD_FROM_ISR(yield_req);
}

/**
 * @brief box_opened task entry function.
 *
 * @param[in] pvParameter   Pointer that will be used as the parameter for the task.
 */
void box_opened(void * pvParameter)
{	
	NRF_LOG_INFO("---------- BOX OPENED TASK ----------");
	// Utility vars
	int ret;
	ret_code_t err_code;

	// App data storage vars
	double temp = 0;
	double humidity = 0;
	double pressure = 0;
	int x = 0;
	int y = 0;
	int z = 0;
	float magnetic_x = 0;
	float magnetic_y = 0;
	float magnetic_z = 0;
	float light = 0;

	// Init GPIO & configure pin interrupt
	gpio_init();

	// Create rtc instance and compare channel
	NRF_LOG_DEBUG("Init box RTC instance");
    err_code = nrf_drv_rtc_init(&m_rtc, &m_rtc_config, periodic_rtc_handler);
    APP_ERROR_CHECK(err_code);
	
    err_code = nrf_drv_rtc_cc_set(&m_rtc, PERIODIC_RTC_BOX_CC, PERIODIC_RTC_BOX_TICKS, true);
    APP_ERROR_CHECK(err_code);
    // Enable RTC instance
	nrf_drv_rtc_enable(&m_rtc);
}

Thanks

Parents Reply Children
  • Hi Adrian,

    It doesn't really matter. The app timer library implementation for FreeRTOS uses FreeRTOS timers under the hood, so essentially it just depends on what API you prefer. The reason for having an app timer implementation for FreeRTOS is that it is needed to make all the other SDK modules that use the app timer work. If you might consider skipping FreeRTOS at some point, then using app timer might be a better option as then you would not have to change that part of the code.

Related