Skip to content

Commit 4f7a96b

Browse files
committed
add support of stm32duino/Arduino_Core_STM32
1 parent d51de8f commit 4f7a96b

File tree

14 files changed

+552
-2
lines changed

14 files changed

+552
-2
lines changed
Loading

MySensors.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
#elif defined(ARDUINO_ARCH_STM32F1)
7171
#include "hal/architecture/STM32F1/MyHwSTM32F1.cpp"
7272
#include "hal/crypto/generic/MyCryptoGeneric.cpp"
73+
#elif defined(ARDUINO_ARCH_STM32)
74+
#include "hal/architecture/STM32/MyHwSTM32.cpp"
75+
#include "hal/crypto/generic/MyCryptoGeneric.cpp"
7376
#elif defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_NRF52)
7477
#include "hal/architecture/NRF5/MyHwNRF5.cpp"
7578
#include "hal/crypto/generic/MyCryptoGeneric.cpp"
@@ -321,7 +324,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
321324
#define MY_RAM_ROUTING_TABLE_ENABLED
322325
#elif defined(MY_RAM_ROUTING_TABLE_FEATURE) && defined(MY_REPEATER_FEATURE)
323326
// activate feature based on architecture
324-
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_STM32F1) || defined(TEENSYDUINO) || defined(__linux__)
327+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_NRF5) || defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32) || defined(TEENSYDUINO) || defined(__linux__)
325328
#define MY_RAM_ROUTING_TABLE_ENABLED
326329
#elif defined(ARDUINO_ARCH_AVR)
327330
#if defined(__avr_atmega1280__) || defined(__avr_atmega1284__) || defined(__avr_atmega2560__)
@@ -446,6 +449,8 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
446449
#include "hal/architecture/Linux/MyMainLinuxGeneric.cpp"
447450
#elif defined(ARDUINO_ARCH_STM32F1)
448451
#include "hal/architecture/STM32F1/MyMainSTM32F1.cpp"
452+
#elif defined(ARDUINO_ARCH_STM32)
453+
#include "hal/architecture/STM32/MyMainSTM32.cpp"
449454
#elif defined(__arm__) && defined(TEENSYDUINO)
450455
#include "hal/architecture/Teensy3/MyMainTeensy3.cpp"
451456
#endif

