khoih-prog / TimerInterrupt_Generic

This library enables you to use Interrupt from Hardware Timers on supported Arduino boards such as AVR, ESP8266, ESP32, SAMD, SAM DUE, nRF52, Teensy, etc. These Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks.
MIT License
38 stars 5 forks source link

Multiple Defintions error #3

Closed Szum123321 closed 3 years ago

Szum123321 commented 3 years ago

Hi!

I'm trying to compile some code for Teensy 3.5 with PlatformIO 2.3.2, and I'm getting multiple definitions error.

I followed the procedure described in README, which sadly didn't work even though I cleaned the build environment and restarted VScode all the time.

Error message looks like this: link

I'm using Arch based linux distro: Linux sz-81nh 5.11.14-arch1-1 #1 SMP PREEMPT Wed, 14 Apr 2021 12:06:34 +0000 x86_64 GNU/Linux

Also, the same code (the only difference being instead of TeensyTimer, I used STM32Timer) compiles and works perfectly on ST Nulceo F303RE

Steps to Reproduce

Minimal example: Teensy_minimal.zip

Expected behavior

Code compiles for Teensy

Actual behavior

Linker spews out a bunch of Multiple definitions error

Szum123321 commented 3 years ago

The library is included in include/I2CEEPROM.h file

khoih-prog commented 3 years ago

You have to modify like this to use new C++ style hpp

  1. main.cpp or Teensy_minimal.ino
#include <Arduino.h>
#include "I2CEEPROM.h"

I2CEEPROM mem;

void setup() 
{
}

void loop() 
{
}

  1. I2CEEPROM.h
#ifndef I2CEEPROM_H
#define I2CEEPROM_H

#include <Arduino.h>
#include <Wire.h>
#include <math.h>
#include "TimerInterrupt_Generic.h"

class I2CEEPROM {};

#include "I2CEEPROM_Impl.hpp"

#endif

  1. I2CEEPROM_Impl.hpp
#ifndef I2CEEPROM_IMPL_HPP
#define I2CEEPROM_IMPL_HPP

#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3)  ||defined(STM32F4) || defined(STM32F7) || \
       defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7)  ||defined(STM32G0) || defined(STM32G4) || \
       defined(STM32WB) || defined(STM32MP1) )
  STM32Timer DEVICE_TICK_TIMER(TIM2);
#elif ( defined(CORE_TEENSY) || defined(TEENSYDUINO) )
  TeensyTimer DEVICE_TICK_TIMER(TEENSY_TIMER_3);
#endif

/*library code here*/

#endif    // I2CEEPROM_IMPL_HPP

Compile is OK on Arduino IDE, and should be OK on PIO, unless you have wrong settings / configurations

Selection_746