Skip to content

Commit

Permalink
[CH32] bring up of GNSS and sub-1GHz radio
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Oct 29, 2024
1 parent aa15769 commit ad4b3d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
21 changes: 15 additions & 6 deletions software/firmware/source/SoftRF/src/platform/CH32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ static bool ADB_is_open = false;
HardwareSerial Serial2(USART2);
HardwareSerial Serial3(USART3);

//SPIClass SPI_1;
#include <SoftSPI.h>
#if defined(USE_SOFTSPI)
SoftSPI RadioSPI(SOC_GPIO_PIN_MOSI, SOC_GPIO_PIN_MISO, SOC_GPIO_PIN_SCK);
#else
SPIClass RadioSPI(SOC_GPIO_PIN_MOSI, SOC_GPIO_PIN_MISO,
SOC_GPIO_PIN_SCK, SOC_GPIO_PIN_SS);
#endif /* USE_SOFTSPI */

//SPIClass SPI_1;
SoftSPI Flash_SPI(SOC_GPIO_YD_FL_MOSI, SOC_GPIO_YD_FL_MISO, SOC_GPIO_YD_FL_CLK);

static Adafruit_SPIFlash *SPIFlash = NULL;
Expand Down Expand Up @@ -194,10 +201,12 @@ static void CH32_setup()
Serial_GNSS_In.setRx(SOC_GPIO_PIN_GNSS_RX);
Serial_GNSS_In.setTx(SOC_GPIO_PIN_GNSS_TX);

SPI.setMISO(SOC_GPIO_PIN_MISO);
SPI.setMOSI(SOC_GPIO_PIN_MOSI);
SPI.setSCLK(SOC_GPIO_PIN_SCK);
SPI.setSSEL(SOC_GPIO_PIN_SS);
#if !defined(USE_SOFTSPI)
RadioSPI.setMISO(SOC_GPIO_PIN_MISO);
RadioSPI.setMOSI(SOC_GPIO_PIN_MOSI);
RadioSPI.setSCLK(SOC_GPIO_PIN_SCK);
RadioSPI.setSSEL(SOC_GPIO_PIN_SS);
#endif /* USE_SOFTSPI */

Wire.setSCL(SOC_GPIO_PIN_SCL);
Wire.setSDA(SOC_GPIO_PIN_SDA);
Expand Down Expand Up @@ -555,7 +564,7 @@ static void CH32_EEPROM_extension(int cmd)

static void CH32_SPI_begin()
{
SPI.begin();
RadioSPI.begin();
}

static void CH32_swSer_begin(unsigned long baud)
Expand Down
6 changes: 6 additions & 0 deletions software/firmware/source/SoftRF/src/platform/CH32.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ struct rst_info {
#define SOC_GPIO_PIN_SCK PB13
#define SOC_GPIO_PIN_SS PB12

#include <SoftSPI.h>
extern SoftSPI RadioSPI;
#undef SPI
#define SPI RadioSPI
#define USE_SOFTSPI

/* NRF905 */
#define SOC_GPIO_PIN_TXE SOC_UNUSED_PIN
#define SOC_GPIO_PIN_CE SOC_UNUSED_PIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#include <cc13xx/cc13xx.h>
#endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */

#if defined(ARDUINO_ARCH_RENESAS) // || defined(ARDUINO_ARCH_SILABS)
#if defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_CH32)
#include <SoftSPI.h>
extern SoftSPI RadioSPI;
#undef SPI
#define SPI RadioSPI
#endif /* ARDUINO_ARCH_RENESAS || ARDUINO_ARCH_SILABS */
#endif /* ARDUINO_ARCH_RENESAS || ARDUINO_ARCH_CH32 */

#include "../lmic.h"
#include "hal.h"
Expand Down Expand Up @@ -422,7 +422,7 @@ u1_t hal_checkTimer (u4_t time) {
}

#if defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_SAMD) || \
defined(ARDUINO_ARCH_RENESAS)
defined(ARDUINO_ARCH_RENESAS) || defined(ARDUINO_ARCH_CH32)

// Fix for STM32 HAL based cores.

Expand Down

0 comments on commit ad4b3d0

Please sign in to comment.