Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 44c3602

Browse files
authored
v1.2.0 to fix multiple-definitions linker error
### Releases v1.2.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project. 3. Optimize library code by using `reference-passing` instead of `value-passing` 4. Update all examples
1 parent 8b4f522 commit 44c3602

23 files changed

+470
-348
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1414

1515
Please ensure to specify the following:
1616

17-
* Arduino IDE version (e.g. 1.8.16) or Platform.io version
18-
* `RP2040` Core Version (e.g. RP2040 core v1.9.5)
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* `RP2040` Core Version (e.g. RP2040 core v1.9.14)
1919
* `RP2040` Board type (e.g. RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
2020
* Contextual information (e.g. what you were trying to achieve)
2121
* Simplest possible steps to reproduce
@@ -27,11 +27,11 @@ Please ensure to specify the following:
2727
### Example
2828

2929
```
30-
Arduino IDE version: 1.8.16
31-
RP2040 core v1.9.5
30+
Arduino IDE version: 1.8.19
31+
RP2040 core v1.9.14
3232
RASPBERRY_PI_PICO Module
3333
OS: Ubuntu 20.04 LTS
34-
Linux xy-Inspiron-3593 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
34+
Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3535
3636
Context:
3737
I encountered a crash while using TimerInterrupt.

README.md

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
## Table of Contents
1313

14+
* [Important Change from v1.2.0](#Important-Change-from-v120)
1415
* [Why do we need this RPI_PICO_TimerInterrupt library](#why-do-we-need-this-rpi_pico_timerinterrupt-library)
1516
* [Features](#features)
1617
* [Why using ISR-based Hardware Timer Interrupt is better](#why-using-isr-based-hardware-timer-interrupt-is-better)
@@ -47,6 +48,7 @@
4748
* [ 7. RPM_Measure](examples/RPM_Measure)
4849
* [ 8. SwitchDebounce](examples/SwitchDebounce)
4950
* [ 9. TimerInterruptTest](examples/TimerInterruptTest)
51+
* [ 10. **multiFileProject**](examples/multiFileProject) **New**
5052
* [Example ISR_Timers_Array_Simple](#example-isr_timers_array_simple)
5153
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
5254
* [1. ISR_Timers_Array_Simple on RASPBERRY_PI_PICO](#1-isr_timers_array_simple-on-raspberry_pi_pico)
@@ -68,6 +70,10 @@
6870
---
6971
---
7072

73+
### Important Change from v1.2.0
74+
75+
Please have a look at [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
76+
7177
### Why do we need this [RPI_PICO_TimerInterrupt library](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt)
7278

7379
## Features
@@ -111,7 +117,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
111117

112118
### Currently supported Boards
113119

114-
1. RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc.
120+
1. RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, Nano_RP2040_Connect, GENERIC_RP2040**, etc.
115121

116122
---
117123

@@ -128,9 +134,12 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
128134

129135
## Prerequisites
130136

131-
1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
132-
2. [`Earle Philhower's arduino-pico core v1.9.5+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
133-
137+
1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest)
138+
2. [`Earle Philhower's arduino-pico core v1.9.14+`](https://github.com/earlephilhower/arduino-pico) for RP2040-based boards such as **RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040**, etc. [![GitHub release](https://img.shields.io/github/release/earlephilhower/arduino-pico.svg)](https://github.com/earlephilhower/arduino-pico/releases/latest)
139+
3. To use with certain example
140+
- [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) and [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) examples.
141+
142+
134143
---
135144
---
136145

@@ -202,24 +211,26 @@ With core after v1.4.0, this step is not necessary anymore thanks to the PR [Add
202211

203212
### HOWTO Fix `Multiple Definitions` Linker Error
204213

205-
The current library implementation, using **xyz-Impl.h instead of standard xyz.cpp**, possibly creates certain `Multiple Definitions` Linker error in certain use cases. Although it's simple to just modify several lines of code, either in the library or in the application, the library is adding 2 more source directories
214+
The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases.
206215

207-
1. **scr_h** for new h-only files
208-
2. **src_cpp** for standard h/cpp files
216+
You can include these `.hpp` or `.h` files
209217

210-
besides the standard **src** directory.
218+
```
219+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
220+
#include "RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
211221
212-
To use the **old standard cpp** way, locate this library' directory, then just
222+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
223+
#include "RPi_Pico_ISR_Timer.hpp" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
224+
```
213225

214-
1. **Delete the all the files in src directory.**
215-
2. **Copy all the files in src_cpp directory into src.**
216-
3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch.
226+
in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
217227

218-
To re-use the **new h-only** way, just
228+
```
229+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
230+
#include "RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
231+
```
219232

220-
1. **Delete the all the files in src directory.**
221-
2. **Copy the files in src_h directory into src.**
222-
3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch.
233+
Check the new [**multiFileProject** example](examples/multiFileProject) for a `HOWTO` demo.
223234

224235
---
225236
---
@@ -425,6 +436,7 @@ void setup()
425436
7. [RPM_Measure](examples/RPM_Measure)
426437
8. [SwitchDebounce](examples/SwitchDebounce)
427438
9. [TimerInterruptTest](examples/TimerInterruptTest)
439+
10. [**multiFileProject**](examples/multiFileProject). **New**
428440

429441
---
430442
---
@@ -438,10 +450,13 @@ void setup()
438450
#define TIMER_INTERRUPT_DEBUG 1
439451
#define _TIMERINTERRUPT_LOGLEVEL_ 4
440452
453+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
441454
#include "RPi_Pico_TimerInterrupt.h"
455+
456+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
442457
#include "RPi_Pico_ISR_Timer.h"
443458
444-
#include <SimpleTimer.h> // https://github.com/schinken/SimpleTimer
459+
#include <SimpleTimer.h> // https://github.com/jfturcot/SimpleTimer
445460
446461
// Init RPI_PICO_Timer
447462
RPI_PICO_Timer ITimer1(1);
@@ -539,18 +554,19 @@ void setup()
539554
Serial.begin(115200);
540555
while (!Serial);
541556
542-
Serial.print(F("\nStarting ISR_Timers_Array_Simple on "));
543-
Serial.println(BOARD_NAME);
557+
Serial.print(F("\nStarting ISR_Timers_Array_Simple on ")); Serial.println(BOARD_NAME);
544558
Serial.println(RPI_PICO_TIMER_INTERRUPT_VERSION);
545559
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
546560
547-
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS *1000, TimerHandler))
561+
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
548562
{
549563
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
550564
}
551565
else
552566
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
553567
568+
previousMillis5s = previousMillis2s = millis();
569+
554570
ISR_timer.setInterval(2000L, doingSomething2s);
555571
ISR_timer.setInterval(5000L, doingSomething5s);
556572
@@ -585,15 +601,12 @@ The following is the sample terminal output when running example [ISR_Timers_Arr
585601
While software timer, **programmed for 2s, is activated after more than 10.000s !!!**
586602

587603
```
604+
588605
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
589-
RPi_Pico_TimerInterrupt v1.1.1
606+
RPi_Pico_TimerInterrupt v1.2.0
590607
CPU Frequency = 125 MHz
591-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
592-
[TISR] _count = 0 - 1000
593-
[TISR] add_repeating_timer_us = 1000
594-
Starting ITimer1 OK, millis() = 1707
595-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 3 , _fre = 1000000.00
596-
[TISR] _count = 0 - 1000
608+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
609+
[TISR] _count = 0-1000
597610
[TISR] add_repeating_timer_us = 1000
598611
Starting ITimer3 OK, millis() = 1707
599612
SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707
@@ -615,15 +628,15 @@ The following is the sample terminal output when running example [TimerInterrupt
615628

616629
```
617630
Starting TimerInterruptTest on RASPBERRY_PI_PICO
618-
RPi_Pico_TimerInterrupt v1.1.1
631+
RPi_Pico_TimerInterrupt v1.2.0
619632
CPU Frequency = 125 MHz
620-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
621-
[TISR] _count = 0 - 1000000
622-
[TISR] timer_set_alarm_value (us) = 1000000
623-
Starting ITimer0 OK, millis() = 1781
624-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
625-
[TISR] _count = 0 - 3000000
626-
[TISR] timer_set_alarm_value (us) = 3000000
633+
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
634+
[TISR] _count = 0-1000000
635+
[TISR] add_repeating_timer_us = 1000000
636+
Starting ITimer0 OK, millis() = 882
637+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.33
638+
[TISR] _count = 0-3000000
639+
[TISR] add_repeating_timer_us = 3000000
627640
Starting ITimer1 OK, millis() = 1782
628641
ITimer0 called, millis() = 2781
629642
ITimer0 called, millis() = 3781
@@ -659,14 +672,14 @@ The following is the sample terminal output when running example [Change_Interva
659672

660673
```
661674
Starting Change_Interval on RASPBERRY_PI_PICO
662-
RPi_Pico_TimerInterrupt v1.1.1
675+
RPi_Pico_TimerInterrupt v1.2.0
663676
CPU Frequency = 125 MHz
664-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
665-
[TISR] _count = 0 - 2000000
677+
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
678+
[TISR] _count = 0-2000000
666679
[TISR] add_repeating_timer_us = 2000000
667-
Starting ITimer0 OK, millis() = 1544
668-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
669-
[TISR] _count = 0 - 5000000
680+
Starting ITimer0 OK, millis() = 2363
681+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.20
682+
[TISR] _count = 0-5000000
670683
[TISR] add_repeating_timer_us = 5000000
671684
Starting ITimer1 OK, millis() = 1544
672685
ITimer0: millis() = 3544
@@ -740,10 +753,10 @@ The following is the sample terminal output when running example [SwitchDebounce
740753

741754
```
742755
Starting SwitchDebounce on RASPBERRY_PI_PICO
743-
RPi_Pico_TimerInterrupt v1.1.1
756+
RPi_Pico_TimerInterrupt v1.2.0
744757
CPU Frequency = 125 MHz
745-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
746-
[TISR] _count = 0 - 20000
758+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 50.00
759+
[TISR] _count = 0-20000
747760
[TISR] add_repeating_timer_us = 20000
748761
Starting ITimer1 OK, millis() = 1302
749762
SW Press, from millis() = 77377
@@ -764,12 +777,11 @@ SW Pressed total time ms = 1181
764777
The following is the sample terminal output when running example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) on ADAFRUIT_FEATHER_RP2040
765778

766779
```
767-
768-
Starting ISR_Timers_Array_Simple on ADAFRUIT_FEATHER_RP2040
769-
RPi_Pico_TimerInterrupt v1.1.1
780+
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
781+
RPi_Pico_TimerInterrupt v1.2.0
770782
CPU Frequency = 125 MHz
771-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
772-
[TISR] _count = 0 - 1000
783+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
784+
[TISR] _count = 0-1000
773785
[TISR] add_repeating_timer_us = 1000
774786
Starting ITimer1 OK, millis() = 1701
775787
SimpleTimer : programmed 2000ms, current time ms : 11707, Delta ms : 11707
@@ -788,12 +800,11 @@ Timer5s actual : 5000
788800
The following is the sample terminal output when running example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) on ADAFRUIT_ITSYBITSY_RP2040
789801

790802
```
791-
792-
Starting ISR_16_Timers_Array_Complex on ADAFRUIT_ITSYBITSY_RP2040
793-
RPi_Pico_TimerInterrupt v1.1.1
803+
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
804+
RPi_Pico_TimerInterrupt v1.2.0
794805
CPU Frequency = 125 MHz
795-
[TISR] RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
796-
[TISR] _count = 0 - 10000
806+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
807+
[TISR] _count = 0-10000
797808
[TISR] add_repeating_timer_us = 10000
798809
Starting ITimer OK, millis() = 1797
799810
SimpleTimer : 2, ms : 11798, Dms : 10001
@@ -983,7 +994,10 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog
983994
3. Longer time interval
984995
4. Add Version String
985996
5. Add Table of Contents
986-
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, etc.**) using the arduino-pico core
997+
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
998+
7. Fix `multiple-definitions` linker error
999+
8. Optimize library code by using `reference-passing` instead of `value-passing`
1000+
9871001

