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

Commit 9133e3b

Browse files
authored
v1.1.0 to fix multiple-definitions linker error
### Releases v1.1.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 5b2b7d3 commit 9133e3b

25 files changed

+751
-484
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-
* `Arduino mbed_rp2040` Core Version (e.g. Arduino mbed_rp2040 core v2.5.2)
17+
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18+
* `Arduino mbed_rp2040` Core Version (e.g. Arduino mbed_rp2040 core v2.6.1)
1919
* `RP2040` Board type (e.g. Nano_RP2040_Connect, 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-
Arduino mbed_rp2040 core v2.5.2
30+
Arduino IDE version: 1.8.19
31+
Arduino mbed_rp2040 core v2.6.1
3232
RASPBERRY_PI_PICO board
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: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
## Table of Contents
1313

14+
* [Important Change from v1.1.0](#Important-Change-from-v110)
1415
* [Why do we need this MBED_RPI_PICO_TimerInterrupt library](#why-do-we-need-this-mbed_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)
@@ -42,6 +43,8 @@
4243
* [ 6. ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
4344
* [ 7. SwitchDebounce](examples/SwitchDebounce)
4445
* [ 8. TimerInterruptTest](examples/TimerInterruptTest)
46+
* [ 9. **50ms_HWTimer**](examples/50ms_HWTimer) **New**
47+
* [ 10. **multiFileProject**](examples/multiFileProject) **New**
4548
* [Example ISR_Timers_Array_Simple](#example-isr_timers_array_simple)
4649
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
4750
* [1. ISR_Timers_Array_Simple on RaspberryPi Pico](#1-isr_timers_array_simple-on-raspberrypi-pico)
@@ -62,6 +65,10 @@
6265
---
6366
---
6467

68+
### Important Change from v1.1.0
69+
70+
Please have a look at [HOWTO Fix `Multiple Definitions` Linker Error](#howto-fix-multiple-definitions-linker-error)
71+
6572
### Why do we need this [MBED_RPI_PICO_TimerInterrupt library](https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt)
6673

6774
## Features
@@ -123,9 +130,12 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
123130

124131
## Prerequisites
125132

126-
1. [`Arduino IDE 1.8.16+` for Arduino](https://www.arduino.cc/en/Main/Software)
127-
2. [`Arduino mbed_rp2040 core 2.5.2+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
128-
133+
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)
134+
2. [`Arduino mbed_rp2040 core 2.6.1+`](https://github.com/arduino/ArduinoCore-mbed) for Arduino (Use Arduino Board Manager) RP2040-based boards, such as **Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc.**. [![GitHub release](https://img.shields.io/github/release/arduino/ArduinoCore-mbed.svg)](https://github.com/arduino/ArduinoCore-mbed/releases/latest)
135+
3. To use with certain example
136+
- [`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.
137+
138+
129139
---
130140
---
131141

@@ -159,24 +169,29 @@ Another way to install is to:
159169

160170
### HOWTO Fix `Multiple Definitions` Linker Error
161171

162-
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
172+
The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases.
163173

164-
1. **scr_h** for new h-only files
165-
2. **src_cpp** for standard h/cpp files
174+
You can include these `.hpp` files
175+
176+
```
177+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
178+
#include "MBED_RPi_Pico_TimerInterrupt.hpp" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
166179
167-
besides the standard **src** directory.
180+
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
181+
#include "MBED_RPi_Pico_ISR_Timer.hpp" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
182+
```
168183

169-
To use the **old standard cpp** way, locate this library' directory, then just
184+
in many files. But be sure to use the following `.h` files **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
170185

171-
1. **Delete the all the files in src directory.**
172-
2. **Copy all the files in src_cpp directory into src.**
173-
3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch.
186+
```
187+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
188+
#include "MBED_RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
174189
175-
To re-use the **new h-only** way, just
190+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
191+
#include "MBED_RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
192+
```
176193

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

181196
---
182197
---
@@ -404,6 +419,8 @@ void setup()
404419
6. [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
405420
7. [SwitchDebounce](examples/SwitchDebounce)
406421
8. [TimerInterruptTest](examples/TimerInterruptTest)
422+
9. [**50ms_HWTimer**](examples/50ms_HWTimer) **New**
423+
10. [**multiFileProject**](examples/multiFileProject) **New**
407424

408425
---
409426
---
@@ -422,7 +439,10 @@ void setup()
422439
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
423440
#define _TIMERINTERRUPT_LOGLEVEL_ 4
424441
442+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
425443
#include "MBED_RPi_Pico_TimerInterrupt.h"
444+
445+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
426446
#include "MBED_RPi_Pico_ISR_Timer.h"
427447
428448
#include <SimpleTimer.h> // https://github.com/schinken/SimpleTimer
@@ -578,9 +598,9 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
578598

579599
```
580600
Starting ISR_Timers_Array_Simple on RaspberryPi Pico
581-
MBED_RPi_Pico_TimerInterrupt v1.0.1
582-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
583-
[TISR] _count = 0 - 1000
601+
MBED_RPi_Pico_TimerInterrupt v1.1.0
602+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
603+
[TISR] _count = 0-1000
584604
[TISR] hardware_alarm_set_target, uS = 1000
585605
Starting ITimer1 OK, millis() = 1690
586606
SimpleTimer : programmed 2000ms, current time ms : 11290, Delta ms : 11290
@@ -602,13 +622,13 @@ The following is the sample terminal output when running example [TimerInterrupt
602622

603623
```
604624
Starting TimerInterruptTest on RaspberryPi Pico
605-
MBED_RPi_Pico_TimerInterrupt v1.0.1
606-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
607-
[TISR] _count = 0 - 1000000
625+
MBED_RPi_Pico_TimerInterrupt v1.1.0
626+
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
627+
[TISR] _count = 0-1000000
608628
[TISR] hardware_alarm_set_target, uS = 1000000
609629
Starting ITimer0 OK, millis() = 1787
610-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
611-
[TISR] _count = 0 - 3000000
630+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.33
631+
[TISR] _count = 0-3000000
612632
[TISR] hardware_alarm_set_target, uS = 3000000
613633
Starting ITimer1 OK, millis() = 1789
614634
Stop ITimer0, millis() = 5001
@@ -630,15 +650,15 @@ The following is the sample terminal output when running example [Change_Interva
630650

631651
```
632652
Starting Change_Interval on RaspberryPi Pico
633-
MBED_RPi_Pico_TimerInterrupt v1.0.1
634-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
635-
[TISR] _count = 0 - 2000000
653+
MBED_RPi_Pico_TimerInterrupt v1.1.0
654+
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
655+
[TISR] _count = 0-2000000
636656
[TISR] hardware_alarm_set_target, uS = 2000000
637-
Starting ITimer0 OK, millis() = 1285
638-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
639-
[TISR] _count = 0 - 5000000
657+
Starting ITimer0 OK, millis() = 1282
658+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.20
659+
[TISR] _count = 0-5000000
640660
[TISR] hardware_alarm_set_target, uS = 5000000
641-
Starting ITimer1 OK, millis() = 1287
661+
Starting ITimer1 OK, millis() = 1284
642662
Time = 10001, Timer0Count = 4, Timer1Count = 1
643663
Time = 20002, Timer0Count = 9, Timer1Count = 3
644664
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
@@ -668,9 +688,9 @@ The following is the sample terminal output when running example [SwitchDebounce
668688

669689
```
670690
Starting SwitchDebounce on RaspberryPi Pico
671-
MBED_RPi_Pico_TimerInterrupt v1.0.1
672-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
673-
[TISR] _count = 0 - 1000
691+
MBED_RPi_Pico_TimerInterrupt v1.1.0
692+
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
693+
[TISR] _count = 0-1000
674694
[TISR] hardware_alarm_set_target, uS = 1000
675695
Starting ITimer1 OK, millis() = 1185
676696
SW Pressed, from millis() = 4537
@@ -702,9 +722,9 @@ The following is the sample terminal output when running example [ISR_16_Timers_
702722

703723
```
704724
Starting ISR_16_Timers_Array_Complex on RaspberryPi Pico
705-
MBED_RPi_Pico_TimerInterrupt v1.0.1
706-
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
707-
[TISR] _count = 0 - 10000
725+
MBED_RPi_Pico_TimerInterrupt v1.1.0
726+
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
727+
[TISR] _count = 0-10000
708728
[TISR] hardware_alarm_set_target, uS = 10000
709729
Starting ITimer OK, millis() = 1083
710730
SimpleTimer : 2, ms : 10683, Dms : 9599
@@ -899,7 +919,7 @@ Submit issues to: [MBED_RPI_PICO_TimerInterrupt issues](https://github.com/khoih
899919
## TO DO
900920

901921
1. Search for bug and improvement.
902-
2. Add support to RP2040-based boards such as RASPBERRY_PI_PICO, using [**Arduino-mbed RP2040** core](https://github.com/arduino/ArduinoCore-mbed)
922+
903923

904924
---
905925

@@ -910,6 +930,8 @@ Submit issues to: [MBED_RPI_PICO_TimerInterrupt issues](https://github.com/khoih
910930
3. Longer time interval
911931
4. Add Version String
912932
5. Add Table of Contents
933+
6. Fix `multiple-definitions` linker error
934+
7. Optimize library code by using `reference-passing` instead of `value-passing`
913935

914936
---
915937
---

changelog.md

Lines changed: 9 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.1.0](#releases-v110)
1516
* [Releases v1.0.1](#releases-v101)
1617
* [Initial Releases v1.0.0](#initial-releases-v100)
1718

@@ -20,6 +21,14 @@
2021

2122
## Changelog
2223

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

2534
1. Fix platform in `library.json`

examples/50ms_HWTimer/50ms_HWTimer.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
For MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
44
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
6+
Built by Khoi Hoang https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
77
Licensed under MIT license
88
99
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
@@ -17,13 +17,6 @@
1717
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
20-
21-
Based on SimpleTimer - A timer library for Arduino.
22-
23-
Copyright (c) 2010 OTTOTECNICA Italy
24-
25-
Based on BlynkTimer.h
26-
Author: Volodymyr Shymanskyy
2720
*****************************************************************************************************************************/
2821

2922
/*
@@ -49,6 +42,7 @@
4942
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
5043
#define _TIMERINTERRUPT_LOGLEVEL_ 4
5144

45+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
5246
#include "MBED_RPi_Pico_TimerInterrupt.h"
5347

5448
#ifndef LED_BUILTIN

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
For MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
44
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
6+
Built by Khoi Hoang https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
77
Licensed under MIT license
88
99
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
@@ -17,13 +17,6 @@
1717
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
20-
21-
Based on SimpleTimer - A timer library for Arduino.
22-
23-
Copyright (c) 2010 OTTOTECNICA Italy
24-
25-
Based on BlynkTimer.h
26-
Author: Volodymyr Shymanskyy
2720
*****************************************************************************************************************************/
2821

2922
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
@@ -37,6 +30,7 @@
3730
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
3831
#define _TIMERINTERRUPT_LOGLEVEL_ 4
3932

33+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
4034
#include "MBED_RPi_Pico_TimerInterrupt.h"
4135

4236
#ifndef LED_BUILTIN

examples/Argument_None/Argument_None.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
For MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
44
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
6+
Built by Khoi Hoang https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
77
Licensed under MIT license
88
99
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
@@ -17,13 +17,6 @@
1717
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
20-
21-
Based on SimpleTimer - A timer library for Arduino.
22-
23-
Copyright (c) 2010 OTTOTECNICA Italy
24-
25-
Based on BlynkTimer.h
26-
Author: Volodymyr Shymanskyy
2720
*****************************************************************************************************************************/
2821

2922
/*
@@ -49,6 +42,7 @@
4942
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
5043
#define _TIMERINTERRUPT_LOGLEVEL_ 4
5144

45+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
5246
#include "MBED_RPi_Pico_TimerInterrupt.h"
5347

5448
#ifndef LED_BUILTIN

examples/Argument_Simple/Argument_Simple.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
For MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040.
44
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
6+
Built by Khoi Hoang https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
77
Licensed under MIT license
88
99
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates
@@ -17,13 +17,6 @@
1717
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
20-
21-
Based on SimpleTimer - A timer library for Arduino.
22-
23-
Copyright (c) 2010 OTTOTECNICA Italy
24-
25-
Based on BlynkTimer.h
26-
Author: Volodymyr Shymanskyy
2720
*****************************************************************************************************************************/
2821

2922
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
@@ -37,6 +30,7 @@
3730
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
3831
#define _TIMERINTERRUPT_LOGLEVEL_ 4
3932

33+
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
4034
#include "MBED_RPi_Pico_TimerInterrupt.h"
4135

4236
#ifndef LED_BUILTIN

0 commit comments

Comments
 (0)