init commit
This commit is contained in:
16
SubGHz_Phy/App/app_subghz_phy.c
Normal file
16
SubGHz_Phy/App/app_subghz_phy.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "app_subghz_phy.h"
|
||||
#include "subghz_phy_app.h"
|
||||
#include "sys_app.h"
|
||||
#include "stm32_seq.h"
|
||||
|
||||
void MX_SubGHz_Phy_Init(void)
|
||||
{
|
||||
SystemApp_Init();
|
||||
SubghzApp_Init();
|
||||
}
|
||||
|
||||
void MX_SubGHz_Phy_Process(void)
|
||||
{
|
||||
SubghzApp_Process();
|
||||
UTIL_SEQ_Run(UTIL_SEQ_DEFAULT);
|
||||
}
|
||||
73
SubGHz_Phy/App/app_subghz_phy.h
Normal file
73
SubGHz_Phy/App/app_subghz_phy.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file app_subghz_phy.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header of application of the SubGHz_Phy Middleware
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __APP_SUBGHZ_PHY_H__
|
||||
#define __APP_SUBGHZ_PHY_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported Functions Prototypes ---------------------------------------------*/
|
||||
/**
|
||||
* @brief Init SubGHz Radio Application
|
||||
*/
|
||||
void MX_SubGHz_Phy_Init(void);
|
||||
|
||||
/**
|
||||
* @brief SubGHz Radio Application Process
|
||||
*/
|
||||
void MX_SubGHz_Phy_Process(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__APP_SUBGHZ_PHY_H__*/
|
||||
82
SubGHz_Phy/App/app_version.h
Normal file
82
SubGHz_Phy/App/app_version.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file app_version.h
|
||||
* @author MCD Application Team
|
||||
* @brief Definition the version of the application
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __APP_VERSION_H__
|
||||
#define __APP_VERSION_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define APP_VERSION_MAIN (0x01U) /*!< [31:24] main version */
|
||||
#define APP_VERSION_SUB1 (0x04U) /*!< [23:16] sub1 version */
|
||||
#define APP_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
|
||||
#define APP_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
||||
|
||||
#define APP_VERSION_MAIN_SHIFT 24 /*!< main byte shift */
|
||||
#define APP_VERSION_SUB1_SHIFT 16 /*!< sub1 byte shift */
|
||||
#define APP_VERSION_SUB2_SHIFT 8 /*!< sub2 byte shift */
|
||||
#define APP_VERSION_RC_SHIFT 0 /*!< release candidate byte shift */
|
||||
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Application version
|
||||
*/
|
||||
#define APP_VERSION ((APP_VERSION_MAIN << APP_VERSION_MAIN_SHIFT)\
|
||||
|(APP_VERSION_SUB1 << APP_VERSION_SUB1_SHIFT)\
|
||||
|(APP_VERSION_SUB2 << APP_VERSION_SUB2_SHIFT)\
|
||||
|(APP_VERSION_RC << APP_VERSION_RC_SHIFT))
|
||||
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__APP_VERSION_H__*/
|
||||
901
SubGHz_Phy/App/subghz_phy_app.c
Normal file
901
SubGHz_Phy/App/subghz_phy_app.c
Normal file
@@ -0,0 +1,901 @@
|
||||
#include "platform.h"
|
||||
#include "subghz_phy_app.h"
|
||||
#include "radio.h"
|
||||
#include "usart_if.h"
|
||||
#include "usart.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RX_TIMEOUT_VALUE_MS 0U
|
||||
#define TX_TIMEOUT_VALUE_MS 3000U
|
||||
#define RX_CONTINUOUS_ON 1U
|
||||
#define RADIO_SYNCWORD_LEN 3U
|
||||
#define RADIO_WHITENING_SEED 0x01FFU
|
||||
#define RADIO_CRC_POLY 0x8005U
|
||||
#define RADIO_CRC_SEED 0xFFFFU
|
||||
|
||||
#define UART_DATA_BUFFER_SIZE 220U
|
||||
#define RADIO_MAX_PAYLOAD_SIZE 220U
|
||||
#define TX_QUEUE_DEPTH 4U
|
||||
#define CONFIG_LINE_SIZE 96U
|
||||
#define CONFIG_ESCAPE_GUARD_MS 800U
|
||||
#define DEFAULT_UART_PACKET_TIMEOUT_MS 20U
|
||||
|
||||
typedef enum
|
||||
{
|
||||
APP_MODE_DATA = 0,
|
||||
APP_MODE_CONFIG
|
||||
} AppMode_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t rf_frequency;
|
||||
int8_t tx_power;
|
||||
uint32_t fsk_bitrate;
|
||||
uint32_t fsk_bandwidth;
|
||||
uint32_t fsk_fdev;
|
||||
uint16_t fsk_preamble_len;
|
||||
uint8_t syncword[RADIO_SYNCWORD_LEN];
|
||||
uint16_t uart_packet_timeout_ms;
|
||||
uint32_t uart_baudrate;
|
||||
} BridgeConfig_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t data[RADIO_MAX_PAYLOAD_SIZE];
|
||||
uint8_t len;
|
||||
} TxPacket_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t active;
|
||||
uint8_t count;
|
||||
uint8_t bytes[3];
|
||||
uint32_t start_tick;
|
||||
uint32_t last_tick;
|
||||
} EscapeDetector_t;
|
||||
|
||||
static RadioEvents_t RadioEvents;
|
||||
static BridgeConfig_t g_cfg =
|
||||
{
|
||||
.rf_frequency = RF_FREQUENCY_DEFAULT,
|
||||
.tx_power = TX_OUTPUT_POWER_DEFAULT,
|
||||
.fsk_bitrate = FSK_DATARATE_DEFAULT,
|
||||
.fsk_bandwidth = FSK_BANDWIDTH_DEFAULT,
|
||||
.fsk_fdev = FSK_FDEV_DEFAULT,
|
||||
.fsk_preamble_len = FSK_PREAMBLE_LENGTH_DEFAULT,
|
||||
.syncword = {0xC1, 0x94, 0xC1},
|
||||
.uart_packet_timeout_ms = DEFAULT_UART_PACKET_TIMEOUT_MS,
|
||||
.uart_baudrate = 115200UL,
|
||||
};
|
||||
|
||||
static volatile uint8_t g_radio_tx_done = 0;
|
||||
static volatile uint8_t g_radio_tx_timeout = 0;
|
||||
static volatile uint8_t g_radio_rx_done = 0;
|
||||
static volatile uint8_t g_radio_rx_timeout = 0;
|
||||
static volatile uint8_t g_radio_rx_error = 0;
|
||||
static volatile int16_t g_last_rx_rssi = 0;
|
||||
static volatile int8_t g_last_rx_cfo = 0;
|
||||
|
||||
static volatile uint8_t g_radio_busy = 0;
|
||||
static volatile uint8_t g_radio_needs_rx_restart = 0;
|
||||
|
||||
static uint8_t g_rx_payload[RADIO_MAX_PAYLOAD_SIZE];
|
||||
static uint16_t g_rx_payload_len = 0;
|
||||
|
||||
static TxPacket_t g_tx_queue[TX_QUEUE_DEPTH];
|
||||
static uint8_t g_tx_q_head = 0;
|
||||
static uint8_t g_tx_q_tail = 0;
|
||||
static uint8_t g_tx_q_count = 0;
|
||||
|
||||
static uint8_t g_uart_build_buf[UART_DATA_BUFFER_SIZE];
|
||||
static uint16_t g_uart_build_len = 0;
|
||||
static uint32_t g_uart_last_data_tick = 0;
|
||||
|
||||
static EscapeDetector_t g_escape = {0};
|
||||
static AppMode_t g_mode = APP_MODE_DATA;
|
||||
|
||||
static char g_cfg_line[CONFIG_LINE_SIZE];
|
||||
static uint16_t g_cfg_line_len = 0;
|
||||
|
||||
static uint32_t g_stat_uart_packets_tx = 0;
|
||||
static uint32_t g_stat_uart_bytes_tx = 0;
|
||||
static uint32_t g_stat_radio_packets_rx = 0;
|
||||
static uint32_t g_stat_radio_bytes_rx = 0;
|
||||
static uint32_t g_stat_queue_overflow = 0;
|
||||
|
||||
static void OnTxDone(void);
|
||||
static void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t cfo);
|
||||
static void OnTxTimeout(void);
|
||||
static void OnRxTimeout(void);
|
||||
static void OnRxError(void);
|
||||
|
||||
static void UartRxByteCallback(uint8_t *rxChar, uint16_t size, uint8_t error);
|
||||
static void App_ProcessRadioEvents(void);
|
||||
static void App_ProcessUartPacketizer(void);
|
||||
static void App_ProcessEscape(void);
|
||||
static void App_StartNextTxIfPossible(void);
|
||||
static void App_RadioEnterRx(void);
|
||||
static void App_RadioApplyConfig(void);
|
||||
static void App_RadioConfigureRx(void);
|
||||
static void App_RadioConfigureTx(void);
|
||||
static void App_EnterConfigMode(void);
|
||||
static void App_ExitConfigMode(void);
|
||||
static void App_ResetDataPath(void);
|
||||
static void App_DataModeFeedByte(uint8_t ch, uint32_t now);
|
||||
static void App_DataModeFlushBuilder(void);
|
||||
static uint8_t App_QueuePush(const uint8_t *data, uint16_t len);
|
||||
static void App_QueuePop(void);
|
||||
static void App_ConfigFeedByte(uint8_t ch);
|
||||
static void App_ConfigExecuteLine(char *line);
|
||||
static void App_PrintConfigPrompt(void);
|
||||
static void App_PrintHelp(void);
|
||||
static void App_PrintStatus(void);
|
||||
static void App_Printf(const char *fmt, ...);
|
||||
static void App_Write(const uint8_t *data, uint16_t len);
|
||||
static void App_ReconfigureUart(uint32_t baudrate);
|
||||
static uint8_t App_ParseHexSyncWord(const char *text, uint8_t out[3]);
|
||||
static char *App_SkipSpaces(char *s);
|
||||
|
||||
void SubghzApp_Init(void)
|
||||
{
|
||||
RadioEvents.TxDone = OnTxDone;
|
||||
RadioEvents.RxDone = OnRxDone;
|
||||
RadioEvents.TxTimeout = OnTxTimeout;
|
||||
RadioEvents.RxTimeout = OnRxTimeout;
|
||||
RadioEvents.RxError = OnRxError;
|
||||
|
||||
Radio.Init(&RadioEvents);
|
||||
App_RadioApplyConfig();
|
||||
App_RadioEnterRx();
|
||||
|
||||
g_uart_last_data_tick = HAL_GetTick();
|
||||
(void)vcom_ReceiveInit(UartRxByteCallback);
|
||||
|
||||
App_Printf("\r\nSTM32WL UART<->SUBGHZ bridge started\r\n");
|
||||
App_Printf("DATA mode, escape sequence: silence 800 ms + +++ + silence 800 ms\r\n");
|
||||
}
|
||||
|
||||
void SubghzApp_Process(void)
|
||||
{
|
||||
App_ProcessEscape();
|
||||
App_ProcessUartPacketizer();
|
||||
App_ProcessRadioEvents();
|
||||
App_StartNextTxIfPossible();
|
||||
}
|
||||
|
||||
static void App_ProcessRadioEvents(void)
|
||||
{
|
||||
if (g_radio_tx_done != 0U)
|
||||
{
|
||||
g_radio_tx_done = 0U;
|
||||
g_radio_busy = 0U;
|
||||
g_stat_uart_packets_tx++;
|
||||
App_QueuePop();
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
if (g_radio_tx_timeout != 0U)
|
||||
{
|
||||
g_radio_tx_timeout = 0U;
|
||||
g_radio_busy = 0U;
|
||||
App_QueuePop();
|
||||
App_Printf("\r\n[WARN] radio tx timeout\r\n");
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
if (g_radio_rx_done != 0U)
|
||||
{
|
||||
g_radio_rx_done = 0U;
|
||||
g_stat_radio_packets_rx++;
|
||||
g_stat_radio_bytes_rx += g_rx_payload_len;
|
||||
|
||||
if (g_mode == APP_MODE_DATA)
|
||||
{
|
||||
App_Write(g_rx_payload, g_rx_payload_len);
|
||||
}
|
||||
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
if ((g_radio_rx_timeout != 0U) || (g_radio_rx_error != 0U))
|
||||
{
|
||||
g_radio_rx_timeout = 0U;
|
||||
g_radio_rx_error = 0U;
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
if ((g_radio_needs_rx_restart != 0U) && (g_radio_busy == 0U) && (g_tx_q_count == 0U))
|
||||
{
|
||||
g_radio_needs_rx_restart = 0U;
|
||||
App_RadioEnterRx();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_ProcessUartPacketizer(void)
|
||||
{
|
||||
uint32_t now = HAL_GetTick();
|
||||
|
||||
if (g_mode != APP_MODE_DATA)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((g_uart_build_len > 0U) &&
|
||||
((now - g_uart_last_data_tick) >= g_cfg.uart_packet_timeout_ms) &&
|
||||
(g_escape.active == 0U))
|
||||
{
|
||||
App_DataModeFlushBuilder();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_ProcessEscape(void)
|
||||
{
|
||||
uint32_t now = HAL_GetTick();
|
||||
uint8_t i;
|
||||
|
||||
if ((g_mode != APP_MODE_DATA) || (g_escape.active == 0U))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((g_escape.count == 3U) && ((now - g_escape.last_tick) >= CONFIG_ESCAPE_GUARD_MS))
|
||||
{
|
||||
g_escape.active = 0U;
|
||||
g_escape.count = 0U;
|
||||
App_EnterConfigMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((g_escape.count < 3U) && ((now - g_escape.last_tick) >= CONFIG_ESCAPE_GUARD_MS))
|
||||
{
|
||||
for (i = 0U; i < g_escape.count; i++)
|
||||
{
|
||||
App_DataModeFeedByte(g_escape.bytes[i], now);
|
||||
}
|
||||
g_escape.active = 0U;
|
||||
g_escape.count = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
static void App_StartNextTxIfPossible(void)
|
||||
{
|
||||
if ((g_mode != APP_MODE_DATA) || (g_radio_busy != 0U) || (g_tx_q_count == 0U))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
App_RadioConfigureTx();
|
||||
g_radio_busy = 1U;
|
||||
(void)Radio.Send(g_tx_queue[g_tx_q_head].data, g_tx_queue[g_tx_q_head].len);
|
||||
}
|
||||
|
||||
static void App_RadioApplyConfig(void)
|
||||
{
|
||||
Radio.SetChannel(g_cfg.rf_frequency);
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
static void App_RadioConfigureRx(void)
|
||||
{
|
||||
RxConfigGeneric_t rx = {0};
|
||||
|
||||
Radio.SetChannel(g_cfg.rf_frequency);
|
||||
|
||||
rx.fsk.ModulationShaping = RADIO_FSK_MOD_SHAPING_G_BT_05;
|
||||
rx.fsk.Bandwidth = g_cfg.fsk_bandwidth;
|
||||
rx.fsk.BitRate = g_cfg.fsk_bitrate;
|
||||
rx.fsk.PreambleLen = g_cfg.fsk_preamble_len;
|
||||
rx.fsk.SyncWordLength = RADIO_SYNCWORD_LEN;
|
||||
rx.fsk.PreambleMinDetect = RADIO_FSK_PREAMBLE_DETECTOR_08_BITS;
|
||||
rx.fsk.SyncWord = g_cfg.syncword;
|
||||
rx.fsk.whiteSeed = RADIO_WHITENING_SEED;
|
||||
rx.fsk.LengthMode = RADIO_FSK_PACKET_VARIABLE_LENGTH;
|
||||
rx.fsk.CrcLength = RADIO_FSK_CRC_2_BYTES_IBM;
|
||||
rx.fsk.CrcPolynomial = RADIO_CRC_POLY;
|
||||
rx.fsk.CrcSeed = RADIO_CRC_SEED;
|
||||
rx.fsk.Whitening = RADIO_FSK_DC_FREEWHITENING;
|
||||
rx.fsk.MaxPayloadLength = RADIO_MAX_PAYLOAD_SIZE;
|
||||
rx.fsk.StopTimerOnPreambleDetect = 0;
|
||||
rx.fsk.AddrComp = RADIO_FSK_ADDRESSCOMP_FILT_OFF;
|
||||
|
||||
Radio.Standby();
|
||||
if (0UL != Radio.RadioSetRxGenericConfig(GENERIC_FSK, &rx, RX_CONTINUOUS_ON, 0U))
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_RadioConfigureTx(void)
|
||||
{
|
||||
TxConfigGeneric_t tx = {0};
|
||||
|
||||
Radio.SetChannel(g_cfg.rf_frequency);
|
||||
|
||||
tx.fsk.ModulationShaping = RADIO_FSK_MOD_SHAPING_G_BT_05;
|
||||
tx.fsk.FrequencyDeviation = g_cfg.fsk_fdev;
|
||||
tx.fsk.BitRate = g_cfg.fsk_bitrate;
|
||||
tx.fsk.PreambleLen = g_cfg.fsk_preamble_len;
|
||||
tx.fsk.SyncWordLength = RADIO_SYNCWORD_LEN;
|
||||
tx.fsk.SyncWord = g_cfg.syncword;
|
||||
tx.fsk.whiteSeed = RADIO_WHITENING_SEED;
|
||||
tx.fsk.HeaderType = RADIO_FSK_PACKET_VARIABLE_LENGTH;
|
||||
tx.fsk.CrcLength = RADIO_FSK_CRC_2_BYTES_IBM;
|
||||
tx.fsk.CrcPolynomial = RADIO_CRC_POLY;
|
||||
tx.fsk.CrcSeed = RADIO_CRC_SEED;
|
||||
tx.fsk.Whitening = RADIO_FSK_DC_FREEWHITENING;
|
||||
|
||||
Radio.Standby();
|
||||
if (0UL != Radio.RadioSetTxGenericConfig(GENERIC_FSK, &tx, g_cfg.tx_power, TX_TIMEOUT_VALUE_MS))
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
static void App_RadioEnterRx(void)
|
||||
{
|
||||
App_RadioConfigureRx();
|
||||
Radio.Rx(RX_TIMEOUT_VALUE_MS);
|
||||
}
|
||||
|
||||
static void App_EnterConfigMode(void)
|
||||
{
|
||||
App_ResetDataPath();
|
||||
g_mode = APP_MODE_CONFIG;
|
||||
App_Printf("\r\n\r\n[CONFIG MODE]\r\n");
|
||||
App_Printf("type 'help' for commands\r\n");
|
||||
App_PrintConfigPrompt();
|
||||
}
|
||||
|
||||
static void App_ExitConfigMode(void)
|
||||
{
|
||||
g_cfg_line_len = 0U;
|
||||
App_ResetDataPath();
|
||||
g_mode = APP_MODE_DATA;
|
||||
App_Printf("\r\n[DATA MODE]\r\n");
|
||||
g_radio_needs_rx_restart = 1U;
|
||||
}
|
||||
|
||||
static void App_ResetDataPath(void)
|
||||
{
|
||||
g_uart_build_len = 0U;
|
||||
g_escape.active = 0U;
|
||||
g_escape.count = 0U;
|
||||
g_tx_q_head = 0U;
|
||||
g_tx_q_tail = 0U;
|
||||
g_tx_q_count = 0U;
|
||||
}
|
||||
|
||||
static void App_DataModeFeedByte(uint8_t ch, uint32_t now)
|
||||
{
|
||||
if (g_uart_build_len < UART_DATA_BUFFER_SIZE)
|
||||
{
|
||||
g_uart_build_buf[g_uart_build_len++] = ch;
|
||||
g_uart_last_data_tick = now;
|
||||
g_stat_uart_bytes_tx++;
|
||||
}
|
||||
else
|
||||
{
|
||||
App_DataModeFlushBuilder();
|
||||
if (g_uart_build_len < UART_DATA_BUFFER_SIZE)
|
||||
{
|
||||
g_uart_build_buf[g_uart_build_len++] = ch;
|
||||
g_uart_last_data_tick = now;
|
||||
g_stat_uart_bytes_tx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void App_DataModeFlushBuilder(void)
|
||||
{
|
||||
if (g_uart_build_len == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (App_QueuePush(g_uart_build_buf, g_uart_build_len) == 0U)
|
||||
{
|
||||
g_stat_queue_overflow++;
|
||||
}
|
||||
g_uart_build_len = 0U;
|
||||
}
|
||||
|
||||
static uint8_t App_QueuePush(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
if ((len == 0U) || (len > RADIO_MAX_PAYLOAD_SIZE) || (g_tx_q_count >= TX_QUEUE_DEPTH))
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
memcpy(g_tx_queue[g_tx_q_tail].data, data, len);
|
||||
g_tx_queue[g_tx_q_tail].len = (uint8_t)len;
|
||||
g_tx_q_tail = (uint8_t)((g_tx_q_tail + 1U) % TX_QUEUE_DEPTH);
|
||||
g_tx_q_count++;
|
||||
return 1U;
|
||||
}
|
||||
|
||||
static void App_QueuePop(void)
|
||||
{
|
||||
if (g_tx_q_count == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_tx_q_head = (uint8_t)((g_tx_q_head + 1U) % TX_QUEUE_DEPTH);
|
||||
g_tx_q_count--;
|
||||
}
|
||||
|
||||
static void UartRxByteCallback(uint8_t *rxChar, uint16_t size, uint8_t error)
|
||||
{
|
||||
uint8_t ch;
|
||||
uint32_t now;
|
||||
uint8_t i;
|
||||
|
||||
if ((error != 0U) || (size == 0U) || (rxChar == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ch = rxChar[0];
|
||||
now = HAL_GetTick();
|
||||
|
||||
if (g_mode == APP_MODE_CONFIG)
|
||||
{
|
||||
App_ConfigFeedByte(ch);
|
||||
return;
|
||||
}
|
||||
|
||||
if (g_escape.active == 0U)
|
||||
{
|
||||
if (((now - g_uart_last_data_tick) >= CONFIG_ESCAPE_GUARD_MS) && (ch == '+'))
|
||||
{
|
||||
g_escape.active = 1U;
|
||||
g_escape.count = 1U;
|
||||
g_escape.bytes[0] = ch;
|
||||
g_escape.start_tick = now;
|
||||
g_escape.last_tick = now;
|
||||
return;
|
||||
}
|
||||
|
||||
App_DataModeFeedByte(ch, now);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ch == '+') && (g_escape.count < 3U))
|
||||
{
|
||||
g_escape.bytes[g_escape.count++] = ch;
|
||||
g_escape.last_tick = now;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0U; i < g_escape.count; i++)
|
||||
{
|
||||
App_DataModeFeedByte(g_escape.bytes[i], now);
|
||||
}
|
||||
g_escape.active = 0U;
|
||||
g_escape.count = 0U;
|
||||
|
||||
if (((now - g_uart_last_data_tick) >= CONFIG_ESCAPE_GUARD_MS) && (ch == '+'))
|
||||
{
|
||||
g_escape.active = 1U;
|
||||
g_escape.count = 1U;
|
||||
g_escape.bytes[0] = ch;
|
||||
g_escape.start_tick = now;
|
||||
g_escape.last_tick = now;
|
||||
return;
|
||||
}
|
||||
|
||||
App_DataModeFeedByte(ch, now);
|
||||
}
|
||||
|
||||
static void App_ConfigFeedByte(uint8_t ch)
|
||||
{
|
||||
if ((ch == '\r') || (ch == '\n'))
|
||||
{
|
||||
if (g_cfg_line_len > 0U)
|
||||
{
|
||||
g_cfg_line[g_cfg_line_len] = '\0';
|
||||
App_Printf("\r\n");
|
||||
App_ConfigExecuteLine(g_cfg_line);
|
||||
g_cfg_line_len = 0U;
|
||||
}
|
||||
App_PrintConfigPrompt();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((ch == 0x08U) || (ch == 0x7FU))
|
||||
{
|
||||
if (g_cfg_line_len > 0U)
|
||||
{
|
||||
g_cfg_line_len--;
|
||||
App_Write((const uint8_t *)"\b \b", 3U);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((isprint(ch) != 0) && (g_cfg_line_len < (CONFIG_LINE_SIZE - 1U)))
|
||||
{
|
||||
g_cfg_line[g_cfg_line_len++] = (char)ch;
|
||||
App_Write(&ch, 1U);
|
||||
}
|
||||
}
|
||||
|
||||
static void App_ConfigExecuteLine(char *line)
|
||||
{
|
||||
char *arg;
|
||||
uint32_t u32;
|
||||
uint8_t sync[3];
|
||||
|
||||
line = App_SkipSpaces(line);
|
||||
if (*line == '\0')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((strcmp(line, "help") == 0) || (strcmp(line, "?") == 0))
|
||||
{
|
||||
App_PrintHelp();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((strcmp(line, "show") == 0) || (strcmp(line, "status") == 0))
|
||||
{
|
||||
App_PrintStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(line, "exit") == 0)
|
||||
{
|
||||
App_ExitConfigMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(line, "defaults") == 0)
|
||||
{
|
||||
g_cfg.rf_frequency = RF_FREQUENCY_DEFAULT;
|
||||
g_cfg.tx_power = TX_OUTPUT_POWER_DEFAULT;
|
||||
g_cfg.fsk_bitrate = FSK_DATARATE_DEFAULT;
|
||||
g_cfg.fsk_bandwidth = FSK_BANDWIDTH_DEFAULT;
|
||||
g_cfg.fsk_fdev = FSK_FDEV_DEFAULT;
|
||||
g_cfg.fsk_preamble_len = FSK_PREAMBLE_LENGTH_DEFAULT;
|
||||
g_cfg.syncword[0] = 0xC1U;
|
||||
g_cfg.syncword[1] = 0x94U;
|
||||
g_cfg.syncword[2] = 0xC1U;
|
||||
g_cfg.uart_packet_timeout_ms = DEFAULT_UART_PACKET_TIMEOUT_MS;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("defaults restored\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "freq ", 5) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[5], NULL, 10);
|
||||
if (u32 < 150000000UL || u32 > 960000000UL)
|
||||
{
|
||||
App_Printf("bad frequency\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.rf_frequency = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("freq=%lu\r\n", (unsigned long)g_cfg.rf_frequency);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "power ", 6) == 0)
|
||||
{
|
||||
long pwr = strtol(&line[6], NULL, 10);
|
||||
if ((pwr < -9L) || (pwr > 22L))
|
||||
{
|
||||
App_Printf("bad power\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.tx_power = (int8_t)pwr;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("power=%d\r\n", g_cfg.tx_power);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "bitrate ", 8) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[8], NULL, 10);
|
||||
if ((u32 < 600UL) || (u32 > 300000UL))
|
||||
{
|
||||
App_Printf("bad bitrate\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_bitrate = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("bitrate=%lu\r\n", (unsigned long)g_cfg.fsk_bitrate);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "bandwidth ", 10) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[10], NULL, 10);
|
||||
if ((u32 < 2600UL) || (u32 > 250000UL))
|
||||
{
|
||||
App_Printf("bad bandwidth\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_bandwidth = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("bandwidth=%lu\r\n", (unsigned long)g_cfg.fsk_bandwidth);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "fdev ", 5) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[5], NULL, 10);
|
||||
if (u32 > 200000UL)
|
||||
{
|
||||
App_Printf("bad fdev\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_fdev = u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("fdev=%lu\r\n", (unsigned long)g_cfg.fsk_fdev);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "preamble ", 9) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[9], NULL, 10);
|
||||
if ((u32 < 2UL) || (u32 > 65535UL))
|
||||
{
|
||||
App_Printf("bad preamble\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.fsk_preamble_len = (uint16_t)u32;
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("preamble=%u\r\n", g_cfg.fsk_preamble_len);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "timeout ", 8) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[8], NULL, 10);
|
||||
if ((u32 < 1UL) || (u32 > 1000UL))
|
||||
{
|
||||
App_Printf("bad timeout\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.uart_packet_timeout_ms = (uint16_t)u32;
|
||||
App_Printf("timeout=%u\r\n", g_cfg.uart_packet_timeout_ms);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "uart ", 5) == 0)
|
||||
{
|
||||
u32 = strtoul(&line[5], NULL, 10);
|
||||
if ((u32 < 1200UL) || (u32 > 921600UL))
|
||||
{
|
||||
App_Printf("bad uart baudrate\r\n");
|
||||
return;
|
||||
}
|
||||
g_cfg.uart_baudrate = u32;
|
||||
App_Printf("switching uart to %lu baud\r\n", (unsigned long)g_cfg.uart_baudrate);
|
||||
App_ReconfigureUart(g_cfg.uart_baudrate);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp(line, "sync ", 5) == 0)
|
||||
{
|
||||
arg = App_SkipSpaces(&line[5]);
|
||||
if (App_ParseHexSyncWord(arg, sync) == 0U)
|
||||
{
|
||||
App_Printf("bad sync, use 6 hex chars, e.g. C194C1\r\n");
|
||||
return;
|
||||
}
|
||||
memcpy(g_cfg.syncword, sync, sizeof(sync));
|
||||
App_RadioApplyConfig();
|
||||
App_Printf("sync=%02X%02X%02X\r\n", g_cfg.syncword[0], g_cfg.syncword[1], g_cfg.syncword[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
App_Printf("unknown command: %s\r\n", line);
|
||||
}
|
||||
|
||||
static void App_PrintConfigPrompt(void)
|
||||
{
|
||||
if (g_mode == APP_MODE_CONFIG)
|
||||
{
|
||||
App_Printf("cfg> ");
|
||||
}
|
||||
}
|
||||
|
||||
static void App_PrintHelp(void)
|
||||
{
|
||||
App_Printf("commands:\r\n");
|
||||
App_Printf(" help - this help\r\n");
|
||||
App_Printf(" show - current config and counters\r\n");
|
||||
App_Printf(" freq <hz> - rf frequency\r\n");
|
||||
App_Printf(" power <dbm> - tx power (-9..22)\r\n");
|
||||
App_Printf(" bitrate <bps> - fsk bitrate\r\n");
|
||||
App_Printf(" bandwidth <hz> - fsk rx bandwidth\r\n");
|
||||
App_Printf(" fdev <hz> - fsk frequency deviation\r\n");
|
||||
App_Printf(" preamble <bytes> - fsk preamble length\r\n");
|
||||
App_Printf(" sync <hex6> - 3-byte syncword, example C194C1\r\n");
|
||||
App_Printf(" timeout <ms> - uart silence before rf packet send\r\n");
|
||||
App_Printf(" uart <baud> - change uart baudrate immediately\r\n");
|
||||
App_Printf(" defaults - restore default config\r\n");
|
||||
App_Printf(" exit - return to transparent bridge mode\r\n");
|
||||
}
|
||||
|
||||
static void App_PrintStatus(void)
|
||||
{
|
||||
App_Printf("mode=%s\r\n", (g_mode == APP_MODE_CONFIG) ? "config" : "data");
|
||||
App_Printf("freq=%lu Hz\r\n", (unsigned long)g_cfg.rf_frequency);
|
||||
App_Printf("power=%d dBm\r\n", g_cfg.tx_power);
|
||||
App_Printf("bitrate=%lu bps\r\n", (unsigned long)g_cfg.fsk_bitrate);
|
||||
App_Printf("bandwidth=%lu Hz\r\n", (unsigned long)g_cfg.fsk_bandwidth);
|
||||
App_Printf("fdev=%lu Hz\r\n", (unsigned long)g_cfg.fsk_fdev);
|
||||
App_Printf("preamble=%u bytes\r\n", g_cfg.fsk_preamble_len);
|
||||
App_Printf("sync=%02X%02X%02X\r\n", g_cfg.syncword[0], g_cfg.syncword[1], g_cfg.syncword[2]);
|
||||
App_Printf("uart_baud=%lu\r\n", (unsigned long)g_cfg.uart_baudrate);
|
||||
App_Printf("uart_pkt_timeout=%u ms\r\n", g_cfg.uart_packet_timeout_ms);
|
||||
App_Printf("tx_queue=%u/%u\r\n", g_tx_q_count, TX_QUEUE_DEPTH);
|
||||
App_Printf("last_rx_rssi=%d dBm\r\n", (int)g_last_rx_rssi);
|
||||
App_Printf("last_rx_cfo=%d\r\n", (int)g_last_rx_cfo);
|
||||
App_Printf("stat_uart_packets_tx=%lu\r\n", (unsigned long)g_stat_uart_packets_tx);
|
||||
App_Printf("stat_uart_bytes_tx=%lu\r\n", (unsigned long)g_stat_uart_bytes_tx);
|
||||
App_Printf("stat_radio_packets_rx=%lu\r\n", (unsigned long)g_stat_radio_packets_rx);
|
||||
App_Printf("stat_radio_bytes_rx=%lu\r\n", (unsigned long)g_stat_radio_bytes_rx);
|
||||
App_Printf("stat_queue_overflow=%lu\r\n", (unsigned long)g_stat_queue_overflow);
|
||||
}
|
||||
|
||||
static void App_Printf(const char *fmt, ...)
|
||||
{
|
||||
char buffer[192];
|
||||
va_list ap;
|
||||
int len;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((size_t)len >= sizeof(buffer))
|
||||
{
|
||||
len = (int)(sizeof(buffer) - 1U);
|
||||
}
|
||||
|
||||
App_Write((const uint8_t *)buffer, (uint16_t)len);
|
||||
}
|
||||
|
||||
static void App_Write(const uint8_t *data, uint16_t len)
|
||||
{
|
||||
if ((data == NULL) || (len == 0U))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
(void)HAL_UART_Transmit(&huart2, (uint8_t *)data, len, 1000U);
|
||||
}
|
||||
|
||||
static void App_ReconfigureUart(uint32_t baudrate)
|
||||
{
|
||||
huart2.Init.BaudRate = baudrate;
|
||||
|
||||
(void)HAL_UART_AbortReceive(&huart2);
|
||||
|
||||
if (HAL_UART_Init(&huart2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_UARTEx_EnableFifoMode(&huart2) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
(void)vcom_ReceiveInit(UartRxByteCallback);
|
||||
}
|
||||
|
||||
static uint8_t App_ParseHexSyncWord(const char *text, uint8_t out[3])
|
||||
{
|
||||
char buf[7];
|
||||
char *endptr;
|
||||
unsigned long value;
|
||||
size_t i;
|
||||
size_t n = 0U;
|
||||
|
||||
if ((text == NULL) || (out == NULL))
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
while ((*text != '\0') && (n < 6U))
|
||||
{
|
||||
if (isxdigit((unsigned char)*text) != 0)
|
||||
{
|
||||
buf[n++] = *text;
|
||||
}
|
||||
text++;
|
||||
}
|
||||
|
||||
if (n != 6U)
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
for (i = 0U; i < n; i++)
|
||||
{
|
||||
if (isxdigit((unsigned char)buf[i]) == 0)
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
}
|
||||
|
||||
buf[6] = '\0';
|
||||
value = strtoul(buf, &endptr, 16);
|
||||
if ((endptr == NULL) || (*endptr != '\0'))
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
out[0] = (uint8_t)((value >> 16) & 0xFFU);
|
||||
out[1] = (uint8_t)((value >> 8) & 0xFFU);
|
||||
out[2] = (uint8_t)(value & 0xFFU);
|
||||
return 1U;
|
||||
}
|
||||
|
||||
static char *App_SkipSpaces(char *s)
|
||||
{
|
||||
while ((s != NULL) && (*s != '\0') && isspace((unsigned char)*s))
|
||||
{
|
||||
s++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static void OnTxDone(void)
|
||||
{
|
||||
g_radio_tx_done = 1U;
|
||||
}
|
||||
|
||||
static void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t cfo)
|
||||
{
|
||||
g_last_rx_rssi = rssi;
|
||||
g_last_rx_cfo = cfo;
|
||||
|
||||
if (size > RADIO_MAX_PAYLOAD_SIZE)
|
||||
{
|
||||
size = RADIO_MAX_PAYLOAD_SIZE;
|
||||
}
|
||||
|
||||
memcpy(g_rx_payload, payload, size);
|
||||
g_rx_payload_len = size;
|
||||
g_radio_rx_done = 1U;
|
||||
}
|
||||
|
||||
static void OnTxTimeout(void)
|
||||
{
|
||||
g_radio_tx_timeout = 1U;
|
||||
}
|
||||
|
||||
static void OnRxTimeout(void)
|
||||
{
|
||||
g_radio_rx_timeout = 1U;
|
||||
}
|
||||
|
||||
static void OnRxError(void)
|
||||
{
|
||||
g_radio_rx_error = 1U;
|
||||
}
|
||||
24
SubGHz_Phy/App/subghz_phy_app.h
Normal file
24
SubGHz_Phy/App/subghz_phy_app.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef __SUBGHZ_PHY_APP_H__
|
||||
#define __SUBGHZ_PHY_APP_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RF_FREQUENCY_DEFAULT 433100000UL
|
||||
#define TX_OUTPUT_POWER_DEFAULT 14
|
||||
#define FSK_FDEV_DEFAULT 25000UL
|
||||
#define FSK_DATARATE_DEFAULT 50000UL
|
||||
#define FSK_BANDWIDTH_DEFAULT 50000UL
|
||||
#define FSK_PREAMBLE_LENGTH_DEFAULT 4U
|
||||
|
||||
void SubghzApp_Init(void);
|
||||
void SubghzApp_Process(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SUBGHZ_PHY_APP_H__ */
|
||||
72
SubGHz_Phy/Target/mw_log_conf.h
Normal file
72
SubGHz_Phy/Target/mw_log_conf.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file mw_log_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief Configure (enable/disable) traces
|
||||
*******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MW_LOG_CONF_H__
|
||||
#define __MW_LOG_CONF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32_adv_trace.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define MW_LOG_ENABLED
|
||||
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
#ifdef MW_LOG_ENABLED
|
||||
#define MW_LOG(TS,VL, ...) do{ {UTIL_ADV_TRACE_COND_FSend(VL, T_REG_OFF, TS, __VA_ARGS__);} }while(0)
|
||||
#else /* MW_LOG_ENABLED */
|
||||
#define MW_LOG(TS,VL, ...)
|
||||
#endif /* MW_LOG_ENABLED */
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*__MW_LOG_CONF_H__ */
|
||||
256
SubGHz_Phy/Target/radio_board_if.c
Normal file
256
SubGHz_Phy/Target/radio_board_if.c
Normal file
@@ -0,0 +1,256 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file radio_board_if.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides an interface layer between MW and Radio Board
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "radio_board_if.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* External variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Exported functions --------------------------------------------------------*/
|
||||
int32_t RBI_Init(void)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_Init_1 */
|
||||
|
||||
/* USER CODE END RBI_Init_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_Init();
|
||||
#else
|
||||
/* 2/ Or implement RBI_Init here */
|
||||
int32_t retcode = 0;
|
||||
/* USER CODE BEGIN RBI_Init_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_Init_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_DeInit(void)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_DeInit_1 */
|
||||
|
||||
/* USER CODE END RBI_DeInit_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_DeInit();
|
||||
#else
|
||||
/* 2/ Or implement RBI_DeInit here */
|
||||
int32_t retcode = 0;
|
||||
/* USER CODE BEGIN RBI_DeInit_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_DeInit_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_ConfigRFSwitch(RBI_Switch_TypeDef Config)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_ConfigRFSwitch_1 */
|
||||
|
||||
/* USER CODE END RBI_ConfigRFSwitch_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_ConfigRFSwitch((BSP_RADIO_Switch_TypeDef) Config);
|
||||
#else
|
||||
/* 2/ Or implement RBI_ConfigRFSwitch here */
|
||||
int32_t retcode = 0;
|
||||
/* USER CODE BEGIN RBI_ConfigRFSwitch_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_ConfigRFSwitch_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_GetTxConfig(void)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_GetTxConfig_1 */
|
||||
|
||||
/* USER CODE END RBI_GetTxConfig_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_GetTxConfig();
|
||||
#else
|
||||
/* 2/ Or implement RBI_GetTxConfig here */
|
||||
int32_t retcode = RBI_CONF_RFO;
|
||||
/* USER CODE BEGIN RBI_GetTxConfig_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_GetTxConfig_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_IsTCXO(void)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_IsTCXO_1 */
|
||||
|
||||
/* USER CODE END RBI_IsTCXO_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_IsTCXO();
|
||||
#else
|
||||
/* 2/ Or implement RBI_IsTCXO here */
|
||||
int32_t retcode = IS_TCXO_SUPPORTED;
|
||||
/* USER CODE BEGIN RBI_IsTCXO_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_IsTCXO_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_IsDCDC(void)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_IsDCDC_1 */
|
||||
|
||||
/* USER CODE END RBI_IsDCDC_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_IsDCDC();
|
||||
#else
|
||||
/* 2/ Or implement RBI_IsDCDC here */
|
||||
int32_t retcode = IS_DCDC_SUPPORTED;
|
||||
/* USER CODE BEGIN RBI_IsDCDC_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
/* USER CODE END RBI_IsDCDC_2 */
|
||||
return retcode;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
|
||||
int32_t RBI_GetRFOMaxPowerConfig(RBI_RFOMaxPowerConfig_TypeDef Config)
|
||||
{
|
||||
/* USER CODE BEGIN RBI_GetRFOMaxPowerConfig_1 */
|
||||
|
||||
/* USER CODE END RBI_GetRFOMaxPowerConfig_1 */
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* Important note: BSP code is board dependent
|
||||
* STM32WL_Nucleo code can be found
|
||||
* either in STM32CubeWL package under Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* or at https://github.com/STMicroelectronics/STM32CubeWL/tree/main/Drivers/BSP/STM32WLxx_Nucleo/
|
||||
* 1/ For User boards, the BSP/STM32WLxx_Nucleo/ directory can be copied and replaced in the project. The copy must then be updated depending:
|
||||
* on board RF switch configuration (pin control, number of port etc)
|
||||
* on TCXO configuration
|
||||
* on DC/DC configuration
|
||||
* on maximum output power that the board can deliver*/
|
||||
return BSP_RADIO_GetRFOMaxPowerConfig((BSP_RADIO_RFOMaxPowerConfig_TypeDef) Config);
|
||||
#else
|
||||
/* 2/ Or implement RBI_RBI_GetRFOMaxPowerConfig here */
|
||||
int32_t ret = 0;
|
||||
/* USER CODE BEGIN RBI_GetRFOMaxPowerConfig_2 */
|
||||
#warning user to provide its board code or to call his board driver functions
|
||||
if (Config == RBI_RFO_LP_MAXPOWER)
|
||||
{
|
||||
ret = 15; /*dBm*/
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = 22; /*dBm*/
|
||||
}
|
||||
/* USER CODE END RBI_GetRFOMaxPowerConfig_2 */
|
||||
return ret;
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
}
|
||||
/* USER CODE BEGIN EF */
|
||||
|
||||
/* USER CODE END EF */
|
||||
|
||||
/* Private Functions Definition -----------------------------------------------*/
|
||||
/* USER CODE BEGIN PrFD */
|
||||
|
||||
/* USER CODE END PrFD */
|
||||
223
SubGHz_Phy/Target/radio_board_if.h
Normal file
223
SubGHz_Phy/Target/radio_board_if.h
Normal file
@@ -0,0 +1,223 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file radio_board_if.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for Radio interface configuration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef RADIO_BOARD_IF_H
|
||||
#define RADIO_BOARD_IF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "platform.h"
|
||||
/* USER CODE BEGIN include */
|
||||
|
||||
/* USER CODE END include */
|
||||
|
||||
/* Exported defines ----------------------------------------------------------*/
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* code generated by STM32CubeMX does not support BSP */
|
||||
/* In order to use BSP driver, add the correspondent files in the IDE workspace */
|
||||
/* and define USE_BSP_DRIVER in the preprocessor definitions or in platform.h */
|
||||
#define RBI_CONF_RFO_LP_HP RADIO_CONF_RFO_LP_HP
|
||||
#define RBI_CONF_RFO_LP RADIO_CONF_RFO_LP
|
||||
#define RBI_CONF_RFO_HP RADIO_CONF_RFO_HP
|
||||
#else
|
||||
/* USER CODE BEGIN Board Definition */
|
||||
|
||||
/* USER CODE END Board Definition */
|
||||
#define RBI_CONF_RFO_LP_HP 0
|
||||
#define RBI_CONF_RFO_LP 1
|
||||
#define RBI_CONF_RFO_HP 2
|
||||
/* USER CODE BEGIN Board Definition_2 */
|
||||
|
||||
/* USER CODE END Board Definition_2 */
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* code generated by STM32CubeMX does not support BSP */
|
||||
/* In order to use BSP driver, add the correspondent files in the IDE workspace */
|
||||
/* and define USE_BSP_DRIVER in the preprocessor definitions or in platform.h */
|
||||
|
||||
#else
|
||||
/* USER CODE BEGIN Exported Parameters */
|
||||
|
||||
/* USER CODE END Exported Parameters */
|
||||
/* Indicates the type of switch between the ones proposed by CONFIG Constants
|
||||
*/
|
||||
#define RBI_CONF_RFO RBI_CONF_RFO_LP_HP
|
||||
|
||||
/* Indicates whether or not TCXO is supported by the board
|
||||
* 0: TCXO not supported
|
||||
* 1: TCXO supported
|
||||
*/
|
||||
#define IS_TCXO_SUPPORTED 1U
|
||||
|
||||
/* Indicates whether or not DCDC is supported by the board
|
||||
* 0: DCDC not supported
|
||||
* 1: DCDC supported
|
||||
*/
|
||||
#define IS_DCDC_SUPPORTED 1U
|
||||
|
||||
/* USER CODE BEGIN Exported Parameters_2 */
|
||||
|
||||
/* USER CODE END Exported Parameters_2 */
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* code generated by STM32CubeMX does not support BSP */
|
||||
/* In order to use BSP driver, add the correspondent files in the IDE workspace */
|
||||
/* and define USE_BSP_DRIVER in the preprocessor definitions or in platform.h */
|
||||
|
||||
#else
|
||||
/* USER CODE BEGIN Exported PinMapping */
|
||||
#warning user to provide its board definitions pins
|
||||
/* USER CODE END Exported PinMapping */
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
|
||||
/* USER CODE BEGIN ED */
|
||||
|
||||
/* USER CODE END ED */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
|
||||
#if defined(USE_BSP_DRIVER)
|
||||
/* code generated by STM32CubeMX does not support BSP */
|
||||
/* In order to use BSP driver, add the correspondent files in the IDE workspace */
|
||||
/* and define USE_BSP_DRIVER in the preprocessor definitions or in platform.h */
|
||||
typedef enum
|
||||
{
|
||||
RBI_SWITCH_OFF = RADIO_SWITCH_OFF,
|
||||
RBI_SWITCH_RX = RADIO_SWITCH_RX,
|
||||
RBI_SWITCH_RFO_LP = RADIO_SWITCH_RFO_LP,
|
||||
RBI_SWITCH_RFO_HP = RADIO_SWITCH_RFO_HP,
|
||||
} RBI_Switch_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RBI_RFO_LP_MAXPOWER = RADIO_RFO_LP_MAXPOWER,
|
||||
RBI_RFO_HP_MAXPOWER = RADIO_RFO_HP_MAXPOWER,
|
||||
} RBI_RFOMaxPowerConfig_TypeDef;
|
||||
|
||||
#else
|
||||
/* USER CODE BEGIN Exported Types */
|
||||
|
||||
/* USER CODE END Exported Types */
|
||||
typedef enum
|
||||
{
|
||||
RBI_SWITCH_OFF = 0,
|
||||
RBI_SWITCH_RX = 1,
|
||||
RBI_SWITCH_RFO_LP = 2,
|
||||
RBI_SWITCH_RFO_HP = 3,
|
||||
} RBI_Switch_TypeDef;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RBI_RFO_LP_MAXPOWER = 0,
|
||||
RBI_RFO_HP_MAXPOWER = 1,
|
||||
} RBI_RFOMaxPowerConfig_TypeDef;
|
||||
/* USER CODE BEGIN Exported Types_2 */
|
||||
|
||||
/* USER CODE END Exported Types_2 */
|
||||
#endif /* USE_BSP_DRIVER */
|
||||
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
/**
|
||||
* @brief Init Radio Switch
|
||||
* @return BSP status
|
||||
*/
|
||||
int32_t RBI_Init(void);
|
||||
|
||||
/**
|
||||
* @brief DeInit Radio Switch
|
||||
* @return BSP status
|
||||
*/
|
||||
int32_t RBI_DeInit(void);
|
||||
|
||||
/**
|
||||
* @brief Configure Radio Switch.
|
||||
* @param Config: Specifies the Radio RF switch path to be set.
|
||||
* This parameter can be one of following parameters:
|
||||
* @arg RADIO_SWITCH_OFF
|
||||
* @arg RADIO_SWITCH_RX
|
||||
* @arg RADIO_SWITCH_RFO_LP
|
||||
* @arg RADIO_SWITCH_RFO_HP
|
||||
* @return BSP status
|
||||
*/
|
||||
int32_t RBI_ConfigRFSwitch(RBI_Switch_TypeDef Config);
|
||||
|
||||
/**
|
||||
* @brief Return Board Configuration
|
||||
* @retval RBI_CONF_RFO_LP_HP
|
||||
* @retval RBI_CONF_RFO_LP
|
||||
* @retval RBI_CONF_RFO_HP
|
||||
*/
|
||||
int32_t RBI_GetTxConfig(void);
|
||||
|
||||
/**
|
||||
* @brief Get If TCXO is to be present on board
|
||||
* @note never remove called by MW,
|
||||
* @retval return 1 if present, 0 if not present
|
||||
*/
|
||||
int32_t RBI_IsTCXO(void);
|
||||
|
||||
/**
|
||||
* @brief Get If DCDC is to be present on board
|
||||
* @note never remove called by MW,
|
||||
* @retval return 1 if present, 0 if not present
|
||||
*/
|
||||
int32_t RBI_IsDCDC(void);
|
||||
|
||||
/**
|
||||
* @brief Return RF Output Max Power Configuration of matching circuit
|
||||
* @note never remove called by MW,
|
||||
* @retval return Max Power configuration of matching circuit for Low Power or High Power mode in dBm
|
||||
*/
|
||||
int32_t RBI_GetRFOMaxPowerConfig(RBI_RFOMaxPowerConfig_TypeDef Config);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RADIO_BOARD_IF_H */
|
||||
178
SubGHz_Phy/Target/radio_conf.h
Normal file
178
SubGHz_Phy/Target/radio_conf.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file radio_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header of Radio configuration
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RADIO_CONF_H__
|
||||
#define __RADIO_CONF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "platform.h"
|
||||
#include "subghz.h"
|
||||
#include "stm32_mem.h" /* RADIO_MEMSET8 def in this file */
|
||||
#include "mw_log_conf.h" /* mw trace conf */
|
||||
#include "radio_board_if.h" /* low layer api (bsp) */
|
||||
#include "utilities_def.h" /* low layer api (bsp) */
|
||||
#include "sys_debug.h"
|
||||
/* USER CODE BEGIN include */
|
||||
|
||||
/* USER CODE END include */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief drive value used anytime radio is NOT in TX low power mode
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define SMPS_DRIVE_SETTING_DEFAULT SMPS_DRV_40
|
||||
|
||||
/**
|
||||
* @brief drive value used anytime radio is in TX low power mode
|
||||
* TX low power mode is the worst case because the PA sinks from SMPS
|
||||
* while in high power mode, current is sunk directly from the battery
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define SMPS_DRIVE_SETTING_MAX SMPS_DRV_60
|
||||
|
||||
/**
|
||||
* @brief Provides the frequency of the chip running on the radio and the frequency step
|
||||
* @remark These defines are used for computing the frequency divider to set the RF frequency
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define XTAL_FREQ ( 32000000UL )
|
||||
|
||||
/**
|
||||
* @brief in XO mode, set internal capacitor (from 0x00 to 0x2F starting 11.2pF with 0.47pF steps)
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define XTAL_DEFAULT_CAP_VALUE ( 0x20UL )
|
||||
|
||||
/**
|
||||
* @brief voltage of vdd tcxo.
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define TCXO_CTRL_VOLTAGE TCXO_CTRL_1_7V
|
||||
|
||||
/**
|
||||
* @brief Radio maximum wakeup time (in ms)
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define RF_WAKEUP_TIME ( 1UL )
|
||||
|
||||
/**
|
||||
* @brief DCDC is enabled
|
||||
* @remark this define is only used if the DCDC is present on the board
|
||||
* @note override the default configuration of radio_driver.c
|
||||
*/
|
||||
#define DCDC_ENABLE ( 1UL )
|
||||
|
||||
/* USER CODE BEGIN EC */
|
||||
/**
|
||||
* @brief enables the RFW module
|
||||
* @note disabled by default
|
||||
*/
|
||||
#define RFW_ENABLE 1
|
||||
|
||||
/**
|
||||
* @brief enables the RFW long packet feature
|
||||
* @note disabled by default
|
||||
*/
|
||||
#define RFW_LONGPACKET_ENABLE 1
|
||||
|
||||
/**
|
||||
* @brief enables the RFW module log
|
||||
* @note disabled by default
|
||||
*/
|
||||
#define RFW_MW_LOG_ENABLE
|
||||
|
||||
/**
|
||||
* @brief Set RX pin to high or low level
|
||||
*/
|
||||
#define DBG_GPIO_RADIO_RX(set_rst) PROBE_GPIO_##set_rst##_LINE(PROBE_LINE1_PORT, PROBE_LINE1_PIN);
|
||||
|
||||
/**
|
||||
* @brief Set TX pin to high or low level
|
||||
*/
|
||||
#define DBG_GPIO_RADIO_TX(set_rst) PROBE_GPIO_##set_rst##_LINE(PROBE_LINE2_PORT, PROBE_LINE2_PIN);
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macros -----------------------------------------------------------*/
|
||||
#ifndef CRITICAL_SECTION_BEGIN
|
||||
/**
|
||||
* @brief macro used to enter the critical section
|
||||
*/
|
||||
#define CRITICAL_SECTION_BEGIN( ) UTILS_ENTER_CRITICAL_SECTION( )
|
||||
#endif /* !CRITICAL_SECTION_BEGIN */
|
||||
#ifndef CRITICAL_SECTION_END
|
||||
/**
|
||||
* @brief macro used to exit the critical section
|
||||
*/
|
||||
#define CRITICAL_SECTION_END( ) UTILS_EXIT_CRITICAL_SECTION( )
|
||||
#endif /* !CRITICAL_SECTION_END */
|
||||
|
||||
/* Function mapping */
|
||||
/**
|
||||
* @brief SUBGHZ interface init to radio Middleware
|
||||
*/
|
||||
#define RADIO_INIT MX_SUBGHZ_Init
|
||||
|
||||
/**
|
||||
* @brief Delay interface to radio Middleware
|
||||
*/
|
||||
#define RADIO_DELAY_MS HAL_Delay
|
||||
|
||||
/**
|
||||
* @brief Memset utilities interface to radio Middleware
|
||||
*/
|
||||
#define RADIO_MEMSET8( dest, value, size ) UTIL_MEM_set_8( dest, value, size )
|
||||
|
||||
/**
|
||||
* @brief Memcpy utilities interface to radio Middleware
|
||||
*/
|
||||
#define RADIO_MEMCPY8( dest, src, size ) UTIL_MEM_cpy_8( dest, src, size )
|
||||
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RADIO_CONF_H__*/
|
||||
117
SubGHz_Phy/Target/timer.h
Normal file
117
SubGHz_Phy/Target/timer.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file timer.h
|
||||
* @author MCD Application Team
|
||||
* @brief Wrapper to timer server
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2021 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __TIMER_H__
|
||||
#define __TIMER_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32_timer.h"
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Max timer mask
|
||||
*/
|
||||
#define TIMERTIME_T_MAX ( ( uint32_t )~0 )
|
||||
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* External variables --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Timer value on 32 bits
|
||||
*/
|
||||
#define TimerTime_t UTIL_TIMER_Time_t
|
||||
|
||||
/**
|
||||
* @brief Timer object description
|
||||
*/
|
||||
#define TimerEvent_t UTIL_TIMER_Object_t
|
||||
|
||||
/**
|
||||
* @brief Create the timer object
|
||||
*/
|
||||
#define TimerInit(HANDLE, CB) do {\
|
||||
UTIL_TIMER_Create( HANDLE, TIMERTIME_T_MAX, UTIL_TIMER_ONESHOT, CB, NULL);\
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief update the period and start the timer
|
||||
*/
|
||||
#define TimerSetValue(HANDLE, TIMEOUT) do{ \
|
||||
UTIL_TIMER_SetPeriod(HANDLE, TIMEOUT);\
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Start and adds the timer object to the list of timer events
|
||||
*/
|
||||
#define TimerStart(HANDLE) do {\
|
||||
UTIL_TIMER_Start(HANDLE);\
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief Stop and removes the timer object from the list of timer events
|
||||
*/
|
||||
#define TimerStop(HANDLE) do {\
|
||||
UTIL_TIMER_Stop(HANDLE);\
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* @brief return the current time
|
||||
*/
|
||||
#define TimerGetCurrentTime UTIL_TIMER_GetCurrentTime
|
||||
|
||||
/**
|
||||
* @brief return the elapsed time
|
||||
*/
|
||||
#define TimerGetElapsedTime UTIL_TIMER_GetElapsedTime
|
||||
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TIMER_H__*/
|
||||
Reference in New Issue
Block a user