arch/arm/src/stm32f7: port FOC driver from arch/stm32

This commit is contained in:
raiden00pl 2022-07-30 18:38:40 +02:00 committed by Alin Jerpelea
parent a02101efff
commit 6d1646625a
4 changed files with 2495 additions and 0 deletions

View File

@ -7063,4 +7063,163 @@ endchoice # SAI2 synchronization enable
endmenu
menuconfig STM32F7_FOC
bool "STM32 lower-half FOC support"
default n
select ARCH_IRQPRIO
select STM32F7_PWM_MULTICHAN
select STM32F7_PWM_LL_OPS
select STM32F7_ADC_LL_OPS
select STM32F7_ADC_CHANGE_SAMPLETIME
select STM32F7_ADC_NO_STARTUP_CONV
if STM32F7_FOC
config STM32F7_FOC_FOC0
bool "FOC0 device (TIM1 for PWM modulation)"
default n
select STM32F7_FOC_USE_TIM1
---help---
Enable support for FOC0 device that uses TIM1 for PWM modulation
config STM32F7_FOC_FOC1
bool "FOC1 device (TIM8 for PWM modulation)"
default n
select STM32F7_FOC_USE_TIM8
---help---
Enable support for FOC1 device that uses TIM8 for PWM modulation
choice
prompt "FOC ADC trigger selection"
default STM32F7_FOC_ADC_TRGO
config STM32F7_FOC_ADC_CCR4
bool "FOC uses CCR4 as ADC trigger"
---help---
This option uses the software frequency prescaler and is
not possible for 4-phase output.
config STM32F7_FOC_ADC_TRGO
bool "FOC uses TRGO as ADC trigger"
depends on !STM32F7_FOC_FOC1
select STM32F7_PWM_TRGO
---help---
This option allows you to use higher PWM frequency and works for 4-phase output.
It is not possible for ADC IPv1 if FOC1 enabled (no T8TRGO in JEXTSEL).
endchoice # "FOC ADC trigger selection"
if STM32F7_FOC_FOC0
choice
prompt "FOC0 device ADC selection"
default STM32F7_FOC_FOC0_ADC1
config STM32F7_FOC_FOC0_ADC1
bool "FOC0 uses ADC1"
select STM32F7_FOC_USE_ADC1
config STM32F7_FOC_FOC0_ADC2
bool "FOC0 uses ADC2"
select STM32F7_FOC_USE_ADC2
config STM32F7_FOC_FOC0_ADC3
bool "FOC0 uses ADC3"
select STM32F7_FOC_USE_ADC3
endchoice # "FOC0 device ADC selection"
endif # STM32F7_FOC_FOC0
if STM32F7_FOC_FOC1
choice
prompt "FOC1 device ADC selection"
default STM32F7_FOC_FOC1_ADC2
config STM32F7_FOC_FOC1_ADC1
bool "FOC1 uses ADC1"
select STM32F7_FOC_USE_ADC1
config STM32F7_FOC_FOC1_ADC2
bool "FOC1 uses ADC2"
select STM32F7_FOC_USE_ADC2
config STM32F7_FOC_FOC1_ADC3
bool "FOC1 uses ADC3"
select STM32F7_FOC_USE_ADC3
endchoice # "FOC0 device ADC selection"
endif # STM32F7_FOC_FOC1
config STM32F7_FOC_HAS_PWM_COMPLEMENTARY
bool "FOC PWM has complementary outputs"
default n
---help---
Enable complementary outputs for the FOC PWM (sometimes called 6-PWM mode)
# hidden variables and automatic configuration
config STM32F7_FOC_USE_TIM1
bool
default n
select STM32F7_TIM1
select STM32F7_TIM1_PWM
select STM32F7_TIM1_CHANNEL1
select STM32F7_TIM1_CHANNEL2
select STM32F7_TIM1_CHANNEL3
select STM32F7_TIM1_CHANNEL4 if STM32F7_FOC_ADC_CCR4
select STM32F7_TIM1_CH1OUT
select STM32F7_TIM1_CH2OUT
select STM32F7_TIM1_CH3OUT
select STM32F7_TIM1_CH4OUT if STM32F7_FOC_ADC_CCR4
select STM32F7_TIM1_CH1NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
select STM32F7_TIM1_CH2NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
select STM32F7_TIM1_CH3NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
---help---
The TIM1 generates PWM for the FOC
config STM32F7_FOC_USE_TIM8
bool
default n
select STM32F7_TIM8
select STM32F7_TIM8_PWM
select STM32F7_TIM8_CHANNEL1
select STM32F7_TIM8_CHANNEL2
select STM32F7_TIM8_CHANNEL3
select STM32F7_TIM8_CHANNEL4 if STM32F7_FOC_ADC_CCR4
select STM32F7_TIM8_CH1OUT
select STM32F7_TIM8_CH2OUT
select STM32F7_TIM8_CH3OUT
select STM32F7_TIM8_CH4OUT if STM32F7_FOC_ADC_CCR4
select STM32F7_TIM8_CH1NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
select STM32F7_TIM8_CH2NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
select STM32F7_TIM8_CH3NOUT if STM32F7_FOC_HAS_PWM_COMPLEMENTARY
---help---
The TIM8 generates PWM for the FOC
config STM32F7_FOC_USE_ADC1
bool
default n
select STM32F7_ADC1
select STM32F7_ADC1_SCAN
select STM32F7_ADC1_JEXTSEL
config STM32F7_FOC_USE_ADC2
bool
default n
select STM32F7_ADC2
select STM32F7_ADC2_SCAN
select STM32F7_ADC2_JEXTSEL
config STM32F7_FOC_USE_ADC3
bool
default n
select STM32F7_ADC3
select STM32F7_ADC3_SCAN
select STM32F7_ADC3_JEXTSEL
endif #STM32F7_FOC
endif # ARCH_CHIP_STM32F7

