11/* ***************************************************************************************************************************
2- Argument_None.ino
3- For STM32 boards
4- Written by Khoi Hoang
5-
6- Built by Khoi Hoang https://github.com/khoih-prog/STM32_TimerInterrupt
7- Licensed under MIT license
8-
9- Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
10- unsigned long miliseconds), you just consume only one STM32 timer and avoid conflicting with other cores' tasks.
11- The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
12- Therefore, their executions are not blocked by bad-behaving functions / tasks.
13- This important feature is absolutely necessary for mission-critical tasks.
14-
15- Based on SimpleTimer - A timer library for Arduino.
16- 17- Copyright (c) 2010 OTTOTECNICA Italy
18-
19- Based on BlynkTimer.h
20- Author: Volodymyr Shymanskyy
21-
22- Version: 1.1.1
23-
24- Version Modified By Date Comments
25- ------- ----------- ---------- -----------
26- 1.0.0 K Hoang 30/10/2020 Initial coding
27- 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28- 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries
2+ Argument_None.ino
3+ For STM32 boards
4+ Written by Khoi Hoang
5+
6+ Built by Khoi Hoang https://github.com/khoih-prog/STM32_TimerInterrupt
7+ Licensed under MIT license
8+
9+ Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
10+ unsigned long miliseconds), you just consume only one STM32 timer and avoid conflicting with other cores' tasks.
11+ The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
12+ Therefore, their executions are not blocked by bad-behaving functions / tasks.
13+ This important feature is absolutely necessary for mission-critical tasks.
14+
15+ Based on SimpleTimer - A timer library for Arduino.
16+ 17+ Copyright (c) 2010 OTTOTECNICA Italy
18+
19+ Based on BlynkTimer.h
20+ Author: Volodymyr Shymanskyy
21+
22+ Version: 1.2.0
23+
24+ Version Modified By Date Comments
25+ ------- ----------- ---------- -----------
26+ 1.0.0 K Hoang 30/10/2020 Initial coding
27+ 1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28+ 1.1.1 K.Hoang 06/12/2020 Add complex examples. Bump up version to sync with other TimerInterrupt Libraries
29+ 1.2.0 K.Hoang 08/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
2930*****************************************************************************************************************************/
3031
3132/*
4748#endif
4849
4950// These define's must be placed at the beginning before #include "STM32TimerInterrupt.h"
50- // Don't define STM32_STM32_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
51- #define STM32_TIMER_INTERRUPT_DEBUG 1
51+ // _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
52+ // Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
53+ // Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
54+ #define TIMER_INTERRUPT_DEBUG 0
55+ #define _TIMERINTERRUPT_LOGLEVEL_ 0
5256
5357#include " STM32TimerInterrupt.h"
5458
6468 #define LED_RED PB14 // Pin 74/PB14 control on-board LED_BLUE on F767ZI
6569#endif
6670
67-
68- void TimerHandler0 (void )
71+ void TimerHandler0 ()
6972{
7073 static bool toggle0 = false ;
7174 static bool started = false ;
72- static uint32_t preMillis = 0 ;
73- static uint32_t curMillis = 0 ;
7475
7576 if (!started)
7677 {
7778 started = true ;
7879 pinMode (LED_BUILTIN, OUTPUT);
7980 }
8081
81- #if (STM32_TIMER_INTERRUPT_DEBUG > 0)
82+ #if (TIMER_INTERRUPT_DEBUG > 0)
83+ static uint32_t preMillis = 0 ;
84+ static uint32_t curMillis = 0 ;
85+
8286 curMillis = millis ();
83- Serial.println (" ITimer0: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillis));
87+
88+ Serial.print (F (" ITimer0: millis() = " )); Serial.print (curMillis);
89+ Serial.print (F (" , delta = " )); Serial.println (curMillis - preMillis);
90+
8491 preMillis = curMillis;
8592#endif
8693
@@ -89,22 +96,26 @@ void TimerHandler0(void)
8996 toggle0 = !toggle0;
9097}
9198
92- void TimerHandler1 (void )
99+ void TimerHandler1 ()
93100{
94101 static bool toggle1 = false ;
95102 static bool started = false ;
96- static uint32_t preMillis = 0 ;
97- static uint32_t curMillis = 0 ;
98103
99104 if (!started)
100105 {
101106 started = true ;
102107 pinMode (LED_BLUE, OUTPUT);
103108 }
104109
105- #if (STM32_TIMER_INTERRUPT_DEBUG > 0)
110+ #if (TIMER_INTERRUPT_DEBUG > 0)
111+ static uint32_t preMillis = 0 ;
112+ static uint32_t curMillis = 0 ;
113+
106114 curMillis = millis ();
107- Serial.println (" ITimer1: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillis));
115+
116+ Serial.print (F (" ITimer1: millis() = " )); Serial.print (curMillis);
117+ Serial.print (F (" , delta = " )); Serial.println (curMillis - preMillis);
118+
108119 preMillis = curMillis;
109120#endif
110121
@@ -113,22 +124,26 @@ void TimerHandler1(void)
113124 toggle1 = !toggle1;
114125}
115126
116- void TimerHandler2 (void )
127+ void TimerHandler2 ()
117128{
118129 static bool toggle2 = false ;
119130 static bool started = false ;
120- static uint32_t preMillis = 0 ;
121- static uint32_t curMillis = 0 ;
122131
123132 if (!started)
124133 {
125134 started = true ;
126135 pinMode (LED_RED, OUTPUT);
127136 }
128137
129- #if (STM32_TIMER_INTERRUPT_DEBUG > 0)
138+ #if (TIMER_INTERRUPT_DEBUG > 0)
139+ static uint32_t preMillis = 0 ;
140+ static uint32_t curMillis = 0 ;
141+
130142 curMillis = millis ();
131- Serial.println (" ITimer2: millis() = " + String (curMillis) + " , delta = " + String (curMillis - preMillis));
143+
144+ Serial.print (F (" ITimer2: millis() = " )); Serial.print (curMillis);
145+ Serial.print (F (" , delta = " )); Serial.println (curMillis - preMillis);
146+
132147 preMillis = curMillis;
133148#endif
134149
@@ -159,28 +174,34 @@ void setup()
159174 while (!Serial);
160175
161176 delay (100 );
162-
163- Serial.println (" \n Starting Argument_None on " + String (BOARD_NAME));
164- Serial.println (STM32_TIMER_INTERRUPT_VERSION);
165- Serial.println (" CPU Frequency = " + String (F_CPU / 1000000 ) + " MHz" );
166177
178+ Serial.print (F (" \n Starting Argument_None on " )); Serial.println (BOARD_NAME);
179+ Serial.println (STM32_TIMER_INTERRUPT_VERSION);
180+ Serial.print (F (" CPU Frequency = " )); Serial.print (F_CPU / 1000000 ); Serial.println (F (" MHz" ));
181+
167182 // Interval in microsecs
168183 if (ITimer0.attachInterruptInterval (TIMER0_INTERVAL_MS * 1000 , TimerHandler0))
169- Serial.println (" Starting ITimer0 OK, millis() = " + String (millis ()));
184+ {
185+ Serial.print (F (" Starting ITimer0 OK, millis() = " )); Serial.println (millis ());
186+ }
170187 else
171- Serial.println (" Can't set ITimer0. Select another freq. or timer" );
188+ Serial.println (F ( " Can't set ITimer0. Select another freq. or timer" ) );
172189
173190 // Interval in microsecs
174191 if (ITimer1.attachInterruptInterval (TIMER1_INTERVAL_MS * 1000 , TimerHandler1))
175- Serial.println (" Starting ITimer1 OK, millis() = " + String (millis ()));
192+ {
193+ Serial.print (F (" Starting ITimer1 OK, millis() = " )); Serial.println (millis ());
194+ }
176195 else
177- Serial.println (" Can't set ITimer1. Select another freq. or timer" );
196+ Serial.println (F ( " Can't set ITimer1. Select another freq. or timer" ) );
178197
179198 // Interval in microsecs
180199 if (ITimer2.attachInterruptInterval (TIMER2_INTERVAL_MS * 1000 , TimerHandler2))
181- Serial.println (" Starting ITimer2 OK, millis() = " + String (millis ()));
200+ {
201+ Serial.print (F (" Starting ITimer2 OK, millis() = " )); Serial.println (millis ());
202+ }
182203 else
183- Serial.println (" Can't set ITimer2. Select another freq. or timer" );
204+ Serial.println (F ( " Can't set ITimer2. Select another freq. or timer" ) );
184205}
185206
186207void loop ()
0 commit comments