Skip to content

Commit

Permalink
Wio-e5 wip (#2265)
Browse files Browse the repository at this point in the history
* Wio-e5 / STM32WL wip

* Stubbing some FS stuff out

* Wio-e5 / STM32WL wip

* Stubbing some FS stuff out

* Wio-e5 / STM32WL wip

* Stubbing some FS stuff out

* Wio-e5 / STM32WL wip

* Stubbing some FS stuff out

* LittleFS compiles. Can't check with actual device.

* make cppcheck happy again

* Guard against accelerometer thread

* Missed a spot

* Upload via ST-LINK

* Derive MAC address from UID

* upload port

* Trunk it

* Guard it

* Maybe fix the cache error on startup.

* Latest RadioLib ref to fix SubGHZ

* revert nasty Sub-GHz Hack

* Boots and radio inits with RadioLib 6.0, LittleFS doesn't seem to work

---------

Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com>
Co-authored-by: GUVWAF <thijs@havinga.eu>
  • Loading branch information
3 people committed Jun 1, 2023
1 parent 1524c23 commit a491cee
Show file tree
Hide file tree
Showing 25 changed files with 1,153 additions and 108 deletions.
17 changes: 13 additions & 4 deletions arch/stm32/stm32wl5e.ini
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
[stm32wl5e_base]
platform = platformio/ststm32@^15.4.1
platform_packages = platformio/framework-arduinoststm32 @ https://github.com/stm32duino/Arduino_Core_STM32.git#6e3f9910d0122e82a6c3438507dfac3d2fd80a39
platform = ststm32
board = generic_wl5e
framework = arduino

build_type = debug
build_flags =

build_flags =
${arduino_base.build_flags}
-Isrc/platform/stm32wl -g
-DconfigUSE_CMSIS_RTOS_V2=1
-DVECT_TAB_OFFSET=0x08000000

build_src_filter =
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<mesh/api/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<mqtt/> -<input> -<buzz> -<modules/Telemetry> -<platform/nrf52> -<platform/portduino> -<platform/rp2040>

build_src_filter =
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<mesh/api/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<mqtt/> -<graphics> -<input> -<buzz> -<modules/Telemetry> -<platform/nrf52> -<platform/portduino> -<platform/rp2040>
board_upload.offset_address = 0x08000000
upload_protocol = stlink

lib_deps =
${env.lib_deps}
jgromes/RadioLib@^6.0.0
https://github.com/kokke/tiny-AES-c.git#f06ac37fc31dfdaca2e0d9bec83f90d5663c319b
https://github.com/littlefs-project/littlefs.git#v2.5.1
https://github.com/stm32duino/STM32FreeRTOS.git#10.3.1

lib_ignore =
https://github.com/mathertel/OneButton#2.1.0
2 changes: 1 addition & 1 deletion boards/generic_wl5e.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"maximum_ram_size": 65536,
"maximum_size": 262144,
"protocol": "cmsis-dap",
"protocols": ["cmsis-dap"]
"protocols": ["cmsis-dap", "stlink"]
},
"url": "https://www.st.com/en/microcontrollers-microprocessors/stm32wl-series.html",
"vendor": "ST"
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = tbeam
;default_envs = tbeam
;default_envs = pico
;default_envs = tbeam-s3-core
;default_envs = tbeam0.7
Expand All @@ -25,6 +25,7 @@ default_envs = tbeam
;default_envs = meshtastic-dr-dev
;default_envs = m5stack-coreink
;default_envs = rak4631
default_envs = wio-e5

