diff --git a/src/main/drivers/adc_impl.h b/src/main/drivers/adc_impl.h index 51f562e94..56f403285 100644 --- a/src/main/drivers/adc_impl.h +++ b/src/main/drivers/adc_impl.h @@ -51,6 +51,10 @@ typedef struct adcDevice_s { #else DMA_Channel_TypeDef* DMAy_Channelx; #endif +#if defined(STM32F7) + ADC_HandleTypeDef ADCHandle; + DMA_HandleTypeDef DmaHandle; +#endif } adcDevice_t; extern const adcDevice_t adcHardware[]; diff --git a/src/main/drivers/adc_stm32f7xx.c b/src/main/drivers/adc_stm32f7xx.c index 215faf3e9..b8b2abf46 100644 --- a/src/main/drivers/adc_stm32f7xx.c +++ b/src/main/drivers/adc_stm32f7xx.c @@ -85,9 +85,6 @@ ADCDevice adcDeviceByInstance(ADC_TypeDef *instance) void adcInit(adcConfig_t *config) { - DMA_HandleTypeDef DmaHandle; - ADC_HandleTypeDef ADCHandle; - uint8_t i; uint8_t configuredAdcChannels = 0; @@ -136,47 +133,47 @@ void adcInit(adcConfig_t *config) RCC_ClockCmd(adc.rccADC, ENABLE); dmaInit(dmaGetIdentifier(adc.DMAy_Streamx), OWNER_ADC, 0); - ADCHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8; - ADCHandle.Init.ContinuousConvMode = ENABLE; - ADCHandle.Init.Resolution = ADC_RESOLUTION_12B; - ADCHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; - ADCHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; - ADCHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; - ADCHandle.Init.NbrOfConversion = configuredAdcChannels; - ADCHandle.Init.ScanConvMode = configuredAdcChannels > 1 ? ENABLE : DISABLE; // 1=scan more that one channel in group - ADCHandle.Init.DiscontinuousConvMode = DISABLE; - ADCHandle.Init.NbrOfDiscConversion = 0; - ADCHandle.Init.DMAContinuousRequests = ENABLE; - ADCHandle.Init.EOCSelection = DISABLE; - ADCHandle.Instance = adc.ADCx; + adc.ADCHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV8; + adc.ADCHandle.Init.ContinuousConvMode = ENABLE; + adc.ADCHandle.Init.Resolution = ADC_RESOLUTION_12B; + adc.ADCHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; + adc.ADCHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; + adc.ADCHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; + adc.ADCHandle.Init.NbrOfConversion = configuredAdcChannels; + adc.ADCHandle.Init.ScanConvMode = configuredAdcChannels > 1 ? ENABLE : DISABLE; // 1=scan more that one channel in group + adc.ADCHandle.Init.DiscontinuousConvMode = DISABLE; + adc.ADCHandle.Init.NbrOfDiscConversion = 0; + adc.ADCHandle.Init.DMAContinuousRequests = ENABLE; + adc.ADCHandle.Init.EOCSelection = DISABLE; + adc.ADCHandle.Instance = adc.ADCx; /*##-1- Configure the ADC peripheral #######################################*/ - if (HAL_ADC_Init(&ADCHandle) != HAL_OK) + if (HAL_ADC_Init(&adc.ADCHandle) != HAL_OK) { /* Initialization Error */ } - DmaHandle.Init.Channel = adc.channel; - DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; - DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE; - DmaHandle.Init.MemInc = configuredAdcChannels > 1 ? DMA_MINC_ENABLE : DMA_MINC_DISABLE; - DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; - DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; - DmaHandle.Init.Mode = DMA_CIRCULAR; - DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; - DmaHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; - DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; - DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; - DmaHandle.Instance = adc.DMAy_Streamx; + adc.DmaHandle.Init.Channel = adc.channel; + adc.DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; + adc.DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE; + adc.DmaHandle.Init.MemInc = configuredAdcChannels > 1 ? DMA_MINC_ENABLE : DMA_MINC_DISABLE; + adc.DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; + adc.DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; + adc.DmaHandle.Init.Mode = DMA_CIRCULAR; + adc.DmaHandle.Init.Priority = DMA_PRIORITY_HIGH; + adc.DmaHandle.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + adc.DmaHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; + adc.DmaHandle.Init.MemBurst = DMA_MBURST_SINGLE; + adc.DmaHandle.Init.PeriphBurst = DMA_PBURST_SINGLE; + adc.DmaHandle.Instance = adc.DMAy_Streamx; /*##-2- Initialize the DMA stream ##########################################*/ - if (HAL_DMA_Init(&DmaHandle) != HAL_OK) + if (HAL_DMA_Init(&adc.DmaHandle) != HAL_OK) { /* Initialization Error */ } - __HAL_LINKDMA(&ADCHandle, DMA_Handle, DmaHandle); + __HAL_LINKDMA(&adc.ADCHandle, DMA_Handle, adc.DmaHandle); uint8_t rank = 1; for (i = 0; i < ADC_CHANNEL_COUNT; i++) { @@ -190,14 +187,15 @@ void adcInit(adcConfig_t *config) sConfig.Offset = 0; /*##-3- Configure ADC regular channel ######################################*/ - if (HAL_ADC_ConfigChannel(&ADCHandle, &sConfig) != HAL_OK) + if (HAL_ADC_ConfigChannel(&adc.ADCHandle, &sConfig) != HAL_OK) { /* Channel Configuration Error */ } } + HAL_CLEANINVALIDATECACHE((uint32_t*)&adcValues, configuredAdcChannels); /*##-4- Start the conversion process #######################################*/ - if(HAL_ADC_Start_DMA(&ADCHandle, (uint32_t*)&adcValues, configuredAdcChannels) != HAL_OK) + if(HAL_ADC_Start_DMA(&adc.ADCHandle, (uint32_t*)&adcValues, configuredAdcChannels) != HAL_OK) { /* Start Conversation Error */ } diff --git a/src/main/drivers/dma.h b/src/main/drivers/dma.h index 5a06b2c9f..3ae5665c5 100644 --- a/src/main/drivers/dma.h +++ b/src/main/drivers/dma.h @@ -38,11 +38,12 @@ typedef struct dmaChannelDescriptor_s { uint8_t resourceIndex; } dmaChannelDescriptor_t; -#if defined(STM32F4) || defined(STM32F7) - +#if defined(STM32F7) #define HAL_CLEANINVALIDATECACHE(addr, size) (SCB_CleanInvalidateDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) #define HAL_CLEANCACHE(addr, size) (SCB_CleanDCache_by_Addr((uint32_t*)((uint32_t)addr & ~0x1f), ((uint32_t)(addr + size + 0x1f) & ~0x1f) - ((uint32_t)addr & ~0x1f))) +#endif +#if defined(STM32F4) || defined(STM32F7) uint32_t dmaFlag_IT_TCIF(const DMA_Stream_TypeDef *stream); typedef enum { diff --git a/src/main/target/ANYFCF7/target.c b/src/main/target/ANYFCF7/target.c index b2a5a909a..b81a5076d 100644 --- a/src/main/target/ANYFCF7/target.c +++ b/src/main/target/ANYFCF7/target.c @@ -34,16 +34,16 @@ const timerHardware_t timerHardware[USABLE_TIMER_CHANNEL_COUNT] = { DEF_TIM(TIM8, CH4, PC9, TIM_USE_PWM, 0, 0 ), // S5_IN DEF_TIM(TIM8, CH3, PC8, TIM_USE_PWM, 0, 0 ), // S6_IN - DEF_TIM(TIM4, CH3, PB8, TIM_USE_MOTOR, 1, 0 ), // S10_OUT 1 - DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0 ), // S6_OUT 2 - DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 1, 0 ), // S1_OUT 4 - DEF_TIM(TIM5, CH2, PA1, TIM_USE_MOTOR | TIM_USE_LED, 1, 0 ), // S2_OUT - DEF_TIM(TIM3, CH2, PB5, TIM_USE_MOTOR, 1, 0 ), // S4_OUT - DEF_TIM(TIM5, CH1, PA0, TIM_USE_MOTOR, 1, 0 ), // S7_OUT - DEF_TIM(TIM4, CH4, PB9, TIM_USE_MOTOR, 1, 0 ), // S5_OUT 3 + DEF_TIM(TIM4, CH3, PB8, TIM_USE_MOTOR, 1, 0 ), // S10_OUT 1 DMA1_ST7 + DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1, 0 ), // S6_OUT 2 DMA1_ST1 + DEF_TIM(TIM5, CH2, PA1, TIM_USE_MOTOR, 1, 0 ), // S2_OUT 3 DMA1_ST4 + DEF_TIM(TIM2, CH4, PA3, TIM_USE_MOTOR, 1, 1 ), // S1_OUT 4 DMA1_ST7 DMA1_ST6 + DEF_TIM(TIM3, CH2, PB5, TIM_USE_MOTOR | TIM_USE_LED, 1, 0 ), // S4_OUT DMA1_ST5 + DEF_TIM(TIM5, CH1, PA0, TIM_USE_MOTOR, 1, 0 ), // S7_OUT DMA1_ST2 + DEF_TIM(TIM4, CH4, PB9, TIM_USE_MOTOR, 1, 0 ), // S5_OUT DEF_TIM(TIM9, CH2, PE6, TIM_USE_MOTOR, 1, 0 ), // S3_OUT - DEF_TIM(TIM2, CH2, PB3, TIM_USE_MOTOR, 1, 0 ), // S8_OUT - DEF_TIM(TIM3, CH1, PB4, TIM_USE_MOTOR, 1, 0 ), // S9_OUT + DEF_TIM(TIM2, CH2, PB3, TIM_USE_MOTOR, 1, 0 ), // S8_OUT DMA1_ST6 + DEF_TIM(TIM3, CH1, PB4, TIM_USE_MOTOR, 1, 0 ), // S9_OUT DMA1_ST4 }; #else // STANDARD LAYOUT