Skip to content

Commit 695473f

Browse files
authored
Merge pull request #805 from csrutil/tiny-relay-variant
Tiny relay variant
2 parents 4daad75 + a1622ba commit 695473f

File tree

5 files changed

+223
-0
lines changed

5 files changed

+223
-0
lines changed

boards/tiny_relay.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"variant_h": "variant_RAK3172_MODULE.h"
5+
},
6+
"core": "stm32",
7+
"cpu": "cortex-m4",
8+
"extra_flags": "-DSTM32WL -DSTM32WLxx -DSTM32WLE5xx",
9+
"framework_extra_flags": {
10+
"arduino": "-DUSE_CM4_STARTUP_FILE -DARDUINO_RAK3172_MODULE"
11+
},
12+
"f_cpu": "48000000L",
13+
"mcu": "stm32wle5ccu",
14+
"product_line": "STM32WLE5xx",
15+
"variant": "STM32WLxx/WL54CCU_WL55CCU_WLE4C(8-B-C)U_WLE5C(8-B-C)U"
16+
},
17+
"debug": {
18+
"default_tools": ["stlink"],
19+
"jlink_device": "STM32WLE5CC",
20+
"openocd_target": "stm32wlx",
21+
"svd_path": "STM32WLE5_CM4.svd"
22+
},
23+
"frameworks": ["arduino"],
24+
"name": "BB-STM32WL",
25+
"upload": {
26+
"maximum_ram_size": 65536,
27+
"maximum_size": 262144,
28+
"protocol": "stlink",
29+
"protocols": ["stlink", "jlink"]
30+
},
31+
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32wle5cc.html",
32+
"vendor": "YAOYAO"
33+
}

