From dd4849c8b7974d68b71e7195332a22734f70ee32 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Mon, 11 Nov 2024 13:04:40 +0300 Subject: [PATCH] [CH32] build with BASICMAC --- software/firmware/source/SoftRF/src/platform/CH32.cpp | 8 ++++++-- software/firmware/source/SoftRF/src/platform/CH32.h | 10 ++++++---- .../source/libraries/arduino-basicmac/src/hal/hal.cpp | 10 ++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/software/firmware/source/SoftRF/src/platform/CH32.cpp b/software/firmware/source/SoftRF/src/platform/CH32.cpp index c1f8f0e7e..de2d163d6 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.cpp +++ b/software/firmware/source/SoftRF/src/platform/CH32.cpp @@ -47,7 +47,7 @@ lmic_pinmap lmic_pins = { .rxe = LMIC_UNUSED_PIN, .rst = SOC_GPIO_PIN_RST, .dio = {LMIC_UNUSED_PIN, LMIC_UNUSED_PIN, LMIC_UNUSED_PIN}, - .busy = LMIC_UNUSED_PIN, + .busy = SOC_GPIO_PIN_BUSY, .tcxo = LMIC_UNUSED_PIN, }; @@ -310,6 +310,10 @@ static void CH32_setup() FATFS_is_mounted = fatfs.begin(SPIFlash); } +#if defined(USE_RADIOLIB) + lmic_pins.dio[0] = SOC_GPIO_PIN_DIO1; +#endif /* USE_RADIOLIB */ + Serial.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS); #if defined(USE_TINYUSB) && defined(USBCON) @@ -340,7 +344,7 @@ static void CH32_post_init() Serial.println(F("Built-in components:")); Serial.print(F("RADIO : ")); - Serial.println(hw_info.rf == RF_IC_SX1276 ? F("PASS") : F("FAIL")); + Serial.println(hw_info.rf != RF_IC_NONE ? F("PASS") : F("FAIL")); Serial.print(F("GNSS : ")); Serial.println(hw_info.gnss != GNSS_MODULE_NONE ? F("PASS") : F("FAIL")); diff --git a/software/firmware/source/SoftRF/src/platform/CH32.h b/software/firmware/source/SoftRF/src/platform/CH32.h index ffbe6b930..0338813ac 100644 --- a/software/firmware/source/SoftRF/src/platform/CH32.h +++ b/software/firmware/source/SoftRF/src/platform/CH32.h @@ -121,10 +121,10 @@ struct rst_info { #define SOC_GPIO_PIN_CE SOC_UNUSED_PIN #define SOC_GPIO_PIN_PWR SOC_UNUSED_PIN -/* SX1276 */ -#define SOC_GPIO_PIN_RST PB0 -#define SOC_GPIO_PIN_BUSY SOC_UNUSED_PIN -#define SOC_GPIO_PIN_DIO1 PA8 +/* SX12XX */ +#define SOC_GPIO_PIN_RST PB0 /* D9 */ +#define SOC_GPIO_PIN_BUSY PB9 /* D7 */ +#define SOC_GPIO_PIN_DIO1 PA8 /* D2 */ /* RF antenna switch */ #define SOC_GPIO_PIN_ANT_RXTX SOC_UNUSED_PIN @@ -258,6 +258,8 @@ struct rst_info { #define USE_TIME_SLOTS #define USE_OGN_ENCRYPTION +#define USE_BASICMAC +//#define EXCLUDE_SX1276 // - kb #define USE_RADIOLIB //#define ENABLE_RECORDER diff --git a/software/firmware/source/libraries/arduino-basicmac/src/hal/hal.cpp b/software/firmware/source/libraries/arduino-basicmac/src/hal/hal.cpp index bcc426f8e..ee4540716 100644 --- a/software/firmware/source/libraries/arduino-basicmac/src/hal/hal.cpp +++ b/software/firmware/source/libraries/arduino-basicmac/src/hal/hal.cpp @@ -28,6 +28,12 @@ extern SoftSPI RadioSPI; #define SPI RadioSPI #endif /* ARDUINO_ARCH_RENESAS */ +#if defined(ARDUINO_ARCH_CH32) +extern SPIClass RadioSPI; +#undef SPI +#define SPI RadioSPI +#endif /* ARDUINO_ARCH_CH32 */ + #include "../basicmac.h" #include "hal.h" #define _GNU_SOURCE 1 // For fopencookie @@ -552,8 +558,8 @@ u1_t hal_checkTimer (u4_t time) { defined(__ASR6501__) || defined(ARDUINO_ARCH_ASR650X) || \ defined(RASPBERRY_PI) || defined(ARDUINO_ARCH_SAMD) || \ defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_ARCH_ASR6601) || \ - defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350) || \ - defined(ARDUINO_ARCH_RENESAS) + defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350) || \ + defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_CH32) // Fix for STM32 HAL based cores.