From e99980f1bf0c0926269a7e30711b1714b3eac9ff Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Tue, 8 Aug 2023 02:07:07 +0200 Subject: [PATCH] fix(x12s): init periph clocks in ads79xx driver (#3810) --- .../targets/common/arm/stm32/CMakeLists.txt | 1 + .../src/targets/common/arm/stm32/ads79xx.cpp | 4 ++ .../targets/common/arm/stm32/stm32_spi.cpp | 55 +++++++++++++++++++ .../arm/stm32/stm32_spi.h} | 4 +- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 radio/src/targets/common/arm/stm32/stm32_spi.cpp rename radio/src/targets/{horus/x12s_adc_driver.h => common/arm/stm32/stm32_spi.h} (90%) diff --git a/radio/src/targets/common/arm/stm32/CMakeLists.txt b/radio/src/targets/common/arm/stm32/CMakeLists.txt index 7bf033e35..1e0112bf0 100644 --- a/radio/src/targets/common/arm/stm32/CMakeLists.txt +++ b/radio/src/targets/common/arm/stm32/CMakeLists.txt @@ -43,6 +43,7 @@ set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC} ../common/arm/stm32/module_timer_driver.cpp ../common/arm/stm32/stm32_switch_driver.cpp ../common/arm/stm32/stm32_adc.cpp + ../common/arm/stm32/stm32_spi.cpp ../common/arm/stm32/stm32_timer.cpp ../common/arm/stm32/stm32_dma.cpp ../common/arm/stm32/stm32_gpio_driver.cpp diff --git a/radio/src/targets/common/arm/stm32/ads79xx.cpp b/radio/src/targets/common/arm/stm32/ads79xx.cpp index 3040f880a..b91b5113f 100644 --- a/radio/src/targets/common/arm/stm32/ads79xx.cpp +++ b/radio/src/targets/common/arm/stm32/ads79xx.cpp @@ -20,6 +20,8 @@ */ #include "ads79xx.h" +#include "stm32_spi.h" +#include "stm32_gpio_driver.h" #include "delays_driver.h" #include "stm32_hal_ll.h" @@ -39,6 +41,7 @@ static uint16_t ads79xx_rw(SPI_TypeDef* SPIx, uint16_t value) void ads79xx_init(const stm32_spi_adc_t* adc) { + stm32_gpio_enable_clock(adc->GPIOx); LL_GPIO_InitTypeDef pinInit; LL_GPIO_StructInit(&pinInit); @@ -53,6 +56,7 @@ void ads79xx_init(const stm32_spi_adc_t* adc) LL_GPIO_Init(adc->GPIOx, &pinInit); auto SPIx = adc->SPIx; + stm32_spi_enable_clock(SPIx); LL_SPI_DeInit(SPIx); LL_SPI_InitTypeDef spiInit; diff --git a/radio/src/targets/common/arm/stm32/stm32_spi.cpp b/radio/src/targets/common/arm/stm32/stm32_spi.cpp new file mode 100644 index 000000000..711f03790 --- /dev/null +++ b/radio/src/targets/common/arm/stm32/stm32_spi.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) EdgeTx + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "stm32_spi.h" + +void stm32_spi_enable_clock(SPI_TypeDef *SPIx) +{ + if (SPIx == SPI1) { + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1); + } +#if defined(SPI2) + else if (SPIx == SPI2) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2); + } +#endif +#if defined(SPI3) + else if (SPIx == SPI3) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3); + } +#endif +#if defined(SPI4) + else if (SPIx == SPI4) { + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI4); + } +#endif +#if defined(SPI5) + else if (SPIx == SPI5) { + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI5); + } +#endif +#if defined(SPI6) + else if (SPIx == SPI6) { + LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI6); + } +#endif +} + diff --git a/radio/src/targets/horus/x12s_adc_driver.h b/radio/src/targets/common/arm/stm32/stm32_spi.h similarity index 90% rename from radio/src/targets/horus/x12s_adc_driver.h rename to radio/src/targets/common/arm/stm32/stm32_spi.h index 7e8fc8c2c..77dbd72db 100644 --- a/radio/src/targets/horus/x12s_adc_driver.h +++ b/radio/src/targets/common/arm/stm32/stm32_spi.h @@ -21,6 +21,6 @@ #pragma once -#include "hal/adc_driver.h" +#include "stm32_hal_ll.h" -extern const etx_hal_adc_driver_t x12s_adc_driver; +void stm32_spi_enable_clock(SPI_TypeDef *SPIx);