Skip to content

Commit

Permalink
add support for matek devices, including HC04 support, revised readme
Browse files Browse the repository at this point in the history
  • Loading branch information
olliw42 committed Jul 29, 2024
1 parent 1b74e3e commit 7301afe
Show file tree
Hide file tree
Showing 102 changed files with 16,086 additions and 8 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,24 @@ The FLRC and FSK modes are not intended for long range.

## Hardware ##

Hardware is still a problem. Off-the-shelf hardware which is taylored at mLRS and exploits its full potential is not available. The STM32 chipsets were chosen as main platform, and a good number of STM32 based devices are supported. The widely available ExpressLRS hardware is not ideal for mLRS, as they use ESP chipsets which have several restrictions and lack peripherals which are desired for mLRS transmitters. ExpressLRS hardware is however supported.
The STM32 chipsets were chosen as main platform, and a good number of STM32 based devices are supported. The widely available ExpressLRS hardware, which uses ESP chipsets, is not ideal for mLRS, but ExpressLRS devices are supported.

The code currently supports:
- Frsky R9M and R9M Lite Pro transmitter modules and R9 MX, R9 MM and R9 Mini receivers (868/915 MHz)
- MatekSys mLRS boards (2.4 GHz, 868/915 MHz)
- Frsky R9M and R9M Lite Pro transmitter modules and R9 MX, R9 MM and R9 Mini receivers (868/915 MHz*)
- Flysky FRM303 transmitter module (2.4 GHz)
- SeeedStudio Wio-E5 Mini and Grove Wio-E5 boards (868/915 MHz, 433 MHz/70 cm)
- EByte E77 MBL board (868/915 MHz, 433 MHz/70 cm)
- ExpressLRS receivers (2.4 GHz and 868/915 MHz) (support for ExpressLRS transmitter modules is in development)
- ExpressLRS receivers (2.4 GHz and 868/915 MHz*) (support for ExpressLRS transmitter modules is in development)
- several DIY boards you can find in https://github.com/olliw42/mLRS-hardware

