feat: Radiomaster TX15 support (#6484)
Co-authored-by: Malte Langermann <54738901+gagarinlg@users.noreply.github.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com> Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
co-authored by
Malte Langermann
3djc
raphaelcoeffic
philmoz
Peter Feerick
parent
3a00c0812b
commit
324b2c7761
@@ -90,18 +90,15 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(SDMMC1) && defined(SD_SDIO)
|
||||
# if !defined(SD_SDIO_IRQHandler)
|
||||
# define SD_SDIO_IRQHandler SDMMC1_IRQHandler
|
||||
# define SD_SDIO_IRQn SDMMC1_IRQn
|
||||
# endif
|
||||
#if defined(SDMMC1)
|
||||
# define SD_SDIO_TypeDef SDMMC_TypeDef
|
||||
# define SD_SDIO_CLOCK_EDGE_RISING SDMMC_CLOCK_EDGE_RISING
|
||||
# define SD_SDIO_CLOCK_POWER_SAVE_DISABLE SDMMC_CLOCK_POWER_SAVE_DISABLE
|
||||
# define SD_SDIO_BUS_WIDE_1B SDMMC_BUS_WIDE_1B
|
||||
# define SD_SDIO_BUS_WIDE_4B SDMMC_BUS_WIDE_4B
|
||||
# define SD_SDIO_HARDWARE_FLOW_CONTROL_DISABLE SDMMC_HARDWARE_FLOW_CONTROL_DISABLE
|
||||
#elif !defined(SDMMC1)
|
||||
# define SD_SDIO_IRQn SDMMC1_IRQn
|
||||
#else
|
||||
# if !defined(SD_SDIO)
|
||||
# define SD_SDIO SDIO
|
||||
# endif
|
||||
@@ -118,6 +115,24 @@
|
||||
# define SD_SDIO_HARDWARE_FLOW_CONTROL_DISABLE SDIO_HARDWARE_FLOW_CONTROL_DISABLE
|
||||
#endif
|
||||
|
||||
struct {
|
||||
SD_SDIO_TypeDef* periph = SD_SDIO;
|
||||
gpio_t D0 = SD_SDIO_PIN_D0;
|
||||
gpio_t D1 = SD_SDIO_PIN_D1;
|
||||
gpio_t D2 = SD_SDIO_PIN_D2;
|
||||
gpio_t D3 = SD_SDIO_PIN_D3;
|
||||
gpio_t CMD = SD_SDIO_PIN_CMD;
|
||||
gpio_t CLK = SD_SDIO_PIN_CLK;
|
||||
gpio_af_t AF_D0 = SD_SDIO_AF_D0;
|
||||
gpio_af_t AF_D1 = SD_SDIO_AF_D1;
|
||||
gpio_af_t AF_D2 = SD_SDIO_AF_D2;
|
||||
gpio_af_t AF_D3 = SD_SDIO_AF_D3;
|
||||
gpio_af_t AF_CMD = SD_SDIO_AF_CMD;
|
||||
gpio_af_t AF_CLK = SD_SDIO_AF_CLK;
|
||||
IRQn_Type IRQn = SD_SDIO_IRQn;
|
||||
uint32_t SD_CLK_DIV = SD_SDIO_TRANSFER_CLK_DIV;
|
||||
} currentSD;
|
||||
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
#error "Variable sector size is not supported"
|
||||
#endif
|
||||
@@ -156,8 +171,12 @@ extern uint32_t _heap_start;
|
||||
// HAL state
|
||||
static SD_HandleTypeDef sdio;
|
||||
#if defined(SD_SDIO_DMA)
|
||||
#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32H5)
|
||||
static_assert(false,"H7/H5 use dedicated DMA controler");
|
||||
#else
|
||||
static DMA_HandleTypeDef sdioTxDma;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Disk status
|
||||
static volatile uint32_t WriteStatus;
|
||||
@@ -179,26 +198,26 @@ static void _sd_sdio_clk_enable(SD_SDIO_TypeDef* periph)
|
||||
|
||||
static void sdio_low_level_init(void)
|
||||
{
|
||||
_sd_sdio_clk_enable(SD_SDIO);
|
||||
_sd_sdio_clk_enable(currentSD.periph);
|
||||
|
||||
// data pins
|
||||
gpio_init(SD_SDIO_PIN_D0, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_D0, SD_SDIO_AF_D0);
|
||||
gpio_init(currentSD.D0, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.D0, currentSD.AF_D0);
|
||||
|
||||
gpio_init(SD_SDIO_PIN_D1, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_D1, SD_SDIO_AF_D1);
|
||||
|
||||
gpio_init(SD_SDIO_PIN_D2, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_D2, SD_SDIO_AF_D2);
|
||||
gpio_init(currentSD.D1, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.D1, currentSD.AF_D1);
|
||||
|
||||
gpio_init(SD_SDIO_PIN_D3, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_D3, SD_SDIO_AF_D3);
|
||||
gpio_init(currentSD.D2, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.D2, currentSD.AF_D2);
|
||||
|
||||
gpio_init(SD_SDIO_PIN_CMD, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_CMD, SD_SDIO_AF_CMD);
|
||||
|
||||
gpio_init(SD_SDIO_PIN_CLK, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(SD_SDIO_PIN_CLK, SD_SDIO_AF_CLK);
|
||||
gpio_init(currentSD.D3, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.D3, currentSD.AF_D3);
|
||||
|
||||
gpio_init(currentSD.CMD, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.CMD, currentSD.AF_CMD);
|
||||
|
||||
gpio_init(currentSD.CLK, GPIO_IN_PU, GPIO_PIN_SPEED_VERY_HIGH);
|
||||
gpio_set_af(currentSD.CLK, currentSD.AF_CLK);
|
||||
|
||||
#if defined(SD_SDIO_HAS_TRANSCEIVER)
|
||||
gpio_init_af(SD_SDIO_PIN_CKIN, SD_SDIO_AF_CKIN, GPIO_PIN_SPEED_HIGH);
|
||||
@@ -208,8 +227,8 @@ static void sdio_low_level_init(void)
|
||||
#endif
|
||||
|
||||
// SDIO Interrupt ENABLE
|
||||
NVIC_SetPriority(SD_SDIO_IRQn, 0);
|
||||
NVIC_EnableIRQ(SD_SDIO_IRQn);
|
||||
NVIC_SetPriority(currentSD.IRQn, 0);
|
||||
NVIC_EnableIRQ(currentSD.IRQn);
|
||||
|
||||
#if defined(SD_SDIO_DMA)
|
||||
// Init SDIO DMA instance
|
||||
@@ -231,7 +250,7 @@ static void sdio_low_level_init(void)
|
||||
|
||||
__HAL_LINKDMA(&sdio, hdmatx, sdioTxDma);
|
||||
__HAL_LINKDMA(&sdio, hdmarx, sdioTxDma);
|
||||
|
||||
|
||||
// DMA2 STREAMx Interrupt ENABLE
|
||||
NVIC_SetPriority(SD_SDIO_DMA_IRQn, 0);
|
||||
NVIC_EnableIRQ(SD_SDIO_DMA_IRQn);
|
||||
@@ -241,6 +260,27 @@ static void sdio_low_level_init(void)
|
||||
HAL_SD_CardInfoTypeDef cardInfo;
|
||||
static DSTATUS sdio_initialize(BYTE lun)
|
||||
{
|
||||
#if defined(SD2_PRESENT_GPIO)
|
||||
/* Define active SD */
|
||||
if (gpio_read(SD2_PRESENT_GPIO) == 0) {
|
||||
currentSD.periph = SDMMC2;
|
||||
currentSD.D0 = SD2_SDIO_PIN_D0;
|
||||
currentSD.AF_D0 = SD2_SDIO_AF_D0;
|
||||
currentSD.D1 = SD2_SDIO_PIN_D1;
|
||||
currentSD.AF_D1 = SD2_SDIO_AF_D1;
|
||||
currentSD.D2 = SD2_SDIO_PIN_D2;
|
||||
currentSD.AF_D2 = SD2_SDIO_AF_D2;
|
||||
currentSD.D3 = SD2_SDIO_PIN_D3;
|
||||
currentSD.AF_D3 = SD2_SDIO_AF_D3;
|
||||
currentSD.CMD = SD2_SDIO_PIN_CMD;
|
||||
currentSD.AF_CMD = SD2_SDIO_AF_CMD;
|
||||
currentSD.CLK = SD2_SDIO_PIN_CLK;
|
||||
currentSD.AF_CLK = SD2_SDIO_AF_CLK;
|
||||
currentSD.IRQn = SDMMC2_IRQn;
|
||||
currentSD.SD_CLK_DIV = SD2_SDIO_TRANSFER_CLK_DIV;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* SDIO Peripheral Low Level Init */
|
||||
sdio_low_level_init();
|
||||
|
||||
@@ -248,7 +288,7 @@ static DSTATUS sdio_initialize(BYTE lun)
|
||||
/*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
|
||||
/*!< on STM32F4xx devices, SDIOCLK is fixed to 48MHz */
|
||||
|
||||
sdio.Instance = SD_SDIO;
|
||||
sdio.Instance = currentSD.periph;
|
||||
sdio.Init.ClockEdge = SD_SDIO_CLOCK_EDGE_RISING;
|
||||
sdio.Init.ClockPowerSave = SD_SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
sdio.Init.BusWide = SD_SDIO_BUS_WIDE_1B;
|
||||
@@ -259,7 +299,7 @@ static DSTATUS sdio_initialize(BYTE lun)
|
||||
#if defined(SD_SDIO_CLOCK_BYPASS_DISABLE)
|
||||
sdio.Init.ClockBypass = SD_SDIO_CLOCK_BYPASS_DISABLE;
|
||||
#endif
|
||||
sdio.Init.ClockDiv = SD_SDIO_TRANSFER_CLK_DIV;
|
||||
sdio.Init.ClockDiv = currentSD.SD_CLK_DIV;
|
||||
|
||||
HAL_StatusTypeDef halStatus = HAL_SD_Init(&sdio);
|
||||
if (halStatus != HAL_OK) {
|
||||
@@ -311,7 +351,7 @@ static SDTransferState sdio_check_card_state()
|
||||
else if (cardstate == HAL_SD_CARD_ERROR) {
|
||||
return SD_TRANSFER_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return SD_TRANSFER_BUSY;
|
||||
}
|
||||
|
||||
@@ -333,7 +373,11 @@ static DSTATUS sdio_status(BYTE lun)
|
||||
{
|
||||
DSTATUS stat = RES_OK;
|
||||
|
||||
#if defined(SD_PRESENT_GPIO)
|
||||
#if defined(SD2_PRESENT_GPIO)
|
||||
if (currentSD.periph == SDMMC2 && gpio_read(SD2_PRESENT_GPIO)) {
|
||||
stat |= STA_NODISK;
|
||||
}
|
||||
#elif defined(SD_PRESENT_GPIO)
|
||||
if (gpio_read(SD_PRESENT_GPIO)) {
|
||||
stat |= STA_NODISK;
|
||||
}
|
||||
@@ -551,12 +595,28 @@ extern "C" void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)
|
||||
ReadStatus = 1;
|
||||
}
|
||||
|
||||
#if defined(SDMMC1)
|
||||
#if defined(SDMMC1)
|
||||
extern "C" void SDMMC1_IRQHandler(void)
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_SDIO);
|
||||
HAL_SD_IRQHandler(&sdio);
|
||||
}
|
||||
#endif
|
||||
#if defined(SDMMC2) && defined(SD2_PRESENT_GPIO)
|
||||
extern "C" void SDMMC2_IRQHandler(void)
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_SDIO);
|
||||
HAL_SD_IRQHandler(&sdio);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
extern "C" void SD_SDIO_IRQHandler(void)
|
||||
{
|
||||
DEBUG_INTERRUPT(INT_SDIO);
|
||||
HAL_SD_IRQHandler(&sdio);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(SD_SDIO_DMA)
|
||||
extern "C" void SD_SDIO_DMA_IRQHANDLER(void)
|
||||
{
|
||||
|
||||
@@ -48,8 +48,10 @@ static const stm32_usart_t fsUSART = {
|
||||
.IRQn = FLYSKY_HALL_SERIAL_USART_IRQn,
|
||||
.IRQ_Prio = 4,
|
||||
.txDMA = FLYSKY_HALL_SERIAL_DMA,
|
||||
#if defined(FLYSKY_HALL_DMA_Stream_TX)
|
||||
.txDMA_Stream = FLYSKY_HALL_DMA_Stream_TX,
|
||||
.txDMA_Channel = FLYSKY_HALL_DMA_Channel,
|
||||
#endif
|
||||
.rxDMA = FLYSKY_HALL_SERIAL_DMA,
|
||||
.rxDMA_Stream = FLYSKY_HALL_DMA_Stream_RX,
|
||||
.rxDMA_Channel = FLYSKY_HALL_DMA_Channel,
|
||||
@@ -263,12 +265,17 @@ bool flysky_gimbal_init()
|
||||
{
|
||||
if (flysky_gimbal_init_uart() != 0) return false;
|
||||
|
||||
// Wait 70ms for FlySky gimbals to respond. According to LA trace, minimally
|
||||
// 23ms is required
|
||||
_fs_gimbal_detected = false;
|
||||
|
||||
for (uint8_t i = 0; i < 70; i++) {
|
||||
// Wait 70ms for serial gimbals to respond
|
||||
for (uint16_t i = 0; i < 70; i++) {
|
||||
#if defined(HALL_SYNC) && !defined(SIMU)
|
||||
gpio_set(HALL_SYNC);
|
||||
#endif
|
||||
delay_ms(1);
|
||||
#if defined(HALL_SYNC) && !defined(SIMU)
|
||||
gpio_clear(HALL_SYNC);
|
||||
#endif
|
||||
if (_fs_gimbal_detected) {
|
||||
// Try to obtain the version of gimbal for operation mode selection
|
||||
_fs_cmd_get_version();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define __INIT_HOOK __attribute__((section(".init_hook")))
|
||||
|
||||
#define __CCMRAM __attribute__((section(".ccm"), aligned(4)))
|
||||
#define __DMA __attribute__((section(".ram"), aligned(4)))
|
||||
#define __DMA __attribute__((section(".ram"), aligned(32)))
|
||||
#define __DMA_NO_CACHE __attribute__((section(".dram"), aligned(4)))
|
||||
#define __IRAM __attribute__((section(".iram")))
|
||||
#define __SDRAM __attribute__((section(".sdram"), aligned(4)))
|
||||
|
||||
@@ -32,6 +32,10 @@ void pwrInit()
|
||||
gpio_init(SD_PRESENT_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
#if defined(SD2_PRESENT_GPIO)
|
||||
gpio_init(SD2_PRESENT_GPIO, GPIO_IN_PU, GPIO_PIN_SPEED_LOW);
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_BOOTCMD_GPIO)
|
||||
gpio_init(INTMODULE_BOOTCMD_GPIO, GPIO_OUT, GPIO_PIN_SPEED_LOW);
|
||||
gpio_write(INTMODULE_BOOTCMD_GPIO, INTMODULE_BOOTCMD_DEFAULT);
|
||||
|
||||
@@ -154,6 +154,7 @@ void rotaryEncoderStartDelay()
|
||||
|
||||
void rotaryEncoderInit()
|
||||
{
|
||||
#if defined(ROTARY_ENCODER_GPIO)
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
@@ -186,6 +187,44 @@ void rotaryEncoderInit()
|
||||
uint32_t trigger = LL_EXTI_TRIGGER_RISING_FALLING;
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE1, trigger, rotaryEncoderStartDelay);
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE2, trigger, rotaryEncoderStartDelay);
|
||||
#else
|
||||
LL_GPIO_InitTypeDef pinInit;
|
||||
LL_GPIO_StructInit(&pinInit);
|
||||
pinInit.Mode = LL_GPIO_MODE_INPUT;
|
||||
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||
pinInit.Pin = ROTARY_ENCODER_GPIO_PIN_A;
|
||||
|
||||
stm32_gpio_enable_clock(ROTARY_ENCODER_GPIO_A);
|
||||
stm32_gpio_enable_clock(ROTARY_ENCODER_GPIO_B);
|
||||
LL_GPIO_Init(ROTARY_ENCODER_GPIO_A, &pinInit);
|
||||
pinInit.Pin = ROTARY_ENCODER_GPIO_PIN_B;
|
||||
LL_GPIO_Init(ROTARY_ENCODER_GPIO_B, &pinInit);
|
||||
|
||||
stm32_timer_enable_clock(ROTARY_ENCODER_TIMER);
|
||||
ROTARY_ENCODER_TIMER->ARR = 99; // 100uS
|
||||
ROTARY_ENCODER_TIMER->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 1000000 - 1; // 1uS
|
||||
ROTARY_ENCODER_TIMER->CCER = 0;
|
||||
ROTARY_ENCODER_TIMER->CCMR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->EGR = 0;
|
||||
ROTARY_ENCODER_TIMER->CR1 = 0;
|
||||
ROTARY_ENCODER_TIMER->DIER |= TIM_DIER_UIE;
|
||||
|
||||
#if defined(LL_APB4_GRP1_PERIPH_SYSCFG)
|
||||
LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_SYSCFG);
|
||||
#elif defined(LL_APB2_GRP1_PERIPH_SYSCFG)
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
|
||||
#else
|
||||
#error "Unsupported SYSCFG clock"
|
||||
#endif
|
||||
|
||||
LL_SYSCFG_SetEXTISource(ROTARY_ENCODER_EXTI_PORT_A, ROTARY_ENCODER_EXTI_SYS_LINE1);
|
||||
LL_SYSCFG_SetEXTISource(ROTARY_ENCODER_EXTI_PORT_B, ROTARY_ENCODER_EXTI_SYS_LINE2);
|
||||
|
||||
uint32_t trigger = LL_EXTI_TRIGGER_RISING_FALLING;
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE1, trigger, rotaryEncoderStartDelay);
|
||||
stm32_exti_enable(ROTARY_ENCODER_EXTI_LINE2, trigger, rotaryEncoderStartDelay);
|
||||
#endif
|
||||
|
||||
|
||||
NVIC_EnableIRQ(ROTARY_ENCODER_TIMER_IRQn);
|
||||
NVIC_SetPriority(ROTARY_ENCODER_TIMER_IRQn, 7);
|
||||
|
||||
@@ -67,8 +67,14 @@ void rtcInit()
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
#endif
|
||||
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
#if defined(LSE_DRIVE_STRENGTH)
|
||||
__HAL_RCC_LSE_CONFIG(RCC_LSE_OFF);
|
||||
__HAL_RCC_LSEDRIVE_CONFIG(LSE_DRIVE_STRENGTH);
|
||||
#endif
|
||||
|
||||
// Enable LSE Oscillator
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {};
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
|
||||
#if !defined(STM32H7RS) && !defined(STM32H5)
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||
|
||||
@@ -33,8 +33,12 @@
|
||||
#include <string.h>
|
||||
#include "FreeRTOSConfig.h"
|
||||
|
||||
|
||||
#define OVERSAMPLING 4
|
||||
#if defined(STM32H7) || defined(STM32H7RS) || defined(STM32H5)
|
||||
// Disable software oversampling as HW one is used
|
||||
#define OVERSAMPLING 1
|
||||
#else
|
||||
#define OVERSAMPLING 4
|
||||
#endif
|
||||
|
||||
#define SAMPLING_TIMEOUT_US 500
|
||||
|
||||
@@ -78,6 +82,9 @@ static uint8_t _adc_run;
|
||||
static uint8_t _adc_oversampling_disabled;
|
||||
static uint16_t _adc_oversampling[MAX_ADC_INPUTS];
|
||||
|
||||
// Indicates ADC timeout has occured
|
||||
static bool _adc_timeout_error;
|
||||
|
||||
void stm32_hal_set_inputs_mask(uint32_t inputs)
|
||||
{
|
||||
_adc_input_inhibt_mask |= inputs;
|
||||
@@ -232,6 +239,12 @@ static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv)
|
||||
wait_loop_index--;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start ADC calibration in mode single-ended or differential */
|
||||
LL_ADC_StartCalibration(ADCx, LL_ADC_CALIB_OFFSET_LINEARITY, LL_ADC_SINGLE_ENDED);
|
||||
|
||||
/* Wait for calibration completion */
|
||||
while (LL_ADC_IsCalibrationOnGoing(ADCx) != 0UL);
|
||||
#endif
|
||||
|
||||
#if defined(LL_ADC_RESOLUTION_12B_OPT)
|
||||
@@ -253,6 +266,17 @@ static void adc_setup_scan_mode(ADC_TypeDef* ADCx, uint8_t nconv)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(STM32H7RS) || defined(STM32H7) || defined(STM32H5)
|
||||
// set hardware oversampling
|
||||
if (!_adc_oversampling_disabled && ADCx != ADC3) {
|
||||
// LL_ADC_OVS_RATIO_x in stm32h7xx_ll_adc.h is broken
|
||||
// so actual oversampling count need to be used
|
||||
// ADC3 oversampling is disabled because of issues in LL libs
|
||||
LL_ADC_ConfigOverSamplingRatioShift(ADCx, 16, LL_ADC_OVS_SHIFT_RIGHT_4);
|
||||
LL_ADC_SetOverSamplingScope(ADCx, LL_ADC_OVS_GRP_REGULAR_CONTINUED);
|
||||
}
|
||||
#endif
|
||||
|
||||
LL_ADC_REG_Init(ADCx, &adcRegInit);
|
||||
|
||||
// Enable ADC
|
||||
@@ -756,10 +780,12 @@ void stm32_hal_adc_wait_completion(const stm32_adc_t* ADCs, uint8_t n_ADC,
|
||||
// busy wait
|
||||
if ((uint32_t)(timersGetUsTick() - timeout) >= SAMPLING_TIMEOUT_US) {
|
||||
TRACE("ADC timeout");
|
||||
_adc_timeout_error = true;
|
||||
_adc_started_mask = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_adc_timeout_error = false;
|
||||
}
|
||||
|
||||
void stm32_hal_adc_disable_oversampling()
|
||||
@@ -787,7 +813,7 @@ static void _adc_chain_conversions(const stm32_adc_t* adc)
|
||||
for (uint8_t i = 0; i < _adc_n_inputs; i++) {
|
||||
if (~_adc_input_mask & (1 << i)) continue;
|
||||
if (_adc_inhibit_mask & (1 << i)) continue;
|
||||
adcValues[i] = _adc_oversampling[i] / OVERSAMPLING;
|
||||
if (!_adc_timeout_error) adcValues[i] = _adc_oversampling[i] / OVERSAMPLING;
|
||||
}
|
||||
|
||||
// we're done!
|
||||
|
||||
@@ -360,7 +360,14 @@ static int i2c_init_clock_source(I2C_TypeDef* instance)
|
||||
#endif
|
||||
|
||||
#if defined(LL_RCC_I2C123_CLKSOURCE)
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C123_CLKSOURCE_PCLK1);
|
||||
# if defined(LL_RCC_I2C4_CLKSOURCE)
|
||||
if (instance == I2C4) {
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C4_CLKSOURCE_PCLK4);
|
||||
} else
|
||||
# endif
|
||||
{
|
||||
LL_RCC_SetClockSource(LL_RCC_I2C123_CLKSOURCE_PCLK1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
@@ -371,15 +378,17 @@ static int i2c_init_clock_source(I2C_TypeDef* instance)
|
||||
static int i2c_enable_clock(I2C_TypeDef* instance)
|
||||
{
|
||||
/* Peripheral clock enable */
|
||||
if (instance == I2C1) {
|
||||
if (instance == I2C1)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
} else if (instance == I2C2) {
|
||||
else if (instance == I2C2)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2);
|
||||
} else if (instance == I2C3) {
|
||||
else if (instance == I2C3)
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
#if defined(I2C4)
|
||||
else if (instance == I2C4)
|
||||
LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_I2C4);
|
||||
#endif
|
||||
else return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -393,6 +402,10 @@ static int i2c_disable_clock(I2C_TypeDef* instance)
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_I2C2);
|
||||
else if (instance == I2C3)
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
#if defined(I2C4)
|
||||
else if (instance == I2C4)
|
||||
LL_APB4_GRP1_DisableClock(LL_APB4_GRP1_PERIPH_I2C4);
|
||||
#endif
|
||||
else
|
||||
return -1;
|
||||
|
||||
@@ -472,17 +485,17 @@ int stm32_i2c_init(uint8_t bus, uint32_t clock_rate, const stm32_i2c_hw_def_t* h
|
||||
|
||||
if (i2c_gpio_init(hw_def) < 0) {
|
||||
TRACE("I2C ERROR: HAL_I2C_MspInit() I2C_GPIO misconfiguration");
|
||||
return -1;
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (i2c_enable_clock(hw_def->I2Cx) < 0) {
|
||||
TRACE("I2C ERROR: HAL_I2C_MspInit() I2C misconfiguration");
|
||||
return -1;
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (HAL_I2C_Init(h) != HAL_OK) {
|
||||
TRACE("I2C ERROR: HAL_I2C_Init() failed");
|
||||
return -1;
|
||||
return -4;
|
||||
}
|
||||
|
||||
#if defined(I2C_FLTR_ANOFF) && defined(I2C_FLTR_DNF) || defined(STM32H7) || \
|
||||
|
||||
@@ -480,6 +480,7 @@ bool stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
|
||||
if (params->direction & ETX_Dir_TX)
|
||||
usartInit.TransferDirection |= LL_USART_DIRECTION_TX;
|
||||
|
||||
|
||||
LL_USART_Init(usart->USARTx, &usartInit);
|
||||
LL_USART_Enable(usart->USARTx);
|
||||
|
||||
|
||||
@@ -380,6 +380,11 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||
hpcd_USB_OTG.Init.speed = PCD_SPEED_FULL;
|
||||
hpcd_USB_OTG.Init.dma_enable = DISABLE;
|
||||
hpcd_USB_OTG.Init.phy_itface = PCD_PHY_EMBEDDED;
|
||||
#if defined(STM32H7)
|
||||
hpcd_USB_OTG.Init.battery_charging_enable = DISABLE;
|
||||
hpcd_USB_OTG.Init.use_external_vbus = ENABLE;
|
||||
#endif
|
||||
|
||||
hpcd_USB_OTG.Init.Sof_enable = ENABLE;
|
||||
hpcd_USB_OTG.Init.low_power_enable = DISABLE;
|
||||
hpcd_USB_OTG.Init.lpm_enable = DISABLE;
|
||||
|
||||
Reference in New Issue
Block a user