mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-05 17:40:51 +00:00
add stm32wl5e platform and wio-e5 variant (#1631)
Co-authored-by: Peter Lawrence <12226419+majbthrd@users.noreply.github.com> Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
@@ -43,6 +43,10 @@ RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq
|
||||
: NotifiedWorkerThread("RadioIf"), module(cs, irq, rst, busy, spi, spiSettings), iface(_iface)
|
||||
{
|
||||
instance = this;
|
||||
#if defined(ARCH_STM32WL) && defined(USE_SX1262)
|
||||
module.setCb_digitalWrite(stm32wl_emulate_digitalWrite);
|
||||
module.setCb_digitalRead(stm32wl_emulate_digitalRead);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ARCH_ESP32
|
||||
|
||||
36
src/platform/stm32wl/STM32WLCryptoEngine.cpp
Normal file
36
src/platform/stm32wl/STM32WLCryptoEngine.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "configuration.h"
|
||||
#include "CryptoEngine.h"
|
||||
#include "aes.hpp"
|
||||
|
||||
class STM32WLCryptoEngine : public CryptoEngine
|
||||
{
|
||||
public:
|
||||
STM32WLCryptoEngine() {}
|
||||
|
||||
~STM32WLCryptoEngine() {}
|
||||
|
||||
/**
|
||||
* Encrypt a packet
|
||||
*
|
||||
* @param bytes is updated in place
|
||||
*/
|
||||
virtual void encrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override
|
||||
{
|
||||
if (key.length > 0) {
|
||||
AES_ctx ctx;
|
||||
initNonce(fromNode, packetNum);
|
||||
AES_init_ctx_iv(&ctx, key.bytes, nonce);
|
||||
AES_CTR_xcrypt_buffer(&ctx, bytes, numBytes);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void decrypt(uint32_t fromNode, uint64_t packetNum, size_t numBytes, uint8_t *bytes) override
|
||||
{
|
||||
// For CTR, the implementation is the same
|
||||
encrypt(fromNode, packetNum, numBytes, bytes);
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
CryptoEngine *crypto = new STM32WLCryptoEngine();
|
||||
31
src/platform/stm32wl/architecture.h
Normal file
31
src/platform/stm32wl/architecture.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#define ARCH_STM32WL
|
||||
|
||||
//
|
||||
// defaults for STM32WL architecture
|
||||
//
|
||||
|
||||
//
|
||||
// set HW_VENDOR
|
||||
//
|
||||
|
||||
#ifndef HW_VENDOR
|
||||
#define HW_VENDOR HardwareModel_PRIVATE_HW
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
void stm32wl_emulate_digitalWrite(long unsigned int pin, long unsigned int value);
|
||||
int stm32wl_emulate_digitalRead(long unsigned int pin);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* virtual pins for stm32wl_emulate_digitalWrite() / stm32wl_emulate_digitalRead() to recognize */
|
||||
#define SX126X_CS 1000
|
||||
#define SX126X_DIO1 1001
|
||||
#define SX126X_RESET 1003
|
||||
#define SX126X_BUSY 1004
|
||||
|
||||
67
src/platform/stm32wl/layer.c
Normal file
67
src/platform/stm32wl/layer.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <stdbool.h>
|
||||
#include "architecture.h"
|
||||
#include "stm32wlxx.h"
|
||||
#include "stm32wlxx_hal.h"
|
||||
|
||||
void HardFault_Handler(void)
|
||||
{
|
||||
asm("bkpt");
|
||||
}
|
||||
|
||||
void stm32wl_emulate_digitalWrite(long unsigned int pin, long unsigned int value)
|
||||
{
|
||||
switch (pin)
|
||||
{
|
||||
case SX126X_CS: /* active low */
|
||||
if (value)
|
||||
LL_PWR_UnselectSUBGHZSPI_NSS();
|
||||
else
|
||||
LL_PWR_SelectSUBGHZSPI_NSS();
|
||||
break;
|
||||
case SX126X_RESET: /* active low */
|
||||
if (value)
|
||||
LL_RCC_RF_DisableReset();
|
||||
else
|
||||
{
|
||||
LL_RCC_RF_EnableReset();
|
||||
LL_RCC_HSE_EnableTcxo();
|
||||
LL_RCC_HSE_Enable();
|
||||
while (!LL_RCC_HSE_IsReady());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
asm("bkpt");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static bool irq_happened;
|
||||
|
||||
void SUBGHZ_Radio_IRQHandler(void)
|
||||
{
|
||||
NVIC_DisableIRQ(SUBGHZ_Radio_IRQn);
|
||||
irq_happened = true;
|
||||
}
|
||||
|
||||
int stm32wl_emulate_digitalRead(long unsigned int pin)
|
||||
{
|
||||
int outcome = 0;
|
||||
|
||||
switch (pin)
|
||||
{
|
||||
case SX126X_BUSY:
|
||||
// return ((LL_PWR_IsActiveFlag_RFBUSYMS() & LL_PWR_IsActiveFlag_RFBUSYS()) == 1UL);
|
||||
outcome = LL_PWR_IsActiveFlag_RFBUSYS();
|
||||
break;
|
||||
case SX126X_DIO1:
|
||||
default:
|
||||
NVIC_ClearPendingIRQ(SUBGHZ_Radio_IRQn);
|
||||
irq_happened = false;
|
||||
NVIC_EnableIRQ(SUBGHZ_Radio_IRQn);
|
||||
for (int i = 0; i < 64; i++) asm("nop");
|
||||
outcome = irq_happened;
|
||||
break;
|
||||
}
|
||||
return outcome;
|
||||
}
|
||||
|
||||
27
src/platform/stm32wl/main-stm32wl.cpp
Normal file
27
src/platform/stm32wl/main-stm32wl.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stm32wle5xx.h>
|
||||
#include <stm32wlxx_hal.h>
|
||||
#include "configuration.h"
|
||||
#include "RTC.h"
|
||||
|
||||
void setBluetoothEnable(bool on) {}
|
||||
|
||||
void playStartMelody() {}
|
||||
|
||||
void updateBatteryLevel(uint8_t level) {}
|
||||
|
||||
void getMacAddr(uint8_t *dmac)
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
dmac[i] = i;
|
||||
}
|
||||
|
||||
void cpuDeepSleep(uint64_t msecToWake) {}
|
||||
|
||||
/* pacify libc_nano */
|
||||
extern "C" {
|
||||
int _gettimeofday( struct timeval *tv, void *tzvp )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user