In the 915/868 MHz range, the Frsky R9 system and ExpressLRS receivers provide a simple and readily available entry into mLRS. The Frsky R9M transmitter module makes a good mLRS Tx module offering up to 1 W (the R9M Lite Pro cannot be used as transmitter). The R9 receivers are good options but provide low transmission power (50 mW). This can be mitigated by using a R9M Lite Pro (or R9M) as receiver, which offers 1 W. The various ExpressLRS receivers are often better options; some of them provide up to 500 mW transmission power, and some of them are cheaply available. They are also easier to flash. The combination of a Frsky R9M transmitter module and a ExpressLRS receiver is probably the best option currently available in the 900 MHz range. The downside of all these gear is that they only support the 19 Hz mode, and are incompatible with the Wio-E5/E77/E22 based gear ([link](https://github.com/olliw42/mLRS-docu/blob/master/docs/SX126x_SX127x_INCOMPATIBILITY.md)).
MatekSys offers a good selection of high quality mLRS boards, which are currently simply the best option available. They are specifically designed for mLRS exploiting its full potential. They support the 2.4 GHz and 868/915 MHz frequency bands, offer up to 1 W transmit power, and of course employ TCXOs. Furthermore, they use a comparatively beefy STM32 MCU, and are also very well suited for tinkering since all usable pins are broken out and easily accessible.

The SeeedStudio Wio-E5 boards and the EByte E77-MBL board are also readily available, and hence good options too for entering mLRS. The "easy-to-solder" board, which uses an EByte E77 module, is a simple DIY option for building mLRS receivers and transmitters. It can also be used to build mLRS dual-band devices, working e.g. in the 868/915 MHZ and 2.4 GHz ranges. All these boards are based on the STM32WL5E chip and thus provide all advantages of the SX126x, like the 31 Hz mode. Their maximum power is 22 dBm, and they can be used in the 915/868 MHz and 433 MHz/70 cm frequency ranges.
In the 915/868 MHz range, the Frsky R9 system and ExpressLRS receivers provide a relatively simple and readily available entry into mLRS. The Frsky R9M transmitter module makes a reasonable mLRS Tx module offering up to 1 W (the R9M Lite Pro cannot be used as transmitter). The R9 receivers are good options but provide low transmission power (50 mW). This can be mitigated by using a R9M Lite Pro (or R9M) as receiver (1 W). The various ExpressLRS 900 MHz receivers are often better options; some of them provide up to 500 mW transmission power, and some of them are cheaply available. They are also easier to flash. The combination of a Frsky R9M transmitter module and a ExpressLRS receiver can be a okay option in the 900 MHz range. The downside of all these gear is that they only support the 19 Hz mode, and are incompatible with the MatekSys and Wio-E5/E77/E22 based gear ([link](https://github.com/olliw42/mLRS-docu/blob/master/docs/SX126x_SX127x_INCOMPATIBILITY.md)).

In the 2.4 GHz range, the Flysky FRM303 transmitter module is readily available, albeit quite expensive. mLRS supports using it as transmitter as well as receiver. Concerning receivers, the easiest option is ExpressLRS receivers. They are readily available, can provide up to 100 mW power, and some support full diversity. If the full potential of mLRS is however desired, the DIY options are the way to go (they are all based on STM32). For instance, they offer the most capable mLRS transmitters available.
The SeeedStudio Wio-E5 boards and the EByte E77-MBL board are also readily available and reasonable options for entering mLRS. The "easy-to-solder" board, which uses an EByte E77 module, is a simple DIY option for building mLRS receivers and transmitters. It can also be used to build mLRS full diversity devices, as well as dual-band devices, working e.g. in the 868/915 MHZ and 2.4 GHz ranges. All these boards are based on the STM32WL5E chip and thus provide all advantages of the SX126x chipset, such as the 31 Hz mode. Their maximum power is 22 dBm, and they can be used in the 915/868 MHz and 433 MHz/70 cm frequency ranges.

In the 2.4 GHz range, the Flysky FRM303 transmitter module excels in its transmit power, but is quite expensive and also somewhat limited feature-wise. mLRS supports using it as transmitter as well as receiver. The ExpressLRS 2.4 GHz receivers can provide up to 100 mW power, and some support full diversity. If the full potential of mLRS is however desired, the MatekSys or DIY options are the way to go. For instance, the DIY options offer the most feature-rich mLRS transmitters available.

Don't hesitate to join the discussion thread at rcgroups or the discord channel for more details.

Expand Down
Binary file added docs/datasheets/HC-04 CN_Datasheet.pdf
Binary file not shown.
Binary file not shown.
Binary file added docs/datasheets/stm32g431kb.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions mLRS/Common/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ typedef enum {
TX_TASK_FLASH_ESP,
TX_TASK_ESP_PASSTHROUGH,
TX_TASK_CLI_CHANGE_CONFIG_ID,
TX_TASK_HC04_PASSTHROUGH,
TX_TASK_CLI_HC04_SETPIN,
} TX_TASK_ENUM;


Expand Down
41 changes: 41 additions & 0 deletions mLRS/Common/hal/device_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ The default selection of frequency bands can be overruled by feature defines.
#include "../common_conf.h"


//-- MATEKSYS mLRS devices

#ifdef RX_MATEK_MR24_30_G431KB
#define DEVICE_NAME "Matek mR24-30"
#define DEVICE_IS_RECEIVER
#define DEVICE_HAS_SX128x
#define FREQUENCY_BAND_2P4_GHZ
#endif

#ifdef TX_MATEK_MR24_30_G431KB
#define DEVICE_NAME "Matek mR24-30"
#define DEVICE_IS_TRANSMITTER
#define DEVICE_HAS_SX128x
#define FREQUENCY_BAND_2P4_GHZ
#endif

#ifdef RX_MATEK_MR900_30_G431KB
#define DEVICE_NAME "Matek mR900-30"
#define DEVICE_IS_RECEIVER
#define DEVICE_HAS_SX126x
#define FREQUENCY_BAND_868_MHZ
#define FREQUENCY_BAND_915_MHZ_FCC
#endif

#ifdef TX_MATEK_MR900_30_G431KB
#define DEVICE_NAME "Matek mR900-30"
#define DEVICE_IS_TRANSMITTER
#define DEVICE_HAS_SX126x
#define FREQUENCY_BAND_868_MHZ
#define FREQUENCY_BAND_915_MHZ_FCC
#endif

#ifdef RX_MATEK_MR900_22_WLE5CC
#define DEVICE_NAME "Matek mR900-22"
#define DEVICE_IS_RECEIVER
#define DEVICE_HAS_SX126x
#define FREQUENCY_BAND_868_MHZ
#define FREQUENCY_BAND_915_MHZ_FCC
#endif


//-- FrsKy R9 system

#ifdef RX_R9MX_868_L433CB
Expand Down
31 changes: 30 additions & 1 deletion mLRS/Common/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ In tx-hal files:
#define DEVICE_HAS_SERIAL2 // board has a Serial2 port
#define DEVICE_HAS_ESP_WIFI_BRIDGE_ON_SERIAL // board has ESP32 with RESET,GPIO support, on Serial port
#define DEVICE_HAS_ESP_WIFI_BRIDGE_ON_SERIAL2 // board has ESP32 with RESET,GPIO support, on Serial2 port
#define DEVICE_HAS_HC04_MODULE_ON_SERIAL // board has HC04 module on Serial port
#define DEVICE_HAS_HC04_MODULE_ON_SERIAL2 // board has HC04 module on Serial2 port
#define DEVICE_HAS_SYSTEMBOOT // board has a means to invoke the system bootloader on startup
#define DEVICE_HAS_SINGLE_LED // board has only one LED
Expand All @@ -87,6 +89,29 @@ Note: Some "high-level" features are set for each device in the device_conf.h fi
#include "device_conf.h"


//-- MATEKSYS mLRS devices

#ifdef RX_MATEK_MR24_30_G431KB
#include "matek/rx-hal-matek-mr24-30-g431kb.h"
#endif

#ifdef TX_MATEK_MR24_30_G431KB
#include "matek/tx-hal-matek-mr24-30-g431kb.h"
#endif

#ifdef RX_MATEK_MR900_30_G431KB
#include "matek/rx-hal-matek-mr900-30-g431kb.h"
#endif

#ifdef TX_MATEK_MR900_30_G431KB
#include "matek/tx-hal-matek-mr900-30-g431kb.h"
#endif

#ifdef RX_MATEK_MR900_22_WLE5CC
#include "matek/rx-hal-matek-mr900-22-wle5cc.h"
#endif


//-- FrsKy R9 system

#ifdef RX_R9MX_868_L433CB
Expand Down Expand Up @@ -277,7 +302,7 @@ Note: Some "high-level" features are set for each device in the device_conf.h fi
#endif
#endif

#if defined DEVICE_HAS_SERIAL2 || defined DEVICE_HAS_ESP_WIFI_BRIDGE_ON_SERIAL2
#if defined DEVICE_HAS_SERIAL2 || defined DEVICE_HAS_ESP_WIFI_BRIDGE_ON_SERIAL2 || defined DEVICE_HAS_HC04_MODULE_ON_SERIAL2
#define USE_SERIAL2
#endif
#endif // DEVICE_IS_TRANSMITTER
Expand Down Expand Up @@ -322,6 +347,10 @@ Note: Some "high-level" features are set for each device in the device_conf.h fi
#endif
#endif

#if defined DEVICE_HAS_HC04_MODULE_ON_SERIAL || defined DEVICE_HAS_HC04_MODULE_ON_SERIAL2
#define USE_HC04_MODULE
#endif


#if defined DEVICE_HAS_SX126x || defined DEVICE_HAS_DUAL_SX126x_SX128x || defined DEVICE_HAS_DUAL_SX126x_SX126x
#define SX_DRIVER Sx126xDriver
Expand Down
220 changes: 220 additions & 0 deletions mLRS/Common/hal/matek/hal-matek-mr-g431kb-common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
//*******************************************************
// Copyright (c) MLRS project
// GPL3
// https://www.gnu.org/licenses/gpl-3.0.de.html
//*******************************************************
// hal
//*******************************************************

//-------------------------------------------------------
// MATEKSYS mR24-30, mR900-30 STM32G431KB
//-------------------------------------------------------
// common HAL

/*
pins which are available for free use, i.e., are not used for LoRa
they are all broken out on the modules
label location pin functions alternative functions
Tx1 pin header PA9 U1_TX I2C2_SCL / T1_CH2 / T2_CH3
Rx1 pin header PA10 U1_RX T1_CH3 / T2_CH4
Tx2 pin header PB3 U2_TX T2_CH2
Rx2 pin header PB4 U2_RX T3_CH1 / T16_CH1
LT1 pin header PA2 LPU1_TX U2_TX / T2_CH3 / T15_CH1 / ADC1_IN3
LR1 pin header PA3 LPU1_RX U2_RX / T2_CH4 / T15_CH2 / ADC1_IN4
FAN solder pad PA8 GPIO I2C2_SDA / T1_CH1
D- solder pad PA11 USB DM T1_CH4 / T4_CH1 / FDCAN1_RX
D+ solder pad PA12 USB DP T4_CH2 / T16_CH1 / FDCAN1_TX
SWD solder pad PA13 SWDIO I2C1_SCL / T4_CH3
SWC solder pad PA14 SWDCLK I2C1_SDA / T8_CH2
*/

//-- Timers, Timing, EEPROM, and such stuff

#define DELAY_USE_DWT

#define EE_START_PAGE 60 // 128 kB flash, 2 kB page

#define MICROS_TIMx TIM3


//-- UARTS
//--


//-- SX1: SX12xx & SPI

#define SPI_USE_SPI1 // PA5, PA6, PA7
#define SPI_CS_IO IO_PA4
#define SPI_USE_CLK_LOW_1EDGE // datasheet says CPHA = 0 CPOL = 0
#define SPI_USE_CLOCKSPEED_9MHZ

#define SX_RESET IO_PB6
#define SX_DIO1 IO_PA15
#define SX_BUSY IO_PB5
#define SX_RX_EN IO_PB0
#define SX_TX_EN IO_PB7

#define SX_DIO1_SYSCFG_EXTI_PORTx LL_SYSCFG_EXTI_PORTA
#define SX_DIO1_SYSCFG_EXTI_LINEx LL_SYSCFG_EXTI_LINE15
#define SX_DIO_EXTI_LINE_x LL_EXTI_LINE_15
#define SX_DIO_EXTI_IRQn EXTI15_10_IRQn
#define SX_DIO_EXTI_IRQHandler EXTI15_10_IRQHandler
//#define SX_DIO_EXTI_IRQ_PRIORITY 11

void sx_init_gpio(void)
{
gpio_init(SX_RESET, IO_MODE_OUTPUT_PP_HIGH, IO_SPEED_VERYFAST);
gpio_init(SX_DIO1, IO_MODE_INPUT_PD, IO_SPEED_VERYFAST);
gpio_init(SX_BUSY, IO_MODE_INPUT_PU, IO_SPEED_VERYFAST);
gpio_init(SX_TX_EN, IO_MODE_OUTPUT_PP_LOW, IO_SPEED_VERYFAST);
gpio_init(SX_RX_EN, IO_MODE_OUTPUT_PP_LOW, IO_SPEED_VERYFAST);
}

bool sx_busy_read(void)
{
return (gpio_read_activehigh(SX_BUSY)) ? true : false;
}

void sx_amp_transmit(void)
{
gpio_low(SX_RX_EN);
gpio_high(SX_TX_EN);
}

void sx_amp_receive(void)
{
gpio_low(SX_TX_EN);
gpio_high(SX_RX_EN);
}

void sx_dio_init_exti_isroff(void)
{
LL_SYSCFG_SetEXTISource(SX_DIO1_SYSCFG_EXTI_PORTx, SX_DIO1_SYSCFG_EXTI_LINEx);

// let's not use LL_EXTI_Init(), but let's do it by hand, is easier to allow enabling isr later
LL_EXTI_DisableEvent_0_31(SX_DIO_EXTI_LINE_x);
LL_EXTI_DisableIT_0_31(SX_DIO_EXTI_LINE_x);
LL_EXTI_DisableFallingTrig_0_31(SX_DIO_EXTI_LINE_x);
LL_EXTI_EnableRisingTrig_0_31(SX_DIO_EXTI_LINE_x);

NVIC_SetPriority(SX_DIO_EXTI_IRQn, SX_DIO_EXTI_IRQ_PRIORITY);
NVIC_EnableIRQ(SX_DIO_EXTI_IRQn);
}

void sx_dio_enable_exti_isr(void)
{
LL_EXTI_ClearFlag_0_31(SX_DIO_EXTI_LINE_x);
LL_EXTI_EnableIT_0_31(SX_DIO_EXTI_LINE_x);
}

void sx_dio_exti_isr_clearflag(void)
{
LL_EXTI_ClearFlag_0_31(SX_DIO_EXTI_LINE_x);
}


//-- Button

#define BUTTON IO_PB8

void button_init(void)
{
gpio_init(BUTTON, IO_MODE_INPUT_PU, IO_SPEED_DEFAULT);
}

bool button_pressed(void)
{
return gpio_read_activehigh(BUTTON);
}


//-- LEDs

#define LED_GREEN IO_PA1
#define LED_RED IO_PA0

void leds_init(void)
{
gpio_init(LED_GREEN, IO_MODE_OUTPUT_PP_LOW, IO_SPEED_DEFAULT);
gpio_init(LED_RED, IO_MODE_OUTPUT_PP_LOW, IO_SPEED_DEFAULT);
gpio_low(LED_GREEN); // LED_GREEN_OFF
gpio_low(LED_RED); // LED_RED_OFF
}

void led_green_off(void) { gpio_low(LED_GREEN); }
void led_green_on(void) { gpio_high(LED_GREEN); }
void led_green_toggle(void) { gpio_toggle(LED_GREEN); }

void led_red_off(void) { gpio_low(LED_RED); }
void led_red_on(void) { gpio_high(LED_RED); }
void led_red_toggle(void) { gpio_toggle(LED_RED); }


//-- Cooling Fan

#define FAN_IO IO_PA8

void fan_init(void)
{
gpio_init(FAN_IO, IO_MODE_OUTPUT_PP_LOW, IO_SPEED_DEFAULT); // high = on
gpio_low(FAN_IO);
#ifdef DEVICE_HAS_FAN_TEMPCONTROLLED_ONOFF
fan_adc_init();
#endif
}

void fan_set_power(int8_t power_dbm)
{
if (power_dbm >= POWER_27_DBM) {
gpio_high(FAN_IO);
} else {
gpio_low(FAN_IO);
}
}

#ifdef DEVICE_HAS_FAN_TEMPCONTROLLED_ONOFF
#define FAN_TEMPSENS_ADCx ADC1
#include "../../thirdparty/stdstm32-adc-ext.h"
extern "C" { void delay_us(uint32_t us); }

void fan_adc_init(void)
{
adc_init_begin(FAN_TEMPSENS_ADCx);
adc_init_one_channel(FAN_TEMPSENS_ADCx);
adc_config_channel_tempsensor(FAN_TEMPSENS_ADCx, LL_ADC_REG_RANK_1);
adc_enable(FAN_TEMPSENS_ADCx);
delay_us(100);
adc_start_conversion(FAN_TEMPSENS_ADCx);
}

void fan_off(void) { gpio_low(FAN_IO); }
void fan_on(void) { gpio_high(FAN_IO); }

int16_t fan_tempsensor_read_dC(void)
{
return adc_tempsensor_convert_dC(LL_ADC_REG_ReadConversionData12(FAN_TEMPSENS_ADCx));
}
#endif


//-- POWER
//--


//-- TEST

uint32_t porta[] = {
LL_GPIO_PIN_0, LL_GPIO_PIN_1, LL_GPIO_PIN_2, LL_GPIO_PIN_3,
LL_GPIO_PIN_8, LL_GPIO_PIN_9, LL_GPIO_PIN_10, LL_GPIO_PIN_11, LL_GPIO_PIN_12,
};

uint32_t portb[] = {
LL_GPIO_PIN_3, LL_GPIO_PIN_4,
};

uint32_t portc[] = {
};


Loading

0 comments on commit 7301afe

Please sign in to comment.