variants/tiny_relay/platformio.ini

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[Tiny_Relay]
2+
extends = stm32_base
3+
board = tiny_relay
4+
board_upload.maximum_size = 229376 ; 32kb for FS
5+
build_flags = ${stm32_base.build_flags}
6+
-D RADIO_CLASS=CustomSTM32WLx
7+
-D WRAPPER_CLASS=CustomSTM32WLxWrapper
8+
-D SPI_INTERFACES_COUNT=0
9+
-D RX_BOOSTED_GAIN=true
10+
; -D STM32WL_TCXO_VOLTAGE=1.6 ; defaults to 0 if undef
11+
; -D LORA_TX_POWER=14 ; Defaults to 22 for HP, 14 is for LP version
12+
-D LORA_TX_POWER=22 ; Enable 22dBm transmission
13+
-D MAX_LORA_TX_POWER=22 ; Allow setting up to 22dBm in companion radio
14+
-I variants/tiny_relay
15+
build_src_filter = ${stm32_base.build_src_filter}
16+
+<../variants/tiny_relay>
17+
18+
[env:Tiny_Relay-repeater]
19+
extends = Tiny_Relay
20+
build_flags = ${Tiny_Relay.build_flags}
21+
-D ADVERT_NAME='"tiny_relay Repeater"'
22+
-D ADMIN_PASSWORD='"password"'
23+
build_src_filter = ${Tiny_Relay.build_src_filter}
24+
+<../examples/simple_repeater/main.cpp>
25+
26+
[env:Tiny_Relay-sensor]
27+
extends = Tiny_Relay
28+
build_flags = ${Tiny_Relay.build_flags}
29+
-D ADVERT_NAME='"tiny_relay Sensor"'
30+
-D ADMIN_PASSWORD='"password"'
31+
build_src_filter = ${Tiny_Relay.build_src_filter}
32+
+<../examples/simple_sensor>
33+
34+
[env:Tiny_Relay_companion_radio_usb]
35+
extends = Tiny_Relay
36+
build_flags = ${Tiny_Relay.build_flags}
37+
; -D FORMAT_FS=true
38+
-D MAX_CONTACTS=100
39+
-D MAX_GROUP_CHANNELS=8
40+
-D MAX_LORA_TX_POWER=22
41+
build_src_filter = ${Tiny_Relay.build_src_filter}
42+
+<../examples/companion_radio/*.cpp>
43+
lib_deps = ${Tiny_Relay.lib_deps}
44+
densaugeo/base64 @ ~1.4.0

variants/tiny_relay/target.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "target.h"
2+
#include <Arduino.h>
3+
#include <helpers/ArduinoHelpers.h>
4+
5+
TinyRelayBoard board;
6+
7+
RADIO_CLASS radio = new STM32WLx_Module();
8+
9+
WRAPPER_CLASS radio_driver(radio, board);
10+
11+
static const uint32_t rfswitch_pins[] = {LORAWAN_RFSWITCH_PINS, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC};
12+
static const Module::RfSwitchMode_t rfswitch_table[] = {
13+
{STM32WLx::MODE_IDLE, {LOW, LOW}},
14+
{STM32WLx::MODE_RX, {HIGH, LOW}},
15+
{STM32WLx::MODE_TX_LP, {LOW, HIGH}},
16+
{STM32WLx::MODE_TX_HP, {LOW, HIGH}},
17+
END_OF_MODE_TABLE,
18+
};
19+
20+
VolatileRTCClock rtc_clock;
21+
SensorManager sensors;
22+
23+
#ifndef LORA_CR
24+
#define LORA_CR 5
25+
#endif
26+
27+
#ifndef STM32WL_TCXO_VOLTAGE
28+
// TCXO set to 0 for RAK3172
29+
#define STM32WL_TCXO_VOLTAGE 0
30+
#endif
31+
32+
#ifndef LORA_TX_POWER
33+
#define LORA_TX_POWER 22
34+
#endif
35+
36+
bool radio_init()
37+
{
38+
// rtc_clock.begin(Wire);
39+
40+
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
41+
42+
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16,
43+
STM32WL_TCXO_VOLTAGE, 0);
44+
45+
if (status != RADIOLIB_ERR_NONE) {
46+
Serial.print("ERROR: radio init failed: ");
47+
Serial.println(status);
48+
return false; // fail
49+
}
50+
51+
#ifdef RX_BOOSTED_GAIN
52+
radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
53+
#endif
54+
55+
radio.setCRC(1);
56+
57+
return true; // success
58+
}
59+
60+
uint32_t radio_get_rng_seed()
61+
{
62+
return radio.random(0x7FFFFFFF);
63+
}
64+
65+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr)
66+
{
67+
radio.setFrequency(freq);
68+
radio.setSpreadingFactor(sf);
69+
radio.setBandwidth(bw);
70+
radio.setCodingRate(cr);
71+
}
72+
73+
void radio_set_tx_power(uint8_t dbm)
74+
{
75+
radio.setOutputPower(dbm);
76+
}
77+
78+
mesh::LocalIdentity radio_new_identity()
79+
{
80+
RadioNoiseListener rng(radio);
81+
return mesh::LocalIdentity(&rng); // create new random identity
82+
}

variants/tiny_relay/target.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <RadioLib.h>
5+
#include <helpers/ArduinoHelpers.h>
6+
#include <helpers/SensorManager.h>
7+
#include <helpers/radiolib/CustomSTM32WLxWrapper.h>
8+
#include <helpers/radiolib/RadioLibWrappers.h>
9+
#include <helpers/stm32/STM32Board.h>
10+
11+
#define PIN_VBAT_READ A0
12+
#define ADC_MULTIPLIER (5 * 1.73 * 1000)
13+
14+
class TinyRelayBoard : public STM32Board
15+
{
16+
public:
17+
void begin() override
18+
{
19+
STM32Board::begin();
20+
pinMode(PA0, OUTPUT);
21+
pinMode(PA1, OUTPUT);
22+
}
23+
24+
const char *getManufacturerName() const override { return "Tiny Relay"; }
25+
26+
uint16_t getBattMilliVolts() override
27+
{
28+
analogReadResolution(12);
29+
uint32_t raw = 0;
30+
for (int i = 0; i < 8; i++) {
31+
raw += analogRead(PIN_VBAT_READ);
32+
}
33+
return ((double)raw) * ADC_MULTIPLIER / 8 / 4096;
34+
}
35+
36+
void setGpio(uint32_t values) override
37+
{
38+
// set led values
39+
digitalWrite(PA0, values & 1);
40+
digitalWrite(PA1, (values & 2) >> 1);
41+
}
42+
43+
uint32_t getGpio() override
44+
{
45+
// get led value
46+
return (digitalRead(PA1) << 1) | digitalRead(PA0);
47+
}
48+
};
49+
50+
extern TinyRelayBoard board;
51+
extern WRAPPER_CLASS radio_driver;
52+
extern VolatileRTCClock rtc_clock;
53+
extern SensorManager sensors;
54+
55+
bool radio_init();
56+
uint32_t radio_get_rng_seed();
57+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
58+
void radio_set_tx_power(uint8_t dbm);
59+
mesh::LocalIdentity radio_new_identity();

variants/tiny_relay/variant.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <variant_RAK3172_MODULE.h>
4+
5+
#undef RNG

0 commit comments

Comments
 (0)