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

Commit ae085ab

Browse files
authored
v1.2.0
### Releases v1.2.0 1. Add better debug feature. 2. Optimize code and examples to reduce RAM usage
1 parent f7142d2 commit ae085ab

26 files changed

+1424
-869
lines changed

README.md

Lines changed: 224 additions & 72 deletions
Large diffs are not rendered by default.

examples/Argument_None/Argument_None.ino

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
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
/*
@@ -47,8 +48,11 @@
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

@@ -64,23 +68,26 @@
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("\nStarting 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("\nStarting 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

186207
void loop()

examples/Change_Interval/Change_Interval.ino

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
/****************************************************************************************************************************
2-
Change_Interval.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+
Change_Interval.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
/*
@@ -47,8 +48,11 @@
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

@@ -82,10 +86,12 @@ STM32Timer ITimer1(TIM2);
8286

8387
void printResult(uint32_t currTime)
8488
{
85-
Serial.printf("Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n", currTime, Timer0Count, Timer1Count);
89+
Serial.print(F("Time = ")); Serial.print(currTime);
90+
Serial.print(F(", Timer0Count = ")); Serial.print(Timer0Count);
91+
Serial.print(F(", Timer1Count = ")); Serial.println(Timer1Count);
8692
}
8793

88-
void TimerHandler0(void)
94+
void TimerHandler0()
8995
{
9096
static bool toggle0 = false;
9197

@@ -97,7 +103,7 @@ void TimerHandler0(void)
97103
toggle0 = !toggle0;
98104
}
99105

100-
void TimerHandler1(void)
106+
void TimerHandler1()
101107
{
102108
static bool toggle1 = false;
103109

@@ -119,25 +125,25 @@ void setup()
119125

120126
delay(100);
121127

122-
Serial.printf("\nStarting Change_Interval on %s\n", BOARD_NAME);
128+
Serial.print(F("\nStarting Change_Interval on ")); Serial.println(BOARD_NAME);
123129
Serial.println(STM32_TIMER_INTERRUPT_VERSION);
124-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
130+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
125131

126132
// Interval in microsecs
127133
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
128134
{
129-
Serial.printf("Starting ITimer0 OK, millis() = %ld\n", millis());
135+
Serial.print(F("Starting Timer0 OK, millis() = ")); Serial.println(millis());
130136
}
131137
else
132-
Serial.println("Can't set ITimer0. Select another freq. or timer");
138+
Serial.println(F("Can't set ITimer0. Select another freq. or timer"));
133139

134140
// Interval in microsecs
135141
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
136142
{
137-
Serial.printf("Starting ITimer1 OK, millis() = %ld\n", millis());
143+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
138144
}
139145
else
140-
Serial.println("Can't set ITimer1. Select another freq. or timer");
146+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
141147
}
142148

143149
#define CHECK_INTERVAL_MS 10000L
@@ -165,8 +171,9 @@ void loop()
165171
ITimer0.setInterval(TIMER0_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler0);
166172
ITimer1.setInterval(TIMER1_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler1);
167173

168-
Serial.printf("Changing Interval, Timer0 = %lu, Timer1 = %lu\n", TIMER0_INTERVAL_MS * (multFactor + 1), TIMER1_INTERVAL_MS * (multFactor + 1));
169-
174+
Serial.print(F("Changing Interval, Timer0 = ")); Serial.print(TIMER0_INTERVAL_MS * (multFactor + 1));
175+
Serial.print(F(", Timer1 = ")); Serial.println(TIMER1_INTERVAL_MS * (multFactor + 1));
176+
170177
lastChangeTime = currTime;
171178
}
172179
}

0 commit comments

Comments
 (0)