Add STM32 Nucleo-144 support

This commit is contained in:
fauresystems
2020-06-26 09:35:39 +02:00
parent ca26b3253c
commit 4f057a4476
21 changed files with 349 additions and 20 deletions
+4
View File
@@ -42,6 +42,8 @@
<ClCompile Include="$(MSBuildThisFileDirectory)src\Prop.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropAction.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)src\PropData.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)src\Stm32Millis.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)src\Stm32Nucleo144Prop.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProp.cpp" />
</ItemGroup>
<ItemGroup>
@@ -51,6 +53,8 @@
<ClInclude Include="$(MSBuildThisFileDirectory)src\Prop.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropAction.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)src\PropData.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)src\Stm32Millis.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)src\Stm32Nucleo144Prop.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProp.h" />
</ItemGroup>
<ItemGroup>
+12
View File
@@ -80,6 +80,12 @@
<ClCompile Include="$(MSBuildThisFileDirectory)src\WifiProp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)src\Stm32Millis.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)src\Stm32Nucleo144Prop.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)src\ArduinoProps.h">
@@ -103,6 +109,12 @@
<ClInclude Include="$(MSBuildThisFileDirectory)src\WifiProp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)src\Stm32Millis.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)src\Stm32Nucleo144Prop.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="$(MSBuildThisFileDirectory)help\dependencies-shot.png">
+48 -1
View File
@@ -5,6 +5,7 @@ An adaptation of the internal led Blink example (https://www.arduino.cc/en/tutor
2. [**BlinkOnEthernetProp**](#2-blinkonethernetprop-the-blink-example-on-an-ethernet-prop-with-arduinoprops-library): the Blink example on an Ethernet prop with *ArduinoProps library*
3. [**BlinkOnWifiProp**](#3-blinkonwifiprop-the-blink-example-on-a-wifi-prop-with-arduinoprops-library): the Blink example on a Wifi prop with *ArduinoProps library*
4. [**BlinkOnBridgePubSub**](#4-blinkonbridgepubsub-the-blink-example-on-prop-using-pubsubclient-directly): the Blink example on prop using *PubSubClient* directly
5. [**BlinkOnStm32Nucleo144Prop**](#5-blinkonstm32nucelo144prop-the-blink-example-on-an-stm32-nucelo-144-prop-with-arduinoprops-library): the Blink example on an STM32 Nucleo-144 prop with *ArduinoProps library*
MQTT messages are received asynchronously therefore to keep the sketch responsive to MQTT commands, calls to delay() should be avoided (except short ones, say < 100 milliseconds).
@@ -456,9 +457,55 @@ Global variables use 1013 bytes (39%) of dynamic memory, which leaves 1547 bytes
```
## 5. *BlinkOnStm32Nucleo144Prop*: the Blink example on an STM32 Nucleo-144 prop with *ArduinoProps library*
Sketch with *BlinkOnStm32Nucleo144Prop* has been derived *EthernetProp*.
Includes for STM32 are different:
```c
#include <LwIP.h>
#include <STM32Ethernet.h>
#include "Stm32Nucleo144Prop.h"
#include "ArduinoProps.h"
#include "Stm32Millis.h"
extern Stm32MillisClass Stm32Millis;
```
Ethernet connection start is slightly different:
```c
if (ip == IPAddress(0,0,0,0)) {
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Ethernet.begin(mac, IPAddress(10, 90, 90, 239));
}
}
else {
Ethernet.begin(mac, ip);
}
```
`millis()` is missing in STM323duino library, you must start **Stm32Millis** in `setup()`:
```c
// millis() missing in STM32duino
Stm32Millis.begin();
```
#### Pay atention to the board MAC address:
MAC adresses are hardware identifiers on the network so they must be unique.
A good practice is to increment only the byte at the very right (`0x03`) when adding a new Arduino Ethernet on your network.
```csharp
byte mac[] = { 0x46, 0x4F, 0xEA, 0x10, 0x20, 0x03 }; //<<< MAKE SURE IT'S UNIQUE IN YOUR NETWORK!!! and not a reserved MAC
```
## Author
**Faure Systems** (Nov 15th, 2019)
**Faure Systems** (Jun 25th, 2019)
* company: FAURE SYSTEMS SAS
* mail: *dev at faure dot systems*
* github: <a href="https://github.com/fauresystems?tab=repositories" target="_blank">fauresystems</a>
+27 -2
View File
@@ -1,4 +1,4 @@
# ArduinoProps library
# ArduinoProps library
1. [Installation and usage](#1-installation-and-usage)
2. [Escape room 2.0 prop with Arduino](#2-escape-room-20-prop-with-arduino)
3. [*ArduinoProps library* value for escape room 2.0](#3-arduinoprops-library-value-for-escape-room-20)
@@ -49,6 +49,28 @@ Learn more at <a href="https://wiki.dragino.com/index.php?title=Getting_Start_wi
![](help/dragino.png)
### Add the STM32 boards to the *Boards Manager*:
Open **Preferences**, in **Settings** tab, complete the *Additionnal Boards Manager URLs* with:
```bash
https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
```
![](help/preferences-board-manager.png)
Then open the **Boards Manager** in **Tools**:
![](help/open-board-manager.png)
Find **STM32 Cores** by **STMicroelectronics**, **Select versio**n (latest) and **Install**:
![](help/board-manager-1.png)
In **Library Manager**, find STM32 libraries and install what you need:
* **STM32duino Examples**
* **STM32duino LwIP**
* **STM32duino STM32Ethernet**
### Start coding your own prop
Add `#include "ArduinoProps.h"` on top of your sketch and start coding.
@@ -207,6 +229,9 @@ More MQTT topics can be use for anything (room scenario, etc.).
- Arduino MKR WiFi 1010
- Arduino MKR VIDOR 4000
- Any Arduino + Ethernet Shield
- Any STM32 Nucleo-144 (tested with STM32-F767ZI)
* Nucleo-144 boards have on-board Ethernet RJ45
* STM32-H7xx not supported (STM32duino/STM32Ethernet limitation)
For WiFi prop, please update the WiFiNINA firmware: [WiFiNINA firmware update](help/WifiNinaFirmware.md).
@@ -268,7 +293,7 @@ See [EXAMPLES.md](EXAMPLES.md) for an adaptation of the Blink example (https://w
## Author
**Faure Systems** (Apr 18th, 2020)
**Faure Systems** (Jun 26th, 2020)
* company: FAURE SYSTEMS SAS
* mail: *dev at faure dot systems*
* github: <a href="https://github.com/fauresystems?tab=repositories" target="_blank">fauresystems</a>
@@ -0,0 +1,121 @@
/* Stm32Nucleo144Prop.ino
MIT License (c) Faure Systems <dev at faure dot systems>
Adapt the Blink example (https://www.arduino.cc/en/tutorial/blink) as a
simple MQTT prop. Avoid delay() calls (except short ones) in loop() to
ensure CPU for MQTT protocol. Use PropAction checks instead.
Copy and change it to build your first Arduino connected prop, you will
only be limited by your imagination.
Requirements:
- install ArduinoProps.zip library and dependencies (https://github.com/fauresystems/ArduinoProps)
- help: https://github.com/xcape-io/ArduinoProps/blob/master/help/ArduinoProps_sketch.md
- STM32 Nucleo-144 borads require: STM32duino LwIP and STM32duino STM32Ethernet libraries
*/
#include <LwIP.h>
#include <STM32Ethernet.h>
#include "Stm32Nucleo144Prop.h"
#include "ArduinoProps.h"
#include "Stm32Millis.h"
extern Stm32MillisClass Stm32Millis;
// If you're running xcape.io Room software you have to respect prop inbox/outbox
// topicw syntax: Room/[escape room name]/Props/[propsname]/inbox|outbox
// https://xcape.io/go/room
Stm32Nucleo144Prop prop(u8"Nucleo Blink", // as MQTT client id, should be unique per client for given broker
u8"Room/My room/Props/Nucleo Blink/inbox",
u8"Room/My room/Props/Nucleo Blink/outbox",
"192.168.1.42", // your MQTT server IP address
1883); // your MQTT server port;
byte mac[] = { 0x46, 0x4F, 0xEA, 0x10, 0x20, 0x04 }; //<<< MAKE SURE IT'S UNIQUE IN YOUR NETWORK!!! and not a reserved MAC
IPAddress ip(192, 168, 1, 177); //<<< Set to (0,0,0,0) to get an address from DHCP
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192, 168, 1, 42); // numeric IP for Google (no DNS)
//char server[] = "broker.mqtt-dashboard.com"; // name address for mqtt broker (using DNS)
PropDataLogical blinking(u8"blink", u8"yes", u8"no", true);
PropDataLogical led(u8"led");
void blink(); // forward
PropAction blinkingAction = PropAction(1000, blink);
void setup()
{
if (ip == IPAddress(0,0,0,0)) {
if (!Ethernet.begin(mac)) {
// if DHCP fails, start with a hard-coded address:
Ethernet.begin(mac, IPAddress(10, 90, 90, 239));
}
}
else {
Ethernet.begin(mac, ip);
}
delay(1500); // allow the hardware to sort itself out
// millis() missing in STM32duino
Stm32Millis.begin();
prop.addData(&blinking);
prop.addData(&led);
prop.begin(InboxMessage::run);
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output
// At this point, the broker is not connected yet
}
void loop()
{
prop.loop();
led.setValue(digitalRead(LED_BUILTIN)); // read I/O
blinkingAction.check(); // do your stuff, don't freeze the loop with delay() calls
}
void blink()
{
if (blinking.value()) {
led.setValue(!led.value());
digitalWrite(LED_BUILTIN, led.value() ? HIGH : LOW);
}
}
void InboxMessage::run(String a) {
if (a == u8"app:startup")
{
prop.sendAllData();
prop.sendDone(a);
}
else if (a == u8"reset-mcu")
{
prop.resetMcu();
}
else if (a == "blink:1")
{
blinking.setValue(true);
prop.sendAllData(); // all data change, we don't have to be selctive then
prop.sendDone(a); // acknowledge prop command action
}
else if (a == "blink:0")
{
blinking.setValue(false);
prop.sendAllData(); // all data change, we don't have to be selctive then
prop.sendDone(a); // acknowledge prop command action
}
else
{
// acknowledge omition of the prop command
prop.sendOmit(a);
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 246 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+3
View File
@@ -10,6 +10,8 @@ Prop KEYWORD1
BridgeProp KEYWORD1
EthernetProp KEYWORD1
WifiProp KEYWORD1
Stm32Nucleo144Prop KEYWORD1
Stm32Millis KEYWORD1
PropAction KEYWORD1
PropData KEYWORD1
PropDataDecimal KEYWORD1
@@ -56,6 +58,7 @@ setBrokerIpAddress KEYWORD2
checkDataChanges KEYWORD2
resetIntervals KEYWORD2
send KEYWORD2
update KEYWORD2
#######################################
+1 -1
View File
@@ -1,5 +1,5 @@
name=ArduinoProps
version=1.0.0
version=1.1.0
author=Faure Systems
maintainer=Faure Systems <dev at faure dot systems>
sentence=ArduinoProps Library
+8
View File
@@ -10,6 +10,9 @@
#ifndef _ArduinoProps_h
#define _ArduinoProps_h
#if !defined(STM32F4xx) && !defined(STM32F7xx) // tested with STM32F767
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
@@ -19,6 +22,11 @@
#include "BridgeProp.h"
#include "EthernetProp.h"
#include "WifiProp.h"
#else // !STM32F4xx && !STM32F7xx
#include <Arduino.h>
#endif // STM32F4
#include "PropAction.h"
#include "PropData.h"
+2 -2
View File
@@ -8,7 +8,7 @@
*/
#include "Prop.h"
#include <Process.h>
//#include <Process.h>
#if defined(__AVR__)
#include <avr/wdt.h>
#endif
@@ -99,7 +99,7 @@ void Prop::checkDataChanges()
void Prop::resetMcu()
{
#if defined(ARDUINO_ARCH_SAMD)
#if defined(ARDUINO_ARCH_SAMD) || defined(STM32F4xx) || defined(STM32F7xx)
NVIC_SystemReset();
#elif defined(ARDUINO_ARCH_AVR) || defined(__AVR__)
wdt_enable(WDTO_15MS);
+5
View File
@@ -9,6 +9,8 @@
#ifndef PROP_H
#define PROP_H
#if !defined(STM32F4xx) && !defined(STM32F7xx) // tested with STM32F767
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
@@ -16,6 +18,9 @@
#endif
#include <BridgeClient.h>
#endif // !STM32F4xx && !STM32F7xx
#include <PubSubClient.h>
#include <ListLib.h>
#include "PropAction.h"
+5 -1
View File
@@ -1,5 +1,5 @@
/*
Name: PropAction.h
Name: PropAction.cpp
Author: Faure Systems <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Faure Systems <dev at faure dot systems>
@@ -9,6 +9,10 @@
#include "PropAction.h"
#if defined(STM32F4xx) || defined(STM32F7xx)
#include "Stm32Millis.h"
#endif
PropAction::PropAction()
{
_active = true;
-6
View File
@@ -10,12 +10,6 @@
#ifndef PROPACTION_H
#define PROPACTION_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
class PropAction {
public:
+1 -7
View File
@@ -9,12 +9,6 @@
#ifndef PROPDATA_H
#define PROPDATA_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include <inttypes.h>
#include <WString.h>
@@ -59,7 +53,7 @@ class PropDataInteger : public PropData
class PropDataLogical : public PropData
{
public:
PropDataLogical(const char *, const char *trueval = NULL, const char *falseval = NULL, bool initial = false);
PropDataLogical(const char *, const char *trueval = 0, const char *falseval = 0, bool initial = false);
String fetch();
String fetchChange();
void setValue(const bool);
+16
View File
@@ -0,0 +1,16 @@
/*
Name: Stm32Millis.cpp
Author: Faure Systems <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Faure Systems <dev at faure dot systems>
Implement millis() missing in STM32duino.
*/
#if defined(STM32F4xx) || defined(STM32F7xx)
#include "Stm32Millis.h"
unsigned long Stm32MillisClass::milliseconds = 0;
Stm32MillisClass Stm32Millis;
#endif // STM32F4xx|STM32F7xx
+48
View File
@@ -0,0 +1,48 @@
/*
Name: Stm32Millis.h
Author: Faure Systems <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Faure Systems <dev at faure dot systems>
Implement millis() missing in STM32duino.
https://github.com/stm32duino/wiki/wiki/HardwareTimer-library
*/
#ifndef STM32MILLIS_H
#define STM32MILLIS_H
#if defined(STM32F4xx) || defined(STM32F7xx)
#include <Arduino.h>
class Stm32MillisClass {
public:
HardwareTimer *_timer;
static unsigned long milliseconds;
static void update(void) {
++Stm32MillisClass::milliseconds;
}
void begin() {
#if defined(TIM1)
TIM_TypeDef *Instance = TIM1;
#else
TIM_TypeDef *Instance = TIM2;
#endif
// Instantiate HardwareTimer object. Thanks to 'new' instanciation, HardwareTimer is not destructed when setup() function is finished.
_timer = new HardwareTimer(Instance);
_timer->setOverflow(1000, MICROSEC_FORMAT);
_timer->attachInterrupt(update);
_timer->resume();
}
};
extern Stm32MillisClass Stm32Millis;
#endif // STM32F4xx|STM32F7xx
#endif
+21
View File
@@ -0,0 +1,21 @@
/*
Name: Stm32Nucleo144Prop.cpp
Author: Faure Systems <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Faure Systems <dev at faure dot systems>
Prop for Arduino with Ethernet shield.
*/
#include "Stm32Nucleo144Prop.h"
Stm32Nucleo144Prop::Stm32Nucleo144Prop(const char* client_id, const char* in_box, const char* out_box, const char* broker, const int port)
: Prop(client_id, in_box, out_box, broker, port)
{
_client.setClient(_ethernetClient);
}
void Stm32Nucleo144Prop::begin(void(*on_message)(String))
{
if (on_message) onInboxMessageReceived = on_message;
}
+27
View File
@@ -0,0 +1,27 @@
/*
Name: Stm32Nucleo144Prop.h
Author: Faure Systems <dev at faure dot systems>
Editor: https://github.com/fauresystems
License: MIT License (c) Faure Systems <dev at faure dot systems>
Prop for Arduino with Ethernet shield.
*/
#ifndef STM32NUCLEO144PROP_H
#define STM32NUCLEO144PROP_H
#include <LwIP.h>
#include <STM32Ethernet.h>
#include "Prop.h"
class Stm32Nucleo144Prop : public Prop
{
public:
Stm32Nucleo144Prop(const char*, const char*, const char*, const char*, const int);
void begin(void(*)(String) = NULL);
private:
EthernetClient _ethernetClient;
};
#endif