From e8b8e89457da2dc68d1175f4955e158aacbc4beb Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Thu, 20 Jan 2022 01:23:10 -0500 Subject: [PATCH] v1.3.0 to fix `multiple-definitions` linker error ### Releases v1.3.0 1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories 2. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](https://github.com/khoih-prog/ESP8266TimerInterrupt/pull/19) 3. Update `Packages_Patches` --- CONTRIBUTING.md | 10 +- README.md | 200 +++++------------- changelog.md | 58 +++++ examples/Argument_None/Argument_None.ino | 19 +- examples/Change_Interval/Change_Interval.ino | 19 +- .../ISR_16_Timers_Array.ino | 21 +- .../ISR_16_Timers_Array_Complex.ino | 23 +- examples/ISR_RPM_Measure/ISR_RPM_Measure.ino | 17 -- .../ISR_Timer_Complex/ISR_Timer_Complex.ino | 21 +- examples/RPM_Measure/RPM_Measure.ino | 17 -- examples/SwitchDebounce/SwitchDebounce.ino | 17 -- .../TimerInterruptLEDDemo.ino | 17 -- .../TimerInterruptTest/TimerInterruptTest.ino | 19 +- keywords.txt | 8 + library.json | 5 +- library.properties | 6 +- platformio/platformio.ini | 32 +-- src/STM32TimerInterrupt.h | 27 ++- src/STM32_ISR_Timer-Impl.h | 3 +- src/STM32_ISR_Timer.h | 150 +------------ src/STM32_ISR_Timer.hpp | 191 +++++++++++++++++ src/TimerInterrupt_Generic_Debug.h | 3 +- 22 files changed, 377 insertions(+), 506 deletions(-) create mode 100644 changelog.md create mode 100644 src/STM32_ISR_Timer.hpp diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62a57d4..f94db5d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p Please ensure to specify the following: -* Arduino IDE version (e.g. 1.8.15) or Platform.io version -* `STM32` Core Version (e.g. STM32 core v2.0.0) +* Arduino IDE version (e.g. 1.8.19) or Platform.io version +* `STM32` Core Version (e.g. STM32 core v2.2.0) * Contextual information (e.g. what you were trying to achieve) * Simplest possible steps to reproduce * Anything that might be relevant in your opinion, such as: @@ -26,10 +26,10 @@ Please ensure to specify the following: ### Example ``` -Arduino IDE version: 1.8.15 -STM32 Core Version 2.0.0 +Arduino IDE version: 1.8.19 +STM32 Core Version 2.2.0 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +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 Context: I encountered a crash while trying to use the Timer Interrupt. diff --git a/README.md b/README.md index 299a4ad..bcac03f 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,7 @@ * [Why using ISR-based Hardware Timer Interrupt is better](#why-using-isr-based-hardware-timer-interrupt-is-better) * [Currently supported Boards](#currently-supported-boards) * [Important Notes about ISR](#important-notes-about-isr) -* [Changelog](#changelog) - * [Releases v1.2.1](#releases-v121) - * [Releases v1.2.0](#releases-v120) - * [Releases v1.1.1](#releases-v111) - * [Releases v1.0.1](#releases-v101) - * [Releases v1.0.0](#releases-v100) +* [Changelog](changelog.md) * [Prerequisites](#prerequisites) * [Installation](#installation) * [Use Arduino Library Manager](#use-arduino-library-manager) @@ -69,7 +64,6 @@ * [8. ISR_16_Timers_Array_Complex on STM32L5 NUCLEO_L552ZE_Q](#8-isr_16_timers_array_complex-on-stm32l5-nucleo_l552ze_q) * [Debug](#debug) * [Troubleshooting](#troubleshooting) -* [Releases](#releases) * [Issues](#issues) * [TO DO](#to-do) * [DONE](#done) @@ -157,42 +151,12 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine), --- --- -## Changelog - -### Releases v1.2.1 - -1. Add support to **STM32L5 (NUCLEO_L552ZE_Q)** -2. Verify OK with **STM32H7 (NUCLEO_H743ZI2)** - -### Releases v1.2.0 - -1. Add better debug feature. -2. Optimize code and examples to reduce RAM usage -3. Add Table of Contents - -### Releases v1.1.1 - -1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex) -2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String. - - -### Releases v1.0.1 - -1. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers. - -### Releases v1.0.0 - -1. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked -2. Using cpp code besides Impl.h code to use if Multiple-Definition linker error. - ---- ---- ## Prerequisites - 1. [`Arduino IDE 1.8.15+` for Arduino](https://www.arduino.cc/en/Main/Software) - 2. [`Arduino Core for STM32 v2.0.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) - 3. [`Blynk library 0.6.1+`](https://github.com/blynkkk/blynk-library/releases). [![Latest release](https://img.shields.io/github/release/blynkkk/blynk-library.svg)](https://github.com/blynkkk/blynk-library/releases/latest/) to use with certain example. + 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) + 2. [`Arduino Core for STM32 v2.2.0+`](https://github.com/stm32duino/Arduino_Core_STM32) for STM32F/L/H/G/WB/MP1 boards. [![GitHub release](https://img.shields.io/github/release/stm32duino/Arduino_Core_STM32.svg)](https://github.com/stm32duino/Arduino_Core_STM32/releases/latest) + 3. [`Blynk library 1.0.1+`](https://github.com/blynkkk/blynk-library/releases). [![Latest release](https://img.shields.io/github/release/blynkkk/blynk-library.svg)](https://github.com/blynkkk/blynk-library/releases/latest/) to use with certain example. 4. For built-in LAN8742A Ethernet: - [`STM32Ethernet library v1.2.0+`](https://github.com/stm32duino/STM32Ethernet) for built-in LAN8742A Ethernet on (Nucleo-144, Discovery). [![GitHub release](https://img.shields.io/github/release/stm32duino/STM32Ethernet.svg)](https://github.com/stm32duino/STM32Ethernet/releases/latest) - [`LwIP library v2.1.2+`](https://github.com/stm32duino/LwIP) for built-in LAN8742A Ethernet on (Nucleo-144, Discovery). [![GitHub release](https://img.shields.io/github/release/stm32duino/LwIP.svg)](https://github.com/stm32duino/LwIP/releases/latest) @@ -202,11 +166,11 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine), - [`Ethernet2 library v1.0.4+`](https://github.com/khoih-prog/Ethernet2) for W5500. [![GitHub release](https://img.shields.io/github/release/adafruit/Ethernet2.svg)](https://github.com/adafruit/Ethernet2/releases/latest) - [`Ethernet3 library v1.5.5+`](https://github.com/sstaub/Ethernet3) for W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip. [![GitHub release](https://img.shields.io/github/release/sstaub/Ethernet3.svg)](https://github.com/sstaub/Ethernet3/releases/latest) 6. For ENC28J60 Ethernet: - - [`EthernetENC library v2.0.1+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/jandrassy/EthernetENC.svg)](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better** - - [`UIPEthernet library v2.0.10+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/UIPEthernet/UIPEthernet.svg)](https://github.com/UIPEthernet/UIPEthernet/releases/latest) + - [`EthernetENC library v2.0.2+`](https://github.com/jandrassy/EthernetENC) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/jandrassy/EthernetENC.svg)](https://github.com/jandrassy/EthernetENC/releases/latest). **New and Better** + - [`UIPEthernet library v2.0.11+`](https://github.com/UIPEthernet/UIPEthernet) for ENC28J60. [![GitHub release](https://img.shields.io/github/release/UIPEthernet/UIPEthernet.svg)](https://github.com/UIPEthernet/UIPEthernet/releases/latest) 7. To use with certain example - - [`SimpleTimer library`](https://github.com/schinken/SimpleTimer) for [ISR_16_Timers_Array example](examples/ISR_16_Timers_Array). + - [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_16_Timers_Array example](examples/ISR_16_Timers_Array). --- --- @@ -305,24 +269,20 @@ Check if you need to install the UIPEthernet patch [new STM32 core F3/F4 compati ### HOWTO Fix `Multiple Definitions` Linker Error -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 - -1. **scr_h** for new h-only files -2. **src_cpp** for standard h/cpp files +The current library implementation, using `xyz-Impl.h` instead of standard `xyz.cpp`, possibly creates certain `Multiple Definitions` Linker error in certain use cases. -besides the standard **src** directory. +You can use -To use the **old standard cpp** way, locate this library' directory, then just - -1. **Delete the all the files in src directory.** -2. **Copy all the files in src_cpp directory into src.** -3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch. +``` +#include //https://github.com/khoih-prog/STM32_TimerInterrupt +``` -To re-use the **new h-only** way, just +in many files. But be sure to use the following `#include ` **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error -1. **Delete the all the files in src directory.** -2. **Copy the files in src_h directory into src.** -3. Close then reopen the application code in Arduino IDE, etc. to recompile from scratch. +``` +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include //https://github.com/khoih-prog/STM32_TimerInterrupt +``` --- --- @@ -601,12 +561,14 @@ void setup() // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "STM32_ISR_Timer.h" -#include // https://github.com/schinken/SimpleTimer +#include // https://github.com/jfturcot/SimpleTimer #ifndef LED_BUILTIN #define LED_BUILTIN 13 @@ -935,10 +897,10 @@ While software timer, **programmed for 2s, is activated after 9.782s !!!**. Then ``` Starting ISR_Timer_Complex on NUCLEO_F767ZI -STM32_TimerInterrupt v1.2.0 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 216 MHz -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 50000 +[TISR] Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 10000.00 , _count = 100 Starting ITimer OK, millis() = 6 [9] MAC:FE-E1-88-EC-DD-95 2s: Delta ms = 2000 @@ -995,15 +957,14 @@ blynkDoingSomething2s: Delta programmed ms = 2000, actual = 3000 The following is the sample terminal output when running example [**TimerInterruptTest**](examples/TimerInterruptTest) on **STM32F7 Nucleo-144 NUCLEO_F767ZI** to demonstrate how to start/stop Hardware Timers. ``` - Starting TimerInterruptTest on NUCLEO_F767ZI -STM32_TimerInterrupt v1.2.0 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 216 MHz -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 1000000 -Starting ITimer0 OK, millis() = 108 -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 108000000 -[TISR] Frequency = 1000000.00 , _count = 3000000 +[TISR] Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 1.00 , _count = 1000000 +Starting ITimer0 OK, millis() = 108 +[TISR] Timer Input Freq (Hz) = 108000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 0.33 , _count = 3000000 Starting ITimer1 OK, millis() = 119 Stop ITimer0, millis() = 5001 Start ITimer0, millis() = 10002 @@ -1053,16 +1014,16 @@ The following is the sample terminal output when running example [**Argument_Non ``` Starting Argument_None on NUCLEO_F767ZI -STM32_TimerInterrupt v1.2.0 +STM32TimerInterrupt v1.3.0 CPU Frequency = 216 MHz -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 1000000 -Starting ITimer0 OK, millis() = 106 -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 108000000 -[TISR] Frequency = 1000000.00 , _count = 5000000 +[TISR] Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 1.00 , _count = 1000000 +Starting ITimer0 OK, millis() = 106 +[TISR] Timer Input Freq (Hz) = 108000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 0.50 , _count = 2000000 Starting ITimer1 OK, millis() = 117 -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 108000000 -[TISR] Frequency = 1000000.00 , _count = 20000000 +[TISR] Timer Input Freq (Hz) = 108000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 0.20 , _count = 5000000 Starting ITimer2 OK, millis() = 129 ITimer0: millis() = 1106, delta = 1000 ITimer0: millis() = 2106, delta = 1000 @@ -1120,14 +1081,14 @@ The following is the sample terminal output when running example [Change_Interva ``` Starting Change_Interval on NUCLEO_F767ZI -STM32_TimerInterrupt v1.2.0 +STM32TimerInterrupt v1.3.0 CPU Frequency = 216 MHz -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 500000 -Starting ITimer0 OK, millis() = 111 -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 1000000 -Starting ITimer1 OK, millis() = 122 +[TISR] Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 2.00 , _count = 500000 +Starting Timer0 OK, millis() = 111 +[TISR] Timer Input Freq (Hz) = 108000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 1.00 , _count = 1000000 +Starting ITimer1 OK, millis() = 122 Time = 10001, Timer0Count = 20, , Timer1Count = 10 Time = 20002, Timer0Count = 40, , Timer1Count = 20 [TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 @@ -1151,11 +1112,11 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw ``` Starting ISR_16_Timers_Array_Complex on NUCLEO_F767ZI -STM32_TimerInterrupt v1.2.0 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 216 MHz -[TISR] STM32TimerInterrupt: Timer Input Freq (Hz) = 216000000 -[TISR] Frequency = 1000000.00 , _count = 10000 -Starting ITimer OK, millis() = 12 +[TISR] Timer Input Freq (Hz) = 216000000 , Timer Clock Frequency = 1000000.00 +[TISR] Timer Frequency = 100.00 , _count = 10000 +Starting ITimer OK, millis() = 12 SimpleTimer : 2s, ms = 10015, Dms : 10003 Timer : 0, programmed : 5000, actual : 5010 Timer : 1, programmed : 10000, actual : 0 @@ -1323,7 +1284,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw ``` Starting ISR_16_Timers_Array_Complex on BLUEPILL_F103C8 -STM32TimerInterrupt v1.2.1 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 72 MHz Starting ITimer OK, millis() = 8880 SimpleTimer : 2, ms : 18880, Dms : 10000 @@ -1476,7 +1437,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw ``` Starting ISR_16_Timers_Array_Complex on NUCLEO_H743ZI2 -STM32TimerInterrupt v1.2.1 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 480 MHz Starting ITimer OK, millis() = 109 SimpleTimer : 2, ms : 10112, Dms : 10003 @@ -1629,7 +1590,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw ``` Starting ISR_16_Timers_Array_Complex on NUCLEO_L552ZE_Q -STM32TimerInterrupt v1.2.1 +STM32_TimerInterrupt v1.3.0 CPU Frequency = 110 MHz Starting ITimer OK, millis() = 109 SimpleTimer : 2, ms : 10112, Dms : 10003 @@ -1798,65 +1759,11 @@ Sometimes, the library will only work if you update the board core to the latest --- --- -## Releases - -### Releases v1.2.1 - -1. Add support to **STM32L5 (NUCLEO_L552ZE_Q)** -2. Verify OK with **STM32H7 (NUCLEO_H743ZI2)** - -### Releases v1.2.0 - -1. Add better debug feature. -2. Optimize code and examples to reduce RAM usage -3. Add Table of Contents - -### Releases v1.1.1 - -1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex) -2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String. - - -### Releases v1.0.1 - -1. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers. - -### Releases v1.0.0 - -1. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked -2. Using cpp code besides Impl.h code to use if Multiple-Definition linker error. - -#### Supported Boards - -1. **STM32 boards with built-in Ethernet LAN8742A** such as : - - - **Nucleo-144 (F429ZI, F767ZI, NUCLEO_H743ZI2, NUCLEO_L552ZE_Q)** - - **Discovery (STM32F746G-DISCOVERY)** - - **All STM32 boards (STM32F/L/H/G/WB/MP1) with 32K+ Flash, with Built-in Ethernet** - -2. **STM32F/L/H/G/WB/MP1 boards (with 32+K Flash) running W5x00 or ENC28J60 shields)** - -- Nucleo-144 -- Nucleo-64 -- Discovery -- Generic STM32F0, STM32F1, STM32F2, STM32F3, STM32F4, STM32F7 (with 64+K Flash): x8 and up -- STM32L0, STM32L1, STM32L4, STM32L5 -- STM32G0, STM32G4 -- STM32H7 -- STM32WB -- STM32MP1 -- LoRa boards -- 3-D printer boards -- Generic Flight Controllers -- Midatronics boards - ---- ---- - ### Issues Submit issues to: [STM32_TimerInterrupt issues](https://github.com/khoih-prog/STM32_TimerInterrupt/issues) +--- --- ## TO DO @@ -1874,6 +1781,7 @@ Submit issues to: [STM32_TimerInterrupt issues](https://github.com/khoih-prog/ST 4. Similar features for remaining Arduino boards such as ESP32, ESP8266, SAMD21, SAMD51, nRF52, mbed-nRF52, Teensy, etc. 5. Add Table of Contents 6. Add support to **STM32L5 (NUCLEO_L552ZE_Q)** +7. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories --- --- diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..3885267 --- /dev/null +++ b/changelog.md @@ -0,0 +1,58 @@ +# STM32_TimerInterrupt Library + +[![arduino-library-badge](https://www.ardu-badge.com/badge/STM32_TimerInterrupt.svg?)](https://www.ardu-badge.com/STM32_TimerInterrupt) +[![GitHub release](https://img.shields.io/github/release/khoih-prog/STM32_TimerInterrupt.svg)](https://github.com/khoih-prog/STM32_TimerInterrupt/releases) +[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/STM32_TimerInterrupt/blob/master/LICENSE) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) +[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/STM32_TimerInterrupt.svg)](http://github.com/khoih-prog/STM32_TimerInterrupt/issues) + +--- +--- + + +* [Changelog](#changelog) + * [Releases v1.3.0](#releases-v130) + * [Releases v1.2.1](#releases-v121) + * [Releases v1.2.0](#releases-v120) + * [Releases v1.1.1](#releases-v111) + * [Releases v1.0.1](#releases-v101) + * [Releases v1.0.0](#releases-v100) + +--- +--- + + +## Changelog + +### Releases v1.3.0 + +1. Fix `multiple-definitions` linker error. Drop `src_cpp` and `src_h` directories +2. Fix reattachInterrupt() bug. Check [bugfix: reattachInterrupt() pass wrong frequency value to setFrequency() #19](https://github.com/khoih-prog/ESP8266TimerInterrupt/pull/19) +3. Update `Packages_Patches` + +### Releases v1.2.1 + +1. Add support to **STM32L5 (NUCLEO_L552ZE_Q)** +2. Verify OK with **STM32H7 (NUCLEO_H743ZI2)** + +### Releases v1.2.0 + +1. Add better debug feature. +2. Optimize code and examples to reduce RAM usage +3. Add Table of Contents + +### Releases v1.1.1 + +1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex) +2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String. + + +### Releases v1.0.1 + +1. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers. + +### Releases v1.0.0 + +1. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked +2. Using cpp code besides Impl.h code to use if Multiple-Definition linker error. + diff --git a/examples/Argument_None/Argument_None.ino b/examples/Argument_None/Argument_None.ino index 68429c1..c8b62d6 100644 --- a/examples/Argument_None/Argument_None.ino +++ b/examples/Argument_None/Argument_None.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* @@ -53,7 +36,7 @@ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" diff --git a/examples/Change_Interval/Change_Interval.ino b/examples/Change_Interval/Change_Interval.ino index e4b7c34..2122a32 100644 --- a/examples/Change_Interval/Change_Interval.ino +++ b/examples/Change_Interval/Change_Interval.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* @@ -53,7 +36,7 @@ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" diff --git a/examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino b/examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino index a49ae95..86b1571 100644 --- a/examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino +++ b/examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: @@ -72,9 +55,11 @@ #define _TIMERINTERRUPT_LOGLEVEL_ 0 #include "STM32TimerInterrupt.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "STM32_ISR_Timer.h" -#include // https://github.com/schinken/SimpleTimer +#include // https://github.com/jfturcot/SimpleTimer #ifndef LED_BUILTIN #define LED_BUILTIN 13 diff --git a/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino index 97c969c..7187f98 100644 --- a/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino +++ b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: @@ -60,12 +43,14 @@ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "STM32_ISR_Timer.h" -#include // https://github.com/schinken/SimpleTimer +#include // https://github.com/jfturcot/SimpleTimer #ifndef LED_BUILTIN #define LED_BUILTIN 13 diff --git a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino index 8a899d2..04026be 100644 --- a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino +++ b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: diff --git a/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino b/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino index 8bbca03..b285ae6 100644 --- a/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino +++ b/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: @@ -120,9 +103,11 @@ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "STM32_ISR_Timer.h" #define HW_TIMER_INTERVAL_US 100L diff --git a/examples/RPM_Measure/RPM_Measure.ino b/examples/RPM_Measure/RPM_Measure.ino index 0c5e7b2..a1de450 100644 --- a/examples/RPM_Measure/RPM_Measure.ino +++ b/examples/RPM_Measure/RPM_Measure.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: diff --git a/examples/SwitchDebounce/SwitchDebounce.ino b/examples/SwitchDebounce/SwitchDebounce.ino index 0658478..9b7d376 100644 --- a/examples/SwitchDebounce/SwitchDebounce.ino +++ b/examples/SwitchDebounce/SwitchDebounce.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: diff --git a/examples/TimerInterruptLEDDemo/TimerInterruptLEDDemo.ino b/examples/TimerInterruptLEDDemo/TimerInterruptLEDDemo.ino index 2622832..fcd936e 100644 --- a/examples/TimerInterruptLEDDemo/TimerInterruptLEDDemo.ino +++ b/examples/TimerInterruptLEDDemo/TimerInterruptLEDDemo.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* diff --git a/examples/TimerInterruptTest/TimerInterruptTest.ino b/examples/TimerInterruptTest/TimerInterruptTest.ino index 977f853..2430718 100644 --- a/examples/TimerInterruptTest/TimerInterruptTest.ino +++ b/examples/TimerInterruptTest/TimerInterruptTest.ino @@ -11,23 +11,6 @@ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - - Based on SimpleTimer - A timer library for Arduino. - Author: mromani@ottotecnica.com - Copyright (c) 2010 OTTOTECNICA Italy - - Based on BlynkTimer.h - Author: Volodymyr Shymanskyy - - Version: 1.2.1 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.0.0 K Hoang 30/10/2020 Initial coding - 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. - 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries - 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage - 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) *****************************************************************************************************************************/ /* Notes: @@ -52,7 +35,7 @@ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system. // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system. #define TIMER_INTERRUPT_DEBUG 0 -#define _TIMERINTERRUPT_LOGLEVEL_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 #include "STM32TimerInterrupt.h" diff --git a/keywords.txt b/keywords.txt index 5dcaf33..c329b56 100644 --- a/keywords.txt +++ b/keywords.txt @@ -51,3 +51,11 @@ getNumAvailableTimers KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### + +STM32_TIMER_INTERRUPT_VERSION LITERAL1 +STM32_TIMER_INTERRUPT_VERSION_MAJOR LITERAL1 +STM32_TIMER_INTERRUPT_VERSION_MINOR LITERAL1 +STM32_TIMER_INTERRUPT_VERSION_PATCH LITERAL1 +STM32_TIMER_INTERRUPT_VERSION_INT LITERAL1 + +TIM_CLOCK_FREQ LITERAL1 diff --git a/library.json b/library.json index 4792e06..85fe502 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "STM32_TimerInterrupt", - "version": "1.2.1", + "version": "1.3.0", "keywords": "timing, device, control, timer, interrupt, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, stm32, stm32h7, stm32l5, stm32f1, stm32f4, stm32f7, stm32g4, hardware", "description": "This library enables you to use Interrupt from Hardware Timers on an STM32F/L/H/G/WB/MP1-based board. 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. 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 necessary if you need to measure some data requiring better accuracy.", "authors": @@ -22,8 +22,9 @@ "tests" ] }, + "license": "MIT", "frameworks": "*", "platforms": "ststm32", "examples": "examples/*/*/*.ino", - "license": "MIT" + "headers": ["STM32TimerInterrupt.h", "STM32_ISR_Timer.h", "STM32_ISR_Timer.hpp"] } diff --git a/library.properties b/library.properties index 77ff333..40291c3 100644 --- a/library.properties +++ b/library.properties @@ -1,12 +1,12 @@ name=STM32_TimerInterrupt -version=1.2.1 +version=1.3.0 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Interrupt from Hardware Timers on an STM32F/L/H/G/WB/MP1-based board -paragraph=These STM32 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. +paragraph=These STM32 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 is 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 are 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. category=Device Control url=https://github.com/khoih-prog/STM32_TimerInterrupt architectures=stm32 repository=https://github.com/khoih-prog/STM32_TimerInterrupt license=MIT -includes=STM32TimerInterrupt.h,STM32_ISR_Timer.h +includes=STM32TimerInterrupt.h,STM32_ISR_Timer.h,STM32_ISR_Timer.hpp diff --git a/platformio/platformio.ini b/platformio/platformio.ini index 802e09d..56c5249 100644 --- a/platformio/platformio.ini +++ b/platformio/platformio.ini @@ -31,23 +31,23 @@ lib_compat_mode = strict lib_deps = ; PlatformIO 4.x - STM32duino LwIP@~2.1.2 - STM32duino STM32Ethernet@~1.2.0 - UIPEthernet@~2.0.8 - Ethernet@>=2.0.0 - EthernetLarge@>=2.0.0 - Ethernet2@>=1.0.4 - Ethernet3@>=1.5.5 - EthernetENC@>=2.0.0 +; STM32duino LwIP@~2.1.2 +; STM32duino STM32Ethernet@~1.2.0 +; UIPEthernet@~2.0.8 +; Ethernet@>=2.0.0 +; EthernetLarge@>=2.0.0 +; Ethernet2@>=1.0.4 +; Ethernet3@>=1.5.5 +; EthernetENC@>=2.0.2 ; PlatformIO 5.x -; stm32duino/STM32duino LwIP@~2.1.2 -; stm32duino/STM32duino STM32Ethernet@~1.2.0 -; UIPEthernet/UIPEthernet@~2.0.8 -; PaulStoffregen/Ethernet@>=2.0.0 -; PaulStoffregen/EthernetLarge@>=2.0.0 -; adafruit/Ethernet2@>=1.0.4 -; sstaub/Ethernet3@>=1.5.5 -; jandrassy/EthernetENC@>=2.0.0 + stm32duino/STM32duino LwIP@~2.1.2 + stm32duino/STM32duino STM32Ethernet@~1.2.0 + UIPEthernet/UIPEthernet@~2.0.8 + PaulStoffregen/Ethernet@>=2.0.0 + PaulStoffregen/EthernetLarge@>=2.0.0 + adafruit/Ethernet2@>=1.0.4 + sstaub/Ethernet3@>=1.5.5 + jandrassy/EthernetENC@>=2.0.2 build_flags = ; set your build_flags diff --git a/src/STM32TimerInterrupt.h b/src/STM32TimerInterrupt.h index d6fb17b..034735a 100644 --- a/src/STM32TimerInterrupt.h +++ b/src/STM32TimerInterrupt.h @@ -19,7 +19,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.2.1 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -28,6 +28,7 @@ 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) + 1.3.0 K.Hoang 20/01/2022 Fix `multiple-definitions` linker error. Fix bug *****************************************************************************************************************************/ #pragma once @@ -42,7 +43,13 @@ #endif #ifndef STM32_TIMER_INTERRUPT_VERSION - #define STM32_TIMER_INTERRUPT_VERSION "STM32TimerInterrupt v1.2.1" + #define STM32_TIMER_INTERRUPT_VERSION "STM32TimerInterrupt v1.3.0" + + #define STM32_TIMER_INTERRUPT_VERSION_MAJOR 1 + #define STM32_TIMER_INTERRUPT_VERSION_MINOR 3 + #define STM32_TIMER_INTERRUPT_VERSION_PATCH 0 + + #define STM32_TIMER_INTERRUPT_VERSION_INT 1003000 #endif #include "TimerInterrupt_Generic_Debug.h" @@ -85,13 +92,16 @@ class STM32TimerInterrupt // No params and duration now. To be addes in the future by adding similar functions here or to STM32-hal-timer.c bool setFrequency(float frequency, timerCallback callback) { - // select timer frequency is 1MHz for better accuracy. We don't use 16-bit prescaler for now. + // select timer frequency is 1MHz for better accuracy and use MICROSEC_FORMAT. We don't use 16-bit prescaler for now. // Will use later if very low frequency is needed. - _frequency = 1000000; - _timerCount = (uint32_t) _frequency / frequency; + #define TIM_CLOCK_FREQ (1000000.0f) + + _frequency = frequency; + + _timerCount = (uint32_t) ( TIM_CLOCK_FREQ / frequency ); - TISR_LOGWARN1(F("STM32TimerInterrupt: Timer Input Freq (Hz) ="), _hwTimer->getTimerClkFreq()); - TISR_LOGWARN3(F("Frequency ="), _frequency, F(", _count ="), (uint32_t) (_timerCount)); + TISR_LOGWARN3(F("Timer Input Freq (Hz) ="), _hwTimer->getTimerClkFreq(), F(", Timer Clock Frequency ="), TIM_CLOCK_FREQ); + TISR_LOGWARN3(F("Timer Frequency ="), _frequency, F(", _count ="), (uint32_t) (_timerCount)); _hwTimer->setCount(0, MICROSEC_FORMAT); @@ -136,7 +146,8 @@ class STM32TimerInterrupt // Duration (in milliseconds). Duration = 0 or not specified => run indefinitely void reattachInterrupt() { - setFrequency(_frequency, _callback); + if ( (_frequency > 0) && (_timerCount > 0) && (_callback != NULL) ) + setFrequency(_frequency, _callback); } // Duration (in milliseconds). Duration = 0 or not specified => run indefinitely diff --git a/src/STM32_ISR_Timer-Impl.h b/src/STM32_ISR_Timer-Impl.h index ee02f1d..651557c 100644 --- a/src/STM32_ISR_Timer-Impl.h +++ b/src/STM32_ISR_Timer-Impl.h @@ -19,7 +19,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.2.1 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -28,6 +28,7 @@ 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) + 1.3.0 K.Hoang 20/01/2022 Fix `multiple-definitions` linker error. Fix bug *****************************************************************************************************************************/ #pragma once diff --git a/src/STM32_ISR_Timer.h b/src/STM32_ISR_Timer.h index 522d5e7..8b9f5e9 100644 --- a/src/STM32_ISR_Timer.h +++ b/src/STM32_ISR_Timer.h @@ -19,7 +19,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.2.1 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -28,6 +28,7 @@ 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) + 1.3.0 K.Hoang 20/01/2022 Fix `multiple-definitions` linker error. Fix bug *****************************************************************************************************************************/ #pragma once @@ -35,152 +36,7 @@ #ifndef ISR_TIMER_GENERIC_H #define ISR_TIMER_GENERIC_H -#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) || defined(STM32L5)) - #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting. -#endif - -#ifndef STM32_TIMER_INTERRUPT_VERSION - #define STM32_TIMER_INTERRUPT_VERSION "STM32TimerInterrupt v1.2.1" -#endif - -#include "TimerInterrupt_Generic_Debug.h" - -#include - -#include - -#if defined(ARDUINO) - #if ARDUINO >= 100 - #include - #else - #include - #endif -#endif - -#define STM32_ISR_Timer STM32_ISRTimer - -typedef void (*timerCallback)(); -typedef void (*timerCallback_p)(void *); - -class STM32_ISR_Timer -{ - - public: - // maximum number of timers -#define MAX_NUMBER_TIMERS 16 -#define TIMER_RUN_FOREVER 0 -#define TIMER_RUN_ONCE 1 - - // constructor - STM32_ISR_Timer(); - - void init(); - - // this function must be called inside loop() - void run(); - - // Timer will call function 'f' every 'd' milliseconds forever - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setInterval(unsigned long d, timerCallback f); - - // Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setInterval(unsigned long d, timerCallback_p f, void* p); - - // Timer will call function 'f' after 'd' milliseconds one time - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setTimeout(unsigned long d, timerCallback f); - - // Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setTimeout(unsigned long d, timerCallback_p f, void* p); - - // Timer will call function 'f' every 'd' milliseconds 'n' times - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setTimer(unsigned long d, timerCallback f, unsigned n); - - // Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setTimer(unsigned long d, timerCallback_p f, void* p, unsigned n); - - // updates interval of the specified timer - bool changeInterval(unsigned numTimer, unsigned long d); - - // destroy the specified timer - void deleteTimer(unsigned numTimer); - - // restart the specified timer - void restartTimer(unsigned numTimer); - - // returns true if the specified timer is enabled - bool isEnabled(unsigned numTimer); - - // enables the specified timer - void enable(unsigned numTimer); - - // disables the specified timer - void disable(unsigned numTimer); - - // enables all timers - void enableAll(); - - // disables all timers - void disableAll(); - - // enables the specified timer if it's currently disabled, and vice-versa - void toggle(unsigned numTimer); - - // returns the number of used timers - unsigned getNumTimers(); - - // returns the number of available timers - unsigned getNumAvailableTimers() - { - return MAX_NUMBER_TIMERS - numTimers; - }; - - private: - // deferred call constants -#define TIMER_DEFCALL_DONTRUN 0 // don't call the callback function -#define TIMER_DEFCALL_RUNONLY 1 // call the callback function but don't delete the timer -#define TIMER_DEFCALL_RUNANDDEL 2 // call the callback function and delete the timer - - // low level function to initialize and enable a new timer - // returns the timer number (numTimer) on success or - // -1 on failure (f == NULL) or no free timers - int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n); - - // find the first available slot - int findFirstFreeSlot(); - - typedef struct - { - unsigned long prev_millis; // value returned by the millis() function in the previous run() call - void* callback; // pointer to the callback function - void* param; // function parameter - bool hasParam; // true if callback takes a parameter - unsigned long delay; // delay value - unsigned maxNumRuns; // number of runs to be executed - unsigned numRuns; // number of executed runs - bool enabled; // true if enabled - unsigned toBeCalled; // deferred function call (sort of) - N.B.: only used in run() - } timer_t; - - volatile timer_t timer[MAX_NUMBER_TIMERS]; - - // actual number of timers in use (-1 means uninitialized) - volatile int numTimers; -}; - - +#include "STM32_ISR_Timer.hpp" #include "STM32_ISR_Timer-Impl.h" #endif // ISR_TIMER_GENERIC_H diff --git a/src/STM32_ISR_Timer.hpp b/src/STM32_ISR_Timer.hpp new file mode 100644 index 0000000..fba9592 --- /dev/null +++ b/src/STM32_ISR_Timer.hpp @@ -0,0 +1,191 @@ +/**************************************************************************************************************************** + STM32_ISR_Timer.hpp + For STM32 boards + Written by Khoi Hoang + + Built by Khoi Hoang https://github.com/khoih-prog/STM32_TimerInterrupt + Licensed under MIT license + + Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by + unsigned long miliseconds), you just consume only one STM32 timer and avoid conflicting with other cores' tasks. + The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers + Therefore, their executions are not blocked by bad-behaving functions / tasks. + This important feature is absolutely necessary for mission-critical tasks. + + Based on SimpleTimer - A timer library for Arduino. + Author: mromani@ottotecnica.com + Copyright (c) 2010 OTTOTECNICA Italy + + Based on BlynkTimer.h + Author: Volodymyr Shymanskyy + + Version: 1.3.0 + + Version Modified By Date Comments + ------- ----------- ---------- ----------- + 1.0.0 K Hoang 30/10/2020 Initial coding + 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers. + 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries + 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage + 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) + 1.3.0 K.Hoang 20/01/2022 Fix `multiple-definitions` linker error. Fix bug +*****************************************************************************************************************************/ + +#pragma once + +#ifndef ISR_TIMER_GENERIC_HPP +#define ISR_TIMER_GENERIC_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) || defined(STM32L5)) + #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting. +#endif + +#ifndef STM32_TIMER_INTERRUPT_VERSION + #define STM32_TIMER_INTERRUPT_VERSION "STM32TimerInterrupt v1.3.0" + + #define STM32_TIMER_INTERRUPT_VERSION_MAJOR 1 + #define STM32_TIMER_INTERRUPT_VERSION_MINOR 3 + #define STM32_TIMER_INTERRUPT_VERSION_PATCH 0 + + #define STM32_TIMER_INTERRUPT_VERSION_INT 1003000 +#endif + +#include "TimerInterrupt_Generic_Debug.h" + +#include + +#include + +#if defined(ARDUINO) + #if ARDUINO >= 100 + #include + #else + #include + #endif +#endif + +#define STM32_ISR_Timer STM32_ISRTimer + +typedef void (*timerCallback)(); +typedef void (*timerCallback_p)(void *); + +class STM32_ISR_Timer +{ + + public: + // maximum number of timers +#define MAX_NUMBER_TIMERS 16 +#define TIMER_RUN_FOREVER 0 +#define TIMER_RUN_ONCE 1 + + // constructor + STM32_ISR_Timer(); + + void init(); + + // this function must be called inside loop() + void run(); + + // Timer will call function 'f' every 'd' milliseconds forever + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setInterval(unsigned long d, timerCallback f); + + // Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setInterval(unsigned long d, timerCallback_p f, void* p); + + // Timer will call function 'f' after 'd' milliseconds one time + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setTimeout(unsigned long d, timerCallback f); + + // Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setTimeout(unsigned long d, timerCallback_p f, void* p); + + // Timer will call function 'f' every 'd' milliseconds 'n' times + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setTimer(unsigned long d, timerCallback f, unsigned n); + + // Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setTimer(unsigned long d, timerCallback_p f, void* p, unsigned n); + + // updates interval of the specified timer + bool changeInterval(unsigned numTimer, unsigned long d); + + // destroy the specified timer + void deleteTimer(unsigned numTimer); + + // restart the specified timer + void restartTimer(unsigned numTimer); + + // returns true if the specified timer is enabled + bool isEnabled(unsigned numTimer); + + // enables the specified timer + void enable(unsigned numTimer); + + // disables the specified timer + void disable(unsigned numTimer); + + // enables all timers + void enableAll(); + + // disables all timers + void disableAll(); + + // enables the specified timer if it's currently disabled, and vice-versa + void toggle(unsigned numTimer); + + // returns the number of used timers + unsigned getNumTimers(); + + // returns the number of available timers + unsigned getNumAvailableTimers() + { + return MAX_NUMBER_TIMERS - numTimers; + }; + + private: + // deferred call constants +#define TIMER_DEFCALL_DONTRUN 0 // don't call the callback function +#define TIMER_DEFCALL_RUNONLY 1 // call the callback function but don't delete the timer +#define TIMER_DEFCALL_RUNANDDEL 2 // call the callback function and delete the timer + + // low level function to initialize and enable a new timer + // returns the timer number (numTimer) on success or + // -1 on failure (f == NULL) or no free timers + int setupTimer(unsigned long d, void* f, void* p, bool h, unsigned n); + + // find the first available slot + int findFirstFreeSlot(); + + typedef struct + { + unsigned long prev_millis; // value returned by the millis() function in the previous run() call + void* callback; // pointer to the callback function + void* param; // function parameter + bool hasParam; // true if callback takes a parameter + unsigned long delay; // delay value + unsigned maxNumRuns; // number of runs to be executed + unsigned numRuns; // number of executed runs + bool enabled; // true if enabled + unsigned toBeCalled; // deferred function call (sort of) - N.B.: only used in run() + } timer_t; + + volatile timer_t timer[MAX_NUMBER_TIMERS]; + + // actual number of timers in use (-1 means uninitialized) + volatile int numTimers; +}; + +#endif // ISR_TIMER_GENERIC_HPP + diff --git a/src/TimerInterrupt_Generic_Debug.h b/src/TimerInterrupt_Generic_Debug.h index f240ef7..52d9c4a 100644 --- a/src/TimerInterrupt_Generic_Debug.h +++ b/src/TimerInterrupt_Generic_Debug.h @@ -19,7 +19,7 @@ Based on BlynkTimer.h Author: Volodymyr Shymanskyy - Version: 1.2.1 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- @@ -28,6 +28,7 @@ 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage 1.2.1 K.Hoang 20/08/2021 Add support to STM32L5 (NUCLEO_L552ZE_Q). Verify OK with STM32H7 (NUCLEO_H743ZI2) + 1.3.0 K.Hoang 20/01/2022 Fix `multiple-definitions` linker error. Fix bug *****************************************************************************************************************************/ #pragma once