9881002
---
9891003
---

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.2.0](#releases-v120)
1516
* [Releases v1.1.1](#releases-v111)
1617
* [Releases v1.1.0](#releases-v110)
1718
* [Releases v1.0.1](#releases-v101)
@@ -23,6 +24,13 @@
2324

2425
## Changelog
2526

27+
### Releases v1.2.0
28+
29+
1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories
30+
2. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project.
31+
3. Optimize library code by using `reference-passing` instead of `value-passing`
32+
4. Update all examples
33+
2634
### Releases v1.1.1
2735

2836
1. Fix platform in `library.json`

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1919
Therefore, their executions are not blocked by bad-behaving functions / tasks.
2020
This important feature is absolutely necessary for mission-critical tasks.
21-
22-
Based on SimpleTimer - A timer library for Arduino.
23-
24-
Copyright (c) 2010 OTTOTECNICA Italy
25-
26-
Based on BlynkTimer.h
27-
Author: Volodymyr Shymanskyy
2821
*****************************************************************************************************************************/
2922

3023
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
@@ -33,6 +26,7 @@
3326
#define TIMER_INTERRUPT_DEBUG 1
3427
#define _TIMERINTERRUPT_LOGLEVEL_ 4
3528

29+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
3630
#include "RPi_Pico_TimerInterrupt.h"
3731

3832
#if !defined(LED_BUILTIN)

examples/Argument_None/Argument_None.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1919
Therefore, their executions are not blocked by bad-behaving functions / tasks.
2020
This important feature is absolutely necessary for mission-critical tasks.
21-
22-
Based on SimpleTimer - A timer library for Arduino.
23-
24-
Copyright (c) 2010 OTTOTECNICA Italy
25-
26-
Based on BlynkTimer.h
27-
Author: Volodymyr Shymanskyy
2821
*****************************************************************************************************************************/
2922

3023
/*
@@ -46,6 +39,7 @@
4639
#define TIMER_INTERRUPT_DEBUG 1
4740
#define _TIMERINTERRUPT_LOGLEVEL_ 4
4841

42+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
4943
#include "RPi_Pico_TimerInterrupt.h"
5044

5145
#ifndef LED_BUILTIN

examples/Argument_Simple/Argument_Simple.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1919
Therefore, their executions are not blocked by bad-behaving functions / tasks.
2020
This important feature is absolutely necessary for mission-critical tasks.
21-
22-
Based on SimpleTimer - A timer library for Arduino.
23-
24-
Copyright (c) 2010 OTTOTECNICA Italy
25-
26-
Based on BlynkTimer.h
27-
Author: Volodymyr Shymanskyy
2821
*****************************************************************************************************************************/
2922

3023
// These define's must be placed at the beginning before #include "TimerInterrupt_Generic.h"
@@ -33,6 +26,7 @@
3326
#define TIMER_INTERRUPT_DEBUG 1
3427
#define _TIMERINTERRUPT_LOGLEVEL_ 4
3528

29+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
3630
#include "RPi_Pico_TimerInterrupt.h"
3731

3832
#if !defined(LED_BUILTIN)

examples/Change_Interval/Change_Interval.ino

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1919
Therefore, their executions are not blocked by bad-behaving functions / tasks.
2020
This important feature is absolutely necessary for mission-critical tasks.
21-
22-
Based on SimpleTimer - A timer library for Arduino.
23-
24-
Copyright (c) 2010 OTTOTECNICA Italy
25-
26-
Based on BlynkTimer.h
27-
Author: Volodymyr Shymanskyy
2821
*****************************************************************************************************************************/
2922

3023
/*
@@ -45,6 +38,7 @@
4538
#define TIMER_INTERRUPT_DEBUG 1
4639
#define _TIMERINTERRUPT_LOGLEVEL_ 4
4740

41+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
4842
#include "RPi_Pico_TimerInterrupt.h"
4943

5044
#ifndef LED_BUILTIN

0 commit comments

Comments
 (0)