extra_configs =
arch/*/*.ini
Expand Down
2 changes: 1 addition & 1 deletion src/FSCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bool renameFile(const char *pathFrom, const char *pathTo)
#endif
}

void listDir(const char *dirname, uint8_t levels, boolean del = false)
void listDir(const char *dirname, uint8_t levels, bool del = false)
{
#ifdef FSCom
#if (defined(ARCH_ESP32) || defined(ARCH_RP2040) || defined(ARCH_PORTDUINO))
Expand Down
9 changes: 8 additions & 1 deletion src/FSCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
#define FILE_O_READ "r"
#endif

#if defined(ARCH_STM32WL)
#include "platform/stm32wl/InternalFileSystem.h" // STM32WL version
#define FSCom InternalFS
#define FSBegin() FSCom.begin()
using namespace LittleFS_Namespace;
#endif

#if defined(ARCH_RP2040)
// RP2040
#include "LittleFS.h"
Expand Down Expand Up @@ -42,6 +49,6 @@ using namespace Adafruit_LittleFS_Namespace;
void fsInit();
bool copyFile(const char *from, const char *to);
bool renameFile(const char *pathFrom, const char *pathTo);
void listDir(const char *dirname, uint8_t levels, boolean del);
void listDir(const char *dirname, uint8_t levels, bool del);
void rmDir(const char *dirname);
void setupSDCard();
2 changes: 1 addition & 1 deletion src/freertosinc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <freertos/task.h>
#endif

#if defined(ARDUINO_NRF52_ADAFRUIT)
#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_STM32)
#define HAS_FREE_RTOS

#include <FreeRTOS.h>
Expand Down
22 changes: 19 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ NRF52Bluetooth *nrf52Bluetooth;
#include "SX1262Interface.h"
#include "SX1268Interface.h"
#include "SX1280Interface.h"
#ifdef ARCH_STM32WL
#include "STM32WLE5JCInterface.h"
#endif
#if !HAS_RADIO && defined(ARCH_PORTDUINO)
#include "platform/portduino/SimRadio.h"
#endif
Expand All @@ -68,7 +71,7 @@ NRF52Bluetooth *nrf52Bluetooth;
#endif
#include "PowerFSMThread.h"

#if !defined(ARCH_PORTDUINO)
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
#include "AccelerometerThread.h"
#endif

Expand Down Expand Up @@ -347,10 +350,11 @@ void setup()
* nodeTelemetrySensorsMap singleton. This wraps that logic in a temporary scope to declare the temporary field
* "found".
*/

// Only one supported RGB LED currently
rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623);

#if !defined(ARCH_PORTDUINO)
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
auto acc_info = i2cScanner->firstAccelerometer();
accelerometer_found = acc_info.type != ScanI2C::DeviceType::NONE ? acc_info.address : accelerometer_found;
LOG_DEBUG("acc_info = %i\n", acc_info.type);
Expand Down Expand Up @@ -439,7 +443,7 @@ void setup()
screen_model = meshtastic_Config_DisplayConfig_OledType_OLED_SH1107; // keep dimension of 128x64
#endif

#if !defined(ARCH_PORTDUINO)
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
if (acc_info.type != ScanI2C::DeviceType::NONE) {
accelerometerThread = new AccelerometerThread(acc_info.type);
}
Expand Down Expand Up @@ -530,6 +534,18 @@ void setup()
#endif

// radio init MUST BE AFTER service.init, so we have our radio config settings (from nodedb init)
#if defined(USE_STM32WLx)
if (!rIf) {
rIf = new STM32WLE5JCInterface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY);
if (!rIf->init()) {
LOG_WARN("Failed to find STM32WL radio\n");
delete rIf;
rIf = NULL;
} else {
LOG_INFO("STM32WL Radio init succeeded, using STM32WL radio\n");
}
}
#endif

#if !HAS_RADIO && defined(ARCH_PORTDUINO)
if (!rIf) {
Expand Down
3 changes: 3 additions & 0 deletions src/mesh/InterfacesTemplates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ template class SX126xInterface<SX1262>;
template class SX126xInterface<SX1268>;
template class SX126xInterface<LLCC68>;
template class SX128xInterface<SX1280>;
#ifdef ARCH_STM32WL
template class SX126xInterface<STM32WLx>;
#endif

#if HAS_ETHERNET
#include "api/ethServerAPI.h"
Expand Down
17 changes: 17 additions & 0 deletions src/mesh/RadioLibInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ class LockingArduinoHal : public ArduinoHal
void spiEndTransaction() override;
};

