├── .gitignore ├── Firmware ├── Arduino-FOC-2.1.1.zip ├── FocController.zip ├── FocController │ ├── .cproject │ ├── .mxproject │ ├── .project │ ├── .settings │ │ ├── com.st.stm32cube.ide.mcu.sfrview.prefs │ │ ├── language.settings.xml │ │ ├── org.eclipse.cdt.codan.core.prefs │ │ ├── org.eclipse.cdt.core.prefs │ │ └── stm32cubeide.project.prefs │ ├── Core │ │ ├── Inc │ │ │ ├── FreeRTOSConfig.h │ │ │ ├── adc.h │ │ │ ├── can.h │ │ │ ├── gpio.h │ │ │ ├── main.h │ │ │ ├── spi.h │ │ │ ├── stm32f4xx_hal_conf.h │ │ │ ├── stm32f4xx_it.h │ │ │ ├── tim.h │ │ │ └── usart.h │ │ ├── Src │ │ │ ├── adc.c │ │ │ ├── can.c │ │ │ ├── freertos.c │ │ │ ├── gpio.c │ │ │ ├── main.c │ │ │ ├── spi.c │ │ │ ├── stm32f4xx_hal_msp.c │ │ │ ├── stm32f4xx_it.c │ │ │ ├── syscalls.c │ │ │ ├── sysmem.c │ │ │ ├── system_stm32f4xx.c │ │ │ ├── tim.c │ │ │ └── usart.c │ │ └── Startup │ │ │ └── startup_stm32f405rgtx.s │ ├── Drivers │ │ ├── CMSIS │ │ │ ├── Device │ │ │ │ └── ST │ │ │ │ │ └── STM32F4xx │ │ │ │ │ ├── Include │ │ │ │ │ ├── stm32f405xx.h │ │ │ │ │ ├── stm32f4xx.h │ │ │ │ │ └── system_stm32f4xx.h │ │ │ │ │ └── License.md │ │ │ ├── Include │ │ │ │ ├── cmsis_armcc.h │ │ │ │ ├── cmsis_armclang.h │ │ │ │ ├── cmsis_compiler.h │ │ │ │ ├── cmsis_gcc.h │ │ │ │ ├── cmsis_iccarm.h │ │ │ │ ├── cmsis_version.h │ │ │ │ ├── core_armv8mbl.h │ │ │ │ ├── core_armv8mml.h │ │ │ │ ├── core_cm0.h │ │ │ │ ├── core_cm0plus.h │ │ │ │ ├── core_cm1.h │ │ │ │ ├── core_cm23.h │ │ │ │ ├── core_cm3.h │ │ │ │ ├── core_cm33.h │ │ │ │ ├── core_cm4.h │ │ │ │ ├── core_cm7.h │ │ │ │ ├── core_sc000.h │ │ │ │ ├── core_sc300.h │ │ │ │ ├── mpu_armv7.h │ │ │ │ ├── mpu_armv8.h │ │ │ │ └── tz_context.h │ │ │ └── LICENSE.txt │ │ └── STM32F4xx_HAL_Driver │ │ │ ├── Inc │ │ │ ├── Legacy │ │ │ │ └── stm32_hal_legacy.h │ │ │ ├── stm32f4xx_hal.h │ │ │ ├── stm32f4xx_hal_adc.h │ │ │ ├── stm32f4xx_hal_adc_ex.h │ │ │ ├── stm32f4xx_hal_can.h │ │ │ ├── stm32f4xx_hal_cortex.h │ │ │ ├── stm32f4xx_hal_def.h │ │ │ ├── stm32f4xx_hal_dma.h │ │ │ ├── stm32f4xx_hal_dma_ex.h │ │ │ ├── stm32f4xx_hal_exti.h │ │ │ ├── stm32f4xx_hal_flash.h │ │ │ ├── stm32f4xx_hal_flash_ex.h │ │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ │ ├── stm32f4xx_hal_gpio.h │ │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ │ ├── stm32f4xx_hal_pwr.h │ │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ │ ├── stm32f4xx_hal_rcc.h │ │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ │ ├── stm32f4xx_hal_spi.h │ │ │ ├── stm32f4xx_hal_tim.h │ │ │ ├── stm32f4xx_hal_tim_ex.h │ │ │ ├── stm32f4xx_hal_uart.h │ │ │ └── stm32f4xx_ll_adc.h │ │ │ ├── License.md │ │ │ └── Src │ │ │ ├── stm32f4xx_hal.c │ │ │ ├── stm32f4xx_hal_adc.c │ │ │ ├── stm32f4xx_hal_adc_ex.c │ │ │ ├── stm32f4xx_hal_can.c │ │ │ ├── stm32f4xx_hal_cortex.c │ │ │ ├── stm32f4xx_hal_dma.c │ │ │ ├── stm32f4xx_hal_dma_ex.c │ │ │ ├── stm32f4xx_hal_exti.c │ │ │ ├── stm32f4xx_hal_flash.c │ │ │ ├── stm32f4xx_hal_flash_ex.c │ │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ │ ├── stm32f4xx_hal_gpio.c │ │ │ ├── stm32f4xx_hal_pwr.c │ │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ │ ├── stm32f4xx_hal_rcc.c │ │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ │ ├── stm32f4xx_hal_spi.c │ │ │ ├── stm32f4xx_hal_tim.c │ │ │ ├── stm32f4xx_hal_tim_ex.c │ │ │ ├── stm32f4xx_hal_uart.c │ │ │ └── stm32f4xx_ll_adc.c │ ├── FocController.ioc │ ├── Middlewares │ │ └── Third_Party │ │ │ └── FreeRTOS │ │ │ └── Source │ │ │ ├── CMSIS_RTOS_V2 │ │ │ ├── cmsis_os.h │ │ │ ├── cmsis_os2.c │ │ │ ├── cmsis_os2.h │ │ │ ├── freertos_mpool.h │ │ │ └── freertos_os2.h │ │ │ ├── LICENSE │ │ │ ├── croutine.c │ │ │ ├── event_groups.c │ │ │ ├── include │ │ │ ├── FreeRTOS.h │ │ │ ├── StackMacros.h │ │ │ ├── atomic.h │ │ │ ├── croutine.h │ │ │ ├── deprecated_definitions.h │ │ │ ├── event_groups.h │ │ │ ├── list.h │ │ │ ├── message_buffer.h │ │ │ ├── mpu_prototypes.h │ │ │ ├── mpu_wrappers.h │ │ │ ├── portable.h │ │ │ ├── projdefs.h │ │ │ ├── queue.h │ │ │ ├── semphr.h │ │ │ ├── stack_macros.h │ │ │ ├── stream_buffer.h │ │ │ ├── task.h │ │ │ └── timers.h │ │ │ ├── list.c │ │ │ ├── portable │ │ │ ├── GCC │ │ │ │ └── ARM_CM4F │ │ │ │ │ ├── port.c │ │ │ │ │ └── portmacro.h │ │ │ └── MemMang │ │ │ │ └── heap_4.c │ │ │ ├── queue.c │ │ │ ├── stream_buffer.c │ │ │ ├── tasks.c │ │ │ └── timers.c │ ├── MyCode │ │ ├── Class │ │ │ ├── HardwareCan.cpp │ │ │ ├── HardwareCan.h │ │ │ ├── HardwareSerial.cpp │ │ │ ├── HardwareSerial.h │ │ │ ├── PwmLed.cpp │ │ │ ├── PwmLed.h │ │ │ ├── Shycom.cpp │ │ │ └── Shycom.h │ │ ├── FOC │ │ │ ├── AdcValue.cpp │ │ │ ├── AdcValue.h │ │ │ ├── Encoder.cpp │ │ │ ├── Encoder.h │ │ │ ├── FocController.cpp │ │ │ ├── FocController.h │ │ │ ├── FocConverter.cpp │ │ │ ├── FocConverter.h │ │ │ ├── IncrementalEncoder.cpp │ │ │ ├── IncrementalEncoder.h │ │ │ ├── MagneticSensorSPI.cpp │ │ │ ├── MagneticSensorSPI.h │ │ │ ├── Pid.cpp │ │ │ ├── Pid.h │ │ │ ├── SvPwm.cpp │ │ │ └── SvPwm.h │ │ ├── TaskLed.cpp │ │ └── interfaceIRQ.cpp │ ├── STM32F405RGTX_FLASH.ld │ └── STM32F405RGTX_RAM.ld ├── SVPWM算法原理及详解.pdf └── SimpleFoc │ ├── .cproject │ ├── .mxproject │ ├── .project │ ├── .settings │ ├── com.st.stm32cube.ide.mcu.sfrview.prefs │ ├── language.settings.xml │ ├── org.eclipse.cdt.codan.core.prefs │ ├── org.eclipse.cdt.core.prefs │ └── stm32cubeide.project.prefs │ ├── Core │ ├── Inc │ │ ├── FreeRTOSConfig.h │ │ ├── adc.h │ │ ├── gpio.h │ │ ├── main.h │ │ ├── spi.h │ │ ├── stm32f4xx_hal_conf.h │ │ ├── stm32f4xx_it.h │ │ ├── tim.h │ │ └── usart.h │ ├── SimpleFOC │ │ ├── BLDCMotor.cpp │ │ ├── BLDCMotor.h │ │ ├── SimpleFOC.cpp │ │ ├── SimpleFOC.h │ │ ├── common │ │ │ ├── base_classes │ │ │ │ ├── BLDCDriver.h │ │ │ │ ├── CurrentSense.cpp │ │ │ │ ├── CurrentSense.h │ │ │ │ ├── FOCMotor.cpp │ │ │ │ ├── FOCMotor.h │ │ │ │ ├── Sensor.cpp │ │ │ │ └── Sensor.h │ │ │ ├── defaults.h │ │ │ ├── foc_utils.cpp │ │ │ ├── foc_utils.h │ │ │ ├── lowpass_filter.cpp │ │ │ ├── lowpass_filter.h │ │ │ ├── pid.cpp │ │ │ ├── pid.h │ │ │ ├── time_utils.cpp │ │ │ └── time_utils.h │ │ ├── current_sense │ │ │ ├── InlineCurrentSense.cpp │ │ │ ├── InlineCurrentSense.h │ │ │ ├── hardware_api.h │ │ │ └── hardware_specific │ │ │ │ └── generic_mcu.cpp │ │ ├── drivers │ │ │ ├── BLDCDriver3PWM.cpp │ │ │ ├── BLDCDriver3PWM.h │ │ │ ├── BLDCDriver6PWM.cpp │ │ │ ├── BLDCDriver6PWM.h │ │ │ ├── hardware_api.h │ │ │ └── hardware_specific │ │ │ │ ├── Arduino.h │ │ │ │ └── stm32_mcu.cpp │ │ └── sensors │ │ │ ├── Encoder.cpp │ │ │ ├── Encoder.h │ │ │ ├── MagneticSensorSPI.cpp │ │ │ └── MagneticSensorSPI.h │ ├── Src │ │ ├── adc.c │ │ ├── freertos.c │ │ ├── gpio.c │ │ ├── main.c │ │ ├── spi.c │ │ ├── stm32f4xx_hal_msp.c │ │ ├── stm32f4xx_it.c │ │ ├── syscalls.c │ │ ├── sysmem.c │ │ ├── system_stm32f4xx.c │ │ ├── tim.c │ │ └── usart.c │ └── Startup │ │ └── startup_stm32f405rgtx.s │ ├── Drivers │ ├── CMSIS │ │ ├── Device │ │ │ └── ST │ │ │ │ └── STM32F4xx │ │ │ │ ├── Include │ │ │ │ ├── stm32f405xx.h │ │ │ │ ├── stm32f4xx.h │ │ │ │ └── system_stm32f4xx.h │ │ │ │ └── License.md │ │ ├── Include │ │ │ ├── cmsis_armcc.h │ │ │ ├── cmsis_armclang.h │ │ │ ├── cmsis_compiler.h │ │ │ ├── cmsis_gcc.h │ │ │ ├── cmsis_iccarm.h │ │ │ ├── cmsis_version.h │ │ │ ├── core_armv8mbl.h │ │ │ ├── core_armv8mml.h │ │ │ ├── core_cm0.h │ │ │ ├── core_cm0plus.h │ │ │ ├── core_cm1.h │ │ │ ├── core_cm23.h │ │ │ ├── core_cm3.h │ │ │ ├── core_cm33.h │ │ │ ├── core_cm4.h │ │ │ ├── core_cm7.h │ │ │ ├── core_sc000.h │ │ │ ├── core_sc300.h │ │ │ ├── mpu_armv7.h │ │ │ ├── mpu_armv8.h │ │ │ └── tz_context.h │ │ └── LICENSE.txt │ └── STM32F4xx_HAL_Driver │ │ ├── Inc │ │ ├── Legacy │ │ │ └── stm32_hal_legacy.h │ │ ├── stm32f4xx_hal.h │ │ ├── stm32f4xx_hal_adc.h │ │ ├── stm32f4xx_hal_adc_ex.h │ │ ├── stm32f4xx_hal_cortex.h │ │ ├── stm32f4xx_hal_def.h │ │ ├── stm32f4xx_hal_dma.h │ │ ├── stm32f4xx_hal_dma_ex.h │ │ ├── stm32f4xx_hal_exti.h │ │ ├── stm32f4xx_hal_flash.h │ │ ├── stm32f4xx_hal_flash_ex.h │ │ ├── stm32f4xx_hal_flash_ramfunc.h │ │ ├── stm32f4xx_hal_gpio.h │ │ ├── stm32f4xx_hal_gpio_ex.h │ │ ├── stm32f4xx_hal_pwr.h │ │ ├── stm32f4xx_hal_pwr_ex.h │ │ ├── stm32f4xx_hal_rcc.h │ │ ├── stm32f4xx_hal_rcc_ex.h │ │ ├── stm32f4xx_hal_spi.h │ │ ├── stm32f4xx_hal_tim.h │ │ ├── stm32f4xx_hal_tim_ex.h │ │ ├── stm32f4xx_hal_uart.h │ │ └── stm32f4xx_ll_adc.h │ │ ├── License.md │ │ └── Src │ │ ├── stm32f4xx_hal.c │ │ ├── stm32f4xx_hal_adc.c │ │ ├── stm32f4xx_hal_adc_ex.c │ │ ├── stm32f4xx_hal_cortex.c │ │ ├── stm32f4xx_hal_dma.c │ │ ├── stm32f4xx_hal_dma_ex.c │ │ ├── stm32f4xx_hal_exti.c │ │ ├── stm32f4xx_hal_flash.c │ │ ├── stm32f4xx_hal_flash_ex.c │ │ ├── stm32f4xx_hal_flash_ramfunc.c │ │ ├── stm32f4xx_hal_gpio.c │ │ ├── stm32f4xx_hal_pwr.c │ │ ├── stm32f4xx_hal_pwr_ex.c │ │ ├── stm32f4xx_hal_rcc.c │ │ ├── stm32f4xx_hal_rcc_ex.c │ │ ├── stm32f4xx_hal_spi.c │ │ ├── stm32f4xx_hal_tim.c │ │ ├── stm32f4xx_hal_tim_ex.c │ │ ├── stm32f4xx_hal_uart.c │ │ └── stm32f4xx_ll_adc.c │ ├── MC_Driver Debug.launch │ ├── Middlewares │ └── Third_Party │ │ └── FreeRTOS │ │ └── Source │ │ ├── CMSIS_RTOS_V2 │ │ ├── cmsis_os.h │ │ ├── cmsis_os2.c │ │ ├── cmsis_os2.h │ │ ├── freertos_mpool.h │ │ └── freertos_os2.h │ │ ├── LICENSE │ │ ├── croutine.c │ │ ├── event_groups.c │ │ ├── include │ │ ├── FreeRTOS.h │ │ ├── StackMacros.h │ │ ├── atomic.h │ │ ├── croutine.h │ │ ├── deprecated_definitions.h │ │ ├── event_groups.h │ │ ├── list.h │ │ ├── message_buffer.h │ │ ├── mpu_prototypes.h │ │ ├── mpu_wrappers.h │ │ ├── portable.h │ │ ├── projdefs.h │ │ ├── queue.h │ │ ├── semphr.h │ │ ├── stack_macros.h │ │ ├── stream_buffer.h │ │ ├── task.h │ │ └── timers.h │ │ ├── list.c │ │ ├── portable │ │ ├── GCC │ │ │ └── ARM_CM4F │ │ │ │ ├── port.c │ │ │ │ └── portmacro.h │ │ └── MemMang │ │ │ └── heap_4.c │ │ ├── queue.c │ │ ├── stream_buffer.c │ │ ├── tasks.c │ │ └── timers.c │ ├── STM32F405RGTX_FLASH.ld │ ├── STM32F405RGTX_RAM.ld │ └── SimpleFoc.ioc ├── Hardware ├── BOM_mini_Foc_Core.csv ├── BOM_mini_Foc_Power.csv ├── Gerber_mini_Foc_Core.zip ├── Gerber_mini_Foc_Power.zip ├── Schematic_mini_Foc_Core.pdf └── Schematic_mini_Foc_Power.pdf ├── Picture ├── 1.gif ├── 20170708115503600.png ├── 20190410172920395.png ├── 20190706222310599.png ├── Natural-coordinate-system.gif ├── current_loop.png ├── dq-coordinate-system.gif ├── foc-120.jpg ├── foc-2R.jpg ├── foc-3R.jpg ├── foc-clark.jpg ├── foc-core.jpg ├── foc-park.jpg ├── formula-clark.jpg ├── formula-park.jpg ├── space-vectors.gif ├── speed-loop.png └── αβ-coordinate-system.gif ├── README.md └── Software └── shycom ├── build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug ├── .qmake.stash ├── Makefile ├── Makefile.Debug ├── Makefile.Release ├── debug │ ├── SerialThread.o │ ├── main.o │ ├── mainwindow.o │ ├── moc_SerialThread.cpp │ ├── moc_SerialThread.o │ ├── moc_mainwindow.cpp │ ├── moc_mainwindow.o │ ├── moc_mycurvewidget.cpp │ ├── moc_mycurvewidget.o │ ├── moc_mydockwidget.cpp │ ├── moc_mydockwidget.o │ ├── moc_mymotorwidget.cpp │ ├── moc_mymotorwidget.o │ ├── moc_myserialwidget.cpp │ ├── moc_myserialwidget.o │ ├── moc_predefs.h │ ├── mycurvewidget.o │ ├── mydockwidget.o │ ├── mymotorwidget.o │ ├── myserialwidget.o │ └── shycom.exe ├── object_script.shycom.Debug ├── object_script.shycom.Release └── ui_mainwindow.h └── shycom ├── SerialThread.cpp ├── SerialThread.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── mycurvewidget.cpp ├── mycurvewidget.h ├── mydockwidget.cpp ├── mydockwidget.h ├── mymotorwidget.cpp ├── mymotorwidget.h ├── myserialwidget.cpp ├── myserialwidget.h ├── shycom.pro └── shycom.pro.user /.gitignore: -------------------------------------------------------------------------------- 1 | */*/Debug/ 2 | */*/Release/ 3 | -------------------------------------------------------------------------------- /Firmware/Arduino-FOC-2.1.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Firmware/Arduino-FOC-2.1.1.zip -------------------------------------------------------------------------------- /Firmware/FocController.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Firmware/FocController.zip -------------------------------------------------------------------------------- /Firmware/FocController/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | FocController 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature 24 | org.eclipse.cdt.core.cnature 25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature 26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature 27 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 29 | com.st.stm32cube.ide.mcu.MCURootProjectNature 30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 32 | org.eclipse.cdt.core.ccnature 33 | 34 | 35 | -------------------------------------------------------------------------------- /Firmware/FocController/.settings/com.st.stm32cube.ide.mcu.sfrview.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | svd_custom_file_path= 3 | svd_file_path=platform\:/plugin/com.st.stm32cube.ide.mcu.productdb.debug/resources/cmsis/STMicroelectronics_CMSIS_SVD/STM32F405.svd 4 | -------------------------------------------------------------------------------- /Firmware/FocController/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Firmware/FocController/.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | doxygen/doxygen_new_line_after_brief=true 2 | doxygen/doxygen_use_brief_tag=false 3 | doxygen/doxygen_use_javadoc_tags=true 4 | doxygen/doxygen_use_pre_tag=false 5 | doxygen/doxygen_use_structural_commands=false 6 | eclipse.preferences.version=1 7 | -------------------------------------------------------------------------------- /Firmware/FocController/.settings/stm32cubeide.project.prefs: -------------------------------------------------------------------------------- 1 | 2F62501ED4689FB349E356AB974DBE57=C6DCCBD2A6FE9510BBEDE1C64E1F5FBB 2 | 635E684B79701B039C64EA45C3F84D30=EC0CF2E48BB4571606D72637CE1FFEB6 3 | 8DF89ED150041C4CBC7CB9A9CAA90856=C6DCCBD2A6FE9510BBEDE1C64E1F5FBB 4 | DC22A860405A8BF2F2C095E5B6529F12=74C325809E2A0471032BCF1571CA3A68 5 | eclipse.preferences.version=1 6 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/adc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file adc.h 4 | * @brief This file contains all the function prototypes for 5 | * the adc.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __ADC_H__ 21 | #define __ADC_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern ADC_HandleTypeDef hadc1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_ADC1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | uint32_t readPhaseVoltage(const int pinA); 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __ADC_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/can.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file can.h 4 | * @brief This file contains all the function prototypes for 5 | * the can.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __CAN_H__ 21 | #define __CAN_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern CAN_HandleTypeDef hcan1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_CAN1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __CAN_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.h 4 | * @brief This file contains all the function prototypes for 5 | * the gpio.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __GPIO_H__ 21 | #define __GPIO_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ GPIO_H__ */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | void StartFocTask(void *argument); 41 | void protocolTask(void *argument); 42 | /* USER CODE END ET */ 43 | 44 | /* Exported constants --------------------------------------------------------*/ 45 | /* USER CODE BEGIN EC */ 46 | 47 | /* USER CODE END EC */ 48 | 49 | /* Exported macro ------------------------------------------------------------*/ 50 | /* USER CODE BEGIN EM */ 51 | unsigned long micros(void); 52 | unsigned int millis(void); 53 | /* USER CODE END EM */ 54 | 55 | /* Exported functions prototypes ---------------------------------------------*/ 56 | void Error_Handler(void); 57 | 58 | /* USER CODE BEGIN EFP */ 59 | void setupSimpleFOC(void); 60 | void loopSimpleFOC(void); 61 | void disableSimpleFOC(int s); 62 | void setTarget(float t); 63 | /* USER CODE END EFP */ 64 | 65 | /* Private defines -----------------------------------------------------------*/ 66 | /* USER CODE BEGIN Private defines */ 67 | 68 | /* USER CODE END Private defines */ 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif /* __MAIN_H */ 75 | 76 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 77 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.h 4 | * @brief This file contains all the function prototypes for 5 | * the spi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __SPI_H__ 21 | #define __SPI_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern SPI_HandleTypeDef hspi1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_SPI1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __SPI_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_IT_H 23 | #define __STM32F4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void DebugMon_Handler(void); 56 | void SysTick_Handler(void); 57 | void ADC_IRQHandler(void); 58 | void CAN1_RX0_IRQHandler(void); 59 | void UART4_IRQHandler(void); 60 | void TIM6_DAC_IRQHandler(void); 61 | /* USER CODE BEGIN EFP */ 62 | 63 | /* USER CODE END EFP */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __STM32F4xx_IT_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/tim.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file tim.h 4 | * @brief This file contains all the function prototypes for 5 | * the tim.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __TIM_H__ 21 | #define __TIM_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern TIM_HandleTypeDef htim1; 35 | extern TIM_HandleTypeDef htim3; 36 | extern TIM_HandleTypeDef htim6; 37 | 38 | /* USER CODE BEGIN Private defines */ 39 | 40 | /* USER CODE END Private defines */ 41 | 42 | void MX_TIM1_Init(void); 43 | void MX_TIM3_Init(void); 44 | void MX_TIM6_Init(void); 45 | 46 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); 47 | 48 | /* USER CODE BEGIN Prototypes */ 49 | 50 | /* USER CODE END Prototypes */ 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* __TIM_H__ */ 57 | 58 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 59 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart.h 4 | * @brief This file contains all the function prototypes for 5 | * the usart.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USART_H__ 21 | #define __USART_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern UART_HandleTypeDef huart4; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_UART4_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | void uart6SendByte(uint8_t ch); 44 | void uart4SendLen(uint8_t *p, int num); 45 | /* USER CODE END Prototypes */ 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* __USART_H__ */ 52 | 53 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 54 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Src/gpio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.c 4 | * @brief This file provides code for the configuration 5 | * of all used GPIO pins. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "gpio.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /* Configure GPIO */ 29 | /*----------------------------------------------------------------------------*/ 30 | /* USER CODE BEGIN 1 */ 31 | 32 | /* USER CODE END 1 */ 33 | 34 | /** Configure pins as 35 | * Analog 36 | * Input 37 | * Output 38 | * EVENT_OUT 39 | * EXTI 40 | */ 41 | void MX_GPIO_Init(void) 42 | { 43 | 44 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 45 | 46 | /* GPIO Ports Clock Enable */ 47 | __HAL_RCC_GPIOH_CLK_ENABLE(); 48 | __HAL_RCC_GPIOC_CLK_ENABLE(); 49 | __HAL_RCC_GPIOA_CLK_ENABLE(); 50 | __HAL_RCC_GPIOB_CLK_ENABLE(); 51 | 52 | /*Configure GPIO pin Output Level */ 53 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); 54 | 55 | /*Configure GPIO pin Output Level */ 56 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0|GPIO_PIN_11, GPIO_PIN_RESET); 57 | 58 | /*Configure GPIO pin Output Level */ 59 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_SET); 60 | 61 | /*Configure GPIO pin : PA4 */ 62 | GPIO_InitStruct.Pin = GPIO_PIN_4; 63 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 64 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 65 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 66 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 67 | 68 | /*Configure GPIO pins : PB0 PB10 PB11 */ 69 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_10|GPIO_PIN_11; 70 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 71 | GPIO_InitStruct.Pull = GPIO_NOPULL; 72 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 73 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 74 | 75 | /*Configure GPIO pins : PB13 PB14 PB15 */ 76 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; 77 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 78 | GPIO_InitStruct.Pull = GPIO_PULLUP; 79 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 80 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 81 | 82 | } 83 | 84 | /* USER CODE BEGIN 2 */ 85 | 86 | /* USER CODE END 2 */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Src/spi.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.c 4 | * @brief This file provides code for the configuration 5 | * of the SPI instances. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "spi.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | SPI_HandleTypeDef hspi1; 28 | 29 | /* SPI1 init function */ 30 | void MX_SPI1_Init(void) 31 | { 32 | 33 | /* USER CODE BEGIN SPI1_Init 0 */ 34 | 35 | /* USER CODE END SPI1_Init 0 */ 36 | 37 | /* USER CODE BEGIN SPI1_Init 1 */ 38 | 39 | /* USER CODE END SPI1_Init 1 */ 40 | hspi1.Instance = SPI1; 41 | hspi1.Init.Mode = SPI_MODE_MASTER; 42 | hspi1.Init.Direction = SPI_DIRECTION_2LINES; 43 | hspi1.Init.DataSize = SPI_DATASIZE_16BIT; 44 | hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; 45 | hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; 46 | hspi1.Init.NSS = SPI_NSS_SOFT; 47 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; 48 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; 49 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; 50 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; 51 | hspi1.Init.CRCPolynomial = 10; 52 | if (HAL_SPI_Init(&hspi1) != HAL_OK) 53 | { 54 | Error_Handler(); 55 | } 56 | /* USER CODE BEGIN SPI1_Init 2 */ 57 | 58 | /* USER CODE END SPI1_Init 2 */ 59 | 60 | } 61 | 62 | void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) 63 | { 64 | 65 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 66 | if(spiHandle->Instance==SPI1) 67 | { 68 | /* USER CODE BEGIN SPI1_MspInit 0 */ 69 | 70 | /* USER CODE END SPI1_MspInit 0 */ 71 | /* SPI1 clock enable */ 72 | __HAL_RCC_SPI1_CLK_ENABLE(); 73 | 74 | __HAL_RCC_GPIOA_CLK_ENABLE(); 75 | /**SPI1 GPIO Configuration 76 | PA5 ------> SPI1_SCK 77 | PA6 ------> SPI1_MISO 78 | PA7 ------> SPI1_MOSI 79 | */ 80 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; 81 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 82 | GPIO_InitStruct.Pull = GPIO_NOPULL; 83 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 84 | GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; 85 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 86 | 87 | /* USER CODE BEGIN SPI1_MspInit 1 */ 88 | 89 | /* USER CODE END SPI1_MspInit 1 */ 90 | } 91 | } 92 | 93 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle) 94 | { 95 | 96 | if(spiHandle->Instance==SPI1) 97 | { 98 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ 99 | 100 | /* USER CODE END SPI1_MspDeInit 0 */ 101 | /* Peripheral clock disable */ 102 | __HAL_RCC_SPI1_CLK_DISABLE(); 103 | 104 | /**SPI1 GPIO Configuration 105 | PA5 ------> SPI1_SCK 106 | PA6 ------> SPI1_MISO 107 | PA7 ------> SPI1_MOSI 108 | */ 109 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7); 110 | 111 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ 112 | 113 | /* USER CODE END SPI1_MspDeInit 1 */ 114 | } 115 | } 116 | 117 | /* USER CODE BEGIN 1 */ 118 | 119 | /* USER CODE END 1 */ 120 | 121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 122 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | /* PendSV_IRQn interrupt configuration */ 75 | HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); 76 | 77 | /* USER CODE BEGIN MspInit 1 */ 78 | 79 | /* USER CODE END MspInit 1 */ 80 | } 81 | 82 | /* USER CODE BEGIN 1 */ 83 | 84 | /* USER CODE END 1 */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | /* Variables */ 36 | //#undef errno 37 | extern int errno; 38 | extern int __io_putchar(int ch) __attribute__((weak)); 39 | extern int __io_getchar(void) __attribute__((weak)); 40 | 41 | register char * stack_ptr asm("sp"); 42 | 43 | char *__env[1] = { 0 }; 44 | char **environ = __env; 45 | 46 | 47 | /* Functions */ 48 | void initialise_monitor_handles() 49 | { 50 | } 51 | 52 | int _getpid(void) 53 | { 54 | return 1; 55 | } 56 | 57 | int _kill(int pid, int sig) 58 | { 59 | errno = EINVAL; 60 | return -1; 61 | } 62 | 63 | void _exit (int status) 64 | { 65 | _kill(status, -1); 66 | while (1) {} /* Make sure we hang here */ 67 | } 68 | 69 | __attribute__((weak)) int _read(int file, char *ptr, int len) 70 | { 71 | int DataIdx; 72 | 73 | for (DataIdx = 0; DataIdx < len; DataIdx++) 74 | { 75 | *ptr++ = __io_getchar(); 76 | } 77 | 78 | return len; 79 | } 80 | 81 | __attribute__((weak)) int _write(int file, char *ptr, int len) 82 | { 83 | int DataIdx; 84 | 85 | for (DataIdx = 0; DataIdx < len; DataIdx++) 86 | { 87 | __io_putchar(*ptr++); 88 | } 89 | return len; 90 | } 91 | 92 | int _close(int file) 93 | { 94 | return -1; 95 | } 96 | 97 | 98 | int _fstat(int file, struct stat *st) 99 | { 100 | st->st_mode = S_IFCHR; 101 | return 0; 102 | } 103 | 104 | int _isatty(int file) 105 | { 106 | return 1; 107 | } 108 | 109 | int _lseek(int file, int ptr, int dir) 110 | { 111 | return 0; 112 | } 113 | 114 | int _open(char *path, int flags, ...) 115 | { 116 | /* Pretend like we always fail */ 117 | return -1; 118 | } 119 | 120 | int _wait(int *status) 121 | { 122 | errno = ECHILD; 123 | return -1; 124 | } 125 | 126 | int _unlink(char *name) 127 | { 128 | errno = ENOENT; 129 | return -1; 130 | } 131 | 132 | int _times(struct tms *buf) 133 | { 134 | return -1; 135 | } 136 | 137 | int _stat(char *file, struct stat *st) 138 | { 139 | st->st_mode = S_IFCHR; 140 | return 0; 141 | } 142 | 143 | int _link(char *old, char *new) 144 | { 145 | errno = EMLINK; 146 | return -1; 147 | } 148 | 149 | int _fork(void) 150 | { 151 | errno = EAGAIN; 152 | return -1; 153 | } 154 | 155 | int _execve(char *name, char **argv, char **env) 156 | { 157 | errno = ENOMEM; 158 | return -1; 159 | } 160 | -------------------------------------------------------------------------------- /Firmware/FocController/Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | 28 | /** 29 | * Pointer to the current high watermark of the heap usage 30 | */ 31 | static uint8_t *__sbrk_heap_end = NULL; 32 | 33 | /** 34 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 35 | * and others from the C library 36 | * 37 | * @verbatim 38 | * ############################################################################ 39 | * # .data # .bss # newlib heap # MSP stack # 40 | * # # # # Reserved by _Min_Stack_Size # 41 | * ############################################################################ 42 | * ^-- RAM start ^-- _end _estack, RAM end --^ 43 | * @endverbatim 44 | * 45 | * This implementation starts allocating at the '_end' linker symbol 46 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 47 | * The implementation considers '_estack' linker symbol to be RAM end 48 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 49 | * reserved size, please increase the '_Min_Stack_Size'. 50 | * 51 | * @param incr Memory size 52 | * @return Pointer to allocated memory 53 | */ 54 | void *_sbrk(ptrdiff_t incr) 55 | { 56 | extern uint8_t _end; /* Symbol defined in the linker script */ 57 | extern uint8_t _estack; /* Symbol defined in the linker script */ 58 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 59 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 60 | const uint8_t *max_heap = (uint8_t *)stack_limit; 61 | uint8_t *prev_heap_end; 62 | 63 | /* Initialize heap end at first call */ 64 | if (NULL == __sbrk_heap_end) 65 | { 66 | __sbrk_heap_end = &_end; 67 | } 68 | 69 | /* Protect heap from growing into the reserved MSP stack */ 70 | if (__sbrk_heap_end + incr > max_heap) 71 | { 72 | errno = ENOMEM; 73 | return (void *)-1; 74 | } 75 | 76 | prev_heap_end = __sbrk_heap_end; 77 | __sbrk_heap_end += incr; 78 | 79 | return (void *)prev_heap_end; 80 | } 81 | -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Firmware/FocController/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /Firmware/FocController/Drivers/STM32F4xx_HAL_Driver/License.md: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 STMicroelectronics 2 | 3 | This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). -------------------------------------------------------------------------------- /Firmware/FocController/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- 2 | * Copyright (c) 2013-2020 Arm Limited. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * Name: freertos_mpool.h 19 | * Purpose: CMSIS RTOS2 wrapper for FreeRTOS 20 | * 21 | *---------------------------------------------------------------------------*/ 22 | 23 | #ifndef FREERTOS_MPOOL_H_ 24 | #define FREERTOS_MPOOL_H_ 25 | 26 | #include 27 | #include "FreeRTOS.h" 28 | #include "semphr.h" 29 | 30 | /* Memory Pool implementation definitions */ 31 | #define MPOOL_STATUS 0x5EED0000U 32 | 33 | /* Memory Block header */ 34 | typedef struct { 35 | void *next; /* Pointer to next block */ 36 | } MemPoolBlock_t; 37 | 38 | /* Memory Pool control block */ 39 | typedef struct MemPoolDef_t { 40 | MemPoolBlock_t *head; /* Pointer to head block */ 41 | SemaphoreHandle_t sem; /* Pool semaphore handle */ 42 | uint8_t *mem_arr; /* Pool memory array */ 43 | uint32_t mem_sz; /* Pool memory array size */ 44 | const char *name; /* Pointer to name string */ 45 | uint32_t bl_sz; /* Size of a single block */ 46 | uint32_t bl_cnt; /* Number of blocks */ 47 | uint32_t n; /* Block allocation index */ 48 | volatile uint32_t status; /* Object status flags */ 49 | #if (configSUPPORT_STATIC_ALLOCATION == 1) 50 | StaticSemaphore_t mem_sem; /* Semaphore object memory */ 51 | #endif 52 | } MemPool_t; 53 | 54 | /* No need to hide static object type, just align to coding style */ 55 | #define StaticMemPool_t MemPool_t 56 | 57 | /* Define memory pool control block size */ 58 | #define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t)) 59 | 60 | /* Define size of the byte array required to create count of blocks of given size */ 61 | #define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count)) 62 | 63 | #endif /* FREERTOS_MPOOL_H_ */ 64 | -------------------------------------------------------------------------------- /Firmware/FocController/Middlewares/Third_Party/FreeRTOS/Source/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of 3 | this software and associated documentation files (the "Software"), to deal in 4 | the Software without restriction, including without limitation the rights to 5 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 6 | the Software, and to permit persons to whom the Software is furnished to do so, 7 | subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 14 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/HardwareCan.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //HardwareCan::HardwareCan() { 4 | // // TODO Auto-generated destructor stub 5 | //} 6 | void HardwareCan::DoProtocol(void){ 7 | 8 | } 9 | 10 | HardwareCan::~HardwareCan() { 11 | // TODO Auto-generated destructor stub 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/HardwareCan.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_HARDWARECAN_H_ 2 | #define CLASS_HARDWARECAN_H_ 3 | #include "main.h" 4 | #include 5 | 6 | typedef struct { 7 | CAN_RxHeaderTypeDef Header; 8 | uint8_t Data[8]; 9 | } CanMessage_t; 10 | 11 | class HardwareCan { 12 | public: 13 | HardwareCan(CAN_HandleTypeDef *hcan):Hcan(hcan){}; 14 | virtual ~HardwareCan(); 15 | 16 | CAN_HandleTypeDef *Hcan; 17 | 18 | std::vector TransmitMsg; 19 | std::vector ReceiveMsg; 20 | 21 | virtual void DoProtocol(void); 22 | }; 23 | 24 | #endif /* CLASS_HARDWARECAN_H_ */ 25 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | #ifndef HARDWARESERIAL_H_ 2 | #define HARDWARESERIAL_H_ 3 | 4 | #include "string.h" 5 | #include "stdint.h" 6 | #include "FreeRTOS.h" 7 | #include "task.h" 8 | #include "main.h" 9 | #include 10 | #include "usart.h" 11 | #include 12 | #include 13 | 14 | #define SERIAL_RX_BUFFER_SIZE 512 15 | #define SERIAL_TX_BUFFER_SIZE 512 16 | 17 | class HardwareSerial { 18 | public: 19 | HardwareSerial(USART_TypeDef* UartInstance, int32_t baud = 115200); 20 | //HardwareSerial(); 21 | virtual ~HardwareSerial(); 22 | 23 | //public: 24 | protected: 25 | UART_HandleTypeDef Huart; 26 | USART_TypeDef *Instance; 27 | int Baud; 28 | 29 | uint8_t Rx_Buffer[SERIAL_RX_BUFFER_SIZE]; 30 | uint8_t Tx_Buffer[SERIAL_TX_BUFFER_SIZE]; 31 | uint64_t RxTimeStamp; 32 | unsigned int Buffer_Head = 0, Buffer_Tail = 0; /** head当前位置数据有效,tail位置前一位才是有效数据*/ 33 | int Available = 0; /** 接收数据可用长度*/ 34 | int Tx_Len; /** 发送数据长度*/ 35 | 36 | bool Lock; 37 | 38 | public: 39 | void Begin(int baud); 40 | void Begin(void); 41 | int GetAvailable(void){return Available;} 42 | uint64_t GetRxTimeStamp(void){return RxTimeStamp;} 43 | uint8_t Read(void); 44 | int Read(uint8_t* dest, int num); 45 | int Add(uint8_t ch); 46 | int Add(uint8_t* src, int num); 47 | void (*pOneWrite)(uint8_t ch); 48 | void (*pWrite)(uint8_t *src, int num); 49 | 50 | void OneWrite(uint8_t ch){ 51 | while((Instance->SR & 0X40) == 0); 52 | Instance->DR = (uint8_t)ch; 53 | }; 54 | void Write(uint8_t *src, int num){ 55 | while(num--){ 56 | this->OneWrite(*src); 57 | src++; 58 | } 59 | }; 60 | 61 | uint8_t StrBuf[100]; 62 | void printf(char *fmt,...){ 63 | va_list ap; 64 | va_start(ap, fmt); 65 | vsprintf((char*)StrBuf, fmt, ap); 66 | Write(StrBuf, strlen((char*)StrBuf)); 67 | va_end(ap); 68 | } 69 | 70 | virtual void DoProtocol(void){} 71 | 72 | }; 73 | 74 | #endif /* HARDWARESERIAL_H_ */ 75 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/PwmLed.cpp: -------------------------------------------------------------------------------- 1 | #include "PwmLed.h" 2 | 3 | PwmLed::PwmLed() { 4 | // TODO Auto-generated constructor stub 5 | this->Status = this->OFF; 6 | 7 | } 8 | PwmLed::PwmLed(TIM_HandleTypeDef* p, int chan, int t) { 9 | this->Handle_Tim = p; 10 | this->Channel = chan; 11 | this->Status = this->OFF; 12 | if(t > 100) this->Base_Time = 100; 13 | else if(t < 10) this->Base_Time = 10; 14 | else this->Base_Time = t; 15 | //__HAL_TIM_SetCompare(&htim12, TIM_CHANNEL_1, 300); 16 | } 17 | 18 | void PwmLed::SetPwm(int pwm) { 19 | __HAL_TIM_SetCompare((TIM_HandleTypeDef*)this->Handle_Tim, this->Channel, pwm); 20 | } 21 | 22 | void PwmLed::Run(void) { 23 | this->Inc_Time += this->Base_Time; 24 | 25 | switch(this->Status){ 26 | case this->BREATHING: 27 | if(this->Dir) this->Pwm += this->Base_Time / 10; 28 | else this->Pwm -= this->Base_Time / 10; 29 | if(this->Pwm > 100 && this->Dir) this->Dir = 0; /** 呼吸灯的亮度从5~100,太亮看不出区别,没有呼吸效果*/ 30 | else if(this->Pwm < 5 && !this->Dir) this->Dir = 1; 31 | break; 32 | case this->OFF: this->Pwm = 0; break; 33 | case this->ON : this->Pwm = this->High; break; 34 | case this->FLASHING: 35 | if((this->Inc_Time % (500/this->Freq)) < this->Base_Time){ /** 计算频率间隔时间,取模小于一个周期反转状态*/ 36 | if(this->Pwm > this->High/2) this->Pwm = 0; 37 | else this->Pwm = this->High; 38 | this->Inc_Time = 0; 39 | } 40 | break; 41 | } 42 | this->SetPwm(this->Pwm); 43 | } 44 | 45 | void PwmLed::SetOn(void) { 46 | this->Status = this->ON; 47 | } 48 | 49 | void PwmLed::SetOff(void) { 50 | this->Status = this->OFF; 51 | } 52 | 53 | void PwmLed::SetBreathing(void) { 54 | this->Status = this->BREATHING; 55 | } 56 | 57 | void PwmLed::SetFlashing(int freq) { 58 | this->Status = this->FLASHING; 59 | if(freq > 10) freq = 10; 60 | if(freq > 0) this->Freq = freq; 61 | else this->Status = this->OFF; 62 | } 63 | 64 | int PwmLed::SetToggle(void) { 65 | if(this->Status == this->ON) 66 | this->Status = this->OFF; 67 | else if(this->Status == this->OFF) 68 | this->Status = this->ON; 69 | 70 | if(this->Status == this->ON || this->Status == this->OFF) return 1; 71 | else return 0; 72 | } 73 | 74 | PwmLed::~PwmLed() { 75 | // TODO Auto-generated destructor stub 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/PwmLed.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_PWMLED_H_ 2 | #define CLASS_PWMLED_H_ 3 | 4 | #include "main.h" 5 | 6 | class PwmLed { 7 | public: 8 | PwmLed(); 9 | PwmLed(TIM_HandleTypeDef* p, int chan, int t = 10 /*ms*/ ); 10 | virtual ~PwmLed(); 11 | 12 | public: 13 | TIM_HandleTypeDef *Handle_Tim = 0; 14 | int Channel; 15 | 16 | unsigned int Inc_Time = 0; /** run函数运行的时基*/ 17 | int Pwm; /** 暂存当前pwm的值 */ 18 | int Freq; /** 闪烁的频率*/ 19 | int Base_Time; /** run函数运行时间间隔,取值10~100ms*/ 20 | int Dir = 0; /** 呼吸灯计算时的方向*/ 21 | int High = 300; /** 最大亮度*/ 22 | 23 | public: 24 | enum {BREATHING = -2, OFF, ON, FLASHING} Status; 25 | 26 | void SetTime(TIM_HandleTypeDef* p){this->Handle_Tim = p;} 27 | void SetChannel(int chan){this->Channel = chan;} 28 | 29 | void SetPwm(int pwm); 30 | void Run(void); 31 | 32 | void SetOn(void); 33 | void SetOff(void); 34 | void SetBreathing(void); 35 | void SetFlashing(int freq); 36 | void SetBasetime(int t){Base_Time = t;} 37 | 38 | int SetToggle(void); 39 | int GetStatus(void){return Status;} 40 | 41 | }; 42 | 43 | #endif /* CLASS_PWMLED_H_ */ 44 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/Class/Shycom.h: -------------------------------------------------------------------------------- 1 | #ifndef CLASS_SHYCOM_H_ 2 | #define CLASS_SHYCOM_H_ 3 | 4 | #include "HardwareSerial.h" 5 | 6 | #define PROTOCOL_BUFFER_SIZE 100 7 | 8 | class Shycom: public HardwareSerial { 9 | public: 10 | Shycom(USART_TypeDef* UartInstance, int32_t baud = 115200); 11 | virtual ~Shycom(); 12 | 13 | virtual void DoProtocol(); 14 | 15 | uint8_t Param_Len[256]; 16 | int Protocol_Buffer_Len = 0; 17 | uint8_t Protocol_Buffer[PROTOCOL_BUFFER_SIZE]; 18 | 19 | void ReportCurveValue(const float *value, uint8_t len); 20 | 21 | }; 22 | 23 | #endif /* CLASS_SHYCOM_H_ */ 24 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/AdcValue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | AdcValue::AdcValue() { 4 | // TODO Auto-generated constructor stub 5 | } 6 | 7 | AdcValue::~AdcValue() { 8 | // TODO Auto-generated destructor stub 9 | } 10 | 11 | 12 | void AdcValue::Offset(int cnt){ 13 | unsigned int iu = 0, iv = 0, iw = 0; 14 | 15 | if(this->Adc3){ 16 | HAL_ADC_Start(this->Adc1); 17 | HAL_ADC_Start(this->Adc2); 18 | HAL_ADC_Start(this->Adc3); 19 | 20 | for(int i=0; iAdc1, this->Rank1); 22 | iv += HAL_ADCEx_InjectedGetValue(this->Adc2, this->Rank2); 23 | iw += HAL_ADCEx_InjectedGetValue(this->Adc3, this->Rank3); 24 | HAL_Delay(1); 25 | } 26 | this->OffsetValue.iu = (float)iu / cnt * ADC2AMPS; 27 | this->OffsetValue.iv = (float)iv / cnt * ADC2AMPS; 28 | this->OffsetValue.iw = (float)iw / cnt * ADC2AMPS; 29 | }else{ 30 | HAL_ADC_Start(this->Adc1); 31 | HAL_ADC_Start(this->Adc2); 32 | 33 | for(int i=0; iAdc1, this->Rank1); 35 | iv += HAL_ADCEx_InjectedGetValue(this->Adc2, this->Rank2); 36 | HAL_Delay(1); 37 | } 38 | this->OffsetValue.iu = (float)iu / cnt * ADC2AMPS; 39 | this->OffsetValue.iv = (float)iv / cnt * ADC2AMPS; 40 | this->OffsetValue.iw = 0; 41 | } 42 | // HAL_ADCEx_InjectedStart_IT(&hadc1); 43 | } 44 | #include "stdio.h" 45 | void AdcValue::Update(void){ 46 | unsigned int iu = 0, iv = 0, iw = 0; 47 | 48 | if(this->Adc3){ 49 | iu = HAL_ADCEx_InjectedGetValue(this->Adc1, this->Rank1); 50 | iv = HAL_ADCEx_InjectedGetValue(this->Adc2, this->Rank2); 51 | iw = HAL_ADCEx_InjectedGetValue(this->Adc3, this->Rank3); 52 | 53 | this->Value.iu = this->OffsetValue.iu - iu * ADC2AMPS; 54 | this->Value.iv = this->OffsetValue.iv - iv * ADC2AMPS; 55 | this->Value.iw = this->OffsetValue.iw - iw * ADC2AMPS; 56 | }else{ 57 | iu = HAL_ADCEx_InjectedGetValue(this->Adc1, this->Rank1); 58 | iv = HAL_ADCEx_InjectedGetValue(this->Adc2, this->Rank2); 59 | 60 | this->Value.iu = this->OffsetValue.iu - iu * ADC2AMPS; 61 | this->Value.iv = this->OffsetValue.iv - iv * ADC2AMPS; 62 | this->Value.iw = -this->Value.iu - this->Value.iv; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/AdcValue.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_ADCVALUE_H_ 2 | #define FOC_ADCVALUE_H_ 3 | 4 | #include "adc.h" 5 | 6 | #define ADC2VOLTAGE 0.00008056640625 // adcValue/4096*3.3 7 | #define ADC2AMPS 0.0008056640625 // adcValue/4096*3.3/0.1 8 | 9 | class AdcValue { 10 | public: 11 | AdcValue(); 12 | virtual ~AdcValue(); 13 | 14 | AdcValue(ADC_HandleTypeDef *adc1, int rank1, ADC_HandleTypeDef *adc2, int rank2, ADC_HandleTypeDef *adc3 = NULL, int rank3 = 1){ 15 | this->Adc1 = adc1; 16 | this->Rank1 = rank1; 17 | this->Adc2 = adc2; 18 | this->Rank2 = rank2; 19 | this->Adc3 = adc3; 20 | this->Rank3 = rank3; 21 | }; 22 | 23 | void Start(){HAL_ADCEx_InjectedStart_IT(this->Adc1);}; 24 | void Stop(){HAL_ADCEx_InjectedStop_IT(this->Adc1);}; 25 | 26 | ADC_HandleTypeDef *Adc1 = NULL, *Adc2 = NULL, *Adc3 = NULL; 27 | int Rank1 = 1, Rank2 = 1, Rank3 = 1; 28 | 29 | struct{ 30 | float iu = 0; 31 | float iv = 0; 32 | float iw = 0; 33 | }OffsetValue; 34 | 35 | struct{ 36 | float iu = 0; 37 | float iv = 0; 38 | float iw = 0; 39 | }Value; 40 | 41 | void Offset(int cnt = 1000); 42 | void Update(void); 43 | 44 | }; 45 | 46 | #endif /* FOC_ADCVALUE_H_ */ 47 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/Encoder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Encoder.cpp 3 | * 4 | * Created on: 2022年3月16日 5 | * Author: Kepler 6 | */ 7 | 8 | #include 9 | 10 | Encoder::Encoder() { 11 | // TODO Auto-generated constructor stub 12 | 13 | } 14 | 15 | Encoder::~Encoder() { 16 | // TODO Auto-generated destructor stub 17 | } 18 | 19 | void Encoder::Update(){ 20 | 21 | float angle_data = GetRawCount(); 22 | 23 | float d_angle = angle_data - this->AngleDataPrev; 24 | // if overflow happened track it as full rotation 25 | if(abs(d_angle) > (0.8*this->Cpr) ) this->FullRotationOffset += d_angle > 0 ? -_2PI : _2PI; 26 | 27 | // (number of full rotations)*2PI + current sensor angle 28 | this->CurrentAngle = this->Dir * (this->FullRotationOffset + ( angle_data / (float)this->Cpr) * _2PI); 29 | this->AngleDataPrev = angle_data; 30 | 31 | 32 | // calculate sample time 33 | unsigned long now_us = micros(); 34 | float Ts = (now_us - this->VelocityCalcTimestamp)*1e-6; 35 | // quick fix for strange cases (micros overflow) 36 | if(Ts <= 0 || Ts > 0.5) Ts = 1e-4; 37 | 38 | // velocity calculation 39 | float vel = (this->CurrentAngle - this->AnglePrev)/Ts; 40 | 41 | this->AnglePrev = this->CurrentAngle; 42 | this->VelocityCalcTimestamp = now_us; 43 | this->CurrentVelocity = vel; 44 | 45 | } 46 | 47 | // Shaft angle calculation 48 | // angle is in radians [rad] 49 | float Encoder::GetAngle(){ 50 | // float angle_data = GetRawCount(); 51 | // 52 | // float d_angle = angle_data - this->AngleDataPrev; 53 | // // if overflow happened track it as full rotation 54 | // if(abs(d_angle) > (0.8*this->Cpr) ) this->FullRotationOffset += d_angle > 0 ? -_2PI : _2PI; 55 | // 56 | // this->AngleDataPrev = angle_data; 57 | // 58 | // // (number of full rotations)*2PI + current sensor angle 59 | // this->CurrentAngle = this->FullRotationOffset + ( angle_data / (float)this->Cpr) * _2PI; 60 | // //return full_rotation_offset + ( angle_data / (float)cpr) * _2PI; 61 | // return this->CurrentAngle; 62 | 63 | return this->CurrentAngle; 64 | } 65 | 66 | // Shaft velocity calculation 67 | float Encoder::GetVelocity(){ 68 | // // calculate sample time 69 | // unsigned long now_us = micros(); 70 | // float Ts = (now_us - this->VelocityCalcTimestamp)*1e-6; 71 | // // quick fix for strange cases (micros overflow) 72 | // if(Ts <= 0 || Ts > 0.5) Ts = 1e-3; 73 | // 74 | // // current angle 75 | // float angle_c = GetAngle(); 76 | // // velocity calculation 77 | // float vel = (angle_c - this->AnglePrev)/Ts; 78 | // 79 | // // save variables for future pass 80 | // this->AnglePrev = angle_c; 81 | // this->VelocityCalcTimestamp = now_us; 82 | // this->CurrentVelocity = vel; 83 | // return vel; 84 | 85 | return this->CurrentVelocity; 86 | } 87 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/Encoder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Encoder.h 3 | * 4 | * Created on: 2022年3月16日 5 | * Author: Kepler 6 | */ 7 | 8 | #ifndef FOC_ENCODER_H_ 9 | #define FOC_ENCODER_H_ 10 | 11 | #include "main.h" 12 | #include "math.h" 13 | 14 | #ifndef _2PI 15 | #define _2PI 6.2831852 16 | #endif 17 | #ifndef _PI 18 | #define _PI 3.1415926 19 | #endif 20 | 21 | class Encoder { 22 | public: 23 | Encoder(); 24 | virtual ~Encoder(); 25 | 26 | /** sensor initialise pins */ 27 | virtual void Init() = 0; 28 | 29 | /** 30 | * Function getting current angle register value 31 | * it uses angle_register variable 32 | */ 33 | virtual int GetRawCount() = 0; 34 | 35 | // implementation of abstract functions of the Sensor class 36 | void Update(); 37 | /** get current angle (rad) */ 38 | float GetAngle(); 39 | /** get current angular velocity (rad/s) **/ 40 | float GetVelocity(); 41 | 42 | /** Stop communication */ 43 | void Close(); 44 | 45 | void ZeroProcess(){}; 46 | 47 | public: 48 | enum DIR {CW = -1, CCW = 1} Dir = this->CCW; 49 | float Cpr; //!< Maximum range of the sensor 50 | 51 | // total angle tracking variables 52 | float FullRotationOffset; //! 5 | #include 6 | #include "FOC/MagneticSensorSPI.h" 7 | #include "FOC/IncrementalEncoder.h" 8 | #include "FOC/AdcValue.h" 9 | 10 | 11 | class FocController { 12 | public: 13 | FocController(); 14 | virtual ~FocController(); 15 | FocController(FocConverter *foc_Conv, SvPwm *sv_pwm, Encoder *sen, AdcValue *adc){ 16 | this->Adc = adc; 17 | this->Sensor = sen; 18 | this->Svpwm = sv_pwm; 19 | this->FocConv = foc_Conv; 20 | }; 21 | 22 | 23 | AdcValue *Adc; 24 | Encoder *Sensor; 25 | FocConverter *FocConv; 26 | SvPwm *Svpwm; 27 | 28 | void Init(); 29 | void Run(); 30 | 31 | float DeltaT; 32 | unsigned long Timestamp; 33 | float Udc; //电源电压 34 | int PolePair; 35 | int RunTime; 36 | 37 | float ElectronicAngle, MechanicalAngle, OffsetAngle; 38 | float OpenLoopTheta; 39 | 40 | Pid PidSpeed; 41 | Pid PidPosition; 42 | 43 | enum {CW = -1, CCW = 1} Dir = this->CCW; 44 | enum {Disable, InjectionVoltage, NoSensorOpenLoopSpeed, NoSensorOpenLoopPosition, CloseLoopCurrent, CloseLoopSpeed, CloseLoopPosition} Mode = this->Disable; 45 | 46 | 47 | struct{ 48 | float Theta; 49 | float Voltage; 50 | }InjectionVoltageTarget; 51 | struct{ 52 | float Speed; 53 | float Voltage; 54 | }NoSensorOpenLoopSpeedTarget; 55 | struct{ 56 | float Position; 57 | float Speed; 58 | float Voltage; 59 | }NoSensorOpenLoopPositionTarget; 60 | struct{ 61 | float Id; 62 | float Iq; 63 | }CloseLoopCurrentTarget; 64 | struct{ 65 | float Speed; 66 | float Id; 67 | float Iq; 68 | }CloseLoopSpeedTarget; 69 | struct{ 70 | float Position; 71 | float Id; 72 | float Iq; 73 | }CloseLoopPositionTarget; 74 | }; 75 | 76 | #endif /* FOC_FOCCONTROLLER_H_ */ 77 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/FocConverter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "math.h" 3 | 4 | #define FOC_SQRT_3 1.73205f 5 | #define FOC_ANGLE_TO_RADIN 0.01745f 6 | 7 | 8 | FocConverter::FocConverter() { 9 | // TODO Auto-generated constructor stub 10 | 11 | } 12 | 13 | FocConverter::~FocConverter() { 14 | // TODO Auto-generated destructor stub 15 | } 16 | 17 | void FocConverter::Clarke(void){ 18 | this->Clarke(this->Ia, this->Ib, this->Ic); 19 | } 20 | void FocConverter::Clarke(float iA, float iB, float iC){ 21 | this->Ialpha = iA; 22 | this->Ibeta = (iA + 2.0f * iB) / FOC_SQRT_3; 23 | } 24 | 25 | void FocConverter::Park(void){ 26 | this->Park(this->Ialpha, this->Ibeta, this->Theta); 27 | } 28 | 29 | void FocConverter::Park(float iAlpha, float iBeta, float theta){ 30 | float _Cos = cos(theta); 31 | float _Sin = sin(theta); 32 | 33 | this->Id = iAlpha * _Cos + iBeta * _Sin; 34 | this->Iq = -iAlpha * _Sin + iBeta * _Cos; 35 | } 36 | void FocConverter::RevPark(void){ 37 | this->RevPark(this->Ud, this->Uq, this->Theta); 38 | } 39 | void FocConverter::RevPark(float uD, float uQ, float theta){ 40 | float _Cos = cos(theta); 41 | float _Sin = sin(theta); 42 | 43 | if((uD * uD + uQ * uQ) > (this->Um * this->Um)){ 44 | float temp = sqrt(uD * uD + uQ * uQ); 45 | uD = this->Um * uD/temp; 46 | uQ = this->Um * uQ/temp; 47 | } 48 | 49 | this->Ualpha = uD * _Cos - uQ * _Sin; 50 | this->Ubeta = uD * _Sin + uQ * _Cos; 51 | } 52 | 53 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/FocConverter.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_FOCCONVERTER_H_ 2 | #define FOC_FOCCONVERTER_H_ 3 | 4 | #include "Pid.h" 5 | 6 | class FocConverter { 7 | public: 8 | FocConverter(); 9 | virtual ~FocConverter(); 10 | 11 | float Ia, Ib, Ic; 12 | float Ialpha, Ibeta; 13 | float Id, Iq; 14 | float Ualpha, Ubeta; 15 | float Ud, Uq; 16 | 17 | float Theta; 18 | 19 | float Um; //最大电压 Udc * SQRT3_3 20 | 21 | Pid PidD, PidQ; 22 | 23 | void Clarke(float iA, float iB, float iC); 24 | void Clarke(void); 25 | void Park(float iAlpha, float iBeta, float theta); 26 | void Park(void); 27 | void RevPark(float uD, float uQ, float theta); 28 | void RevPark(void); 29 | 30 | 31 | }; 32 | 33 | #endif /* FOC_FOCCONVERTER_H_ */ 34 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/IncrementalEncoder.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | IncrementalEncoder::IncrementalEncoder() { 4 | // TODO Auto-generated constructor stub 5 | 6 | } 7 | 8 | IncrementalEncoder::~IncrementalEncoder() { 9 | // TODO Auto-generated destructor stub 10 | } 11 | 12 | IncrementalEncoder::IncrementalEncoder(TIM_HandleTypeDef* tim, int cpr, DIR dir){ 13 | this->Tim = tim; 14 | 15 | this->Cpr = cpr; 16 | this->Dir = dir; 17 | 18 | // velocity calculation init 19 | this->AnglePrev = 0; 20 | this->VelocityCalcTimestamp = micros(); 21 | 22 | // full rotations tracking number 23 | this->FullRotationOffset = 0; 24 | this->AngleDataPrev = 0;//this->GetRawCount(); 25 | } 26 | 27 | void IncrementalEncoder::Init(TIM_HandleTypeDef* tim, int cpr, DIR dir){ 28 | this->Tim = tim; 29 | 30 | this->Cpr = cpr; 31 | this->Dir = dir; 32 | 33 | // velocity calculation init 34 | this->AnglePrev = 0; 35 | this->VelocityCalcTimestamp = micros(); 36 | 37 | // full rotations tracking number 38 | this->FullRotationOffset = 0; 39 | this->AngleDataPrev = this->GetRawCount(); 40 | } 41 | 42 | int IncrementalEncoder::GetRawCount(){ 43 | uint16_t count = this->Tim->Instance->CNT; 44 | return count; 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/IncrementalEncoder.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_INCREMENTALENCODER_H_ 2 | #define FOC_INCREMENTALENCODER_H_ 3 | 4 | #include 5 | 6 | class IncrementalEncoder: public Encoder { 7 | public: 8 | IncrementalEncoder(); 9 | virtual ~IncrementalEncoder(); 10 | 11 | IncrementalEncoder(TIM_HandleTypeDef* tim, int cpr, DIR dir = DIR::CCW); 12 | 13 | virtual void Init(TIM_HandleTypeDef* tim, int cpr, DIR dir = DIR::CCW); 14 | virtual void Init(){}; 15 | 16 | virtual int GetRawCount(); 17 | 18 | 19 | TIM_HandleTypeDef* Tim; 20 | }; 21 | 22 | #endif /* FOC_INCREMENTALENCODER_H_ */ 23 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/MagneticSensorSPI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stdio.h" 4 | MagneticSensorSPI::MagneticSensorSPI() { 5 | // TODO Auto-generated constructor stub 6 | 7 | } 8 | 9 | MagneticSensorSPI::~MagneticSensorSPI() { 10 | // TODO Auto-generated destructor stub 11 | } 12 | 13 | MagneticSensorSPI::MagneticSensorSPI(SPI_HandleTypeDef* spi, GPIO_TypeDef* chip_select_gpiox, int chip_select_pin, int angle_register, int cpr, DIR dir){ 14 | this->Spi = spi; 15 | this->ChipSelectGpiox = chip_select_gpiox; 16 | this->ChipSelectPin = chip_select_pin; 17 | 18 | this->AngleRegister = angle_register; 19 | this->Cpr = cpr; 20 | this->Dir = dir; 21 | 22 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 23 | // velocity calculation init 24 | this->AnglePrev = 0; 25 | this->VelocityCalcTimestamp = micros(); 26 | 27 | // full rotations tracking number 28 | this->FullRotationOffset = 0; 29 | this->AngleDataPrev = 0;//this->GetRawCount(); 30 | } 31 | 32 | void MagneticSensorSPI::Init(SPI_HandleTypeDef* spi, GPIO_TypeDef* chip_select_gpiox, int chip_select_pin, int angle_register, int cpr, DIR dir){ 33 | this->Spi = spi; 34 | this->ChipSelectGpiox = chip_select_gpiox; 35 | this->ChipSelectPin = chip_select_pin; 36 | 37 | this->AngleRegister = angle_register; 38 | this->Cpr = cpr; 39 | this->Dir = dir; 40 | 41 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 42 | // velocity calculation init 43 | this->AnglePrev = 0; 44 | this->VelocityCalcTimestamp = micros(); 45 | 46 | // full rotations tracking number 47 | this->FullRotationOffset = 0; 48 | this->AngleDataPrev = this->GetRawCount(); 49 | } 50 | 51 | int MagneticSensorSPI::GetRawCount(){ 52 | 53 | uint16_t command = this->AngleRegister | 0xc000; 54 | 55 | //Send the command 56 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_RESET); 57 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_RESET); 58 | HAL_SPI_Transmit(this->Spi ,(unsigned char *)&command, 1, 100); 59 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 60 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 61 | 62 | //Now read the response 63 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_RESET); 64 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_RESET); 65 | uint16_t register_value = 0; 66 | HAL_SPI_TransmitReceive(this->Spi ,(unsigned char *)&command, (unsigned char *)®ister_value, 1, 100); 67 | //HAL_SPI_Receive(this->Spi , (unsigned char *)®ister_value, 1, 100); 68 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 69 | HAL_GPIO_WritePin(this->ChipSelectGpiox, this->ChipSelectPin, GPIO_PIN_SET); 70 | 71 | return register_value & 0x3fff; 72 | } 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/MagneticSensorSPI.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_MAGNETICSENSORSPI_H_ 2 | #define FOC_MAGNETICSENSORSPI_H_ 3 | 4 | #include 5 | #include "spi.h" 6 | 7 | class MagneticSensorSPI: public Encoder { 8 | public: 9 | MagneticSensorSPI(); 10 | virtual ~MagneticSensorSPI(); 11 | MagneticSensorSPI(SPI_HandleTypeDef* spi, GPIO_TypeDef* chip_select_gpiox, int chip_select_pin, int angle_register, int cpr, DIR dir = DIR::CCW); 12 | 13 | virtual void Init(SPI_HandleTypeDef* spi, GPIO_TypeDef* chip_select_gpiox, int chip_select_pin, int angle_register, int cpr, DIR dir = DIR::CCW); 14 | virtual void Init(){}; 15 | virtual int GetRawCount(); 16 | 17 | public: 18 | SPI_HandleTypeDef* Spi; 19 | GPIO_TypeDef* ChipSelectGpiox; 20 | int ChipSelectPin; //!< SPI chip select pin 21 | 22 | int AngleRegister; 23 | 24 | /** Calculate parity value */ 25 | uint8_t spiCalcEvenParity(uint16_t value); 26 | 27 | }; 28 | 29 | #endif /* FOC_MAGNETICSENSORSPI_H_ */ 30 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/Pid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define LIMIT(VALUE, MIN, MAX) ((VALUE)<(MIN)? (MIN): ((VALUE)>(MAX)? (MAX): (VALUE))) 4 | 5 | Pid::Pid() { 6 | // TODO Auto-generated constructor stub 7 | 8 | } 9 | 10 | Pid::~Pid() { 11 | // TODO Auto-generated destructor stub 12 | } 13 | void Pid::PidProcess(void){ 14 | this->Error = LIMIT(this->Target - this->Actual, -this->Limit_Error, this->Limit_Error); 15 | 16 | this->Integral += this->Ki * this->Error * this->DeltaT; 17 | this->Integral = LIMIT(this->Integral, -this->Limit_Integral, this->Limit_Integral); 18 | 19 | if(this->Integral * this->Error < 0) this->Integral *= this->Integral_Attenuation; 20 | 21 | if(this->Kd){ 22 | this->D_Error = 0.001 * (this->Error - this->ErrorPrev) / this->DeltaT; 23 | this->ErrorPrev = this->Error; 24 | this->Result = this->Kp * this->Error + this->Integral + this->Kd * this->D_Error; 25 | }else this->Result = this->Kp * this->Error + this->Integral; 26 | 27 | this->Result = LIMIT(this->Result, -this->Limit_Result, this->Limit_Result); 28 | } 29 | void Pid::PidProcess(float t){ 30 | this->Target = t; 31 | this->PidProcess(); 32 | } 33 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/Pid.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_PID_H_ 2 | #define FOC_PID_H_ 3 | 4 | class Pid { 5 | public: 6 | Pid(); 7 | virtual ~Pid(); 8 | 9 | float DeltaT; 10 | float Target; 11 | float Actual; 12 | 13 | float Kp; 14 | float Ki; 15 | float Integral_Attenuation; // range[0, 1] 16 | unsigned int Kd; 17 | float Error; 18 | float ErrorPrev; 19 | float Integral; 20 | float D_Error; 21 | 22 | float Limit_Error; 23 | float Limit_Integral;//积分项下限 24 | float Limit_Result; //总输出下限 25 | 26 | float Result; 27 | 28 | void PidProcess(void); 29 | void PidProcess(float t); 30 | }; 31 | 32 | #endif /* FOC_PID_H_ */ 33 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/SvPwm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SvPwm::SvPwm() { 4 | // TODO Auto-generated constructor stub 5 | } 6 | 7 | SvPwm::~SvPwm() { 8 | // TODO Auto-generated destructor stub 9 | } 10 | 11 | SvPwm::SvPwm(TIM_HandleTypeDef* tim, int period) { 12 | // TODO Auto-generated constructor stub 13 | this->Tim = tim; 14 | this->PERIOD = period; 15 | this->PwmOutput(0, 0, 0); 16 | } 17 | 18 | void SvPwm::Svpwm(float uAlpha, float uBeta){ 19 | float U1, U2, U3; 20 | float T1, T2, T3, T4, T5, T6, T7, Ts = 1.0f; 21 | 22 | U1 = uBeta; 23 | U2 = uAlpha * SVPWM_SQRT3_2 - uBeta / 2; // -temp3 24 | U3 = -uAlpha * SVPWM_SQRT3_2 - uBeta / 2;//-temp2 25 | 26 | uint8_t A = 0, B = 0, C = 0; 27 | if (U1 > 0) A = 1; 28 | if (U2 > 0) B = 1; 29 | if (U3 > 0) C = 1; 30 | 31 | uint8_t N = 4*C + 2*B + A; 32 | switch (N) { 33 | case 3: this->Sector = 1; break; 34 | case 1: this->Sector = 2; break; 35 | case 5: this->Sector = 3; break; 36 | case 4: this->Sector = 4; break; 37 | case 6: this->Sector = 5; break; 38 | case 2: this->Sector = 6; break; 39 | } 40 | 41 | switch (this->Sector) { 42 | case 1: 43 | T4 = SVPWM_SQRT3 * Ts / this->Udc * U2; 44 | T6 = SVPWM_SQRT3 * Ts / this->Udc * U1; 45 | T7 = (Ts - T4 - T6) / 2; 46 | break; 47 | case 2: 48 | T2 = -SVPWM_SQRT3 * Ts / this->Udc * U2; 49 | T6 = -SVPWM_SQRT3 * Ts / this->Udc * U3; 50 | T7 = (Ts - T2 - T6) / 2; 51 | break; 52 | case 3: 53 | T2 = SVPWM_SQRT3 * Ts / this->Udc * U1; 54 | T3 = SVPWM_SQRT3 * Ts / this->Udc * U3; 55 | T7 = (Ts - T2 - T3) / 2; 56 | break; 57 | case 4: 58 | T1 = -SVPWM_SQRT3 * Ts / this->Udc * U1; 59 | T3 = -SVPWM_SQRT3 * Ts / this->Udc * U2; 60 | T7 = (Ts - T1 - T3) / 2; 61 | break; 62 | case 5: 63 | T1 = SVPWM_SQRT3 * Ts / this->Udc * U3; 64 | T5 = SVPWM_SQRT3 * Ts / this->Udc * U2; 65 | T7 = (Ts - T1 - T5) / 2; 66 | break; 67 | case 6: 68 | T4 = -SVPWM_SQRT3 * Ts / this->Udc * U3; 69 | T5 = -SVPWM_SQRT3 * Ts / this->Udc * U1; 70 | T7 = (Ts - T4 - T5) / 2; 71 | break; 72 | } 73 | 74 | 75 | float Ta; 76 | float Tb; 77 | float Tc; 78 | switch (this->Sector) { 79 | case 1: 80 | Ta = T4 + T6 + T7; 81 | Tb = T6 + T7; 82 | Tc = T7; 83 | break; 84 | case 2: 85 | Ta = T6 + T7; 86 | Tb = T2 + T6 + T7; 87 | Tc = T7; 88 | break; 89 | case 3: 90 | Ta = T7; 91 | Tb = T2 + T3 + T7; 92 | Tc = T3 + T7; 93 | break; 94 | case 4: 95 | Ta = T7; 96 | Tb = T3 + T7; 97 | Tc = T1 + T3 + T7; 98 | break; 99 | case 5: 100 | Ta = T5 + T7; 101 | Tb = T7; 102 | Tc = T1 + T5 + T7; 103 | break; 104 | case 6: 105 | Ta = T4 + T5 + T7; 106 | Tb = T7; 107 | Tc = T5 + T7; 108 | break; 109 | } 110 | 111 | this->T1 = (Ta * this->PERIOD); 112 | if (this->T1 > this->PERIOD) this->T1 = this->PERIOD; 113 | if (this->T1 < 0) this->T1 = 0; 114 | 115 | this->T2 = (Tb * this->PERIOD); 116 | if (this->T2 > this->PERIOD) this->T2 = this->PERIOD; 117 | if (this->T2 < 0) this->T2 = 0; 118 | 119 | this->T3 = (Tc * this->PERIOD); 120 | if (this->T3 > this->PERIOD) this->T3 = this->PERIOD; 121 | if (this->T3 < 0) this->T3 = 0; 122 | } 123 | 124 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/FOC/SvPwm.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_SVPWM_H_ 2 | #define FOC_SVPWM_H_ 3 | 4 | #include "tim.h" 5 | 6 | #define SVPWM_SQRT3_2 0.8660254f 7 | #define SVPWM_SQRT3 1.7320508f 8 | 9 | class SvPwm { 10 | public: 11 | SvPwm(); 12 | virtual ~SvPwm(); 13 | 14 | SvPwm(TIM_HandleTypeDef* tim, int period); 15 | 16 | TIM_HandleTypeDef* Tim; 17 | 18 | int PERIOD = 4200; 19 | int T1, T2, T3; 20 | float Udc = 12; 21 | int Sector; 22 | 23 | void Svpwm(float uAlpha, float uBeta); 24 | void Svpwm(); 25 | 26 | void PwmOutput(int t1, int t2, int t3){ 27 | if(t1 > PERIOD) t1 = PERIOD; 28 | if(t2 > PERIOD) t2 = PERIOD; 29 | if(t3 > PERIOD) t3 = PERIOD; 30 | if(t1 < 0) t1 = 0; 31 | if(t2 < 0) t2 = 0; 32 | if(t3 < 0) t3 = 0; 33 | this->Tim->Instance->CCR1 = t1; 34 | this->Tim->Instance->CCR2 = t2; 35 | this->Tim->Instance->CCR3 = t3; 36 | } 37 | void PwmOutput(){ 38 | PwmOutput(T1, T2, T3); 39 | } 40 | }; 41 | 42 | #endif /* FOC_SVPWM_H_ */ 43 | -------------------------------------------------------------------------------- /Firmware/FocController/MyCode/TaskLed.cpp: -------------------------------------------------------------------------------- 1 | #include "PwmLed.h" 2 | #include "FreeRTOS.h" 3 | #include "task.h" 4 | #include "main.h" 5 | 6 | //extern TIM_HandleTypeDef htim12; 7 | //extern TIM_HandleTypeDef htim14; 8 | // 9 | //PwmLed Red(&htim12, TIM_CHANNEL_1, 50); 10 | //PwmLed Green(&htim12, TIM_CHANNEL_2, 50); 11 | //PwmLed Blue(&htim14, TIM_CHANNEL_1, 50); 12 | // 13 | //void ledTask(void *argument){ 14 | // Red.SetBreathing(); 15 | // Green.SetOff(); 16 | // Blue.SetOff(); 17 | // while(1){ 18 | // vTaskDelay(50); 19 | // Red.Run(); 20 | // Blue.Run(); 21 | // Green.Run(); 22 | // } 23 | //} 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Firmware/SVPWM算法原理及详解.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Firmware/SVPWM算法原理及详解.pdf -------------------------------------------------------------------------------- /Firmware/SimpleFoc/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SimpleFoc 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | com.st.stm32cube.ide.mcu.MCUProjectNature 23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature 24 | org.eclipse.cdt.core.cnature 25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAev2ProjectNature 26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature 27 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature 28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature 29 | com.st.stm32cube.ide.mcu.MCURootProjectNature 30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 32 | org.eclipse.cdt.core.ccnature 33 | 34 | 35 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/.settings/com.st.stm32cube.ide.mcu.sfrview.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | svd_custom_file_path= 3 | svd_file_path=platform\:/plugin/com.st.stm32cube.ide.mcu.productdb.debug/resources/cmsis/STMicroelectronics_CMSIS_SVD/STM32F405.svd 4 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/.settings/language.settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/.settings/org.eclipse.cdt.core.prefs: -------------------------------------------------------------------------------- 1 | doxygen/doxygen_new_line_after_brief=true 2 | doxygen/doxygen_use_brief_tag=false 3 | doxygen/doxygen_use_javadoc_tags=true 4 | doxygen/doxygen_use_pre_tag=false 5 | doxygen/doxygen_use_structural_commands=false 6 | eclipse.preferences.version=1 7 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/.settings/stm32cubeide.project.prefs: -------------------------------------------------------------------------------- 1 | 2F62501ED4689FB349E356AB974DBE57=C6DCCBD2A6FE9510BBEDE1C64E1F5FBB 2 | 635E684B79701B039C64EA45C3F84D30=EC0CF2E48BB4571606D72637CE1FFEB6 3 | 8DF89ED150041C4CBC7CB9A9CAA90856=C6DCCBD2A6FE9510BBEDE1C64E1F5FBB 4 | DC22A860405A8BF2F2C095E5B6529F12=74C325809E2A0471032BCF1571CA3A68 5 | eclipse.preferences.version=1 6 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/adc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file adc.h 4 | * @brief This file contains all the function prototypes for 5 | * the adc.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __ADC_H__ 21 | #define __ADC_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern ADC_HandleTypeDef hadc1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_ADC1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | uint32_t readPhaseVoltage(const int pinA); 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __ADC_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/gpio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file gpio.h 4 | * @brief This file contains all the function prototypes for 5 | * the gpio.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __GPIO_H__ 21 | #define __GPIO_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* USER CODE BEGIN Private defines */ 35 | 36 | /* USER CODE END Private defines */ 37 | 38 | void MX_GPIO_Init(void); 39 | 40 | /* USER CODE BEGIN Prototypes */ 41 | 42 | /* USER CODE END Prototypes */ 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | #endif /*__ GPIO_H__ */ 48 | 49 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 50 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/main.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file : main.h 5 | * @brief : Header for main.c file. 6 | * This file contains the common defines of the application. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __MAIN_H 24 | #define __MAIN_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal.h" 32 | 33 | /* Private includes ----------------------------------------------------------*/ 34 | /* USER CODE BEGIN Includes */ 35 | 36 | /* USER CODE END Includes */ 37 | 38 | /* Exported types ------------------------------------------------------------*/ 39 | /* USER CODE BEGIN ET */ 40 | uint32_t getSysTime(); 41 | /* USER CODE END ET */ 42 | 43 | /* Exported constants --------------------------------------------------------*/ 44 | /* USER CODE BEGIN EC */ 45 | 46 | /* USER CODE END EC */ 47 | 48 | /* Exported macro ------------------------------------------------------------*/ 49 | /* USER CODE BEGIN EM */ 50 | 51 | /* USER CODE END EM */ 52 | 53 | /* Exported functions prototypes ---------------------------------------------*/ 54 | void Error_Handler(void); 55 | 56 | /* USER CODE BEGIN EFP */ 57 | void setupSimpleFOC(void); 58 | void loopSimpleFOC(void); 59 | void disableSimpleFOC(int s); 60 | void setTarget(float t); 61 | /* USER CODE END EFP */ 62 | 63 | /* Private defines -----------------------------------------------------------*/ 64 | /* USER CODE BEGIN Private defines */ 65 | 66 | /* USER CODE END Private defines */ 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* __MAIN_H */ 73 | 74 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 75 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/spi.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file spi.h 4 | * @brief This file contains all the function prototypes for 5 | * the spi.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __SPI_H__ 21 | #define __SPI_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern SPI_HandleTypeDef hspi1; 35 | 36 | /* USER CODE BEGIN Private defines */ 37 | 38 | /* USER CODE END Private defines */ 39 | 40 | void MX_SPI1_Init(void); 41 | 42 | /* USER CODE BEGIN Prototypes */ 43 | 44 | /* USER CODE END Prototypes */ 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* __SPI_H__ */ 51 | 52 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 53 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/stm32f4xx_it.h: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_it.h 5 | * @brief This file contains the headers of the interrupt handlers. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2021 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* USER CODE END Header */ 20 | 21 | /* Define to prevent recursive inclusion -------------------------------------*/ 22 | #ifndef __STM32F4xx_IT_H 23 | #define __STM32F4xx_IT_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /* Private includes ----------------------------------------------------------*/ 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | /* Exported types ------------------------------------------------------------*/ 35 | /* USER CODE BEGIN ET */ 36 | 37 | /* USER CODE END ET */ 38 | 39 | /* Exported constants --------------------------------------------------------*/ 40 | /* USER CODE BEGIN EC */ 41 | 42 | /* USER CODE END EC */ 43 | 44 | /* Exported macro ------------------------------------------------------------*/ 45 | /* USER CODE BEGIN EM */ 46 | 47 | /* USER CODE END EM */ 48 | 49 | /* Exported functions prototypes ---------------------------------------------*/ 50 | void NMI_Handler(void); 51 | void HardFault_Handler(void); 52 | void MemManage_Handler(void); 53 | void BusFault_Handler(void); 54 | void UsageFault_Handler(void); 55 | void DebugMon_Handler(void); 56 | void SysTick_Handler(void); 57 | void ADC_IRQHandler(void); 58 | void UART4_IRQHandler(void); 59 | void TIM6_DAC_IRQHandler(void); 60 | void USART6_IRQHandler(void); 61 | /* USER CODE BEGIN EFP */ 62 | 63 | /* USER CODE END EFP */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __STM32F4xx_IT_H */ 70 | 71 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 72 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/tim.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file tim.h 4 | * @brief This file contains all the function prototypes for 5 | * the tim.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __TIM_H__ 21 | #define __TIM_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern TIM_HandleTypeDef htim1; 35 | extern TIM_HandleTypeDef htim6; 36 | 37 | /* USER CODE BEGIN Private defines */ 38 | 39 | /* USER CODE END Private defines */ 40 | 41 | void MX_TIM1_Init(void); 42 | void MX_TIM6_Init(void); 43 | 44 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); 45 | 46 | /* USER CODE BEGIN Prototypes */ 47 | 48 | /* USER CODE END Prototypes */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* __TIM_H__ */ 55 | 56 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 57 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Inc/usart.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file usart.h 4 | * @brief This file contains all the function prototypes for 5 | * the usart.c file 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __USART_H__ 21 | #define __USART_H__ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "main.h" 29 | 30 | /* USER CODE BEGIN Includes */ 31 | 32 | /* USER CODE END Includes */ 33 | 34 | extern UART_HandleTypeDef huart4; 35 | extern UART_HandleTypeDef huart6; 36 | 37 | /* USER CODE BEGIN Private defines */ 38 | 39 | /* USER CODE END Private defines */ 40 | 41 | void MX_UART4_Init(void); 42 | void MX_USART6_UART_Init(void); 43 | 44 | /* USER CODE BEGIN Prototypes */ 45 | void uart6SendByte(uint8_t ch); 46 | void uart4SendLen(uint8_t *p, int num); 47 | /* USER CODE END Prototypes */ 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __USART_H__ */ 54 | 55 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 56 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/SimpleFOC.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "cmsis_os.h" 3 | #include "FreeRTOS.h" 4 | #include "task.h" 5 | #include "SimpleFOC.h" 6 | #include "sensors/MagneticSensorSPI.h" 7 | #include "spi.h" 8 | 9 | BLDCMotor motor = BLDCMotor(7); 10 | BLDCDriver3PWM driver = BLDCDriver3PWM(Gpio_pin2Index(GPIOA, GPIO_PIN_8), Gpio_pin2Index(GPIOA, GPIO_PIN_9),Gpio_pin2Index(GPIOA, GPIO_PIN_10), Gpio_pin2Index(GPIOC, GPIO_PIN_7)); 11 | MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, Gpio_pin2Index(GPIOA, GPIO_PIN_4)); 12 | InlineCurrentSense current_sense = InlineCurrentSense(0.1, 10.0, Gpio_pin2Index(GPIOC, GPIO_PIN_0), Gpio_pin2Index(GPIOC, GPIO_PIN_1),Gpio_pin2Index(GPIOC, GPIO_PIN_2)); 13 | Print Serial; 14 | 15 | void setupSimpleFOC() { 16 | 17 | vTaskDelay(1000); 18 | 19 | // initialise magnetic sensor hardware 20 | sensor.init(&hspi1); 21 | // link the motor to the sensor 22 | motor.linkSensor(&sensor); 23 | 24 | // driver config 25 | // power supply voltage [V] 26 | driver.voltage_power_supply = 12; 27 | driver.init(); 28 | // link the motor and the driver 29 | motor.linkDriver(&driver); 30 | 31 | // choose FOC modulation (optional) 32 | motor.voltage_sensor_align = 1; 33 | // set control loop type to be used 34 | 35 | motor.torque_controller = TorqueControlType::foc_current; 36 | motor.controller = MotionControlType::angle; 37 | 38 | 39 | // maximal voltage to be set to the motor 40 | motor.voltage_limit = 6; 41 | 42 | // velocity low pass filtering time constant 43 | // the lower the less filtered 44 | motor.LPF_velocity.Tf = 0.01; 45 | 46 | // angle P controller 47 | motor.P_angle.P = 30; 48 | // maximal velocity of the position control 49 | motor.velocity_limit = 12; 50 | 51 | 52 | motor.useMonitoring(Serial); 53 | motor.monitor_downsample = 0; // disable intially 54 | motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE; // monitor target velocity and angle 55 | 56 | 57 | current_sense.init(); 58 | motor.linkCurrentSense(¤t_sense); 59 | 60 | // initialize motor 61 | motor.init(); 62 | // align sensor and start FOC 63 | motor.initFOC(); 64 | } 65 | 66 | float target = 1; 67 | 68 | void loopSimpleFOC() { 69 | motor.loopFOC(); 70 | motor.move(target); 71 | motor.monitor(); 72 | } 73 | 74 | void disableSimpleFOC(int s) { 75 | if(s == 1) 76 | motor.enable(); 77 | else motor.disable(); 78 | } 79 | void setTarget(float t){ 80 | target = t; 81 | } 82 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/SimpleFOC.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file SimpleFOC.h 3 | * 4 | * @mainpage Simple Field Oriented Control BLDC motor control library 5 | * 6 | * @section intro_sec Introduction 7 | * 8 | * Proper low-cost and low-power FOC supporting boards are very hard to find these days and even may not exist.
Even harder to find is a stable and simple FOC algorithm code capable of running on Arduino devices. Therefore this is an attempt to: 9 | * - Demystify FOC algorithm and make a robust but simple Arduino library: Arduino SimpleFOC library 10 | * - Develop a modular BLDC driver board: Arduino SimpleFOC shield. 11 | * 12 | * @section features Features 13 | * - Arduino compatible: Arduino library code 14 | * - Easy to setup and configure: 15 | * - Easy hardware configuration 16 | * - Easy tuning the control loops 17 | * - Modular: 18 | * - Supports as many sensors , BLDC motors and driver boards as possible 19 | * - Supports as many application requirements as possible 20 | * - Plug & play: Arduino SimpleFOC shield 21 | * 22 | * @section dependencies Supported Hardware 23 | * - Motors 24 | * - BLDC motors 25 | * - Stepper motors 26 | * - Drivers 27 | * - BLDC drivers 28 | * - Gimbal drivers 29 | * - Stepper drivers 30 | * - Position sensors 31 | * - Encoders 32 | * - Magnetic sensors 33 | * - Hall sensors 34 | * - Open-loop control 35 | * - Microcontrollers 36 | * - Arduino 37 | * - STM32 38 | * - ESP32 39 | * - Teensy 40 | * 41 | * @section example_code Example code 42 | * @code 43 | 44 | * @endcode 45 | * 46 | * @section license License 47 | * 48 | * MIT license, all text here must be included in any redistribution. 49 | * 50 | */ 51 | 52 | #ifndef SIMPLEFOC_H 53 | #define SIMPLEFOC_H 54 | 55 | #include "BLDCMotor.h" 56 | //#include "StepperMotor.h" 57 | #include "sensors/Encoder.h" 58 | //#include "sensors/MagneticSensorSPI.h" 59 | //#include "sensors/MagneticSensorI2C.h" 60 | //#include "sensors/MagneticSensorAnalog.h" 61 | //#include "sensors/MagneticSensorPWM.h" 62 | //#include "sensors/HallSensor.h" 63 | #include "drivers/BLDCDriver3PWM.h" 64 | #include "drivers/BLDCDriver6PWM.h" 65 | //#include "drivers/StepperDriver4PWM.h" 66 | //#include "drivers/StepperDriver2PWM.h" 67 | #include "current_sense/InlineCurrentSense.h" 68 | //#include "communication/Commander.h" 69 | //#include "communication/StepDirListener.h" 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/base_classes/BLDCDriver.h: -------------------------------------------------------------------------------- 1 | #ifndef BLDCDRIVER_H 2 | #define BLDCDRIVER_H 3 | 4 | #include "Arduino.h" 5 | 6 | class BLDCDriver{ 7 | public: 8 | 9 | /** Initialise hardware */ 10 | virtual int init() = 0; 11 | /** Enable hardware */ 12 | virtual void enable() = 0; 13 | /** Disable hardware */ 14 | virtual void disable() = 0; 15 | 16 | long pwm_frequency; //!< pwm frequency value in hertz 17 | float voltage_power_supply; //!< power supply voltage 18 | float voltage_limit; //!< limiting voltage set to the motor 19 | 20 | 21 | float dc_a; //!< currently set duty cycle on phaseA 22 | float dc_b; //!< currently set duty cycle on phaseB 23 | float dc_c; //!< currently set duty cycle on phaseC 24 | 25 | /** 26 | * Set phase voltages to the harware 27 | * 28 | * @param Ua - phase A voltage 29 | * @param Ub - phase B voltage 30 | * @param Uc - phase C voltage 31 | */ 32 | virtual void setPwm(float Ua, float Ub, float Uc) = 0; 33 | 34 | /** 35 | * Set phase state, enable/disable 36 | * 37 | * @param sc - phase A state : active / disabled ( high impedance ) 38 | * @param sb - phase B state : active / disabled ( high impedance ) 39 | * @param sa - phase C state : active / disabled ( high impedance ) 40 | */ 41 | virtual void setPhaseState(int sa, int sb, int sc) = 0; 42 | }; 43 | 44 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/base_classes/CurrentSense.cpp: -------------------------------------------------------------------------------- 1 | #include "CurrentSense.h" 2 | 3 | 4 | // get current magnitude 5 | // - absolute - if no electrical_angle provided 6 | // - signed - if angle provided 7 | float CurrentSense::getDCCurrent(float motor_electrical_angle){ 8 | // read current phase currents 9 | PhaseCurrent_s current = getPhaseCurrents(); 10 | // currnet sign - if motor angle not provided the magnitude is always positive 11 | float sign = 1; 12 | 13 | // calculate clarke transform 14 | float i_alpha, i_beta; 15 | if(!current.c){ 16 | // if only two measured currents 17 | i_alpha = current.a; 18 | i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b; 19 | }else{ 20 | // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed. 21 | float mid = (1.f/3) * (current.a + current.b + current.c); 22 | float a = current.a - mid; 23 | float b = current.b - mid; 24 | i_alpha = a; 25 | i_beta = _1_SQRT3 * a + _2_SQRT3 * b; 26 | } 27 | 28 | // if motor angle provided function returns signed value of the current 29 | // determine the sign of the current 30 | // sign(atan2(current.q, current.d)) is the same as c.q > 0 ? 1 : -1 31 | if(motor_electrical_angle) 32 | sign = (i_beta * _cos(motor_electrical_angle) - i_alpha*_sin(motor_electrical_angle)) > 0 ? 1 : -1; 33 | // return current magnitude 34 | return sign*_sqrt(i_alpha*i_alpha + i_beta*i_beta); 35 | } 36 | 37 | // function used with the foc algorihtm 38 | // calculating DQ currents from phase currents 39 | // - function calculating park and clarke transform of the phase currents 40 | // - using getPhaseCurrents internally 41 | DQCurrent_s CurrentSense::getFOCCurrents(float angle_el){ 42 | // read current phase currents 43 | PhaseCurrent_s current = getPhaseCurrents(); 44 | 45 | // calculate clarke transform 46 | float i_alpha, i_beta; 47 | if(!current.c){ 48 | // if only two measured currents 49 | i_alpha = current.a; 50 | i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b; 51 | } else { 52 | // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed. 53 | float mid = (1.f/3) * (current.a + current.b + current.c); 54 | float a = current.a - mid; 55 | float b = current.b - mid; 56 | i_alpha = a; 57 | i_beta = _1_SQRT3 * a + _2_SQRT3 * b; 58 | } 59 | 60 | // calculate park transform 61 | float ct = _cos(angle_el); 62 | float st = _sin(angle_el); 63 | DQCurrent_s return_current; 64 | return_current.d = i_alpha * ct + i_beta * st; 65 | return_current.q = i_beta * ct - i_alpha * st; 66 | return return_current; 67 | } -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/base_classes/CurrentSense.h: -------------------------------------------------------------------------------- 1 | #ifndef CURRENTSENSE_H 2 | #define CURRENTSENSE_H 3 | 4 | #include "BLDCDriver.h" 5 | #include "../foc_utils.h" 6 | 7 | /** 8 | * Current sensing abstract class defintion 9 | * Each current sensoring implementation needs to extend this interface 10 | */ 11 | class CurrentSense{ 12 | public: 13 | 14 | /** 15 | * Function intialising the CurrentSense class 16 | * All the necessary intialisations of adc and sync should be implemented here 17 | */ 18 | virtual void init() = 0; 19 | 20 | /** 21 | * Function intended to implement all that is needed to sync and current sensing with the driver. 22 | * If no such thing is needed it can be left empty (return 1) 23 | * @returns - 0 - for failure & 1 - for success 24 | */ 25 | virtual int driverSync(BLDCDriver *driver) = 0; 26 | 27 | // calibration variables 28 | bool skip_align = false; //!< variable signaling that the phase current direction should be verified during initFOC() 29 | /** 30 | * Function intended to verify if: 31 | * - phase current are oriented properly 32 | * - if their order is the same as driver phases 33 | * 34 | * This function corrects the alignment errors if possible ans if no such thing is needed it can be left empty (return 1) 35 | * @returns - 0 - for failure & positive number (with status) - for success 36 | */ 37 | virtual int driverAlign(BLDCDriver *driver, float voltage) = 0; 38 | 39 | /** 40 | * Function rading the phase currents a, b and c 41 | * This function will be used with the foc control throught the function 42 | * CurrentSense::getFOCCurrents(electrical_angle) 43 | * - it returns current c equal to 0 if only two phase measurements available 44 | * 45 | * @return PhaseCurrent_s current values 46 | */ 47 | virtual PhaseCurrent_s getPhaseCurrents() = 0; 48 | /** 49 | * Function reading the magnitude of the current set to the motor 50 | * It returns the abosolute or signed magnitude if possible 51 | * It can receive the motor electrical angle to help with calculation 52 | * This function is used with the current control (not foc) 53 | * 54 | * @param angle_el - electrical angle of the motor (optional) 55 | */ 56 | virtual float getDCCurrent(float angle_el = 0); 57 | 58 | /** 59 | * Function used for FOC contorl, it reads the DQ currents of the motor 60 | * It uses the function getPhaseCurrents internally 61 | * 62 | * @param angle_el - motor electrical angle 63 | */ 64 | DQCurrent_s getFOCCurrents(float angle_el); 65 | }; 66 | 67 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/base_classes/Sensor.cpp: -------------------------------------------------------------------------------- 1 | #include "Sensor.h" 2 | #include "../foc_utils.h" 3 | #include "../time_utils.h" 4 | 5 | /** 6 | * returns 0 if it does need search for absolute zero 7 | * 0 - magnetic sensor (& encoder with index which is found) 8 | * 1 - ecoder with index (with index not found yet) 9 | */ 10 | int Sensor::needsSearch(){ 11 | return 0; 12 | } 13 | 14 | /** get current angular velocity (rad/s)*/ 15 | float Sensor::getVelocity(){ 16 | 17 | // calculate sample time 18 | unsigned long now_us = _micros(); 19 | float Ts = (now_us - velocity_calc_timestamp)*1e-6; 20 | // quick fix for strange cases (micros overflow) 21 | if(Ts <= 0 || Ts > 0.5) Ts = 1e-3; 22 | 23 | // current angle 24 | float angle_c = getAngle(); 25 | // velocity calculation 26 | float vel = (angle_c - angle_prev)/Ts; 27 | 28 | // save variables for future pass 29 | angle_prev = angle_c; 30 | velocity_calc_timestamp = now_us; 31 | return vel; 32 | } -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/base_classes/Sensor.h: -------------------------------------------------------------------------------- 1 | #ifndef SENSOR_H 2 | #define SENSOR_H 3 | 4 | /** 5 | * Direction structure 6 | */ 7 | enum Direction{ 8 | CW = 1, //clockwise 9 | CCW = -1, // counter clockwise 10 | UNKNOWN = 0 //not yet known or invalid state 11 | }; 12 | 13 | 14 | /** 15 | * Pullup configuration structure 16 | */ 17 | enum Pullup{ 18 | USE_INTERN, //!< Use internal pullups 19 | USE_EXTERN //!< Use external pullups 20 | }; 21 | 22 | /** 23 | * Sensor abstract class defintion 24 | * Each sensor needs to have these functions implemented 25 | */ 26 | class Sensor{ 27 | public: 28 | 29 | /** get current angle (rad) */ 30 | virtual float getAngle()=0; 31 | /** get current angular velocity (rad/s)*/ 32 | virtual float getVelocity(); 33 | 34 | /** 35 | * returns 0 if it does need search for absolute zero 36 | * 0 - magnetic sensor (& encoder with index which is found) 37 | * 1 - ecoder with index (with index not found yet) 38 | */ 39 | virtual int needsSearch(); 40 | private: 41 | // velocity calculation variables 42 | float angle_prev=0; //!< angle in previous velocity calculation step 43 | long velocity_calc_timestamp=0; //!< last velocity calculation timestamp 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/defaults.h: -------------------------------------------------------------------------------- 1 | // default configuration values 2 | // change this file to optimal values for your application 3 | 4 | #define DEF_POWER_SUPPLY 12.0 //!< default power supply voltage 5 | // velocity PI controller params 6 | #define DEF_PID_VEL_P 0.5 //!< default PID controller P value 7 | #define DEF_PID_VEL_I 10.0 //!< default PID controller I value 8 | #define DEF_PID_VEL_D 0.0 //!< default PID controller D value 9 | #define DEF_PID_VEL_RAMP 1000.0 //!< default PID controller voltage ramp value 10 | #define DEF_PID_VEL_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit 11 | 12 | // current sensing PID values 13 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) 14 | // for 16Mhz controllers like Arduino uno and mega 15 | #define DEF_PID_CURR_P 2 //!< default PID controller P value 16 | #define DEF_PID_CURR_I 100 //!< default PID controller I value 17 | #define DEF_PID_CURR_D 0.0 //!< default PID controller D value 18 | #define DEF_PID_CURR_RAMP 1000.0 //!< default PID controller voltage ramp value 19 | #define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit 20 | #define DEF_CURR_FILTER_Tf 0.01 //!< default velocity filter time constant 21 | #else 22 | // for stm32, due, teensy, esp32 and similar 23 | #define DEF_PID_CURR_P 3 //!< default PID controller P value 24 | #define DEF_PID_CURR_I 300.0 //!< default PID controller I value 25 | #define DEF_PID_CURR_D 0.0 //!< default PID controller D value 26 | #define DEF_PID_CURR_RAMP 0 //!< default PID controller voltage ramp value 27 | #define DEF_PID_CURR_LIMIT (DEF_POWER_SUPPLY) //!< default PID controller voltage limit 28 | #define DEF_CURR_FILTER_Tf 0.005 //!< default currnet filter time constant 29 | #endif 30 | // default current limit values 31 | #define DEF_CURRENT_LIM 0.2 //!< 2Amps current limit by default 32 | 33 | // default monitor downsample 34 | #define DEF_MON_DOWNSMAPLE 100 //!< default monitor downsample 35 | #define DEF_MOTION_DOWNSMAPLE 0 //!< default motion downsample - disable 36 | 37 | // angle P params 38 | #define DEF_P_ANGLE_P 20.0 //!< default P controller P value 39 | #define DEF_VEL_LIM 20.0 //!< angle velocity limit default 40 | 41 | // index search 42 | #define DEF_INDEX_SEARCH_TARGET_VELOCITY 1.0 //!< default index search velocity 43 | // align voltage 44 | #define DEF_VOLTAGE_SENSOR_ALIGN 3.0 //!< default voltage for sensor and motor zero alignemt 45 | // low pass filter velocity 46 | #define DEF_VEL_FILTER_Tf 0.005 //!< default velocity filter time constant -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/foc_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "foc_utils.h" 2 | 3 | // int array instead of float array 4 | // 4x200 points per 360 deg 5 | // 2x storage save (int 2Byte float 4 Byte ) 6 | // sin*10000 7 | const int sine_array[200] = {0,79,158,237,316,395,473,552,631,710,789,867,946,1024,1103,1181,1260,1338,1416,1494,1572,1650,1728,1806,1883,1961,2038,2115,2192,2269,2346,2423,2499,2575,2652,2728,2804,2879,2955,3030,3105,3180,3255,3329,3404,3478,3552,3625,3699,3772,3845,3918,3990,4063,4135,4206,4278,4349,4420,4491,4561,4631,4701,4770,4840,4909,4977,5046,5113,5181,5249,5316,5382,5449,5515,5580,5646,5711,5775,5839,5903,5967,6030,6093,6155,6217,6279,6340,6401,6461,6521,6581,6640,6699,6758,6815,6873,6930,6987,7043,7099,7154,7209,7264,7318,7371,7424,7477,7529,7581,7632,7683,7733,7783,7832,7881,7930,7977,8025,8072,8118,8164,8209,8254,8298,8342,8385,8428,8470,8512,8553,8594,8634,8673,8712,8751,8789,8826,8863,8899,8935,8970,9005,9039,9072,9105,9138,9169,9201,9231,9261,9291,9320,9348,9376,9403,9429,9455,9481,9506,9530,9554,9577,9599,9621,9642,9663,9683,9702,9721,9739,9757,9774,9790,9806,9821,9836,9850,9863,9876,9888,9899,9910,9920,9930,9939,9947,9955,9962,9969,9975,9980,9985,9989,9992,9995,9997,9999,10000,10000}; 8 | 9 | // function approximating the sine calculation by using fixed size array 10 | // ~40us (float array) 11 | // ~50us (int array) 12 | // precision +-0.005 13 | // it has to receive an angle in between 0 and 2PI 14 | float _sin(float a){ 15 | if(a < _PI_2){ 16 | //return sine_array[(int)(199.0*( a / (_PI/2.0)))]; 17 | //return sine_array[(int)(126.6873* a)]; // float array optimized 18 | return 0.0001*sine_array[_round(126.6873* a)]; // int array optimized 19 | }else if(a < _PI){ 20 | // return sine_array[(int)(199.0*(1.0 - (a-_PI/2.0) / (_PI/2.0)))]; 21 | //return sine_array[398 - (int)(126.6873*a)]; // float array optimized 22 | return 0.0001*sine_array[398 - _round(126.6873*a)]; // int array optimized 23 | }else if(a < _3PI_2){ 24 | // return -sine_array[(int)(199.0*((a - _PI) / (_PI/2.0)))]; 25 | //return -sine_array[-398 + (int)(126.6873*a)]; // float array optimized 26 | return -0.0001*sine_array[-398 + _round(126.6873*a)]; // int array optimized 27 | } else { 28 | // return -sine_array[(int)(199.0*(1.0 - (a - 3*_PI/2) / (_PI/2.0)))]; 29 | //return -sine_array[796 - (int)(126.6873*a)]; // float array optimized 30 | return -0.0001*sine_array[796 - _round(126.6873*a)]; // int array optimized 31 | } 32 | } 33 | 34 | // function approximating cosine calculation by using fixed size array 35 | // ~55us (float array) 36 | // ~56us (int array) 37 | // precision +-0.005 38 | // it has to receive an angle in between 0 and 2PI 39 | float _cos(float a){ 40 | float a_sin = a + _PI_2; 41 | a_sin = a_sin > _2PI ? a_sin - _2PI : a_sin; 42 | return _sin(a_sin); 43 | } 44 | 45 | 46 | // normalizing radian angle to [0,2PI] 47 | float _normalizeAngle(float angle){ 48 | float a = fmod(angle, _2PI); 49 | return a >= 0 ? a : (a + _2PI); 50 | } 51 | 52 | // Electrical angle calculation 53 | float _electricalAngle(float shaft_angle, int pole_pairs) { 54 | return (shaft_angle * pole_pairs); 55 | } 56 | 57 | // square root approximation function using 58 | // https://reprap.org/forum/read.php?147,219210 59 | // https://en.wikipedia.org/wiki/Fast_inverse_square_root 60 | float _sqrtApprox(float number) {//low in fat 61 | long i; 62 | float y; 63 | // float x; 64 | // const float f = 1.5F; // better precision 65 | 66 | // x = number * 0.5F; 67 | y = number; 68 | i = * ( long * ) &y; 69 | i = 0x5f375a86 - ( i >> 1 ); 70 | y = * ( float * ) &i; 71 | // y = y * ( f - ( x * y * y ) ); // better precision 72 | return number * y; 73 | } 74 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/foc_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef FOCUTILS_LIB_H 2 | #define FOCUTILS_LIB_H 3 | 4 | #include 5 | 6 | // sign function 7 | #define _sign(a) ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) ) 8 | #define _round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) 9 | #define _constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) 10 | #define _sqrt(a) (_sqrtApprox(a)) 11 | #define _isset(a) ( (a) != (NOT_SET) ) 12 | 13 | // utility defines 14 | #define _2_SQRT3 1.15470053838 15 | #define _SQRT3 1.73205080757 16 | #define _1_SQRT3 0.57735026919 17 | #define _SQRT3_2 0.86602540378 18 | #define _SQRT2 1.41421356237 19 | #define _120_D2R 2.09439510239 20 | #define _PI 3.14159265359 21 | #define _PI_2 1.57079632679 22 | #define _PI_3 1.0471975512 23 | #define _2PI 6.28318530718 24 | #define _3PI_2 4.71238898038 25 | #define _PI_6 0.52359877559 26 | 27 | #define NOT_SET -12345.0 28 | #define _HIGH_IMPEDANCE 0 29 | #define _HIGH_Z _HIGH_IMPEDANCE 30 | #define _ACTIVE 1 31 | 32 | // dq current structure 33 | struct DQCurrent_s 34 | { 35 | float d; 36 | float q; 37 | }; 38 | // phase current structure 39 | struct PhaseCurrent_s 40 | { 41 | float a; 42 | float b; 43 | float c; 44 | }; 45 | // dq voltage structs 46 | struct DQVoltage_s 47 | { 48 | float d; 49 | float q; 50 | }; 51 | 52 | 53 | /** 54 | * Function approximating the sine calculation by using fixed size array 55 | * - execution time ~40us (Arduino UNO) 56 | * 57 | * @param a angle in between 0 and 2PI 58 | */ 59 | float _sin(float a); 60 | /** 61 | * Function approximating cosine calculation by using fixed size array 62 | * - execution time ~50us (Arduino UNO) 63 | * 64 | * @param a angle in between 0 and 2PI 65 | */ 66 | float _cos(float a); 67 | 68 | /** 69 | * normalizing radian angle to [0,2PI] 70 | * @param angle - angle to be normalized 71 | */ 72 | float _normalizeAngle(float angle); 73 | 74 | 75 | /** 76 | * Electrical angle calculation 77 | * 78 | * @param shaft_angle - shaft angle of the motor 79 | * @param pole_pairs - number of pole pairs 80 | */ 81 | float _electricalAngle(float shaft_angle, int pole_pairs); 82 | 83 | /** 84 | * Function approximating square root function 85 | * - using fast inverse square root 86 | * 87 | * @param value - number 88 | */ 89 | float _sqrtApprox(float value); 90 | 91 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/lowpass_filter.cpp: -------------------------------------------------------------------------------- 1 | #include "lowpass_filter.h" 2 | 3 | LowPassFilter::LowPassFilter(float time_constant) 4 | : Tf(time_constant) 5 | , y_prev(0.0f) 6 | { 7 | timestamp_prev = _micros(); 8 | } 9 | 10 | 11 | float LowPassFilter::operator() (float x) 12 | { 13 | unsigned long timestamp = _micros(); 14 | float dt = (timestamp - timestamp_prev)*1e-6f; 15 | 16 | if (dt < 0.0f || dt > 0.5f) 17 | dt = 1e-3f; 18 | 19 | float alpha = Tf/(Tf + dt); 20 | float y = alpha*y_prev + (1.0f - alpha)*x; 21 | 22 | y_prev = y; 23 | timestamp_prev = timestamp; 24 | return y; 25 | } 26 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/lowpass_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef LOWPASS_FILTER_H 2 | #define LOWPASS_FILTER_H 3 | 4 | 5 | #include "time_utils.h" 6 | #include "foc_utils.h" 7 | 8 | /** 9 | * Low pass filter class 10 | */ 11 | class LowPassFilter 12 | { 13 | public: 14 | /** 15 | * @param Tf - Low pass filter time constant 16 | */ 17 | LowPassFilter(float Tf); 18 | ~LowPassFilter() = default; 19 | 20 | float operator() (float x); 21 | float Tf; //!< Low pass filter time constant 22 | 23 | protected: 24 | unsigned long timestamp_prev; //!< Last execution timestamp 25 | float y_prev; //!< filtered value in previous execution step 26 | }; 27 | 28 | #endif // LOWPASS_FILTER_H -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/pid.cpp: -------------------------------------------------------------------------------- 1 | #include "pid.h" 2 | 3 | PIDController::PIDController(float P, float I, float D, float ramp, float limit) 4 | : P(P) 5 | , I(I) 6 | , D(D) 7 | , output_ramp(ramp) // output derivative limit [volts/second] 8 | , limit(limit) // output supply limit [volts] 9 | , integral_prev(0.0) 10 | , error_prev(0.0) 11 | , output_prev(0.0) 12 | { 13 | timestamp_prev = _micros(); 14 | } 15 | 16 | // PID controller function 17 | float PIDController::operator() (float error){ 18 | // calculate the time from the last call 19 | unsigned long timestamp_now = _micros(); 20 | float Ts = (timestamp_now - timestamp_prev) * 1e-6; 21 | // quick fix for strange cases (micros overflow) 22 | if(Ts <= 0 || Ts > 0.5) Ts = 1e-3; 23 | 24 | // u(s) = (P + I/s + Ds)e(s) 25 | // Discrete implementations 26 | // proportional part 27 | // u_p = P *e(k) 28 | float proportional = P * error; 29 | // Tustin transform of the integral part 30 | // u_ik = u_ik_1 + I*Ts/2*(ek + ek_1) 31 | float integral = integral_prev + I*Ts*0.5*(error + error_prev); 32 | // antiwindup - limit the output 33 | integral = _constrain(integral, -limit, limit); 34 | // Discrete derivation 35 | // u_dk = D(ek - ek_1)/Ts 36 | float derivative = D*(error - error_prev)/Ts; 37 | 38 | // sum all the components 39 | float output = proportional + integral + derivative; 40 | // antiwindup - limit the output variable 41 | output = _constrain(output, -limit, limit); 42 | 43 | // if output ramp defined 44 | if(output_ramp > 0){ 45 | // limit the acceleration by ramping the output 46 | float output_rate = (output - output_prev)/Ts; 47 | if (output_rate > output_ramp) 48 | output = output_prev + output_ramp*Ts; 49 | else if (output_rate < -output_ramp) 50 | output = output_prev - output_ramp*Ts; 51 | } 52 | // saving for the next pass 53 | integral_prev = integral; 54 | output_prev = output; 55 | error_prev = error; 56 | timestamp_prev = timestamp_now; 57 | return output; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/pid.h: -------------------------------------------------------------------------------- 1 | #ifndef PID_H 2 | #define PID_H 3 | 4 | 5 | #include "time_utils.h" 6 | #include "foc_utils.h" 7 | 8 | /** 9 | * PID controller class 10 | */ 11 | class PIDController 12 | { 13 | public: 14 | /** 15 | * 16 | * @param P - Proportional gain 17 | * @param I - Integral gain 18 | * @param D - Derivative gain 19 | * @param ramp - Maximum speed of change of the output value 20 | * @param limit - Maximum output value 21 | */ 22 | PIDController(float P, float I, float D, float ramp, float limit); 23 | ~PIDController() = default; 24 | 25 | float operator() (float error); 26 | 27 | float P; //!< Proportional gain 28 | float I; //!< Integral gain 29 | float D; //!< Derivative gain 30 | float output_ramp; //!< Maximum speed of change of the output value 31 | float limit; //!< Maximum output value 32 | 33 | protected: 34 | float integral_prev; //!< last integral component value 35 | float error_prev; //!< last tracking error value 36 | unsigned long timestamp_prev; //!< Last execution timestamp 37 | float output_prev; //!< last pid output value 38 | }; 39 | 40 | #endif // PID_H -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/time_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "time_utils.h" 2 | 3 | // function buffering delay() 4 | // arduino uno function doesn't work well with interrupts 5 | void _delay(unsigned long ms){ 6 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) 7 | // if arduino uno and other atmega328p chips 8 | // use while instad of delay, 9 | // due to wrong measurement based on changed timer0 10 | unsigned long t = _micros() + ms*1000; 11 | while( _micros() < t ){}; 12 | #else 13 | // regular micros 14 | delay(ms); 15 | #endif 16 | } 17 | 18 | 19 | // function buffering _micros() 20 | // arduino function doesn't work well with interrupts 21 | unsigned long _micros(){ 22 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) 23 | // if arduino uno and other atmega328p chips 24 | //return the value based on the prescaler 25 | if((TCCR0B & 0b00000111) == 0x01) return (micros()/32); 26 | else return (micros()); 27 | #else 28 | // regular micros 29 | return micros(); 30 | #endif 31 | } 32 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/common/time_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef TIME_UTILS_H 2 | #define TIME_UTILS_H 3 | 4 | #include "foc_utils.h" 5 | 6 | /** 7 | * Function implementing delay() function in milliseconds 8 | * - blocking function 9 | * - hardware specific 10 | 11 | * @param ms number of milliseconds to wait 12 | */ 13 | void _delay(unsigned long ms); 14 | 15 | /** 16 | * Function implementing timestamp getting function in microseconds 17 | * hardware specific 18 | */ 19 | unsigned long _micros(); 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/current_sense/InlineCurrentSense.h: -------------------------------------------------------------------------------- 1 | #ifndef INLINE_CS_LIB_H 2 | #define INLINE_CS_LIB_H 3 | 4 | #include "Arduino.h" 5 | #include "../common/foc_utils.h" 6 | #include "../common/time_utils.h" 7 | #include "../common/base_classes/CurrentSense.h" 8 | #include "hardware_api.h" 9 | 10 | 11 | class InlineCurrentSense: public CurrentSense{ 12 | public: 13 | /** 14 | InlineCurrentSense class constructor 15 | @param shunt_resistor shunt resistor value 16 | @param gain current-sense op-amp gain 17 | @param phA A phase adc pin 18 | @param phB B phase adc pin 19 | @param phC C phase adc pin (optional) 20 | */ 21 | InlineCurrentSense(float shunt_resistor, float gain, int pinA, int pinB, int pinC = NOT_SET); 22 | 23 | // CurrentSense interface implementing functions 24 | void init() override; 25 | PhaseCurrent_s getPhaseCurrents() override; 26 | int driverSync(BLDCDriver *driver) override; 27 | int driverAlign(BLDCDriver *driver, float voltage) override; 28 | 29 | // ADC measuremnet gain for each phase 30 | // support for different gains for different phases of more commonly - inverted phase currents 31 | // this should be automated later 32 | float gain_a; //!< phase A gain 33 | float gain_b; //!< phase B gain 34 | float gain_c; //!< phase C gain 35 | 36 | private: 37 | 38 | // hardware variables 39 | int pinA; //!< pin A analog pin for current measurement 40 | int pinB; //!< pin B analog pin for current measurement 41 | int pinC; //!< pin C analog pin for current measurement 42 | 43 | // gain variables 44 | double shunt_resistor; //!< Shunt resistor value 45 | double amp_gain; //!< amp gain value 46 | double volts_to_amps_ratio; //!< Volts to amps ratio 47 | 48 | /** 49 | * Function finding zero offsets of the ADC 50 | */ 51 | void calibrateOffsets(); 52 | double offset_ia; //!< zero current A voltage value (center of the adc reading) 53 | double offset_ib; //!< zero current B voltage value (center of the adc reading) 54 | double offset_ic; //!< zero current C voltage value (center of the adc reading) 55 | 56 | }; 57 | 58 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/current_sense/hardware_api.h: -------------------------------------------------------------------------------- 1 | #ifndef HARDWARE_UTILS_H 2 | #define HARDWARE_UTILS_H 3 | 4 | #include "../common/foc_utils.h" 5 | #include "../common/time_utils.h" 6 | 7 | /** 8 | * function reading an ADC value and returning the read voltage 9 | * 10 | * @param pinA - the arduino pin to be read (it has to be ADC pin) 11 | */ 12 | float _readADCVoltage(const int pinA); 13 | 14 | /** 15 | * function reading an ADC value and returning the read voltage 16 | * 17 | * @param pinA - adc pin A 18 | * @param pinB - adc pin B 19 | * @param pinC - adc pin C 20 | */ 21 | void _configureADC(const int pinA,const int pinB,const int pinC = NOT_SET); 22 | 23 | #endif -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/current_sense/hardware_specific/generic_mcu.cpp: -------------------------------------------------------------------------------- 1 | #include "../hardware_api.h" 2 | #include "adc.h" 3 | 4 | 5 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) // if mcu is atmega328 or atmega2560 6 | #define _ADC_VOLTAGE 5.0 7 | #define _ADC_RESOLUTION 1024.0 8 | #ifndef cbi 9 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 10 | #endif 11 | #ifndef sbi 12 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 13 | #endif 14 | #elif defined(__arm__) && defined(CORE_TEENSY) // or teensy 15 | #define _ADC_VOLTAGE 3.3 16 | #define _ADC_RESOLUTION 1024.0 17 | #elif defined(__arm__) && defined(__SAM3X8E__) // or due 18 | #define _ADC_VOLTAGE 3.3 19 | #define _ADC_RESOLUTION 1024.0 20 | #elif defined(ESP_H) // or esp32 21 | #define _ADC_VOLTAGE 3.3 22 | #define _ADC_RESOLUTION 4095.0 23 | #elif defined(_STM32_DEF_) // or stm32 24 | #define _ADC_VOLTAGE 3.3 25 | #define _ADC_RESOLUTION 1024.0 26 | #else 27 | #define _ADC_VOLTAGE 3.3 28 | #define _ADC_RESOLUTION 4095.0 29 | #endif 30 | 31 | // adc counts to voltage conversion ratio 32 | // some optimizing for faster execution 33 | #define _ADC_CONV ( (_ADC_VOLTAGE) / (_ADC_RESOLUTION) ) 34 | 35 | // function reading an ADC value and returning the read voltage 36 | float _readADCVoltage(const int pinA){ 37 | uint32_t raw_adc = readPhaseVoltage(pinA); //analogRead(pinA); 38 | return raw_adc * _ADC_CONV; 39 | } 40 | 41 | 42 | // function reading an ADC value and returning the read voltage 43 | void _configureADC(const int pinA,const int pinB,const int pinC){ 44 | // pinMode(pinA, INPUT); 45 | // pinMode(pinB, INPUT); 46 | // if( _isset(pinC) ) pinMode(pinC, INPUT); 47 | // 48 | // #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega2560__) // if mcu is atmega328 or atmega2560 49 | // // set hight frequency adc - ADPS2,ADPS1,ADPS0 | 001 (16mhz/2) | 010 ( 16mhz/4 ) | 011 (16mhz/8) | 100(16mhz/16) | 101 (16mhz/32) | 110 (16mhz/64) | 111 (16mhz/128 default) 50 | // // set divisor to 8 - adc frequency 16mhz/8 = 2 mhz 51 | // // arduino takes 25 conversions per sample so - 2mhz/25 = 80k samples per second - 12.5us per sample 52 | // cbi(ADCSRA, ADPS2); 53 | // sbi(ADCSRA, ADPS1); 54 | // sbi(ADCSRA, ADPS0); 55 | // #endif 56 | } 57 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/drivers/BLDCDriver3PWM.cpp: -------------------------------------------------------------------------------- 1 | #include "BLDCDriver3PWM.h" 2 | 3 | BLDCDriver3PWM::BLDCDriver3PWM(int phA, int phB, int phC, int en1, int en2, int en3){ 4 | // Pin initialization 5 | pwmA = phA; 6 | pwmB = phB; 7 | pwmC = phC; 8 | 9 | // enable_pin pin 10 | enableA_pin = en1; 11 | enableB_pin = en2; 12 | enableC_pin = en3; 13 | 14 | // default power-supply value 15 | voltage_power_supply = DEF_POWER_SUPPLY; 16 | voltage_limit = NOT_SET; 17 | 18 | } 19 | 20 | // enable motor driver 21 | void BLDCDriver3PWM::enable(){ 22 | // enable_pin the driver - if enable_pin pin available 23 | if ( _isset(enableA_pin) ) digitalWrite(enableA_pin, HIGH); 24 | if ( _isset(enableB_pin) ) digitalWrite(enableB_pin, HIGH); 25 | if ( _isset(enableC_pin) ) digitalWrite(enableC_pin, HIGH); 26 | // set zero to PWM 27 | setPwm(0,0,0); 28 | } 29 | 30 | // disable motor driver 31 | void BLDCDriver3PWM::disable() 32 | { 33 | // set zero to PWM 34 | setPwm(0, 0, 0); 35 | // disable the driver - if enable_pin pin available 36 | if ( _isset(enableA_pin) ) digitalWrite(enableA_pin, LOW); 37 | if ( _isset(enableB_pin) ) digitalWrite(enableB_pin, LOW); 38 | if ( _isset(enableC_pin) ) digitalWrite(enableC_pin, LOW); 39 | 40 | } 41 | 42 | // init hardware pins 43 | int BLDCDriver3PWM::init() { 44 | // PWM pins 45 | pinMode(pwmA, OUTPUT); 46 | pinMode(pwmB, OUTPUT); 47 | pinMode(pwmC, OUTPUT); 48 | if( _isset(enableA_pin)) pinMode(enableA_pin, OUTPUT); 49 | if( _isset(enableB_pin)) pinMode(enableB_pin, OUTPUT); 50 | if( _isset(enableC_pin)) pinMode(enableC_pin, OUTPUT); 51 | 52 | 53 | // sanity check for the voltage limit configuration 54 | if(!_isset(voltage_limit) || voltage_limit > voltage_power_supply) voltage_limit = voltage_power_supply; 55 | 56 | // Set the pwm frequency to the pins 57 | // hardware specific function - depending on driver and mcu 58 | _configure3PWM(pwm_frequency, pwmA, pwmB, pwmC); 59 | return 0; 60 | } 61 | 62 | 63 | 64 | // Set voltage to the pwm pin 65 | void BLDCDriver3PWM::setPhaseState(int sa, int sb, int sc) { 66 | // disable if needed 67 | if( _isset(enableA_pin) && _isset(enableB_pin) && _isset(enableC_pin) ){ 68 | digitalWrite(enableA_pin, sa == _HIGH_IMPEDANCE ? LOW : HIGH); 69 | digitalWrite(enableB_pin, sb == _HIGH_IMPEDANCE ? LOW : HIGH); 70 | digitalWrite(enableC_pin, sc == _HIGH_IMPEDANCE ? LOW : HIGH); 71 | } 72 | } 73 | 74 | // Set voltage to the pwm pin 75 | void BLDCDriver3PWM::setPwm(float Ua, float Ub, float Uc) { 76 | 77 | // limit the voltage in driver 78 | Ua = _constrain(Ua, 0.0, voltage_limit); 79 | Ub = _constrain(Ub, 0.0, voltage_limit); 80 | Uc = _constrain(Uc, 0.0, voltage_limit); 81 | // calculate duty cycle 82 | // limited in [0,1] 83 | dc_a = _constrain(Ua / voltage_power_supply, 0.0 , 1.0 ); 84 | dc_b = _constrain(Ub / voltage_power_supply, 0.0 , 1.0 ); 85 | dc_c = _constrain(Uc / voltage_power_supply, 0.0 , 1.0 ); 86 | 87 | // hardware specific writing 88 | // hardware specific function - depending on driver and mcu 89 | _writeDutyCycle3PWM(dc_a, dc_b, dc_c, pwmA, pwmB, pwmC); 90 | } -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/drivers/BLDCDriver3PWM.h: -------------------------------------------------------------------------------- 1 | #ifndef BLDCDriver3PWM_h 2 | #define BLDCDriver3PWM_h 3 | 4 | #include "../common/base_classes/BLDCDriver.h" 5 | #include "../common/foc_utils.h" 6 | #include "../common/time_utils.h" 7 | #include "../common/defaults.h" 8 | #include "hardware_api.h" 9 | 10 | /** 11 | 3 pwm bldc driver class 12 | */ 13 | class BLDCDriver3PWM: public BLDCDriver 14 | { 15 | public: 16 | /** 17 | BLDCDriver class constructor 18 | @param phA A phase pwm pin 19 | @param phB B phase pwm pin 20 | @param phC C phase pwm pin 21 | @param en1 enable pin (optional input) 22 | @param en2 enable pin (optional input) 23 | @param en3 enable pin (optional input) 24 | */ 25 | BLDCDriver3PWM(int phA,int phB,int phC, int en1 = NOT_SET, int en2 = NOT_SET, int en3 = NOT_SET); 26 | 27 | /** Motor hardware init function */ 28 | int init() override; 29 | /** Motor disable function */ 30 | void disable() override; 31 | /** Motor enable function */ 32 | void enable() override; 33 | 34 | // hardware variables 35 | int pwmA; //!< phase A pwm pin number 36 | int pwmB; //!< phase B pwm pin number 37 | int pwmC; //!< phase C pwm pin number 38 | int enableA_pin; //!< enable pin number 39 | int enableB_pin; //!< enable pin number 40 | int enableC_pin; //!< enable pin number 41 | 42 | /** 43 | * Set phase voltages to the harware 44 | * 45 | * @param Ua - phase A voltage 46 | * @param Ub - phase B voltage 47 | * @param Uc - phase C voltage 48 | */ 49 | void setPwm(float Ua, float Ub, float Uc) override; 50 | 51 | /** 52 | * Set phase voltages to the harware 53 | * 54 | * @param sc - phase A state : active / disabled ( high impedance ) 55 | * @param sb - phase B state : active / disabled ( high impedance ) 56 | * @param sa - phase C state : active / disabled ( high impedance ) 57 | */ 58 | virtual void setPhaseState(int sa, int sb, int sc) override; 59 | private: 60 | 61 | }; 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/drivers/BLDCDriver6PWM.cpp: -------------------------------------------------------------------------------- 1 | #include "BLDCDriver6PWM.h" 2 | 3 | BLDCDriver6PWM::BLDCDriver6PWM(int phA_h,int phA_l,int phB_h,int phB_l,int phC_h,int phC_l, int en){ 4 | // Pin initialization 5 | pwmA_h = phA_h; 6 | pwmB_h = phB_h; 7 | pwmC_h = phC_h; 8 | pwmA_l = phA_l; 9 | pwmB_l = phB_l; 10 | pwmC_l = phC_l; 11 | 12 | // enable_pin pin 13 | enable_pin = en; 14 | 15 | // default power-supply value 16 | voltage_power_supply = DEF_POWER_SUPPLY; 17 | voltage_limit = NOT_SET; 18 | 19 | // dead zone initial - 2% 20 | dead_zone = 0.02; 21 | 22 | } 23 | 24 | // enable motor driver 25 | void BLDCDriver6PWM::enable(){ 26 | // enable_pin the driver - if enable_pin pin available 27 | if ( _isset(enable_pin) ) digitalWrite(enable_pin, enable_active_high); 28 | // set zero to PWM 29 | setPwm(0, 0, 0); 30 | } 31 | 32 | // disable motor driver 33 | void BLDCDriver6PWM::disable() 34 | { 35 | // set zero to PWM 36 | setPwm(0, 0, 0); 37 | // disable the driver - if enable_pin pin available 38 | if ( _isset(enable_pin) ) digitalWrite(enable_pin, !enable_active_high); 39 | 40 | } 41 | 42 | // init hardware pins 43 | int BLDCDriver6PWM::init() { 44 | 45 | // PWM pins 46 | pinMode(pwmA_h, OUTPUT); 47 | pinMode(pwmB_h, OUTPUT); 48 | pinMode(pwmC_h, OUTPUT); 49 | pinMode(pwmA_l, OUTPUT); 50 | pinMode(pwmB_l, OUTPUT); 51 | pinMode(pwmC_l, OUTPUT); 52 | if(_isset(enable_pin)) pinMode(enable_pin, OUTPUT); 53 | 54 | 55 | // sanity check for the voltage limit configuration 56 | if( !_isset(voltage_limit) || voltage_limit > voltage_power_supply) voltage_limit = voltage_power_supply; 57 | 58 | // configure 6pwm 59 | // hardware specific function - depending on driver and mcu 60 | return _configure6PWM(pwm_frequency, dead_zone, pwmA_h,pwmA_l, pwmB_h,pwmB_l, pwmC_h,pwmC_l); 61 | } 62 | 63 | // Set voltage to the pwm pin 64 | void BLDCDriver6PWM::setPwm(float Ua, float Ub, float Uc) { 65 | // limit the voltage in driver 66 | Ua = _constrain(Ua, 0, voltage_limit); 67 | Ub = _constrain(Ub, 0, voltage_limit); 68 | Uc = _constrain(Uc, 0, voltage_limit); 69 | // calculate duty cycle 70 | // limited in [0,1] 71 | dc_a = _constrain(Ua / voltage_power_supply, 0.0 , 1.0 ); 72 | dc_b = _constrain(Ub / voltage_power_supply, 0.0 , 1.0 ); 73 | dc_c = _constrain(Uc / voltage_power_supply, 0.0 , 1.0 ); 74 | // hardware specific writing 75 | // hardware specific function - depending on driver and mcu 76 | _writeDutyCycle6PWM(dc_a, dc_b, dc_c, dead_zone, pwmA_h,pwmA_l, pwmB_h,pwmB_l, pwmC_h,pwmC_l); 77 | } 78 | 79 | 80 | // Set voltage to the pwm pin 81 | void BLDCDriver6PWM::setPhaseState(int sa, int sb, int sc) { 82 | // TODO implement disabling 83 | } 84 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/drivers/BLDCDriver6PWM.h: -------------------------------------------------------------------------------- 1 | #ifndef BLDCDriver6PWM_h 2 | #define BLDCDriver6PWM_h 3 | 4 | #include "../common/base_classes/BLDCDriver.h" 5 | #include "../common/foc_utils.h" 6 | #include "../common/time_utils.h" 7 | #include "../common/defaults.h" 8 | #include "hardware_api.h" 9 | 10 | /** 11 | 6 pwm bldc driver class 12 | */ 13 | class BLDCDriver6PWM: public BLDCDriver 14 | { 15 | public: 16 | /** 17 | BLDCDriver class constructor 18 | @param phA_h A phase pwm pin 19 | @param phA_l A phase pwm pin 20 | @param phB_h B phase pwm pin 21 | @param phB_l A phase pwm pin 22 | @param phC_h C phase pwm pin 23 | @param phC_l A phase pwm pin 24 | @param en enable pin (optional input) 25 | */ 26 | BLDCDriver6PWM(int phA_h,int phA_l,int phB_h,int phB_l,int phC_h,int phC_l, int en = NOT_SET); 27 | 28 | /** Motor hardware init function */ 29 | int init() override; 30 | /** Motor disable function */ 31 | void disable() override; 32 | /** Motor enable function */ 33 | void enable() override; 34 | 35 | // hardware variables 36 | int pwmA_h,pwmA_l; //!< phase A pwm pin number 37 | int pwmB_h,pwmB_l; //!< phase B pwm pin number 38 | int pwmC_h,pwmC_l; //!< phase C pwm pin number 39 | int enable_pin; //!< enable pin number 40 | bool enable_active_high = true; 41 | 42 | float dead_zone; //!< a percentage of dead-time(zone) (both high and low side in low) for each pwm cycle [0,1] 43 | 44 | /** 45 | * Set phase voltages to the harware 46 | * 47 | * @param Ua - phase A voltage 48 | * @param Ub - phase B voltage 49 | * @param Uc - phase C voltage 50 | */ 51 | void setPwm(float Ua, float Ub, float Uc) override; 52 | 53 | /** 54 | * Set phase voltages to the harware 55 | * 56 | * @param sc - phase A state : active / disabled ( high impedance ) 57 | * @param sb - phase B state : active / disabled ( high impedance ) 58 | * @param sa - phase C state : active / disabled ( high impedance ) 59 | */ 60 | virtual void setPhaseState(int sa, int sb, int sc) override; 61 | 62 | private: 63 | 64 | }; 65 | 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/drivers/hardware_specific/Arduino.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Arduino.h 3 | * 4 | * Created on: 2021年9月1日 5 | * Author: tajor 6 | */ 7 | 8 | #ifndef SIMPLEFOC_DRIVERS_HARDWARE_SPECIFIC_ARDUINO_H_ 9 | #define SIMPLEFOC_DRIVERS_HARDWARE_SPECIFIC_ARDUINO_H_ 10 | 11 | #include "main.h" 12 | #include "stm32f4xx_hal.h" 13 | #include "tim.h" 14 | #include "math.h" 15 | #include "stdlib.h" 16 | #include "stdio.h" 17 | #include "string.h" 18 | #include "freertos.h" 19 | #include "task.h" 20 | 21 | 22 | class Print{ 23 | public: 24 | void print(char* value){ 25 | printf("%s", value); 26 | }; 27 | void print(float value){ 28 | printf("%f", value); 29 | }; 30 | void print(double value){ 31 | printf("%f", value); 32 | }; 33 | void print(int value){ 34 | printf("%d", value); 35 | }; 36 | void print(char value){ 37 | printf("%c", value); 38 | }; 39 | void println(char* value){ 40 | printf("%s \n", value); 41 | }; 42 | void println(float value){ 43 | printf("%f \n", value); 44 | }; 45 | void println(double value){ 46 | printf("%lf \n", value); 47 | }; 48 | void println(int value){ 49 | printf("%d \n", value); 50 | }; 51 | void println(char value){ 52 | printf("%c \n", value); 53 | }; 54 | void print(char* value, int len){ 55 | printf("%s", value); 56 | }; 57 | void print(float value, int len){ 58 | printf("%f", value); 59 | }; 60 | void print(double value, int len){ 61 | printf("%lf", value); 62 | }; 63 | void print(int value, int len){ 64 | printf("%d", value); 65 | }; 66 | void print(char value, int len){ 67 | printf("%c", value); 68 | }; 69 | void println(char* value, int len){ 70 | printf("%s \n", value); 71 | }; 72 | void println(float value, int len){ 73 | printf("%f \n", value); 74 | }; 75 | void println(double value, int len){ 76 | printf("%f \n", value); 77 | }; 78 | void println(int value, int len){ 79 | printf("%d \n", value); 80 | }; 81 | 82 | void println(void){ 83 | printf("\n"); 84 | }; 85 | }; 86 | 87 | #ifndef HIGH 88 | #define HIGH 1 89 | #endif 90 | #ifndef LOW 91 | #define LOW 0 92 | #endif 93 | #ifndef INPUT 94 | #define INPUT 0 95 | #endif 96 | #ifndef OUTPUT 97 | #define OUTPUT 1 98 | #endif 99 | 100 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 101 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 102 | 103 | 104 | char *F(char* str); 105 | void delay(int t); 106 | unsigned long micros(void); 107 | GPIO_TypeDef* index2Gpio_x(uint32_t index); 108 | uint16_t index2Pin_x(uint32_t index); 109 | uint32_t Gpio_pin2Index(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 110 | void digitalWrite(int ulPin, bool high_or_low); 111 | uint32_t analogRead(int ulPin); 112 | void pinMode(int ulPin, bool in_or_out); 113 | 114 | 115 | float _readADCVoltage(const int pinA); 116 | void _configureADC(const int pinA,const int pinB,const int pinC); 117 | 118 | 119 | #endif /* SIMPLEFOC_DRIVERS_HARDWARE_SPECIFIC_ARDUINO_H_ */ 120 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/sensors/Encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODER_LIB_H 2 | #define ENCODER_LIB_H 3 | 4 | #include "Arduino.h" 5 | #include "../common/foc_utils.h" 6 | #include "../common/time_utils.h" 7 | #include "../common/base_classes/Sensor.h" 8 | 9 | 10 | /** 11 | * Quadrature mode configuration structure 12 | */ 13 | enum Quadrature{ 14 | ON, //!< Enable quadrature mode CPR = 4xPPR 15 | OFF //!< Disable quadrature mode / CPR = PPR 16 | }; 17 | 18 | class Encoder: public Sensor{ 19 | public: 20 | /** 21 | Encoder class constructor 22 | @param encA encoder B pin 23 | @param encB encoder B pin 24 | @param ppr impulses per rotation (cpr=ppr*4) 25 | @param index index pin number (optional input) 26 | */ 27 | Encoder(int encA, int encB , float ppr, int index = 0); 28 | 29 | /** encoder initialise pins */ 30 | void init(); 31 | /** 32 | * function enabling hardware interrupts for the encoder channels with provided callback functions 33 | * if callback is not provided then the interrupt is not enabled 34 | * 35 | * @param doA pointer to the A channel interrupt handler function 36 | * @param doB pointer to the B channel interrupt handler function 37 | * @param doIndex pointer to the Index channel interrupt handler function 38 | * 39 | */ 40 | void enableInterrupts(void (*doA)() = nullptr, void(*doB)() = nullptr, void(*doIndex)() = nullptr); 41 | 42 | // Encoder interrupt callback functions 43 | /** A channel callback function */ 44 | void handleA(); 45 | /** B channel callback function */ 46 | void handleB(); 47 | /** Index channel callback function */ 48 | void handleIndex(); 49 | 50 | 51 | // pins A and B 52 | int pinA; //!< encoder hardware pin A 53 | int pinB; //!< encoder hardware pin B 54 | int index_pin; //!< index pin 55 | 56 | // Encoder configuration 57 | Pullup pullup; //!< Configuration parameter internal or external pullups 58 | Quadrature quadrature;//!< Configuration parameter enable or disable quadrature mode 59 | float cpr;//!< encoder cpr number 60 | 61 | // Abstract functions of the Sensor class implementation 62 | /** get current angle (rad) */ 63 | float getAngle() override; 64 | /** get current angular velocity (rad/s) */ 65 | float getVelocity() override; 66 | /** 67 | * returns 0 if it does need search for absolute zero 68 | * 0 - encoder without index 69 | * 1 - ecoder with index 70 | */ 71 | int needsSearch() override; 72 | 73 | private: 74 | int hasIndex(); //!< function returning 1 if encoder has index pin and 0 if not. 75 | 76 | volatile long pulse_counter;//!< current pulse counter 77 | volatile long pulse_timestamp;//!< last impulse timestamp in us 78 | volatile int A_active; //!< current active states of A channel 79 | volatile int B_active; //!< current active states of B channel 80 | volatile int I_active; //!< current active states of Index channel 81 | volatile bool index_found = false; //!< flag stating that the index has been found 82 | 83 | // velocity calculation variables 84 | float prev_Th, pulse_per_second; 85 | volatile long prev_pulse_counter, prev_timestamp_us; 86 | }; 87 | 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/SimpleFOC/sensors/MagneticSensorSPI.h: -------------------------------------------------------------------------------- 1 | #ifndef MAGNETICSENSORSPI_LIB_H 2 | #define MAGNETICSENSORSPI_LIB_H 3 | 4 | #ifndef TARGET_RP2040 5 | 6 | #include "Arduino.h" 7 | #include 8 | #include "../common/base_classes/Sensor.h" 9 | #include "../common/foc_utils.h" 10 | #include "../common/time_utils.h" 11 | 12 | #define DEF_ANGLE_REGISTER 0x3FFF 13 | 14 | typedef uint16_t word; 15 | typedef uint8_t byte; 16 | 17 | struct MagneticSensorSPIConfig_s { 18 | int spi_mode; 19 | long clock_speed; 20 | int bit_resolution; 21 | int angle_register; 22 | int data_start_bit; 23 | int command_rw_bit; 24 | int command_parity_bit; 25 | }; 26 | // typical configuration structures 27 | extern MagneticSensorSPIConfig_s AS5147_SPI,AS5048_SPI,AS5047_SPI, MA730_SPI; 28 | 29 | class MagneticSensorSPI: public Sensor{ 30 | public: 31 | /** 32 | * MagneticSensorSPI class constructor 33 | * @param cs SPI chip select pin 34 | * @param bit_resolution sensor resolution bit number 35 | * @param angle_register (optional) angle read register - default 0x3FFF 36 | */ 37 | MagneticSensorSPI(int cs, float bit_resolution, int angle_register = 0); 38 | /** 39 | * MagneticSensorSPI class constructor 40 | * @param config SPI config 41 | * @param cs SPI chip select pin 42 | */ 43 | MagneticSensorSPI(MagneticSensorSPIConfig_s config, int cs); 44 | 45 | /** sensor initialise pins */ 46 | void init(SPI_HandleTypeDef* _spi); 47 | 48 | // implementation of abstract functions of the Sensor class 49 | /** get current angle (rad) */ 50 | float getAngle() override; 51 | /** get current angular velocity (rad/s) **/ 52 | float getVelocity() override; 53 | 54 | // returns the spi mode (phase/polarity of read/writes) i.e one of SPI_MODE0 | SPI_MODE1 | SPI_MODE2 | SPI_MODE3 55 | int spi_mode; 56 | 57 | /* returns the speed of the SPI clock signal */ 58 | long clock_speed; 59 | 60 | 61 | private: 62 | float cpr; //!< Maximum range of the magnetic sensor 63 | // spi variables 64 | int angle_register; //!< SPI angle register to read 65 | int chip_select_pin; //!< SPI chip select pin 66 | // SPISettings settings; //!< SPI settings variable 67 | // spi functions 68 | /** Stop SPI communication */ 69 | void close(); 70 | /** Read one SPI register value */ 71 | word read(word angle_register); 72 | /** Calculate parity value */ 73 | byte spiCalcEvenParity(word value); 74 | 75 | /** 76 | * Function getting current angle register value 77 | * it uses angle_register variable 78 | */ 79 | int getRawCount(); 80 | 81 | // total angle tracking variables 82 | float full_rotation_offset; //!
© Copyright (c) 2022 STMicroelectronics. 10 | * All rights reserved.
11 | * 12 | * This software component is licensed by ST under Ultimate Liberty license 13 | * SLA0044, the "License"; You may not use this file except in compliance with 14 | * the License. You may obtain a copy of the License at: 15 | * www.st.com/SLA0044 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Includes ------------------------------------------------------------------*/ 21 | #include "gpio.h" 22 | 23 | /* USER CODE BEGIN 0 */ 24 | 25 | /* USER CODE END 0 */ 26 | 27 | /*----------------------------------------------------------------------------*/ 28 | /* Configure GPIO */ 29 | /*----------------------------------------------------------------------------*/ 30 | /* USER CODE BEGIN 1 */ 31 | 32 | /* USER CODE END 1 */ 33 | 34 | /** Configure pins as 35 | * Analog 36 | * Input 37 | * Output 38 | * EVENT_OUT 39 | * EXTI 40 | */ 41 | void MX_GPIO_Init(void) 42 | { 43 | 44 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 45 | 46 | /* GPIO Ports Clock Enable */ 47 | __HAL_RCC_GPIOH_CLK_ENABLE(); 48 | __HAL_RCC_GPIOC_CLK_ENABLE(); 49 | __HAL_RCC_GPIOA_CLK_ENABLE(); 50 | __HAL_RCC_GPIOB_CLK_ENABLE(); 51 | 52 | /*Configure GPIO pin Output Level */ 53 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); 54 | 55 | /*Configure GPIO pin Output Level */ 56 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); 57 | 58 | /*Configure GPIO pin Output Level */ 59 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_SET); 60 | 61 | /*Configure GPIO pin : PA4 */ 62 | GPIO_InitStruct.Pin = GPIO_PIN_4; 63 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 64 | GPIO_InitStruct.Pull = GPIO_PULLDOWN; 65 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 66 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 67 | 68 | /*Configure GPIO pin : PB0 */ 69 | GPIO_InitStruct.Pin = GPIO_PIN_0; 70 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 71 | GPIO_InitStruct.Pull = GPIO_NOPULL; 72 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 73 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 74 | 75 | /*Configure GPIO pins : PB13 PB14 PB15 */ 76 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; 77 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 78 | GPIO_InitStruct.Pull = GPIO_PULLUP; 79 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 80 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 81 | 82 | } 83 | 84 | /* USER CODE BEGIN 2 */ 85 | 86 | /* USER CODE END 2 */ 87 | 88 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 89 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Src/stm32f4xx_hal_msp.c: -------------------------------------------------------------------------------- 1 | /* USER CODE BEGIN Header */ 2 | /** 3 | ****************************************************************************** 4 | * @file stm32f4xx_hal_msp.c 5 | * @brief This file provides code for the MSP Initialization 6 | * and de-Initialization codes. 7 | ****************************************************************************** 8 | * @attention 9 | * 10 | *

