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

Commit dc97b37

Browse files
authored
Initial v1.2.1 for Portenta_H7
### Initial Releases v1.2.1 1. Initial coding to support **Portenta_H7 boards** such as Portenta_H7 Rev2 ABX00042, etc., using [**ArduinoCore-mbed mbed_portenta** core](https://github.com/arduino/ArduinoCore-mbed) 2. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked 3. Using cpp code besides Impl.h code to use if Multiple-Definition linker error. 4. Bump version to v1.2.1 to sync with [STM32_TimerInterrupt library](https://github.com/khoih-prog/STM32_TimerInterrupt)
0 parents  commit dc97b37

37 files changed

+11514
-0
lines changed

.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app

CONTRIBUTING.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Contributing to Portenta_H7_TimerInterrupt
2+
3+
### Reporting Bugs
4+
5+
Please report bugs in [Portenta_H7_TimerInterrupt Issues](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/issues) if you find them.
6+
7+
However, before reporting a bug please check through the following:
8+
9+
* [Existing Open Issues](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/issues) - someone might have already encountered this.
10+
11+
If you don't find anything, please [open a new issue](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/issues/new).
12+
13+
### How to submit a bug report
14+
15+
Please ensure to specify the following:
16+
17+
* Arduino IDE version (e.g. 1.8.16) or Platform.io version
18+
* `ArduinoCore-mbed` Core Version (e.g. `ArduinoCore-mbed` mbed_portenta core v2.4.1)
19+
* `Portenta_H7` Board type (e.g. Portenta_H7 Rev2 ABX00042, etc.)
20+
* Contextual information (e.g. what you were trying to achieve)
21+
* Simplest possible steps to reproduce
22+
* Anything that might be relevant in your opinion, such as:
23+
* Operating system (Windows, Ubuntu, etc.) and the output of `uname -a`
24+
* Network configuration
25+
26+
27+
### Example
28+
29+
```
30+
Arduino IDE version: 1.8.16
31+
`ArduinoCore-mbed` mbed_portenta core v2.4.1
32+
Portenta_H7 Rev2 ABX00042
33+
OS: Ubuntu 20.04 LTS
34+
Linux xy-Inspiron-3593 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
35+
36+
Context:
37+
I encountered a crash while using TimerInterrupt.
38+
39+
Steps to reproduce:
40+
1. ...
41+
2. ...
42+
3. ...
43+
4. ...
44+
```
45+
46+
### Sending Feature Requests
47+
48+
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
49+
50+
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
51+
52+
### Sending Pull Requests
53+
54+
Pull Requests with changes and fixes are also welcome!

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Khoi Hoang
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
portenta_h7_rules () {
4+
echo ""
5+
echo "# Portenta H7 bootloader mode UDEV rules"
6+
echo ""
7+
cat <<EOF
8+
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
9+
EOF
10+
}
11+
12+
if [ "$EUID" -ne 0 ]
13+
then echo "Please run as root"
14+
exit
15+
fi
16+
17+
portenta_h7_rules > /etc/udev/rules.d/49-portenta_h7.rules
18+
19+
# reload udev rules
20+
echo "Reload rules..."
21+
udevadm trigger
22+
udevadm control --reload-rules

README.md

+1,236
Large diffs are not rendered by default.