#if defined(USE_STM32WLx)
/**
* A wrapper for the RadioLib STM32WLx_Module class, that doesn't connect any pins as they are virtual
*/
class STM32WLx_ModuleWrapper : public STM32WLx_Module
{
public:
STM32WLx_ModuleWrapper(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst,
RADIOLIB_PIN_TYPE busy)
: STM32WLx_Module(){};
};
#endif

class RadioLibInterface : public RadioInterface, protected concurrency::NotifiedWorkerThread
{
/// Used as our notification from the ISR
Expand Down Expand Up @@ -56,7 +69,11 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified

float currentLimit = 100; // 100mA OCP - Should be acceptable for RFM95/SX127x chipset.

#if !defined(USE_STM32WLx)
Module module; // The HW interface to the radio
#else
STM32WLx_ModuleWrapper module;
#endif

/**
* provides lowest common denominator RadioLib API
Expand Down
45 changes: 45 additions & 0 deletions src/mesh/STM32WLE5JCInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "STM32WLE5JCInterface.h"
#include "configuration.h"
#include "error.h"

#ifndef STM32WLx_MAX_POWER
#define STM32WLx_MAX_POWER 22
#endif

#ifdef ARCH_STM32WL

STM32WLE5JCInterface::STM32WLE5JCInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq,
RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy)
: SX126xInterface(hal, cs, irq, rst, busy)
{
}

bool STM32WLE5JCInterface::init()
{
RadioLibInterface::init();

lora.setRfSwitchTable(rfswitch_pins, rfswitch_table);

if (power == 0)
power = STM32WLx_MAX_POWER;

if (power > STM32WLx_MAX_POWER) // This chip has lower power limits than some
power = STM32WLx_MAX_POWER;

limitPower();

int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage);

LOG_INFO("STM32WLx init result %d\n", res);

LOG_INFO("Frequency set to %f\n", getFreq());
LOG_INFO("Bandwidth set to %f\n", bw);
LOG_INFO("Power output set to %d\n", power);

if (res == RADIOLIB_ERR_NONE)
startReceive(); // start receiving

return res == RADIOLIB_ERR_NONE;
}

#endif // ARCH_STM32WL
31 changes: 31 additions & 0 deletions src/mesh/STM32WLE5JCInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "SX126xInterface.h"

#ifdef ARCH_STM32WL

/**
* Our adapter for STM32WLE5JC radios
*/
class STM32WLE5JCInterface : public SX126xInterface<STM32WLx>
{
public:
STM32WLE5JCInterface(LockingArduinoHal *hal, RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst,
RADIOLIB_PIN_TYPE busy);

virtual bool init() override;
};

// https://github.com/Seeed-Studio/LoRaWan-E5-Node/blob/main/Middlewares/Third_Party/SubGHz_Phy/stm32_radio_driver/radio_driver.c
static const float tcxoVoltage = 1.7;

/* https://wiki.seeedstudio.com/LoRa-E5_STM32WLE5JC_Module/
* Wio-E5 module ONLY transmits through RFO_HP
* Receive: PA4=1, PA5=0
* Transmit(high output power, SMPS mode): PA4=0, PA5=1 */
static const RADIOLIB_PIN_TYPE rfswitch_pins[3] = {PA4, PA5, RADIOLIB_NC};

static const Module::RfSwitchMode_t rfswitch_table[4] = {
{STM32WLx::MODE_IDLE, {LOW, LOW}}, {STM32WLx::MODE_RX, {HIGH, LOW}}, {STM32WLx::MODE_TX_HP, {LOW, HIGH}}, END_OF_MODE_TABLE};

#endif // ARCH_STM32WL
2 changes: 1 addition & 1 deletion src/modules/ExternalNotificationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "SinglePortModule.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
#ifndef ARCH_PORTDUINO
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
#include <NonBlockingRtttl.h>
#else
// Noop class for portduino.
Expand Down
Loading

0 comments on commit a491cee

Please sign in to comment.