© Copyright (c) 2021 STMicroelectronics. 11 | * All rights reserved.

12 | * 13 | * This software component is licensed by ST under BSD 3-Clause license, 14 | * the "License"; You may not use this file except in compliance with the 15 | * License. You may obtain a copy of the License at: 16 | * opensource.org/licenses/BSD-3-Clause 17 | * 18 | ****************************************************************************** 19 | */ 20 | /* USER CODE END Header */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "main.h" 24 | /* USER CODE BEGIN Includes */ 25 | 26 | /* USER CODE END Includes */ 27 | 28 | /* Private typedef -----------------------------------------------------------*/ 29 | /* USER CODE BEGIN TD */ 30 | 31 | /* USER CODE END TD */ 32 | 33 | /* Private define ------------------------------------------------------------*/ 34 | /* USER CODE BEGIN Define */ 35 | 36 | /* USER CODE END Define */ 37 | 38 | /* Private macro -------------------------------------------------------------*/ 39 | /* USER CODE BEGIN Macro */ 40 | 41 | /* USER CODE END Macro */ 42 | 43 | /* Private variables ---------------------------------------------------------*/ 44 | /* USER CODE BEGIN PV */ 45 | 46 | /* USER CODE END PV */ 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | /* USER CODE BEGIN PFP */ 50 | 51 | /* USER CODE END PFP */ 52 | 53 | /* External functions --------------------------------------------------------*/ 54 | /* USER CODE BEGIN ExternalFunctions */ 55 | 56 | /* USER CODE END ExternalFunctions */ 57 | 58 | /* USER CODE BEGIN 0 */ 59 | 60 | /* USER CODE END 0 */ 61 | /** 62 | * Initializes the Global MSP. 63 | */ 64 | void HAL_MspInit(void) 65 | { 66 | /* USER CODE BEGIN MspInit 0 */ 67 | 68 | /* USER CODE END MspInit 0 */ 69 | 70 | __HAL_RCC_SYSCFG_CLK_ENABLE(); 71 | __HAL_RCC_PWR_CLK_ENABLE(); 72 | 73 | /* System interrupt init*/ 74 | /* PendSV_IRQn interrupt configuration */ 75 | HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0); 76 | 77 | /* USER CODE BEGIN MspInit 1 */ 78 | 79 | /* USER CODE END MspInit 1 */ 80 | } 81 | 82 | /* USER CODE BEGIN 1 */ 83 | 84 | /* USER CODE END 1 */ 85 | 86 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 87 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Src/syscalls.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file syscalls.c 4 | * @author Auto-generated by STM32CubeIDE 5 | * @brief STM32CubeIDE Minimal System calls file 6 | * 7 | * For more information about which c-functions 8 | * need which of these lowlevel functions 9 | * please consult the Newlib libc-manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | /* Variables */ 36 | //#undef errno 37 | extern int errno; 38 | extern int __io_putchar(int ch) __attribute__((weak)); 39 | extern int __io_getchar(void) __attribute__((weak)); 40 | 41 | register char * stack_ptr asm("sp"); 42 | 43 | char *__env[1] = { 0 }; 44 | char **environ = __env; 45 | 46 | 47 | /* Functions */ 48 | void initialise_monitor_handles() 49 | { 50 | } 51 | 52 | int _getpid(void) 53 | { 54 | return 1; 55 | } 56 | 57 | int _kill(int pid, int sig) 58 | { 59 | errno = EINVAL; 60 | return -1; 61 | } 62 | 63 | void _exit (int status) 64 | { 65 | _kill(status, -1); 66 | while (1) {} /* Make sure we hang here */ 67 | } 68 | 69 | __attribute__((weak)) int _read(int file, char *ptr, int len) 70 | { 71 | int DataIdx; 72 | 73 | for (DataIdx = 0; DataIdx < len; DataIdx++) 74 | { 75 | *ptr++ = __io_getchar(); 76 | } 77 | 78 | return len; 79 | } 80 | 81 | __attribute__((weak)) int _write(int file, char *ptr, int len) 82 | { 83 | int DataIdx; 84 | 85 | for (DataIdx = 0; DataIdx < len; DataIdx++) 86 | { 87 | __io_putchar(*ptr++); 88 | } 89 | return len; 90 | } 91 | 92 | int _close(int file) 93 | { 94 | return -1; 95 | } 96 | 97 | 98 | int _fstat(int file, struct stat *st) 99 | { 100 | st->st_mode = S_IFCHR; 101 | return 0; 102 | } 103 | 104 | int _isatty(int file) 105 | { 106 | return 1; 107 | } 108 | 109 | int _lseek(int file, int ptr, int dir) 110 | { 111 | return 0; 112 | } 113 | 114 | int _open(char *path, int flags, ...) 115 | { 116 | /* Pretend like we always fail */ 117 | return -1; 118 | } 119 | 120 | int _wait(int *status) 121 | { 122 | errno = ECHILD; 123 | return -1; 124 | } 125 | 126 | int _unlink(char *name) 127 | { 128 | errno = ENOENT; 129 | return -1; 130 | } 131 | 132 | int _times(struct tms *buf) 133 | { 134 | return -1; 135 | } 136 | 137 | int _stat(char *file, struct stat *st) 138 | { 139 | st->st_mode = S_IFCHR; 140 | return 0; 141 | } 142 | 143 | int _link(char *old, char *new) 144 | { 145 | errno = EMLINK; 146 | return -1; 147 | } 148 | 149 | int _fork(void) 150 | { 151 | errno = EAGAIN; 152 | return -1; 153 | } 154 | 155 | int _execve(char *name, char **argv, char **env) 156 | { 157 | errno = ENOMEM; 158 | return -1; 159 | } 160 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Core/Src/sysmem.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sysmem.c 4 | * @author Generated by STM32CubeIDE 5 | * @brief STM32CubeIDE System Memory calls file 6 | * 7 | * For more information about which C functions 8 | * need which of these lowlevel functions 9 | * please consult the newlib libc manual 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | *

© Copyright (c) 2020 STMicroelectronics. 14 | * All rights reserved.

15 | * 16 | * This software component is licensed by ST under BSD 3-Clause license, 17 | * the "License"; You may not use this file except in compliance with the 18 | * License. You may obtain a copy of the License at: 19 | * opensource.org/licenses/BSD-3-Clause 20 | * 21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes */ 25 | #include 26 | #include 27 | 28 | /** 29 | * Pointer to the current high watermark of the heap usage 30 | */ 31 | static uint8_t *__sbrk_heap_end = NULL; 32 | 33 | /** 34 | * @brief _sbrk() allocates memory to the newlib heap and is used by malloc 35 | * and others from the C library 36 | * 37 | * @verbatim 38 | * ############################################################################ 39 | * # .data # .bss # newlib heap # MSP stack # 40 | * # # # # Reserved by _Min_Stack_Size # 41 | * ############################################################################ 42 | * ^-- RAM start ^-- _end _estack, RAM end --^ 43 | * @endverbatim 44 | * 45 | * This implementation starts allocating at the '_end' linker symbol 46 | * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack 47 | * The implementation considers '_estack' linker symbol to be RAM end 48 | * NOTE: If the MSP stack, at any point during execution, grows larger than the 49 | * reserved size, please increase the '_Min_Stack_Size'. 50 | * 51 | * @param incr Memory size 52 | * @return Pointer to allocated memory 53 | */ 54 | void *_sbrk(ptrdiff_t incr) 55 | { 56 | extern uint8_t _end; /* Symbol defined in the linker script */ 57 | extern uint8_t _estack; /* Symbol defined in the linker script */ 58 | extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ 59 | const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; 60 | const uint8_t *max_heap = (uint8_t *)stack_limit; 61 | uint8_t *prev_heap_end; 62 | 63 | /* Initialize heap end at first call */ 64 | if (NULL == __sbrk_heap_end) 65 | { 66 | __sbrk_heap_end = &_end; 67 | } 68 | 69 | /* Protect heap from growing into the reserved MSP stack */ 70 | if (__sbrk_heap_end + incr > max_heap) 71 | { 72 | errno = ENOMEM; 73 | return (void *)-1; 74 | } 75 | 76 | prev_heap_end = __sbrk_heap_end; 77 | __sbrk_heap_end += incr; 78 | 79 | return (void *)prev_heap_end; 80 | } 81 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Firmware/SimpleFoc/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/CMSIS/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.2 5 | * @date 19. April 2017 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/CMSIS/Include/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_dma_ex.h 4 | * @author MCD Application Team 5 | * @brief Header file of DMA HAL extension module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_HAL_DMA_EX_H 22 | #define __STM32F4xx_HAL_DMA_EX_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /* Includes ------------------------------------------------------------------*/ 29 | #include "stm32f4xx_hal_def.h" 30 | 31 | /** @addtogroup STM32F4xx_HAL_Driver 32 | * @{ 33 | */ 34 | 35 | /** @addtogroup DMAEx 36 | * @{ 37 | */ 38 | 39 | /* Exported types ------------------------------------------------------------*/ 40 | /** @defgroup DMAEx_Exported_Types DMAEx Exported Types 41 | * @brief DMAEx Exported types 42 | * @{ 43 | */ 44 | 45 | /** 46 | * @brief HAL DMA Memory definition 47 | */ 48 | typedef enum 49 | { 50 | MEMORY0 = 0x00U, /*!< Memory 0 */ 51 | MEMORY1 = 0x01U /*!< Memory 1 */ 52 | }HAL_DMA_MemoryTypeDef; 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /* Exported functions --------------------------------------------------------*/ 59 | /** @defgroup DMAEx_Exported_Functions DMAEx Exported Functions 60 | * @brief DMAEx Exported functions 61 | * @{ 62 | */ 63 | 64 | /** @defgroup DMAEx_Exported_Functions_Group1 Extended features functions 65 | * @brief Extended features functions 66 | * @{ 67 | */ 68 | 69 | /* IO operation functions *******************************************************/ 70 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 71 | HAL_StatusTypeDef HAL_DMAEx_MultiBufferStart_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t SecondMemAddress, uint32_t DataLength); 72 | HAL_StatusTypeDef HAL_DMAEx_ChangeMemory(DMA_HandleTypeDef *hdma, uint32_t Address, HAL_DMA_MemoryTypeDef memory); 73 | 74 | /** 75 | * @} 76 | */ 77 | /** 78 | * @} 79 | */ 80 | 81 | /* Private functions ---------------------------------------------------------*/ 82 | /** @defgroup DMAEx_Private_Functions DMAEx Private Functions 83 | * @brief DMAEx Private functions 84 | * @{ 85 | */ 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /*__STM32F4xx_HAL_DMA_EX_H*/ 103 | 104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 105 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f4xx_hal_flash_ramfunc.h 4 | * @author MCD Application Team 5 | * @brief Header file of FLASH RAMFUNC driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | *

© Copyright (c) 2017 STMicroelectronics. 10 | * All rights reserved.

11 | * 12 | * This software component is licensed by ST under BSD 3-Clause license, 13 | * the "License"; You may not use this file except in compliance with the 14 | * License. You may obtain a copy of the License at: 15 | * opensource.org/licenses/BSD-3-Clause 16 | * 17 | ****************************************************************************** 18 | */ 19 | 20 | /* Define to prevent recursive inclusion -------------------------------------*/ 21 | #ifndef __STM32F4xx_FLASH_RAMFUNC_H 22 | #define __STM32F4xx_FLASH_RAMFUNC_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F412Zx) ||\ 28 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f4xx_hal_def.h" 32 | 33 | /** @addtogroup STM32F4xx_HAL_Driver 34 | * @{ 35 | */ 36 | 37 | /** @addtogroup FLASH_RAMFUNC 38 | * @{ 39 | */ 40 | 41 | /* Exported types ------------------------------------------------------------*/ 42 | /* Exported macro ------------------------------------------------------------*/ 43 | /* Exported functions --------------------------------------------------------*/ 44 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions 45 | * @{ 46 | */ 47 | 48 | /** @addtogroup FLASH_RAMFUNC_Exported_Functions_Group1 49 | * @{ 50 | */ 51 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StopFlashInterfaceClk(void); 52 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_StartFlashInterfaceClk(void); 53 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_EnableFlashSleepMode(void); 54 | __RAM_FUNC HAL_StatusTypeDef HAL_FLASHEx_DisableFlashSleepMode(void); 55 | /** 56 | * @} 57 | */ 58 | 59 | /** 60 | * @} 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** 68 | * @} 69 | */ 70 | 71 | #endif /* STM32F410xx || STM32F411xE || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */ 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | 77 | #endif /* __STM32F4xx_FLASH_RAMFUNC_H */ 78 | 79 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 80 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Drivers/STM32F4xx_HAL_Driver/License.md: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2016 STMicroelectronics 2 | 3 | This software component is licensed by STMicroelectronics under the **BSD-3-Clause** license. You may not use this file except in compliance with this license. You may obtain a copy of the license [here](https://opensource.org/licenses/BSD-3-Clause). -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/freertos_mpool.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- 2 | * Copyright (c) 2013-2020 Arm Limited. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | * Name: freertos_mpool.h 19 | * Purpose: CMSIS RTOS2 wrapper for FreeRTOS 20 | * 21 | *---------------------------------------------------------------------------*/ 22 | 23 | #ifndef FREERTOS_MPOOL_H_ 24 | #define FREERTOS_MPOOL_H_ 25 | 26 | #include 27 | #include "FreeRTOS.h" 28 | #include "semphr.h" 29 | 30 | /* Memory Pool implementation definitions */ 31 | #define MPOOL_STATUS 0x5EED0000U 32 | 33 | /* Memory Block header */ 34 | typedef struct { 35 | void *next; /* Pointer to next block */ 36 | } MemPoolBlock_t; 37 | 38 | /* Memory Pool control block */ 39 | typedef struct MemPoolDef_t { 40 | MemPoolBlock_t *head; /* Pointer to head block */ 41 | SemaphoreHandle_t sem; /* Pool semaphore handle */ 42 | uint8_t *mem_arr; /* Pool memory array */ 43 | uint32_t mem_sz; /* Pool memory array size */ 44 | const char *name; /* Pointer to name string */ 45 | uint32_t bl_sz; /* Size of a single block */ 46 | uint32_t bl_cnt; /* Number of blocks */ 47 | uint32_t n; /* Block allocation index */ 48 | volatile uint32_t status; /* Object status flags */ 49 | #if (configSUPPORT_STATIC_ALLOCATION == 1) 50 | StaticSemaphore_t mem_sem; /* Semaphore object memory */ 51 | #endif 52 | } MemPool_t; 53 | 54 | /* No need to hide static object type, just align to coding style */ 55 | #define StaticMemPool_t MemPool_t 56 | 57 | /* Define memory pool control block size */ 58 | #define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t)) 59 | 60 | /* Define size of the byte array required to create count of blocks of given size */ 61 | #define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count)) 62 | 63 | #endif /* FREERTOS_MPOOL_H_ */ 64 | -------------------------------------------------------------------------------- /Firmware/SimpleFoc/Middlewares/Third_Party/FreeRTOS/Source/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | Permission is hereby granted, free of charge, to any person obtaining a copy of 3 | this software and associated documentation files (the "Software"), to deal in 4 | the Software without restriction, including without limitation the rights to 5 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 6 | the Software, and to permit persons to whom the Software is furnished to do so, 7 | subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all 10 | copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 14 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 15 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 16 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 17 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | 19 | -------------------------------------------------------------------------------- /Hardware/BOM_mini_Foc_Core.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/BOM_mini_Foc_Core.csv -------------------------------------------------------------------------------- /Hardware/BOM_mini_Foc_Power.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/BOM_mini_Foc_Power.csv -------------------------------------------------------------------------------- /Hardware/Gerber_mini_Foc_Core.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/Gerber_mini_Foc_Core.zip -------------------------------------------------------------------------------- /Hardware/Gerber_mini_Foc_Power.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/Gerber_mini_Foc_Power.zip -------------------------------------------------------------------------------- /Hardware/Schematic_mini_Foc_Core.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/Schematic_mini_Foc_Core.pdf -------------------------------------------------------------------------------- /Hardware/Schematic_mini_Foc_Power.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Hardware/Schematic_mini_Foc_Power.pdf -------------------------------------------------------------------------------- /Picture/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/1.gif -------------------------------------------------------------------------------- /Picture/20170708115503600.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/20170708115503600.png -------------------------------------------------------------------------------- /Picture/20190410172920395.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/20190410172920395.png -------------------------------------------------------------------------------- /Picture/20190706222310599.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/20190706222310599.png -------------------------------------------------------------------------------- /Picture/Natural-coordinate-system.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/Natural-coordinate-system.gif -------------------------------------------------------------------------------- /Picture/current_loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/current_loop.png -------------------------------------------------------------------------------- /Picture/dq-coordinate-system.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/dq-coordinate-system.gif -------------------------------------------------------------------------------- /Picture/foc-120.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-120.jpg -------------------------------------------------------------------------------- /Picture/foc-2R.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-2R.jpg -------------------------------------------------------------------------------- /Picture/foc-3R.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-3R.jpg -------------------------------------------------------------------------------- /Picture/foc-clark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-clark.jpg -------------------------------------------------------------------------------- /Picture/foc-core.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-core.jpg -------------------------------------------------------------------------------- /Picture/foc-park.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/foc-park.jpg -------------------------------------------------------------------------------- /Picture/formula-clark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/formula-clark.jpg -------------------------------------------------------------------------------- /Picture/formula-park.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/formula-park.jpg -------------------------------------------------------------------------------- /Picture/space-vectors.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/space-vectors.gif -------------------------------------------------------------------------------- /Picture/speed-loop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/speed-loop.png -------------------------------------------------------------------------------- /Picture/αβ-coordinate-system.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Picture/αβ-coordinate-system.gif -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/.qmake.stash: -------------------------------------------------------------------------------- 1 | QMAKE_CXX.QT_COMPILER_STDCXX = 201402L 2 | QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 7 3 | QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 3 4 | QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0 5 | QMAKE_CXX.COMPILER_MACROS = \ 6 | QT_COMPILER_STDCXX \ 7 | QMAKE_GCC_MAJOR_VERSION \ 8 | QMAKE_GCC_MINOR_VERSION \ 9 | QMAKE_GCC_PATCH_VERSION 10 | QMAKE_CXX.INCDIRS = \ 11 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++ \ 12 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32 \ 13 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward \ 14 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include \ 15 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed \ 16 | C:/Qt/Qt5.12.12/Tools/mingw730_64/x86_64-w64-mingw32/include 17 | QMAKE_CXX.LIBDIRS = \ 18 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc/x86_64-w64-mingw32/7.3.0 \ 19 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib/gcc \ 20 | C:/Qt/Qt5.12.12/Tools/mingw730_64/x86_64-w64-mingw32/lib \ 21 | C:/Qt/Qt5.12.12/Tools/mingw730_64/lib 22 | -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/SerialThread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/SerialThread.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/main.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mainwindow.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mainwindow.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_SerialThread.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_SerialThread.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mainwindow.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mainwindow.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mycurvewidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mycurvewidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mydockwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mydockwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mymotorwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_mymotorwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_myserialwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/moc_myserialwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mycurvewidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mycurvewidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mydockwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mydockwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mymotorwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/mymotorwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/myserialwidget.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/myserialwidget.o -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/shycom.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huyanghong/Foc-Controller/fb41c815289e4d521f168bfe4f22c428b1a992db/Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/debug/shycom.exe -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/object_script.shycom.Debug: -------------------------------------------------------------------------------- 1 | debug/SerialThread.o 2 | debug/main.o 3 | debug/mainwindow.o 4 | debug/mycurvewidget.o 5 | debug/myserialwidget.o 6 | debug/mydockwidget.o 7 | debug/mymotorwidget.o 8 | debug/moc_SerialThread.o 9 | debug/moc_mainwindow.o 10 | debug/moc_mycurvewidget.o 11 | debug/moc_myserialwidget.o 12 | debug/moc_mydockwidget.o 13 | debug/moc_mymotorwidget.o 14 | -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/object_script.shycom.Release: -------------------------------------------------------------------------------- 1 | release/SerialThread.o 2 | release/main.o 3 | release/mainwindow.o 4 | release/mycurvewidget.o 5 | release/myserialwidget.o 6 | release/mydockwidget.o 7 | release/mymotorwidget.o 8 | release/moc_SerialThread.o 9 | release/moc_mainwindow.o 10 | release/moc_mycurvewidget.o 11 | release/moc_myserialwidget.o 12 | release/moc_mydockwidget.o 13 | release/moc_mymotorwidget.o 14 | -------------------------------------------------------------------------------- /Software/shycom/build-shycom-Desktop_Qt_5_12_12_MinGW_64_bit-Debug/ui_mainwindow.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'mainwindow.ui' 3 | ** 4 | ** Created by: Qt User Interface Compiler version 5.12.12 5 | ** 6 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 7 | ********************************************************************************/ 8 | 9 | #ifndef UI_MAINWINDOW_H 10 | #define UI_MAINWINDOW_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | QT_BEGIN_NAMESPACE 20 | 21 | class Ui_MainWindow 22 | { 23 | public: 24 | QWidget *centralwidget; 25 | QMenuBar *menubar; 26 | QStatusBar *statusbar; 27 | 28 | void setupUi(QMainWindow *MainWindow) 29 | { 30 | if (MainWindow->objectName().isEmpty()) 31 | MainWindow->setObjectName(QString::fromUtf8("MainWindow")); 32 | MainWindow->resize(977, 635); 33 | centralwidget = new QWidget(MainWindow); 34 | centralwidget->setObjectName(QString::fromUtf8("centralwidget")); 35 | MainWindow->setCentralWidget(centralwidget); 36 | menubar = new QMenuBar(MainWindow); 37 | menubar->setObjectName(QString::fromUtf8("menubar")); 38 | menubar->setGeometry(QRect(0, 0, 977, 22)); 39 | MainWindow->setMenuBar(menubar); 40 | statusbar = new QStatusBar(MainWindow); 41 | statusbar->setObjectName(QString::fromUtf8("statusbar")); 42 | MainWindow->setStatusBar(statusbar); 43 | 44 | retranslateUi(MainWindow); 45 | 46 | QMetaObject::connectSlotsByName(MainWindow); 47 | } // setupUi 48 | 49 | void retranslateUi(QMainWindow *MainWindow) 50 | { 51 | MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr)); 52 | } // retranslateUi 53 | 54 | }; 55 | 56 | namespace Ui { 57 | class MainWindow: public Ui_MainWindow {}; 58 | } // namespace Ui 59 | 60 | QT_END_NAMESPACE 61 | 62 | #endif // UI_MAINWINDOW_H 63 | -------------------------------------------------------------------------------- /Software/shycom/shycom/SerialThread.cpp: -------------------------------------------------------------------------------- 1 | #include "SerialThread.h" 2 | #include "mainwindow.h" 3 | 4 | SerialThread::SerialThread(QObject *parent) : QObject(parent) 5 | { 6 | thread = new QThread(this); 7 | this->moveToThread(thread); 8 | connect(thread, &QThread::finished, this, &SerialThread::deleteLater); 9 | thread->start(); 10 | 11 | for(int i=0; iquit(); 16 | thread->wait(); 17 | } 18 | void SerialThread::slotReceiveSerialBuf(const QByteArray &qba){ 19 | serial_buf += qba; 20 | if(serial_buf.length() >= 8){ 21 | for(int i=0; i 512) 56 | serial_buf.remove(0, serial_buf.length() - 512); 57 | } 58 | -------------------------------------------------------------------------------- /Software/shycom/shycom/SerialThread.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIAL_THREAD_H 2 | #define SERIAL_THREAD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class SerialThread : public QObject 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit SerialThread(QObject *parent = nullptr); 16 | ~SerialThread(); 17 | 18 | signals: 19 | void signalSendModelPose(const float *q); 20 | void signalSendCurvePoint(const QByteArray &qba); 21 | void signalSendSquareWaveFreq(const uint16_t *f); 22 | 23 | public slots: 24 | void slotReceiveSerialBuf(const QByteArray &qba); 25 | 26 | public: 27 | QThread *thread; 28 | QByteArray serial_buf; 29 | uint8_t param_len[256]; 30 | 31 | float curve_value[16]; 32 | uint8_t curve_receive_status = 0; 33 | 34 | }; 35 | 36 | #endif // SERIAL_THREAD_H 37 | -------------------------------------------------------------------------------- /Software/shycom/shycom/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.resize(700, 400); 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include //中文支持 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "SerialThread.h" 32 | #include "QByteArray" 33 | #include "QPen" 34 | 35 | #include "qwt_point_data.h" 36 | #include "qwt_plot_curve.h" 37 | #include "qwt_plot.h" 38 | 39 | #include "mycurvewidget.h" 40 | #include "myserialwidget.h" 41 | #include "mydockwidget.h" 42 | #include "mymotorwidget.h" 43 | 44 | QT_BEGIN_NAMESPACE 45 | namespace Ui { class MainWindow; } 46 | QT_END_NAMESPACE 47 | 48 | class MainWindow : public QMainWindow 49 | { 50 | Q_OBJECT 51 | 52 | public: 53 | MainWindow(QWidget *parent = nullptr); 54 | ~MainWindow(); 55 | 56 | void initToolBar(); 57 | void initGuiSerialBase(); 58 | void initGuiCurveBase(); 59 | void initGuiMotorBase(uint8_t id); 60 | 61 | void addMotorItem(QString name, uint8_t modu_id); 62 | signals: 63 | 64 | public slots: 65 | void slotSerialActionDockwidgetClose(); 66 | void slotCurveActionDockwidgetClose(); 67 | void slotMotorActionDockwidgetClose(uint8_t id); 68 | void slotAddMotorItem0(){addMotorItem("other", 0);}; 69 | void slotAddMotorItem1(){addMotorItem("other", 1);}; 70 | void slotAddMotorItem2(){addMotorItem("other", 2);}; 71 | void slotAddMotorItem3(){addMotorItem("other", 3);}; 72 | void initGuiMotorBase0(){initGuiMotorBase(0);}; 73 | void initGuiMotorBase1(){initGuiMotorBase(1);}; 74 | void initGuiMotorBase2(){initGuiMotorBase(2);}; 75 | void initGuiMotorBase3(){initGuiMotorBase(3);}; 76 | void slotMotorActionDockwidgetClose0(){slotMotorActionDockwidgetClose(0);}; 77 | void slotMotorActionDockwidgetClose1(){slotMotorActionDockwidgetClose(1);}; 78 | void slotMotorActionDockwidgetClose2(){slotMotorActionDockwidgetClose(2);}; 79 | void slotMotorActionDockwidgetClose3(){slotMotorActionDockwidgetClose(3);}; 80 | private: 81 | Ui::MainWindow *ui; 82 | QTimer *uTimer; 83 | 84 | //*******串口THREAD***********// 85 | SerialThread *serial_thread; 86 | 87 | //*******串口GUI组件***********// 88 | MyDockWidget *dock_serial_base_gui; 89 | QAction *serialAction; 90 | MySerialWidget *myserialwidget; 91 | 92 | //*******CURVE-GUI组件***********// 93 | QAction *curveAction; 94 | MyDockWidget *dock_curve_base_gui; 95 | MyCurveWidget *mycurvewidget; 96 | 97 | //*******MOTOR-GUI组件***********/ 98 | MyDockWidget *dock_motor_base_gui[4]; 99 | QAction *motorAction[4]; 100 | MyMotorWidget *myMotorWidget[4]; 101 | QWidget *motorWidget[4]; 102 | QVBoxLayout *motorLayout[4]; 103 | QPushButton *btn_add_motor[4]; 104 | uint8_t modular_id[4] = {0, 1, 2, 3}; 105 | QString modular_name[4] = {"电流环", "速度环", "位置环", "其他"}; 106 | 107 | }; 108 | #endif // MAINWINDOW_H 109 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 977 10 | 635 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 977 23 | 22 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mycurvewidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYCURVEWIDGET_H 2 | #define MYCURVEWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include //中文支持 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "SerialThread.h" 32 | #include "QByteArray" 33 | #include "QPen" 34 | 35 | #include "qwt_point_data.h" 36 | #include "qwt_plot_curve.h" 37 | #include "qwt_plot.h" 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #define plot_num 10 48 | 49 | class MyCurveWidget : public QWidget 50 | { 51 | Q_OBJECT 52 | public: 53 | explicit MyCurveWidget(QWidget *parent = nullptr); 54 | 55 | signals: 56 | 57 | public slots: 58 | void slotBtnCurveShow(void); 59 | void slotCurvePlotShow(void); 60 | void slotCurveClear(void); 61 | void slotReceiveCurvePoint(const QByteArray &qba); 62 | 63 | public: 64 | QwtPlot *curvePlot; 65 | QCheckBox *cb_curve[plot_num]; 66 | QCheckBox *cb_auto_adaption; 67 | QPushButton *btn_curve_show; 68 | QPushButton *btn_curve_clear; 69 | QLineEdit *te_curve_size_X; 70 | QVector curve_vector[plot_num]; 71 | int frame_cnt = 0; 72 | QwtPlotCurve curve[plot_num]; 73 | QPen curve_color[plot_num]; 74 | float window_min_Y, window_max_Y; 75 | }; 76 | 77 | #endif // MYCURVEWIDGET_H 78 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mydockwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "mydockwidget.h" 2 | #include 3 | 4 | MyDockWidget::MyDockWidget(QWidget *parent): QDockWidget(parent) 5 | { 6 | isOpen = true; 7 | } 8 | 9 | void MyDockWidget::closeEvent(QCloseEvent *event){ 10 | isOpen = false; 11 | emit signalDockwidgetClose(); 12 | } 13 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mydockwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYDOCKWIDGET_H 2 | #define MYDOCKWIDGET_H 3 | 4 | #include 5 | 6 | class MyDockWidget : public QDockWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MyDockWidget(QWidget *parent = nullptr); 11 | 12 | protected: 13 | void closeEvent(QCloseEvent *event); 14 | 15 | signals: 16 | void signalDockwidgetClose(); 17 | 18 | 19 | public: 20 | bool isOpen; 21 | }; 22 | #endif // MYDOCKWIDGET_H 23 | -------------------------------------------------------------------------------- /Software/shycom/shycom/mymotorwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMOTORWIDGET_H 2 | #define MYMOTORWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | class MyMotorWidget : public QWidget 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit MyMotorWidget(QWidget *parent = nullptr); 20 | 21 | signals: 22 | void signalWriteParameter(const QByteArray &qba); 23 | 24 | public slots: 25 | void slotUpdateSliderFormSpin(); 26 | void slotUpdateSpinFormSlider(); 27 | void slotLineEditValueChanged(); 28 | 29 | public: 30 | uint8_t modular_id, object_id; 31 | QLabel *lab_min, *lab_max, *lab_step, *lab_set; 32 | QLineEdit *le_min, *le_max, *le_step; 33 | QDoubleSpinBox *sb_set; 34 | QSlider *hs_set; 35 | QLabel *lab_object_id; 36 | 37 | void initUi(QString name, uint8_t obj_id, uint8_t modu_id); 38 | }; 39 | #endif // MYMOTORWIDGET_H 40 | 41 | 42 | -------------------------------------------------------------------------------- /Software/shycom/shycom/myserialwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSERIALWIDGET_H 2 | #define MYSERIALWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include //中文支持 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "SerialThread.h" 32 | #include 33 | 34 | class MySerialWidget : public QWidget 35 | { 36 | Q_OBJECT 37 | public: 38 | explicit MySerialWidget(QWidget *parent = nullptr); 39 | 40 | signals: 41 | void signalSerialReceiveBuf(const QByteArray &qba); 42 | 43 | 44 | public slots: 45 | void slotSerialSend(const QByteArray &qba); 46 | void slotBtnClearClicked(void); 47 | void slotBtnSendClicked(void); 48 | void slotUpdateSerialList(void); 49 | void slotReadySerialRead(void); 50 | void slotOpenOrCloseSerial(void); 51 | void slot_cbb_baud_currentIndexChanged(void); 52 | void slot_cbb_com_activated(void); 53 | 54 | public: 55 | QTimer *uTimer; 56 | QSerialPort *serial; 57 | QTextBrowser *tb_rx_buf; 58 | QTextEdit *te_tx_buf; 59 | QCheckBox *cb_hex_receive; 60 | QCheckBox *cb_hex_send; 61 | QCheckBox *cb_send_enter; 62 | QCheckBox *cb_auto_enter; 63 | QLabel *lab_txbyte; 64 | QLabel *lab_rxbyte; 65 | QPushButton *btn_send; 66 | QPushButton *btn_clear; 67 | QComboBox *cbb_com; 68 | QComboBox *cbb_baud; 69 | QPushButton *btn_serial_sw; 70 | }; 71 | 72 | #endif // MYSERIALWIDGET_H 73 | -------------------------------------------------------------------------------- /Software/shycom/shycom/shycom.pro: -------------------------------------------------------------------------------- 1 | QT += core gui serialport opengl 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | LIBS += -lopengl32 \ 6 | -lglu32 \ 7 | 8 | 9 | 10 | CONFIG += c++11 11 | 12 | # The following define makes your compiler emit warnings if you use 13 | # any Qt feature that has been marked deprecated (the exact warnings 14 | # depend on your compiler). Please consult the documentation of the 15 | # deprecated API in order to know how to port your code away from it. 16 | DEFINES += QT_DEPRECATED_WARNINGS 17 | 18 | # You can also make your code fail to compile if it uses deprecated APIs. 19 | # In order to do so, uncomment the following line. 20 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 21 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 22 | 23 | SOURCES += \ 24 | SerialThread.cpp \ 25 | main.cpp \ 26 | mainwindow.cpp \ 27 | mycurvewidget.cpp \ 28 | myserialwidget.cpp \ 29 | mydockwidget.cpp \ 30 | mymotorwidget.cpp 31 | 32 | HEADERS += \ 33 | SerialThread.h \ 34 | mainwindow.h \ 35 | mycurvewidget.h \ 36 | myserialwidget.h \ 37 | mydockwidget.h \ 38 | mymotorwidget.h 39 | 40 | FORMS += \ 41 | mainwindow.ui 42 | 43 | 44 | #INCLUDEPATH += /usr/local/qwt-6.1.3/include 45 | #LIBS += -L "/usr/local/qwt-6.1.3/lib/" -lqwt 46 | 47 | # Default rules for deployment. 48 | #qnx: target.path = /tmp/$${TARGET}/bin 49 | #else: unix:!android: target.path = /opt/$${TARGET}/bin 50 | #!isEmpty(target.path): INSTALLS += target 51 | 52 | #DEFINES += QT_DLL QWT_DLL 53 | 54 | LIBS += -L "C:\Qt\Qt5.12.12\5.12.12\mingw73_64\lib" -lqwtd 55 | 56 | #LIBS += -L "C:\Qt\Qt5.12.12\5.12.12\mingw73_64\lib" -lqwt 57 | 58 | INCLUDEPATH += "C:\Qt\Qt5.12.12\5.12.12\mingw73_64\include\qwt" 59 | --------------------------------------------------------------------------------