【动手学电机驱动】 STM32-FOC(11)ST MCSDK6.0 电机控制软件框架

STM32-FOC(1)STM32 电机控制的软件开发环境
STM32-FOC(2)STM32 导入和创建项目
STM32-FOC(3)STM32 三路互补 PWM 输出
STM32-FOC(4)IHM03 电机控制套件介绍
STM32-FOC(5)基于 IHM03 的无感方波控制
STM32-FOC(6)基于 IHM03 的无感FOC 控制
STM32-FOC(7)MCSDK Pilot 上位机控制与调试
STM32-FOC(8)MCSDK Profiler 电机参数辨识
STM32-FOC(9)无感 FOC 电机转速调节
STM32-FOC(10)使用旋钮调节电机转速
STM32-FOC(11)ST MCSDK6.0 电机控制软件框架

【动手学电机驱动】 STM32-FOC(11)ST MCSDK6.0 电机控制软件框架

    • [1. STM32 MCSDK 简介](#1. STM32 MCSDK 简介)
      • [1.1 电机控制开发套件(MCSDK)](#1.1 电机控制开发套件(MCSDK))
      • [1.2 MCSDK 的内容](#1.2 MCSDK 的内容)
      • [1.3 电机控制应用工作流程](#1.3 电机控制应用工作流程)
      • [1.4 入门指南](#1.4 入门指南)
    • [2. 简介](#2. 简介)
      • [2.1 固件功能](#2.1 固件功能)
      • [2.2 组件列表](#2.2 组件列表)
      • [2.3 文件列表](#2.3 文件列表)
      • [2.4 开发环境](#2.4 开发环境)

1. STM32 MCSDK 简介

MC SDK用于开发基于Arm® Cortex®-M处理器的STM32 32位微控制器上运行的电机控制应用程序。

1.1 电机控制开发套件(MCSDK)

STM32 电机控制软件开发套件(MC SDK)专为 STM32 微控制器设计,并与之配合使用。MC SDK 包含一个软件库,该库实现了磁场定向控制(FOC)和六步(6-step)方法,以驱动表贴式(SMPMSM)和内嵌式(I-PMSM)的三相永磁同步电机(PMSM)。

STM32系列32位闪存微控制器是专门为嵌入式应用而开发的:STM32F0、STM32C0、STM32F3、STM32G0、STM32G4、STM32F4、STM32L4、STM32H7、STM33F7和STM32H5。这些微控制器将高性能与外围设备相结合,使其适用于执行三相电机FOC。

MCSDK 电机控制库可用于快速评估ST微控制器,完成ST应用平台,并在开发在ST微控制器上运行的电机控制算法时节省时间。它用C语言编写,实现了核心电机控制算法,以及用于转子位置重建的传感器读取/解码算法和无传感器算法。该库可以轻松配置,以利用STM32F30x和STM32G4的嵌入式高级模拟外设(快速比较器和可编程增益放大器(PGA))进行电流传感和保护,从而简化应用板。

该库可以定制以适应用户应用程序参数(电机、传感器、功率级、控制级、引脚分配),并提供一个现成的应用程序编程接口(API)。PC图形用户界面ST电机控制工作台允许对库进行完整和轻松的定制。因此,用户可以在很短的时间内运行永磁同步电机或无刷直流电机。

STM32电机控制SDK作为STM32 CubeMX工具的扩展包交付,FOC&Six-Step库基于STM32 Cube固件库。

1.2 MCSDK 的内容

STM32 MCSDK包含以下项目:

  • STM32 MC firmware(固件)
  • STM32 MC Workbench(STMCWB)
  • STM32 MC Board Manager(控制板管理工具,STMCBM)
  • STM32 MC Board Designer(控制板设计工具,STMCBD)
  • STM32 MC Pilot(包括 MC Profiler工具)
  • STM32 MC 固件的参考文档和其它文档

STM32 MCSDK 软件包作为可执行文件提供,可在用户的计算机上安装上述所有项目。

STM32 MC SDK 依赖于 STM32Cube 和 STM32CubeMx。因此,在安装 MCSDK 之前,必须安装最新的 STM32CubeMx 版本。注意:在安装MCSDK之前,必须至少运行一次STM32CubeMx。

1.3 电机控制应用工作流程

使用STM32 MCSDK的电机控制软件应用程序的设计通常从MC Workbench开始。使用此工具,用户可以根据其电机、功率级、控制级和所选STM32 MCU的特性配置MC SDK。

MC Workbench 从 PMSM FOC 或 6Step库中选择适当的固件组件,计算其配置参数,生成 STM32CubeMx 项目文件(IOC文件),并使用此项目执行 STM32CubeMX,生成一个完整的软件项目,其中包含启动应用程序电机所需的源代码和库。生成的软件项目可以直接在选择的IDE中打开。

ST MC SDK 构建的电机控制应用程序的项目结构如下图所示。

该软件项目由几个相互关联的不同部分组成:

  • 应用程序(Application) 是最重要的部分。应用程序由ST电机控制SDK的用户开发,它侧重于最终应用程序的功能实现,而纯粹属于电机控制的内容由 ST MCSDK生成的代码实现。
  • UI 库提供了用户在应用程序开发过程中的控制和调试工具:它处理硬件功能,如用于启动和停止电机的按钮、用于设置转子速度参考的电位计。它还提供了调试功能,如电机控制协议套件,允许将电机控制应用程序与ST电机先导工具或DAC功能连接。电机控制应用程序中是否使用UI库是可选的,而且它通常不会出现在最终的应用程序中。
  • 电机控制库(MC Library) 是ST MCSDK固件的核心。由一组组件组成,每个组件实现SDK提供的一个功能。大多数功能,提供了几个不同的实现方法。用户可以通过电机控制工作台来选择应用程序所需的组件。
  • 电机控制驾驶舱(Cockpit) 使用所选择的电机控制库组件,将选定的组件集成,以实现电机驱动的核心算法。电机控制驾驶舱还充当了电机和应用程序之间的主要接口。
  • 电机控制应用程序编程接口(MC API) 是应用程序与系统其余部分之间的主要接口,它提供了控制应用程序驱动电机所需的所有功能。
  • MC低级接口(LowLevel API) 包含电机控制应用程序的所有组件提供的接口功能,用于微调一些内部参数或获取比MCAPI所能提供的更详细的信息。
  • STM32外设驱动程序(STM32Cube Drivers),用户可以选择 HAL 或 LL。电机控制库本身仅使用LL,硬件外设初始化可以使用 HAL 或 LL。这些驱动程序被复制到为电机控制应用程序生成的软件项目中。

具体应用示例的详细步骤,可以参见本系列之前的文章:

STM32-FOC(5)基于 IHM03 的无感方波控制
STM32-FOC(6)基于 IHM03 的无感FOC 控制

1.4 入门指南

下列文档可以帮助用户开始使用STM32 MCSDK:

  • ST MCSDK入门(Getting Started with ST Motor Control SDK)
  • ST MC Workbench 用户手册(MotorControl Workbench User Manual)
  • ST Motor Pilot 快速指南(Motor Pilot Startup Guide)
  • 高灵敏度观测器快速指南(HSO Startup Guide)

之后,下列用户手册可以提供有关固件功能和操作的详细信息:

  • STM32 MC SDK overview,介绍有关使用 FOC 和 6-step 驱动器的SDK工作流程。
  • Introduction to the PMSM FOC drive ,介绍了 MCSDK 磁场定向控制(FOC)的基本方法。
  • Six-step Firmware Algorithm,详细介绍了 MCSDK 的 6-step 实现。

最后,构成SDK的固件组件在 Components section 中进行了介绍。

2. 简介

2.1 固件功能

  • 核心功能:FOC,MTPA,弱侧控制,前馈控制,电机参数测量
  • 传感器:速度传感器,电流传感器,直流母线电压检测,温度检测
  • 执行器:SVPWM
  • PI控制器:速度环控制,电流环控制,转矩控制
  • MCU:覆盖全部 STM32 系列

2.2 组件列表

c 复制代码
- MCSDK	
   - Application Programming Interface	Interface for Motor Control applications using the classic SDK
      - Motor Control API	High level Programming Interface of the Motor Control SDK
      - Motor Control Interface	MC Interface component of the Motor Control SDK
   - Application Programming Interface for High Sensitivity Observer	Interface for application using the High Sensitivity Observer
      - Motor Control API for HSO	High level Programming Interface of the Motor Control SDK for HSO applications
      - Motor Control Interface for HSO	MC Interface component of the Motor Control SDK for HSO applications
   - Bus Voltage Sensing	Bus Voltage Sensor components of the Motor Control SDK
      - Resistor Divider Bus Voltage Sensor	Resistor Divider Bus Voltage Sensor implementation
      - Virtual Bus Voltage Sensor	Virtual Bus Voltage Sensor implementation
   - Circle Limitation	Circle Limitation component of the Motor Control SDK
   - Current controller	Current controller component
   - Digital Output	Digital output component of the Motor Control SDK
   - Encoder Alignment Controller	Encoder Alignment Controller component of the Motor Control SDK
   - Feed-forward Control	Feed-forward Control component of the Motor Control SDK
   - Flux Weakening Control	Flux Weakening (FW) Control component of the Motor Control SDK
   - Inrush Current Limiter	Inrush Current Limiter component of the Motor Control SDK
   - Linear Potentiometer	Linear Potentiometer reading component of the Motor Control SDK
      - Speed Potentiometer	Potentiometer reading component that sets the motor speed reference from the potentiometer value
   - MC Potentiometer	Todo
   - MCUI	
      - DAC User Interface	DAC User Interface
   - Maximum Torque Per Ampere Control	Maximum Torque Per Ampere (MTPA) Control component of the Motor Control SDK
   - Motor Control Math functions	Motor Control Mathematic functions of the Motor Control SDK
   - Motor Control Protocol	Motor Control Protocol components of the Motor Control SDK
   - Motor Control Tasks	Motor Control subsystem configuration and operation routines.
      - Motor Control Applicative hooks	User defined functions that are called in the Motor Control tasks
   - Motor Control types	
   - NTC Temperature Sensor	Allows to read the temperature of the heat sink
   - Open Loop Control	Open Loop component of the Motor Control SDK
   - Oversampling	Oversampling component
   - PID Regulator	PID Regulator component of the Motor Control SDK
   - PID current regulator	PID current regulator component of the Motor Control SDK
   - PID speed regulator	PID speed regulator component of the Motor Control SDK
   - PQD Motor Power Measurement	Motor Power Measurement component using DQ-frame current and voltage values
   - PWM & Current Feedback	PWM & Current Feedback components of the Motor Control SDK
      - ICS 2 ADCs PWM & Current Feedback	ICS, 2 ADCs, PWM & Current Feedback implementation for F30X, F4XX, F7XX, G4XX and L4XX MCUs
      - R1 PWM & Current Feedback	1-Shunt with phase shift PWM & Current Feedback implementation for C0xx, F30X, F7XX, G0XX, G4XX, H5XX and L4XX MCUs
      - R3 1 ADC PWM & Current Feedback	3-Shunt, 1 ADC, PWM & Current Feedback implementation for F0XX, F30X, F4XX, F7XX, G0XX, G4XX, H5XX, C0XX and L4XX MCUs
      - R3 2 ADCs PWM & Current Feedback	3-Shunt, 2 ADCs, PWM & Current Feedback implementation for F30X, F4XX, F7XX, G4XX, H5XX, H7XX and L4XX MCUs
   - Polarisation detection	PolPulse component of the Motor Control SDK
   - Position Control	Position Control component of the Motor Control SDK
   - Profiler Component	Profiler component of the Motor Control SDK
   - Ramp Manager	Ramp Extended Manager component of the Motor Control SDK
   - Regular Conversion Manager	Regular Conversion Manager component of the Motor Control SDK
   - Rev-Up Control	Rev-Up Control component of the Motor Control SDK
      - FOC Rev-Up Control component	Rev-Up control component used to start motor driven with the Field Oriented Control technique
   - Rs DC estimation	Rs DC estimation process
   - STGAP1x controller	A component to interface with the configuration and diagnostic features of STGAP1x gate drivers through SPI
   - SixStep	
      - BEMF Sensing	Back-EMF sensing components of the Motor Control SDK for G4XX, G0XX, F0XX and C0XX
      - Current Reference control	PWM generation of the current reference for Six-Step drive with current mode
      - Demagnetization management	Demagnetization time management
      - OpenLoop management	OpenLoop component of the 6-step Motor Control SDK
      - PWM management	PWM generation implementation for Six-Step drive
      - RevUp management	Rev-Up Control component used to start motor driven with the Six-Step technique
   - Speed & Position Feedback	Speed & Position Feedback components of the Motor Control SDK
      - BEMF Sensing	Back-EMF sensing components of the Motor Control SDK for G4XX, G0XX, F0XX and C0XX
      - Encoder Speed & Position Feedback	Quadrature Encoder based Speed & Position Feedback implementation
      - Hall Speed & Position Feedback	Hall Sensor based Speed & Position Feedback implementation
      - High Sensitivity Observer Speed & position feedback	Speed & Position feedback HSO component of the Motor Control SDK
      - State Observer CORDIC Speed & Position Feedback	State Observer with CORDIC Speed & Position Feedback implementation
      - State Observer PLL Speed & Position Feedback.	State Observer with PLL Speed & Position Feedback component of MCSDK
      - Virtual Speed & Position Feedback	Virtual Speed Speed & Position Feedback implementation
   - Speed & Torque Control	Speed & Torque Control component of the Motor Control SDK
      - Classic Speed & Torque Control	Speed & Torque Control component for the classic FOC drive
      - Speed & torque control for HSO	Speed and torque control component for the High Sensitivity Observer
   - Speed Control	Speed Control component of the Motor Control SDK

- SpeedCtrl	
   - STM32_PMSM_MC_Library	
      - OneTouchTuning	
   - OneTouchTuning class exported types	
      - SelfComCtrl	
   - SelfComCtrl class private types	

- STSPIN32G4 Driver Library	
   - Basic	Basic function and definitions to work with STSPIN32G4
   - Driver Registers	Function and definitions to directly access I2C registers of STSPIN32G4
   - Power Management	Function and definitions to manage regulators embedded in STSPIN32G4 and standby
   - Protections	Function and definitions to configure protection features of STSPIN32G4

2.3 文件列表

STM32 MCSDK v6.3.1 所包括文件的详细列表如下。

c 复制代码
- Inc	
   - COMMON	
      - aspep.h	This file provides aspep API that implement the aspep protocol
      - dac_ui.h	This file contains all definitions and functions prototypes for the dac_ui component of the Motor Control SDK
      - hall_speed_pos_fdbk.h	This file contains all definitions and functions prototypes for the Hall Speed & Position Feedback component of the Motor Control SDK
      - mc_api.h	This file defines the high level interface of the Motor Control SDK
      - mc_app_hooks.h	This file implements tasks definition
      - mc_config_common.h	Motor Control Subsystem components configuration and handler structures declarations
      - mc_configuration_registers.h	This file provides the definitions needed to build the project configuration information registers
      - mc_curr_ctrl.h	This file contains all definitions and functions prototypes for the current controller component of the Motor Control SDK
      - mc_interface.h	This file contains all definitions and functions prototypes for the MC Interface component of the Motor Control SDK
      - mc_math.h	This file provides mathematics functions useful for and specific to Motor Control
      - mc_potentiometer.h	This file contains all definitions and functions prototypes for the potentiometer component of the Motor Control SDK
      - mc_stm_types.h	Includes HAL/LL headers relevant to the current configuration
      - mc_tasks.h	This file implementes tasks definition
      - mc_type.h	Motor Control SDK global types definitions
      - mcp_config.h	This file provides configuration definition of the MCP protocol
      - motorcontrol.h	Motor Control Subsystem initialization functions
      - pmsm_motor_parameters.h	This file contains the parameters needed for the Motor Control SDK in order to configure the motor to drive
      - power_stage_parameters.h	This file contains the parameters needed for the Motor Control SDK in order to configure a power stage
      - pwm_common.h	This file contains all definitions and functions prototypes for the PWM & Current Feedback component of the Motor Control SDK
      - pwm_curr_fdbk.h	This file contains all definitions and functions prototypes for the PWM & Current Feedback component of the Motor Control SDK
      - r1_ps_pwm_curr_fdbk.h	This file contains all definitions and functions prototypes for the r1_ps_pwm_curr_fdbk component of the Motor Control SDK
      - register_interface.h	This file provides firmware registers definitions used by MCP protocol
      - regular_conversion_manager.h	This file contains all definitions and functions prototypes for the regular_conversion_manager component of the Motor Control SDK
   - FOC
      - drive_parameters.h	This file contains the parameters needed for the Motor Control SDK in order to configure a motor drive
      - mc_config.h	Motor Control Subsystem components configuration and handler structures declarations
      - mc_parameters.h	This file provides declarations of HW parameters specific to the configuration of the subsystem
      - parameters_conversion.h	This file includes the proper Parameter conversion on the base of stdlib for the first drive
   - HSO
      - flash_parameters.h	This file includes the type definition of data aimed to be written by the application
      - mc_api.h	This file defines the high level interface of the Motor Control SDK
      - mc_interface.h	This file contains all definitions and functions prototypes for the MC Interface component of the Motor Control SDK
      - rsdc_est.h	This file contains all definitions and functions prototypes for the Rs DC estimation of the Motor Control SDK
      - speed_pos_fdbk_hso.h	This file contains all definitions and functions prototypes for the sensorless HSO component of the Motor Control SDK
      - speed_torq_ctrl_hso.h	This file contains all definitions and functions prototypes for the speed and torque HSO component of the Motor Control SDK

   - SIXSTEP	
      - drive_parameters.h	This file contains the parameters needed for the Motor Control SDK in order to configure a motor drive
      - mc_config.h	Motor Control Subsystem components configuration and handler structures declarations
      - mc_parameters.h	This file provides declarations of HW parameters specific to the configuration of the subsystem
      - parameters_conversion.h	This file includes the proper Parameter conversion on the base of stdlib for the first drive

- MCSDK	
   - MCLib	
      - Any	
      - C0xx	
      - F0xx	
      - F3xx	
      - F4xx	
      - F7xx	
      - G0xx	
      - G4xx	
      - H5xx	
      - H7xx	
      - L4xx	

- Src	
   - COMMON
      - aspep.c	This file provides firmware functions that implement the aspep protocol
      - dac_ui.c	This file provides firmware functions that implement the following features of the dac component of the Motor Control SDK:
      - hall_speed_pos_fdbk.c	This file provides firmware functions that implement the features of the Hall Speed & Position Feedback component of the Motor Control SDK
      - mc_api.c	This file implements the high level interface of the Motor Control SDK
      - mc_app_hooks.c	This file implements default motor control app hooks
      - mc_config_common.c	Motor Control Subsystem components configuration and handler structures
      - mc_curr_ctrl.c	This file provides firmware functions of the current controller component
      - mc_interface.c	This file provides firmware functions that implement the features of the MC Interface component of the Motor Control SDK:
      - mc_math.c	This file provides mathematics functions useful for and specific to Motor Control
      - mc_perf.c	Execution time measurement
      - mc_potentiometer.c	This file implements potentiometer application
      - mc_tasks.c	This file implements tasks definition
      - mcp.c	This file provides firmware functions that implement the MCP protocol
      - mcp_config.c	This file provides configuration information of the MCP protocol
      - motorcontrol.c	Motor Control Subsystem initialization functions
      - pwm_common.c	This file provides firmware functions that implement common features of the PWM & Current Feedback component of the Motor Control SDK:
      - pwm_curr_fdbk.c	This file provides firmware functions that implement the following features of the PWM & Current Feedback component of the Motor Control SDK:
      - r1_ps_pwm_curr_fdbk.c	This file provides firmware functions that implement the following features of the CCC component of the Motor Control SDK:
      - register_interface.c	This file provides firmware functions that implement the register access for the MCP protocol
      - regular_conversion_manager.c	This file provides firmware functions that implement the following features of the regular_conversion_manager component of the Motor Control SDK: Register conversion with or without callback Execute regular conv directly from Temperature and VBus sensors Execute user regular conversion scheduled by medium frequency task Manage user conversion state machine
      - usart_aspep_driver.c	This file provides firmware functions that implement the uart driver for the aspep protocol
   - FOC
      - mc_config.c	Motor Control Subsystem components configuration and handler structures
      - mc_parameters.c	This file provides definitions of HW parameters specific to the configuration of the subsystem
      - mc_tasks_foc.c	This file implements tasks definition
   - HSO	
      - mc_api.c	This file implements the high level interface of the Motor Control SDK
      - mc_interface.c	This file provides firmware functions that implement the features of the MC Interface component of the Motor Control SDK
      - mc_polpulse.c	This file provides the code to trigger the PolPulse component
      - oversampling.c	This file provides firmware functions of oversampling component
      - rsdc_est.c	This file implements Rs DC estimation routines
      - speed_pos_fdbk_hso.c	This file provides firmware functions that implement the features of the Speed & Position Feedback HSO component of the Motor Control SDK
      - speed_torq_ctrl_hso.c	This file provides firmware functions of the speed and torque control HSO component
   - SIXSTEP	
      - mc_config.c	Motor Control Subsystem components configuration and handler structures
      - mc_parameters.c	This file provides definitions of HW parameters specific to the configuration of the subsystem
      - mc_tasks_sixstep.c	This file implements tasks definition

从 STM32 MCSDK v6.3.1 的帮助文档(/MC_SDK_6.3.1/Documentation/html/globals.html)或 Wiki,可以查阅函数、变量、定义、枚举和typedef的列表和文档。

2.4 开发环境

MC SDK5.x 包含有芯片外设库、电机库和电机应用层三个主要部分,其中芯片外设库使用 ST HAL/LL 库,可被各个层级调用; 电机库则是主要的电机FOC控制层;最上层为电机应用层,供用户直接使用电机库,而不去关心底层如何实现的,加快用户 程序开发;另外 MC SDK5.x 还提供 UI 库,用于界面调试通讯使用,比如和 Workbench 之间的交互就是通过 UI 库实现; 这边强调的一点是电机库是综合体,包含 FOC 算法,单片机外设配置,中断机制等各个环节, 简单控制可能只需要关心电机 应用层即可,如果复杂控制将涉及到整体操作;

在 SDK 使用过程中,电机本体,电机控制硬件板,控制管脚,控制策略在 MC workbench 中配置完成,顺序为 MC Workbench→CubeMx工程→电机库代码(芯片外设库+电机控制库+电机驾驶舱+用户界面库+系统初始化),该生成 代码加入简单API后(比如 MC_StartMotor1)可以直接运行对应电机,当需要细化控制或者复杂控制时才有可能涉及到修改电机控制库中的代码

MC SDK用于开发基于Arm® Cortex®-M处理器的STM32 32位微控制器上运行的电机控制应用程序。

参考资料:

  1. P-NUCLEO-IHM03 STM32电机控制套件
  2. UM2505 - STM32G4 Nucleo-64 boards (MB1367), STMicroelectronics/意法半导体, 2021
  3. UM2538 - STM32 motor-control pack using the FOC algorithm for three-phase, low-voltage, and low‑current motor evaluationl, STMicroelectronics/意法半导体, 2023
  4. 许少伦等,STM32G4入门与电机控制实战,电子工业出版社,2023

版权声明:

欢迎订阅youcans@qq 原创作品 【动手学电机驱动专栏】

转载必须标注原文链接:(https://blog.csdn.net/youcans/category_12645064.html)

Copyright@youcans 2024

Crated:2025-11

相关推荐
rechol2 小时前
cpu异常中断(2)
单片机·嵌入式硬件
会编程是什么感觉...3 小时前
硬件 - 常见通信协议整合
单片机·嵌入式硬件·fpga开发
沐欣工作室_lvyiyi3 小时前
基于单片机的垃圾容量监测与语音交互系统设计(论文+源码)
stm32·单片机·嵌入式硬件·垃圾桶
rechol4 小时前
mcu启动流程
stm32·单片机·mcu·嵌入式
chuwengeileyan14 小时前
stm32 adc采集光敏传感器模块的模拟输出脚A0的值
单片机·嵌入式硬件
啊森要自信4 小时前
【C语言】 C语言文件操作
c语言·开发语言·汇编·stm32·单片机
1+2单片机电子设计5 小时前
基于 STM32 的数控 BUCK-BOOST 升降压电源设计
stm32·单片机·嵌入式硬件
SUNNYSPY0015 小时前
SI2301S-ASEMI工业控制专用SI2301S
单片机
易水寒陈6 小时前
解析器模式,解析不同协议
stm32·单片机