changelog.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Portenta_H7_TimerInterrupt Library
2+
3+
[![arduino-library-badge](https://www.ardu-badge.com/badge/Portenta_H7_TimerInterrupt.svg?)](https://www.ardu-badge.com/Portenta_H7_TimerInterrupt)
4+
[![GitHub release](https://img.shields.io/github/release/khoih-prog/Portenta_H7_TimerInterrupt.svg)](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/releases)
5+
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/Portenta_H7_TimerInterrupt/blob/master/LICENSE)
6+
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
7+
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/Portenta_H7_TimerInterrupt.svg)](http://github.com/khoih-prog/Portenta_H7_TimerInterrupt/issues)
8+
9+
---
10+
---
11+
12+
## Table of Contents
13+
14+
* [Changelog](#changelog)
15+
* [Initial Releases v1.2.1](#initial-releases-v121)
16+
17+
---
18+
---
19+
20+
## Changelog
21+
22+
### Initial Releases v1.2.1
23+
24+
1. Initial coding to support **Portenta_H7 boards** such as Portenta_H7 Rev2 ABX00042, etc., using [**ArduinoCore-mbed mbed_portenta** core](https://github.com/arduino/ArduinoCore-mbed)
25+
2. Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
26+
3. Using cpp code besides Impl.h code to use if Multiple-Definition linker error.
27+
4. Bump version to v1.2.1 to sync with [STM32_TimerInterrupt library](https://github.com/khoih-prog/STM32_TimerInterrupt)
28+
29+
---
30+
---
31+
32+
## Copyright
33+
34+
Copyright 2021- Khoi Hoang
35+
36+
+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/****************************************************************************************************************************
2+
Argument_None.ino
3+
For Portenta_H7 boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/Portenta_H7_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 Portenta_H7 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.1
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.2.1 K.Hoang 15/09/2021 Initial coding for Portenta_H7.
27+
*****************************************************************************************************************************/
28+
29+
/*
30+
Notes:
31+
Special design is necessary to share data between interrupt code and the rest of your program.
32+
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume
33+
variable can not spontaneously change. Because your function may change variables while your program is using them,
34+
the compiler needs this hint. But volatile alone is often not enough.
35+
When accessing shared variables, usually interrupts must be disabled. Even with volatile,
36+
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
37+
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
38+
or the entire sequence of your code which accesses the data.
39+
*/
40+
41+
#if !( ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) && defined(ARDUINO_ARCH_MBED) )
42+
#error This code is designed to run on Portenta_H7 platform! Please check your Tools->Board setting.
43+
#endif
44+
45+
// These define's must be placed at the beginning before #include "Portenta_H7_TimerInterrupt.h"
46+
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
47+
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
48+
#define _TIMERINTERRUPT_LOGLEVEL_ 4
49+
50+
#include "Portenta_H7_TimerInterrupt.h"
51+
52+
#define LED_OFF HIGH
53+
#define LED_ON LOW
54+
55+
#ifndef LED_BUILTIN
56+
#define LED_BUILTIN 24 //LEDG // Pin 24 control on-board LED_GREEN on Portenta_H7
57+
#endif
58+
59+
#ifndef LED_BLUE
60+
#define LED_BLUE 25 //LEDB // Pin 25 control on-board LED_BLUE on Portenta_H7
61+
#endif
62+
63+
#ifndef LED_RED
64+
#define LED_RED 23 // LEDR // Pin 23 control on-board LED_RED on Portenta_H7
65+
#endif
66+
67+
// In Portenta_H7, avoid doing something fancy in ISR, for example Serial.print
68+
// Or you can get this run-time error / crash
69+
70+
void TimerHandler0()
71+
{
72+
static bool toggle0 = false;
73+
74+
//timer interrupt toggles pin LED_BUILTIN
75+
digitalWrite(LED_BUILTIN, toggle0);
76+
toggle0 = !toggle0;
77+
}
78+
79+
void TimerHandler1()
80+
{
81+
static bool toggle1 = false;
82+
83+
//timer interrupt toggles outputPin
84+
digitalWrite(LED_BLUE, toggle1);
85+
toggle1 = !toggle1;
86+
}
87+
88+
void TimerHandler2()
89+
{
90+
static bool toggle2 = false;
91+
92+
//timer interrupt toggles outputPin
93+
digitalWrite(LED_RED, toggle2);
94+
toggle2 = !toggle2;
95+
}
96+
97+
#define TIMER0_INTERVAL_MS 1000
98+
#define TIMER1_INTERVAL_MS 2000
99+
#define TIMER2_INTERVAL_MS 5000
100+
101+
// Depending on the board, you can select STM32H7 Hardware Timer from TIM1-TIM22
102+
// If you select a Timer not correctly, you'll get a message from compiler
103+
// 'TIMxx' was not declared in this scope; did you mean 'TIMyy'?
104+
105+
// Portenta_H7 OK : TIM1, TIM4, TIM7, TIM8, TIM12, TIM13, TIM14, TIM15, TIM16, TIM17
106+
// Portenta_H7 Not OK : TIM2, TIM3, TIM5, TIM6, TIM18, TIM19, TIM20, TIM21, TIM22
107+
// Portenta_H7 No timer : TIM9, TIM10, TIM11. Only for STM32F2, STM32F4 and STM32L1
108+
// Portenta_H7 No timer : TIM18, TIM19, TIM20, TIM21, TIM22
109+
110+
// Init timer TIM15
111+
Portenta_H7_Timer ITimer0(TIM15);
112+
// Init timer TIM16
113+
Portenta_H7_Timer ITimer1(TIM16);
114+
// Init timer TIM17
115+
Portenta_H7_Timer ITimer2(TIM17);
116+
117+
void setup()
118+
{
119+
pinMode(LED_BUILTIN, OUTPUT);
120+
pinMode(LED_BLUE, OUTPUT);
121+
pinMode(LED_RED, OUTPUT);
122+
123+
digitalWrite(LED_BUILTIN, LED_OFF);
124+
digitalWrite(LED_BLUE, LED_OFF);
125+
digitalWrite(LED_RED, LED_OFF);
126+
127+
128+
Serial.begin(115200);
129+
while (!Serial);
130+
131+
delay(100);
132+
133+
Serial.print(F("\nStarting Argument_None on ")); Serial.println(BOARD_NAME);
134+
Serial.println(PORTENTA_H7_TIMER_INTERRUPT_VERSION);
135+
136+
// Interval in microsecs
137+
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
138+
{
139+
Serial.print(F("Starting ITimer0 OK, millis() = ")); Serial.println(millis());
140+
}
141+
else
142+
Serial.println(F("Can't set ITimer0. Select another freq. or timer"));
143+
144+
// Interval in microsecs
145+
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
146+
{
147+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
148+
}
149+
else
150+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
151+
152+
// Interval in microsecs
153+
if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS * 1000, TimerHandler2))
154+
{
155+
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
156+
}
157+
else
158+
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
159+
}
160+
161+
void loop()
162+
{
163+
164+
}

0 commit comments

Comments
 (0)