View File

@ -166,3 +166,7 @@ endif
ifeq ($(CONFIG_STM32F7_PWM),y)
CHIP_CSRCS += stm32_pwm.c
endif
ifeq ($(CONFIG_STM32F7_FOC),y)
CHIP_CSRCS += stm32_foc.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,188 @@
/****************************************************************************
* arch/arm/src/stm32f7/stm32_foc.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_STM32F7_STM32_FOC_H
#define __ARCH_ARM_SRC_STM32F7_STM32_FOC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include "stm32_adc.h"
#include <nuttx/motor/foc/foc_lower.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/* ADC configuration for the FOC device */
struct stm32_foc_adc_s
{
/* ADC interface used by the FOC */
uint8_t intf;
/* The number of ADC channels (regular + injected) */
uint8_t nchan;
/* The number of auxiliary regular channels (only for DMA transfer) */
uint8_t regch;
/* The list of ADC channels (regular first, then injected) */
uint8_t *chan;
/* The list of ADC pins */
uint32_t *pins;
/* The list of ADC channels sample time configuration */
adc_channel_t *stime;
};
/* Board-specific operations.
*
* These are calls from the lower-half to the board-specific logic.
* They must be provided by board-specific logic even if not used.
*/
struct stm32_foc_board_ops_s
{
/* Board-specific setup */
int (*setup)(struct foc_dev_s *dev);
/* Board-specific shutdown */
int (*shutdown)(struct foc_dev_s *dev);
/* Board-specific calibration setup */
int (*calibration)(struct foc_dev_s *dev, bool state);
/* Board-specific fault clear */
int (*fault_clear)(struct foc_dev_s *dev);
/* Board-specific PWM start */
int (*pwm_start)(struct foc_dev_s *dev, bool state);
/* Get phase currents */
int (*current_get)(struct foc_dev_s *dev, int16_t *curr_raw,
foc_current_t *curr);
#ifdef CONFIG_MOTOR_FOC_TRACE
/* FOC trace interface setup */
int (*trace_init)(struct foc_dev_s *dev);
/* FOC trace */
void (*trace)(struct foc_dev_s *dev, int type, bool state);
#endif
};
/* Board-specific FOC data */
struct stm32_foc_board_data_s
{
/* ADC configuration */
struct stm32_foc_adc_s *adc_cfg;
/* PWM deadtime register value */
uint8_t pwm_dt;
/* PWM deadtime in ns */
uint16_t pwm_dt_ns;
/* PWM max supported duty cycle */
foc_duty_t duty_max;
};
/* Board-specific FOC configuration */
struct stm32_foc_board_s
{
/* Board-specific FOC operations */
struct stm32_foc_board_ops_s *ops;
/* Board-specific FOC data */
struct stm32_foc_board_data_s *data;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: stm32_foc_initialize
****************************************************************************/
struct foc_dev_s *
stm32_foc_initialize(int inst, struct stm32_foc_board_s *board);
/****************************************************************************
* Name: stm32_foc_adcget
****************************************************************************/
struct adc_dev_s *stm32_foc_adcget(struct foc_dev_s *dev);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_ARM_SRC_STM32F7_STM32_FOC_H */