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
  • Hi,

    The FreeRTOS port use RTC1 for as a tick source, so it is not available to the application. You can see this from FreeRTOSConfig.h.

    Are you sure you need an additional RTC? If you need it for some form of timers, then you can use FreeRTOS timers or the app_timer library (which is based on FreeRTOS timers in this case). These in turn use the FreeRTOS tick source, which is RTC1.

    Note that it is possible to configure FreeRTOS to use SysTick instead of RTC1, but that is not recommended for several reasons (bad resolution, timer will not run when CPU is not running etc.).

  • Hi Einar, regarding the problem mentioned above - if RTC1 is used by the FreeRTOS port than how can we use nrf_power_mgmt_run() function? it seems that the Event which interrupts the function is somehow related to NVIC->ISPR[0] ant the fact that RTC1 is set:

    hgf

Reply Children
No Data
Related