README.stm32duino.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# MySensors Library readme for [stm32duino](https://github.com/stm32duino/Arduino_Core_STM32)
2+
3+
## Why start this since there is STM32 support of [rogerclarkmelbourne/Arduino_STM32](https://github.com/rogerclarkmelbourne/Arduino_STM32)
4+
- It lacks low power support, which is important for battery powered nodes.
5+
- Rich features of STM32 are limited, such as STM32 has more interrupt than AVR.
6+
7+
## Task status
8+
- [x] STM32F1 basic support
9+
- [ ] Low Power support
10+
- [ ] Extra Interrupt support
11+
12+
## Development Memo
13+
Tested on:
14+
- Hardware: STM32F103C8T6 Bluepill 128KB
15+
- configuration
16+
17+
<img src="./Documentation/img/configuration-stm32duino-stm32f1c8t6.png" alt="configuration of stm32f1c8t6 bluepill" width="500"/>
18+
19+
- STM32 Cores by STMicroelectronics Version 1.9.0
20+
21+
# Thanks
22+
- [#Arduino_Core_STM32](https://github.com/stm32duino/Arduino_Core_STM32) for the rich support of STM32 series.
23+
- [Arduino_STM32](https://github.com/rogerclarkmelbourne/Arduino_STM32) for the first STM32 support on STM32.
24+
- [NodeManager](https://github.com/mysensors/NodeManager) for the fast development on mysensors gateways/nodes.
25+
- [MySensors](https://github.com/mysensors/MySensors) for building the base.

core/MyCapabilities.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@
166166
#elif defined(ARDUINO_ARCH_AVR)
167167
#define MY_CAP_ARCH "A"
168168
#elif defined(ARDUINO_ARCH_STM32F1)
169-
#define MY_CAP_ARCH "M"
169+
#define MY_CAP_ARCH "F"
170+
#elif defined(ARDUINO_ARCH_STM32)
171+
#define MY_CAP_ARCH "f"
170172
#elif defined(__arm__) && defined(TEENSYDUINO)
171173
#define MY_CAP_ARCH "T"
172174
#elif defined(__linux__)

examples/SecurityPersonalizer/SecurityPersonalizer.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,8 @@ static void probe_and_print_peripherals(void)
13491349
Serial.print(F("| SAMD | DETECTED | N/A | "));
13501350
#elif defined(ARDUINO_ARCH_STM32F1)
13511351
Serial.print(F("| STM32F1 | DETECTED | N/A | "));
1352+
#elif defined(ARDUINO_ARCH_STM32)
1353+
Serial.print(F("| STM32 | DETECTED | N/A | "));
13521354
#elif defined(__linux__)
13531355
Serial.print(F("| Linux | DETECTED | N/A | "));
13541356
#else

hal/architecture/STM32/MyHwSTM32.cpp

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* The MySensors Arduino library handles the wireless radio link and protocol
3+
* between your home built sensors/actuators and HA controller of choice.
4+
* The sensors forms a self healing radio network with optional repeaters. Each
5+
* repeater and gateway builds a routing tables in EEPROM which keeps track of
6+
* the network topology allowing messages to be routed to nodes.
7+
*
8+
* Created by Henrik Ekblad <[email protected]>
9+
* Copyright (C) 2013-2019 Sensnology AB
10+
* Full contributor list:
11+
* https://github.com/mysensors/MySensors/graphs/contributors
12+
*
13+
* Documentation: http://www.mysensors.org
14+
* Support Forum: http://forum.mysensors.org
15+
*
16+
* This program is free software; you can redistribute it and/or
17+
* modify it under the terms of the GNU General Public License
18+
* version 2 as published by the Free Software Foundation.
19+
*/
20+
21+
#include "MyHwSTM32.h"
22+
#include "drivers/hal_conf_custom.h"
23+
#include "drivers/stm32_ADC_internal_channels.h"
24+
25+
/*
26+
* Pinout STM32F103C8 dev board:
27+
* http://wiki.stm32duino.com/images/a/ae/Bluepillpinout.gif
28+
*
29+
* Wiring RFM69 radio / SPI1
30+
* --------------------------------------------------
31+
* CLK PA5
32+
* MISO PA6
33+
* MOSI PA7
34+
* CSN PA4
35+
* CE NA
36+
* IRQ PA3 (default)
37+
*
38+
* Wiring RF24 radio / SPI1
39+
* --------------------------------------------------
40+
* CLK PA5
41+
* MISO PA6
42+
* MOSI PA7
43+
* CSN PA4
44+
* CE PB0 (default)
45+
* IRQ NA
46+
*
47+
*/
48+
bool hwInit(void) {
49+
#if !defined(MY_DISABLED_SERIAL)
50+
MY_SERIALDEVICE.begin(MY_BAUD_RATE);
51+
#if defined(MY_GATEWAY_SERIAL)
52+
while (!MY_SERIALDEVICE) {
53+
}
54+
#endif
55+
#endif
56+
return true;
57+
// return EEPROM.begin();
58+
59+
// if (EEPROM.init() == EEPROM_OK) {
60+
// uint16 cnt;
61+
// EEPROM.count(&cnt);
62+
// if(cnt>=EEPROM.maxcount()) {
63+
// // tmp, WIP: format eeprom if full
64+
// EEPROM.format();
65+
// }
66+
// return true;
67+
// }
68+
// return false;
69+
}
70+
71+
void hwReadConfigBlock(void *buf, void *addr, size_t length) {
72+
uint8_t *dst = static_cast<uint8_t *>(buf);
73+
int pos = reinterpret_cast<int>(addr);
74+
eeprom_buffer_fill();
75+
// return eeprom_buffered_read_byte(pos);
76+
77+
// while (length-- > 0) {
78+
// *dst++ = EEPROM.read(pos++);
79+
// }
80+
while (length-- > 0) {
81+
*dst++ = eeprom_buffered_read_byte(pos++);
82+
}
83+
}
84+
85+
void hwWriteConfigBlock(void *buf, void *addr, size_t length) {
86+
uint8_t *src = static_cast<uint8_t *>(buf);
87+
int pos = reinterpret_cast<int>(addr);
88+
// while (length-- > 0) {
89+
// EEPROM.write(pos++, *src++);
90+
// }
91+
while (length-- > 0) {
92+
// EEPROM.write(pos++, *src++);
93+
eeprom_buffered_write_byte(pos++, *src++);
94+
}
95+
eeprom_buffer_flush();
96+
}
97+
98+
// void hwReadConfigBlock(void *buf, void *addr, size_t length) {
99+
// uint8_t *dst = static_cast<uint8_t *>(buf);
100+
// int pos = reinterpret_cast<int>(addr);
101+
// while (length-- > 0) {
102+
// *dst++ = EEPROM.read(pos++);
103+
// }
104+
// }
105+
106+
// void hwWriteConfigBlock(void *buf, void *addr, size_t length) {
107+
// uint8_t *src = static_cast<uint8_t *>(buf);
108+
// int pos = reinterpret_cast<int>(addr);
109+
// while (length-- > 0) {
110+
// EEPROM.write(pos++, *src++);
111+
// }
112+
// }
113+
114+
// uint8_t hwReadConfig(const int addr) {
115+
// uint8_t value;
116+
// hwReadConfigBlock(&value, reinterpret_cast<void *>(addr), 1);
117+
// return value;
118+
// }
119+
120+
// void hwWriteConfig(const int addr, uint8_t value) {
121+
// hwWriteConfigBlock(&value, reinterpret_cast<void *>(addr), 1);
122+
// }
123+
124+
int8_t hwSleep(uint32_t ms) {
125+
// TODO: Not supported!
126+
(void)ms;
127+
return MY_SLEEP_NOT_POSSIBLE;
128+
}
129+
130+
int8_t hwSleep(const uint8_t interrupt, const uint8_t mode, uint32_t ms) {
131+
// TODO: Not supported!
132+
(void)interrupt;
133+
(void)mode;
134+
(void)ms;
135+
return MY_SLEEP_NOT_POSSIBLE;
136+
}
137+
138+
int8_t hwSleep(const uint8_t interrupt1, const uint8_t mode1,
139+
const uint8_t interrupt2, const uint8_t mode2, uint32_t ms) {
140+
// TODO: Not supported!
141+
(void)interrupt1;
142+
(void)mode1;
143+
(void)interrupt2;
144+
(void)mode2;
145+
(void)ms;
146+
return MY_SLEEP_NOT_POSSIBLE;
147+
}
148+
149+
void hwRandomNumberInit(void) {
150+
// use internal temperature sensor as noise source
151+
uint32_t seed = 0;
152+
uint16_t currentValue = 0;
153+
uint16_t newValue = 0;
154+
155+
for (uint8_t i = 0; i < 32; i++) {
156+
const uint32_t timeout = hwMillis() + 20;
157+
while (timeout >= hwMillis()) {
158+
newValue = analogRead(ATEMP);
159+
if (newValue != currentValue) {
160+
currentValue = newValue;
161+
break;
162+
}
163+
}
164+
seed ^= ((newValue + hwMillis()) & 7) << i;
165+
}
166+
randomSeed(seed);
167+
}
168+
169+
bool hwUniqueID(unique_id_t *uniqueID) {
170+
(void)memcpy((uint8_t *)uniqueID, (uint32_t *)0x1FFFF7E0,
171+
16); // FlashID + ChipID
172+
return true;
173+
}
174+
175+
uint16_t hwCPUVoltage(void) { return (uint16_t)readVref(); }
176+
177+
uint16_t hwCPUFrequency(void) { return F_CPU / 100000UL; }
178+
179+
int8_t hwCPUTemperature(void) { return (int8_t)readTempSensor(readVref()); }
180+
181+
uint16_t hwFreeMem(void) {
182+
// Not yet implemented
183+
return FUNCTION_NOT_SUPPORTED;
184+
}

hal/architecture/STM32/MyHwSTM32.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* The MySensors Arduino library handles the wireless radio link and protocol
3+
* between your home built sensors/actuators and HA controller of choice.
4+
* The sensors forms a self healing radio network with optional repeaters. Each
5+
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
6+
* network topology allowing messages to be routed to nodes.
7+
*
8+
* Created by Henrik Ekblad <[email protected]>
9+
* Copyright (C) 2013-2019 Sensnology AB
10+
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11+
*
12+
* Documentation: http://www.mysensors.org
13+
* Support Forum: http://forum.mysensors.org
14+
*
15+
* This program is free software; you can redistribute it and/or
16+
* modify it under the terms of the GNU General Public License
17+
* version 2 as published by the Free Software Foundation.
18+
*/
19+
20+
#ifndef MyHwSTM32_h
21+
#define MyHwSTM32_h
22+
23+
// #include <libmaple/iwdg.h>
24+
#include <IWatchdog.h>
25+
// #include <stm32yyxx_ll_iwdg.h>
26+
#include <itoa.h>
27+
#include <EEPROM.h>
28+
#include <SPI.h>
29+
30+
#ifdef __cplusplus
31+
#include <Arduino.h>
32+
#endif
33+
34+
#define CRYPTO_LITTLE_ENDIAN
35+
36+
#ifndef MY_SERIALDEVICE
37+
#define MY_SERIALDEVICE Serial
38+
#endif
39+
40+
#ifndef MY_DEBUGDEVICE
41+
#define MY_DEBUGDEVICE MY_SERIALDEVICE
42+
#endif
43+
44+
#ifndef MY_STM32F1_TEMPERATURE_OFFSET
45+
#define MY_STM32F1_TEMPERATURE_OFFSET (0.0f)
46+
#endif
47+
48+
#ifndef MY_STM32F1_TEMPERATURE_GAIN
49+
#define MY_STM32F1_TEMPERATURE_GAIN (1.0f)
50+
#endif
51+
52+
// SS default
53+
#ifndef SS
54+
#define SS PA4
55+
#endif
56+
57+
// mapping
58+
#define snprintf_P snprintf
59+
#define vsnprintf_P vsnprintf
60+
#define strncpy_P strncpy
61+
#define printf_P printf
62+
#define yield() // not defined
63+
64+
#ifndef digitalPinToInterrupt
65+
#define digitalPinToInterrupt(__pin) (__pin)
66+
#endif
67+
68+
#define hwDigitalWrite(__pin, __value) digitalWrite(__pin, __value)
69+
#define hwDigitalRead(__pin) digitalRead(__pin)
70+
#define hwPinMode(__pin, __value) pinMode(__pin, __value)
71+
#define hwWatchdogReset() IWatchdog.reload() // iwdg_feed()
72+
// #define hwReboot() nvic_sys_reset()
73+
#define hwReboot() HAL_NVIC_SystemReset()
74+
#define hwMillis() millis()
75+
#define hwGetSleepRemaining() (0ul)
76+
77+
extern void serialEventRun(void) __attribute__((weak));
78+
bool hwInit(void);
79+
void hwRandomNumberInit(void);
80+
void hwReadConfigBlock(void *buf, void *addr, size_t length);
81+
void hwWriteConfigBlock(void *buf, void *addr, size_t length);
82+
// void hwWriteConfig(const int addr, uint8_t value);
83+
// uint8_t hwReadConfig(const int addr);
84+
#define hwReadConfig(__pos) eeprom_read_byte((const uint32_t)__pos)
85+
#define hwWriteConfig(__pos, __val) eeprom_write_byte((const uint32_t)__pos, (uint8_t)__val)
86+
87+
// SOFTSPI
88+
#ifdef MY_SOFTSPI
89+
#error Soft SPI is not available on this architecture!
90+
#endif
91+
#define hwSPI SPI //!< hwSPI
92+
93+
94+
#ifndef DOXYGEN
95+
#define MY_CRITICAL_SECTION
96+
#endif /* DOXYGEN */
97+
98+
#endif

0 commit comments

Comments
 (0)