From 6cdec19cb7f331c577678ef186bef69b3db0f41e Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 13 Aug 2025 18:44:54 +0200 Subject: [PATCH] MD-UV3x0: using new STM32 GPS driver --- meson.build | 3 ++- platform/targets/MD-UV3x0/hwconfig.c | 23 +++++++++++++++++++++- platform/targets/MD-UV3x0/hwconfig.h | 3 +++ platform/targets/MD-UV3x0/platform.c | 29 ++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 74a2293c..86a20fe4 100644 --- a/meson.build +++ b/meson.build @@ -403,7 +403,8 @@ md3x0_def += openrtx_def + stm32f405_def mduv3x0_src = ['platform/drivers/CPS/cps_io_native_MDUV3x0.c', 'platform/targets/MD-UV3x0/platform.c', 'platform/targets/MD-UV3x0/hwconfig.c', - 'platform/drivers/GPS/GPS_MDx.cpp', + 'platform/drivers/GPS/gps_stm32.cpp', + 'platform/drivers/GPS/nmea_rbuf.c', 'platform/drivers/keyboard/keyboard_MD3x.c', 'platform/drivers/display/HX8353_MD3x.cpp', 'platform/drivers/backlight/backlight_MDx.c', diff --git a/platform/targets/MD-UV3x0/hwconfig.c b/platform/targets/MD-UV3x0/hwconfig.c index 2db49a49..171607e8 100644 --- a/platform/targets/MD-UV3x0/hwconfig.c +++ b/platform/targets/MD-UV3x0/hwconfig.c @@ -25,7 +25,8 @@ #include #include #include - +#include +#include static pthread_mutex_t c6000_mutex; static pthread_mutex_t adcMutex; @@ -73,6 +74,26 @@ static uint8_t spiC6000_func(const void *priv, uint8_t value) return incoming; } +static void gpsEnable(void *priv) +{ + gpio_setPin(GPS_EN); + gpsStm32_enable(priv); +} + +static void gpsDisable(void *priv) +{ + gpio_clearPin(GPS_EN); + gpsStm32_disable(priv); +} + SPI_CUSTOM_DEVICE_DEFINE(c6000_spi, spiC6000_func, NULL, &c6000_mutex) SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL) ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adcMutex, ADC_COUNTS_TO_UV(3300000, 12)) + +const struct gpsDevice gps = +{ + .priv = NULL, + .enable = gpsEnable, + .disable = gpsDisable, + .getSentence = gpsStm32_getNmeaSentence +}; diff --git a/platform/targets/MD-UV3x0/hwconfig.h b/platform/targets/MD-UV3x0/hwconfig.h index 2d48011b..48e2ab20 100644 --- a/platform/targets/MD-UV3x0/hwconfig.h +++ b/platform/targets/MD-UV3x0/hwconfig.h @@ -40,6 +40,7 @@ enum AdcChannel ADC_MIC_CH = 3, }; +extern const struct gpsDevice gps; extern const struct spiCustomDevice c6000_spi; extern const struct spiDevice nvm_spi; extern const struct Adc adc1; @@ -49,6 +50,8 @@ extern const struct Adc adc1; /* Device supports an optional GPS chip */ #define CONFIG_GPS +#define CONFIG_GPS_STM32_USART1 +#define CONFIG_NMEA_RBUF_SIZE 128 /* Screen dimensions */ #define CONFIG_SCREEN_WIDTH 160 diff --git a/platform/targets/MD-UV3x0/platform.c b/platform/targets/MD-UV3x0/platform.c index cf6baa2d..523ddcac 100644 --- a/platform/targets/MD-UV3x0/platform.c +++ b/platform/targets/MD-UV3x0/platform.c @@ -18,6 +18,7 @@ ***************************************************************************/ #include +#include #include #include #include @@ -29,6 +30,8 @@ #include #include #include +#include +#include #ifdef CONFIG_SCREEN_BRIGHTNESS #include @@ -72,6 +75,7 @@ void platform_terminate() /* Shut down all the modules */ adcStm32_terminate(&adc1); + gpsStm32_terminate(); nvm_terminate(); toneGen_terminate(); chSelector_terminate(); @@ -209,6 +213,31 @@ const hwInfo_t *platform_getHwInfo() return &hwInfo; } +const struct gpsDevice *platform_initGps() +{ + const struct gpsDevice *dev = NULL; + + // Turn on the GPS and check if there is voltage on the RXD pin + gpio_setMode(GPS_DATA, INPUT_PULL_DOWN); + gpio_setMode(GPS_EN, OUTPUT); + gpio_setPin(GPS_EN); + + for(size_t i = 0; i < 50; i++) { + if(gpio_readPin(GPS_DATA) != 0) { + dev = &gps; + gpsStm32_init(9600); + break; + } + + sleepFor(0, 1); + } + + gpio_clearPin(GPS_EN); + gpio_setMode(GPS_DATA, ALTERNATE | ALTERNATE_FUNC(7)); + + return dev; +} + /* * NOTE: implementation of this API function is provided in * platform/drivers/chSelector/chSelector_MDUV3x0.c