stm32/stm32_foc.c: add the lower-half FOC device support
This commit is contained in:
parent
59ed02c604
commit
c1c4ca4ffd
@ -10664,3 +10664,187 @@ config STM32_QENCODER_SAMPLE_EVENT_8
|
|||||||
endchoice
|
endchoice
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
menuconfig STM32_FOC
|
||||||
|
bool "STM32 lower-half FOC support"
|
||||||
|
default n
|
||||||
|
select ARCH_IRQPRIO
|
||||||
|
select STM32_PWM_MULTICHAN
|
||||||
|
select STM32_PWM_LL_OPS
|
||||||
|
select STM32_ADC_LL_OPS
|
||||||
|
select STM32_ADC_CHANGE_SAMPLETIME
|
||||||
|
select STM32_ADC_NO_STARTUP_CONV
|
||||||
|
select STM32_ADC_FORCE_SCAN if STM32_HAVE_IP_ADC_V1
|
||||||
|
|
||||||
|
if STM32_FOC
|
||||||
|
|
||||||
|
config STM32_FOC_FOC0
|
||||||
|
bool "FOC0 device (TIM1 for PWM modulation)"
|
||||||
|
default n
|
||||||
|
depends on STM32_HAVE_TIM1
|
||||||
|
select STM32_FOC_USE_TIM1
|
||||||
|
---help---
|
||||||
|
Enable support for FOC0 device that uses TIM1 for PWM modulation
|
||||||
|
|
||||||
|
config STM32_FOC_FOC1
|
||||||
|
bool "FOC1 device (TIM8 for PWM modulation)"
|
||||||
|
default n
|
||||||
|
depends on STM32_HAVE_TIM8
|
||||||
|
select STM32_FOC_USE_TIM8
|
||||||
|
---help---
|
||||||
|
Enable support for FOC1 device that uses TIM8 for PWM modulation
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "FOC ADC trigger selection"
|
||||||
|
default STM32_FOC_ADC_TRGO
|
||||||
|
|
||||||
|
config STM32_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 STM32_FOC_ADC_TRGO
|
||||||
|
bool "FOC uses TRGO as ADC trigger"
|
||||||
|
depends on STM32_HAVE_IP_ADC_V2 || (STM32_HAVE_IP_ADC_V1 && !STM32_FOC_FOC1)
|
||||||
|
select STM32_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 STM32_FOC_FOC0
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "FOC0 device ADC selection"
|
||||||
|
default STM32_FOC_FOC0_ADC1
|
||||||
|
|
||||||
|
config STM32_FOC_FOC0_ADC1
|
||||||
|
bool "FOC0 uses ADC1"
|
||||||
|
depends on STM32_HAVE_ADC1
|
||||||
|
select STM32_FOC_USE_ADC1
|
||||||
|
|
||||||
|
config STM32_FOC_FOC0_ADC2
|
||||||
|
bool "FOC0 uses ADC2"
|
||||||
|
depends on STM32_HAVE_ADC2
|
||||||
|
select STM32_FOC_USE_ADC2
|
||||||
|
|
||||||
|
config STM32_FOC_FOC0_ADC3
|
||||||
|
bool "FOC0 uses ADC3"
|
||||||
|
depends on STM32_HAVE_ADC3
|
||||||
|
select STM32_FOC_USE_ADC3
|
||||||
|
|
||||||
|
config STM32_FOC_FOC0_ADC4
|
||||||
|
bool "FOC0 uses ADC4"
|
||||||
|
depends on STM32_HAVE_ADC4
|
||||||
|
select STM32_FOC_USE_ADC4
|
||||||
|
|
||||||
|
endchoice # "FOC0 device ADC selection"
|
||||||
|
|
||||||
|
endif # STM32_FOC_FOC0
|
||||||
|
|
||||||
|
if STM32_FOC_FOC1
|
||||||
|
|
||||||
|
choice
|
||||||
|
prompt "FOC1 device ADC selection"
|
||||||
|
default STM32_FOC_FOC1_ADC2
|
||||||
|
|
||||||
|
config STM32_FOC_FOC1_ADC1
|
||||||
|
bool "FOC1 uses ADC1"
|
||||||
|
depends on STM32_HAVE_ADC1
|
||||||
|
select STM32_FOC_USE_ADC1
|
||||||
|
|
||||||
|
config STM32_FOC_FOC1_ADC2
|
||||||
|
bool "FOC1 uses ADC2"
|
||||||
|
depends on STM32_HAVE_ADC2
|
||||||
|
select STM32_FOC_USE_ADC2
|
||||||
|
|
||||||
|
config STM32_FOC_FOC1_ADC3
|
||||||
|
bool "FOC1 uses ADC3"
|
||||||
|
depends on STM32_HAVE_ADC3
|
||||||
|
select STM32_FOC_USE_ADC3
|
||||||
|
|
||||||
|
config STM32_FOC_FOC1_ADC4
|
||||||
|
bool "FOC1 uses ADC4"
|
||||||
|
depends on STM32_HAVE_ADC4
|
||||||
|
select STM32_FOC_USE_ADC4
|
||||||
|
|
||||||
|
endchoice # "FOC0 device ADC selection"
|
||||||
|
|
||||||
|
endif # STM32_FOC_FOC1
|
||||||
|
|
||||||
|
config STM32_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)
|
||||||
|
|
||||||
|
# hiden variables and automatic configuration
|
||||||
|
|
||||||
|
config STM32_FOC_USE_TIM1
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_TIM1
|
||||||
|
select STM32_TIM1_PWM
|
||||||
|
select STM32_TIM1_CHANNEL1
|
||||||
|
select STM32_TIM1_CHANNEL2
|
||||||
|
select STM32_TIM1_CHANNEL3
|
||||||
|
select STM32_TIM1_CHANNEL4 if STM32_FOC_ADC_CCR4
|
||||||
|
select STM32_TIM1_CH1OUT
|
||||||
|
select STM32_TIM1_CH2OUT
|
||||||
|
select STM32_TIM1_CH3OUT
|
||||||
|
select STM32_TIM1_CH4OUT if STM32_FOC_ADC_CCR4
|
||||||
|
select STM32_TIM1_CH1NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
select STM32_TIM1_CH2NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
select STM32_TIM1_CH3NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
---help---
|
||||||
|
The TIM1 generates PWM for the FOC
|
||||||
|
|
||||||
|
config STM32_FOC_USE_TIM8
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_TIM8
|
||||||
|
select STM32_TIM8_PWM
|
||||||
|
select STM32_TIM8_CHANNEL1
|
||||||
|
select STM32_TIM8_CHANNEL2
|
||||||
|
select STM32_TIM8_CHANNEL3
|
||||||
|
select STM32_TIM8_CHANNEL4 if STM32_FOC_ADC_CCR4
|
||||||
|
select STM32_TIM8_CH1OUT
|
||||||
|
select STM32_TIM8_CH2OUT
|
||||||
|
select STM32_TIM8_CH3OUT
|
||||||
|
select STM32_TIM8_CH4OUT if STM32_FOC_ADC_CCR4
|
||||||
|
select STM32_TIM8_CH1NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
select STM32_TIM8_CH2NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
select STM32_TIM8_CH3NOUT if STM32_FOC_HAS_PWM_COMPLEMENTARY
|
||||||
|
---help---
|
||||||
|
The TIM8 generates PWM for the FOC
|
||||||
|
|
||||||
|
config STM32_FOC_USE_ADC1
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_ADC1
|
||||||
|
select STM32_ADC1_SCAN if STM32_HAVE_IP_ADC_V1
|
||||||
|
select STM32_ADC1_JEXTSEL
|
||||||
|
|
||||||
|
config STM32_FOC_USE_ADC2
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_ADC2
|
||||||
|
select STM32_ADC2_SCAN if STM32_HAVE_IP_ADC_V1
|
||||||
|
select STM32_ADC2_JEXTSEL
|
||||||
|
|
||||||
|
config STM32_FOC_USE_ADC3
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_ADC3
|
||||||
|
select STM32_ADC3_SCAN if STM32_HAVE_IP_ADC_V1
|
||||||
|
select STM32_ADC3_JEXTSEL
|
||||||
|
|
||||||
|
config STM32_FOC_USE_ADC4
|
||||||
|
bool
|
||||||
|
default n
|
||||||
|
select STM32_ADC4
|
||||||
|
select STM32_ADC3_JEXTSEL
|
||||||
|
|
||||||
|
endif #STM32_FOC
|
||||||
|
@ -269,3 +269,7 @@ endif
|
|||||||
ifeq ($(CONFIG_STM32_FSMC),y)
|
ifeq ($(CONFIG_STM32_FSMC),y)
|
||||||
CHIP_CSRCS += stm32_fsmc.c
|
CHIP_CSRCS += stm32_fsmc.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_STM32_FOC),y)
|
||||||
|
CHIP_CSRCS += stm32_foc.c
|
||||||
|
endif
|
||||||
|
2271
arch/arm/src/stm32/stm32_foc.c
Normal file
2271
arch/arm/src/stm32/stm32_foc.c
Normal file
File diff suppressed because it is too large
Load Diff
188
arch/arm/src/stm32/stm32_foc.h
Normal file
188
arch/arm/src/stm32/stm32_foc.h
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/arm/src/stm32/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_STM32_FOC_H
|
||||||
|
#define __ARCH_ARM_SRC_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 auxliary regular channles (only for DMA transfer) */
|
||||||
|
|
||||||
|
uint8_t regch;
|
||||||
|
|
||||||
|
/* The list of ADC channels (regular first, then injected) */
|
||||||
|
|
||||||
|
FAR uint8_t *chan;
|
||||||
|
|
||||||
|
/* The list of ADC pins */
|
||||||
|
|
||||||
|
FAR uint32_t *pins;
|
||||||
|
|
||||||
|
/* The list of ADC channels sample time configuration */
|
||||||
|
|
||||||
|
FAR 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 */
|
||||||
|
|
||||||
|
CODE int (*setup)(FAR struct foc_dev_s *dev);
|
||||||
|
|
||||||
|
/* Board-specific shutdown */
|
||||||
|
|
||||||
|
CODE int (*shutdown)(FAR struct foc_dev_s *dev);
|
||||||
|
|
||||||
|
/* Board-specific calibration setup */
|
||||||
|
|
||||||
|
CODE int (*calibration)(FAR struct foc_dev_s *dev, bool state);
|
||||||
|
|
||||||
|
/* Board-specific fault clear */
|
||||||
|
|
||||||
|
CODE int (*fault_clear)(FAR struct foc_dev_s *dev);
|
||||||
|
|
||||||
|
/* Board-specific PWM start */
|
||||||
|
|
||||||
|
CODE int (*pwm_start)(FAR struct foc_dev_s *dev, bool state);
|
||||||
|
|
||||||
|
/* Get phase currents */
|
||||||
|
|
||||||
|
CODE int (*current_get)(FAR struct foc_dev_s *dev, FAR int16_t *curr_raw,
|
||||||
|
FAR foc_current_t *curr);
|
||||||
|
|
||||||
|
#ifdef CONFIG_MOTOR_FOC_TRACE
|
||||||
|
/* FOC trace interface setup */
|
||||||
|
|
||||||
|
CODE int (*trace_init)(FAR struct foc_dev_s *dev);
|
||||||
|
|
||||||
|
/* FOC trace */
|
||||||
|
|
||||||
|
CODE void (*trace)(FAR struct foc_dev_s *dev, int type, bool state);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Board-specific FOC data */
|
||||||
|
|
||||||
|
struct stm32_foc_board_data_s
|
||||||
|
{
|
||||||
|
/* ADC configuration */
|
||||||
|
|
||||||
|
FAR 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 */
|
||||||
|
|
||||||
|
FAR struct stm32_foc_board_ops_s *ops;
|
||||||
|
|
||||||
|
/* Board-specific FOC data */
|
||||||
|
|
||||||
|
FAR 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
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct foc_dev_s *
|
||||||
|
stm32_foc_initialize(int inst, FAR struct stm32_foc_board_s *board);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: stm32_foc_adcget
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct adc_dev_s *stm32_foc_adcget(FAR struct foc_dev_s *dev);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
#endif /* __ARCH_ARM_SRC_STM32_FOC_H */
|
Loading…
Reference in New Issue
Block a user