作者 XieC

1/20 首次提交

正在显示 41 个修改的文件 包含 4777 行增加0 行删除

要显示太多修改。

为保证性能只显示 41 of 41+ 个文件。

A2_Motor_Board_V1/build
A2_Motor_Board_V1/MDK-ARM/A2_Motor_Board_V1
A2_Motor_Board_V1/.gitgnore
FOC_IAP_BootLoader/MDK-ARM/FOC_IAP_BootLoader
... ...
{
"folders": [
{
"path": "A2_Motor_Board_V1"
},
{
"path": "Ext_Common"
}
],
"settings": {
"cortex-debug.armToolchainPath": "D:\\STM32_DEV_TOOLS\\STM32_DEV_TOOLS\\GCC-ARM-NONE-EABI-10.3-2021.10-WIN32\\GCC-ARM-NONE-EABI-10.3-2021.10\\BIN",
"cortex-debug.openocdPath": "D:\\STM32_DEV_TOOLS\\STM32_DEV_TOOLS\\OPENOCD-20231002-0.12.0\\BIN\\OPENOCD.EXE",
"files.associations": {
"bmcl_paraloadf1.h": "c",
"motor_manage.h": "c",
"upgrade.h": "c",
"stmflash.h": "c",
"upgrade_opt.h": "c",
"monitor.h": "c"
}
}
}
\ No newline at end of file
... ...
.vscode/*
build/*
Middlewares/*
Drivers/*
.gitgnore
openocd.cfg
\ No newline at end of file
... ...
[PreviousLibFiles]
LibFiles=Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_spi.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_spi.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_utils.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usart.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_spi.h;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_def.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_rcc_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_bus.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_rcc.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_system.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_utils.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_gpio_ex.h;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_dma.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_cortex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_pwr.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_flash_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_exti.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal_tim_ex.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_tim.h;Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_ll_usart.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f103xb.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h;
[PreviousUsedMakefileFiles]
SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\dma.c;Core\Src\spi.c;Core\Src\tim.c;Core\Src\usart.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_spi.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_utils.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_spi.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_rcc.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_utils.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_exti.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_tim.c;Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usart.c;Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;Core\Src\system_stm32f1xx.c;;;
HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;
CDefines=USE_FULL_LL_DRIVER;USE_HAL_DRIVER;STM32F103xB;USE_FULL_LL_DRIVER;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=9
HeaderFiles#0=..\Core\Inc\gpio.h
HeaderFiles#1=..\Core\Inc\dma.h
HeaderFiles#2=..\Core\Inc\spi.h
HeaderFiles#3=..\Core\Inc\tim.h
HeaderFiles#4=..\Core\Inc\usart.h
HeaderFiles#5=..\Core\Inc\stm32f1xx_it.h
HeaderFiles#6=..\Core\Inc\stm32_assert.h
HeaderFiles#7=..\Core\Inc\stm32f1xx_hal_conf.h
HeaderFiles#8=..\Core\Inc\main.h
HeaderFolderListSize=1
HeaderPath#0=..\Core\Inc
HeaderFiles=;
SourceFileListSize=8
SourceFiles#0=..\Core\Src\gpio.c
SourceFiles#1=..\Core\Src\dma.c
SourceFiles#2=..\Core\Src\spi.c
SourceFiles#3=..\Core\Src\tim.c
SourceFiles#4=..\Core\Src\usart.c
SourceFiles#5=..\Core\Src\stm32f1xx_it.c
SourceFiles#6=..\Core\Src\stm32f1xx_hal_msp.c
SourceFiles#7=..\Core\Src\main.c
SourceFolderListSize=1
SourcePath#0=..\Core\Src
SourceFiles=;
[PreviousUsedKeilFiles]
SourceFiles=..\Core\Src\main.c;..\Core\Src\gpio.c;..\Core\Src\dma.c;..\Core\Src\spi.c;..\Core\Src\tim.c;..\Core\Src\usart.c;..\Core\Src\stm32f1xx_it.c;..\Core\Src\stm32f1xx_hal_msp.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_gpio.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_dma.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_spi.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_rcc.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_utils.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_exti.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_tim.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usart.c;..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;..\Core\Src\system_stm32f1xx.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_gpio.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_dma.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_spi.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_rcc_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_gpio.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_dma.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_cortex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_pwr.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_flash_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_exti.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_rcc.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_utils.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_exti.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_hal_tim_ex.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_tim.c;..\Drivers\STM32F1xx_HAL_Driver\Src\stm32f1xx_ll_usart.c;..\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\system_stm32f1xx.c;..\Core\Src\system_stm32f1xx.c;;;
HeaderPath=..\Drivers\STM32F1xx_HAL_Driver\Inc;..\Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;..\Drivers\CMSIS\Device\ST\STM32F1xx\Include;..\Drivers\CMSIS\Include;..\Core\Inc;
CDefines=USE_FULL_LL_DRIVER;USE_HAL_DRIVER;STM32F103xB;USE_FULL_LL_DRIVER;USE_HAL_DRIVER;USE_HAL_DRIVER;
... ...
# environment variable file used by stm32-for-vscode and the STM32Make.make makefile
# Other environment variables can be added here. If wanting to use the generated makefile in CI/CD context please
# configure the following variables: GCC_PATH, OPENOCD
ARM_GCC_PATH = D:\STM32_DEV_TOOLS\STM32_DEV_TOOLS\GCC-ARM-NONE-EABI-10.3-2021.10-WIN32\GCC-ARM-NONE-EABI-10.3-2021.10\BIN
OPENOCD = D:\STM32_DEV_TOOLS\STM32_DEV_TOOLS\OPENOCD-20231002-0.12.0\BIN\OPENOCD.EXE
\ No newline at end of file
... ...
#MicroXplorer Configuration settings - do not modify
CAD.formats=
CAD.pinconfig=
CAD.provider=
Dma.Request0=USART1_TX
Dma.Request1=USART1_RX
Dma.RequestsNb=2
Dma.USART1_RX.1.Direction=DMA_PERIPH_TO_MEMORY
Dma.USART1_RX.1.Instance=DMA1_Channel5
Dma.USART1_RX.1.MemDataAlignment=DMA_MDATAALIGN_BYTE
Dma.USART1_RX.1.MemInc=DMA_MINC_ENABLE
Dma.USART1_RX.1.Mode=DMA_NORMAL
Dma.USART1_RX.1.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
Dma.USART1_RX.1.PeriphInc=DMA_PINC_DISABLE
Dma.USART1_RX.1.Priority=DMA_PRIORITY_LOW
Dma.USART1_RX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
Dma.USART1_TX.0.Direction=DMA_MEMORY_TO_PERIPH
Dma.USART1_TX.0.Instance=DMA1_Channel4
Dma.USART1_TX.0.MemDataAlignment=DMA_MDATAALIGN_BYTE
Dma.USART1_TX.0.MemInc=DMA_MINC_ENABLE
Dma.USART1_TX.0.Mode=DMA_NORMAL
Dma.USART1_TX.0.PeriphDataAlignment=DMA_PDATAALIGN_BYTE
Dma.USART1_TX.0.PeriphInc=DMA_PINC_DISABLE
Dma.USART1_TX.0.Priority=DMA_PRIORITY_HIGH
Dma.USART1_TX.0.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority
File.Version=6
GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false
Mcu.CPN=STM32F103T8U6
Mcu.Family=STM32F1
Mcu.IP0=DMA
Mcu.IP1=NVIC
Mcu.IP2=RCC
Mcu.IP3=SPI1
Mcu.IP4=SYS
Mcu.IP5=TIM2
Mcu.IP6=TIM3
Mcu.IP7=TIM4
Mcu.IP8=USART1
Mcu.IPNb=9
Mcu.Name=STM32F103T(8-B)Ux
Mcu.Package=VFQFPN36
Mcu.Pin0=PD0-OSC_IN
Mcu.Pin1=PD1-OSC_OUT
Mcu.Pin10=PB1
Mcu.Pin11=PA8
Mcu.Pin12=PA9
Mcu.Pin13=PA10
Mcu.Pin14=PA13
Mcu.Pin15=PA14
Mcu.Pin16=VP_SYS_VS_Systick
Mcu.Pin17=VP_TIM2_VS_ClockSourceINT
Mcu.Pin18=VP_TIM3_VS_ClockSourceINT
Mcu.Pin19=VP_TIM4_VS_ClockSourceINT
Mcu.Pin2=PA1
Mcu.Pin3=PA2
Mcu.Pin4=PA3
Mcu.Pin5=PA4
Mcu.Pin6=PA5
Mcu.Pin7=PA6
Mcu.Pin8=PA7
Mcu.Pin9=PB0
Mcu.PinsNb=20
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F103T8Ux
MxCube.Version=6.12.1
MxDb.Version=DB.6.0.121
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.DMA1_Channel4_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.DMA1_Channel5_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:true
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
NVIC.TIM4_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA1.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
PA1.GPIO_Label=SIGN1_LED
PA1.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA1.Locked=true
PA1.PinState=GPIO_PIN_RESET
PA1.Signal=GPIO_Output
PA10.GPIOParameters=GPIO_Label
PA10.GPIO_Label=UART_BUS_RX
PA10.Mode=Asynchronous
PA10.Signal=USART1_RX
PA13.Mode=Serial_Wire
PA13.Signal=SYS_JTMS-SWDIO
PA14.Mode=Serial_Wire
PA14.Signal=SYS_JTCK-SWCLK
PA2.GPIOParameters=GPIO_PuPd,GPIO_Label
PA2.GPIO_Label=MOT_SELECT_1
PA2.GPIO_PuPd=GPIO_PULLUP
PA2.Locked=true
PA2.Signal=GPIO_Input
PA3.Locked=true
PA3.Signal=S_TIM2_CH4
PA4.GPIOParameters=GPIO_PuPd,GPIO_Label
PA4.GPIO_Label=MOT_SELECT_2
PA4.GPIO_PuPd=GPIO_PULLUP
PA4.Locked=true
PA4.Signal=GPIO_Input
PA5.GPIOParameters=GPIO_Label
PA5.GPIO_Label=MGE_SCK
PA5.Mode=Full_Duplex_Master
PA5.Signal=SPI1_SCK
PA6.GPIOParameters=GPIO_Label
PA6.GPIO_Label=MGE_MISO
PA6.Mode=Full_Duplex_Master
PA6.Signal=SPI1_MISO
PA7.GPIOParameters=GPIO_Label
PA7.GPIO_Label=MGE_MOSI
PA7.Mode=Full_Duplex_Master
PA7.Signal=SPI1_MOSI
PA8.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
PA8.GPIO_Label=MGE_CS
PA8.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
PA8.Locked=true
PA8.PinState=GPIO_PIN_SET
PA8.Signal=GPIO_Output
PA9.GPIOParameters=GPIO_Label
PA9.GPIO_Label=UART_BUS_TX
PA9.Mode=Asynchronous
PA9.Signal=USART1_TX
PB0.Locked=true
PB0.Signal=S_TIM3_CH3
PB1.Locked=true
PB1.Signal=S_TIM3_CH4
PD0-OSC_IN.Mode=HSE-External-Oscillator
PD0-OSC_IN.Signal=RCC_OSC_IN
PD1-OSC_OUT.Mode=HSE-External-Oscillator
PD1-OSC_OUT.Signal=RCC_OSC_OUT
PinOutPanel.RotationAngle=0
ProjectManager.AskForMigrate=true
ProjectManager.BackupPrevious=false
ProjectManager.CompilerOptimize=6
ProjectManager.ComputerToolchain=false
ProjectManager.CoupleFile=true
ProjectManager.CustomerFirmwarePackage=
ProjectManager.DefaultFWLocation=true
ProjectManager.DeletePrevious=true
ProjectManager.DeviceId=STM32F103T8Ux
ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.6
ProjectManager.FreePins=false
ProjectManager.HalAssertFull=false
ProjectManager.HeapSize=0x200
ProjectManager.KeepUserCode=true
ProjectManager.LastFirmware=true
ProjectManager.LibraryCopy=0
ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=
ProjectManager.ProjectBuild=false
ProjectManager.ProjectFileName=A2_Motor_Board_V1.ioc
ProjectManager.ProjectName=A2_Motor_Board_V1
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=MDK-ARM V5.32
ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-LL-true,3-MX_DMA_Init-DMA-false-LL-true,4-MX_SPI1_Init-SPI1-false-LL-true,5-MX_TIM2_Init-TIM2-false-LL-true,6-MX_TIM3_Init-TIM3-false-LL-true,7-MX_USART1_UART_Init-USART1-false-LL-true,8-MX_TIM4_Init-TIM4-false-LL-true
RCC.ADCFreqValue=36000000
RCC.AHBFreq_Value=72000000
RCC.APB1CLKDivider=RCC_HCLK_DIV2
RCC.APB1Freq_Value=36000000
RCC.APB1TimFreq_Value=72000000
RCC.APB2Freq_Value=72000000
RCC.APB2TimFreq_Value=72000000
RCC.FCLKCortexFreq_Value=72000000
RCC.FamilyName=M
RCC.HCLKFreq_Value=72000000
RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
RCC.MCOFreq_Value=72000000
RCC.PLLCLKFreq_Value=72000000
RCC.PLLMCOFreq_Value=36000000
RCC.PLLMUL=RCC_PLL_MUL9
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
RCC.SYSCLKFreq_VALUE=72000000
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
RCC.TimSysFreq_Value=72000000
RCC.USBFreq_Value=72000000
RCC.VCOOutput2Freq_Value=8000000
SH.S_TIM2_CH4.0=TIM2_CH4,PWM Generation4 CH4
SH.S_TIM2_CH4.ConfNb=1
SH.S_TIM3_CH3.0=TIM3_CH3,PWM Generation3 CH3
SH.S_TIM3_CH3.ConfNb=1
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
SH.S_TIM3_CH4.ConfNb=1
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
SPI1.CLKPhase=SPI_PHASE_2EDGE
SPI1.CalculateBaudRate=9.0 MBits/s
SPI1.DataSize=SPI_DATASIZE_16BIT
SPI1.Direction=SPI_DIRECTION_2LINES
SPI1.IPParameters=VirtualType,Mode,Direction,BaudRatePrescaler,CalculateBaudRate,DataSize,CLKPhase
SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER
TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM2.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM2.CounterMode=TIM_COUNTERMODE_CENTERALIGNED1
TIM2.IPParameters=Channel-PWM Generation4 CH4,Period,AutoReloadPreload,CounterMode
TIM2.Period=1600-1
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM3.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM3.CounterMode=TIM_COUNTERMODE_CENTERALIGNED1
TIM3.IPParameters=Channel-PWM Generation3 CH3,Channel-PWM Generation4 CH4,CounterMode,Period,AutoReloadPreload
TIM3.Period=1600-1
TIM4.IPParameters=Period,Prescaler
TIM4.Period=50000-1
TIM4.Prescaler=72-1
USART1.BaudRate=115200
USART1.IPParameters=VirtualMode,BaudRate
USART1.VirtualMode=VM_ASYNC
VP_SYS_VS_Systick.Mode=SysTick
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
VP_TIM2_VS_ClockSourceINT.Mode=Internal
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
VP_TIM3_VS_ClockSourceINT.Mode=Internal
VP_TIM3_VS_ClockSourceINT.Signal=TIM3_VS_ClockSourceINT
VP_TIM4_VS_ClockSourceINT.Mode=Internal
VP_TIM4_VS_ClockSourceINT.Signal=TIM4_VS_ClockSourceINT
board=custom
... ...
#include "BMCL.h"
#include "stddef.h"
BMCL_GENSEAMP_s bmcl_ahrs_CurAngArr = {0};
BMCL_GENSEAMP_s bmcl_ahrs_TarAngArr = {0};
BMCL_GENSEAMP_s bmcl_Calibration = {0};
BMCL_GENSEAMP_s bmcl_Music = {0};
BMCL_COMM_SEQ_s bmcl_comm_seq_1 = {
.commStatus = BMCL_COMM_SEQ_STATUS_0
};
BMCL_PROTOCOL_REMOTESEN bmcl_protocol_reData = {0};
void BMCL_Init(){
}
void BMCL_Genseamp_give( BMCL_GENSEAMP_s * s , uint32_t data ){
s->sign = BMCL_GENSEAMP_STA_GIVEN;
s->data = data;
}
int32_t BMCL_GenSemap_take( BMCL_GENSEAMP_s * s , uint32_t* data ){
if( s->sign == BMCL_GENSEAMP_STA_GIVEN ){
if( data == NULL){
s->sign = BMCL_GENSEAMP_STA_TAKEN;
return BMCL_GENSEAMP_RESULT_GET_GIVEN;
}
*data = s->data;
s->sign = BMCL_GENSEAMP_STA_TAKEN;
return BMCL_GENSEAMP_RESULT_GET_GIVEN;
}else{
return BMCL_GENSEAMP_RESULT_NOT_GIVEN;
}
}
\ No newline at end of file
... ...
#ifndef __BARE_METAL_CONTROL_LAYER_
#define __BARE_METAL_CONTROL_LAYER_
#include "stdint.h"
#include "stdbool.h"
#define BMCL_SEMAP_STA_VAILD true
#define BMCL_SEMAP_STA_INVALID false
typedef struct
{
uint8_t sign;
uint32_t data;
}BMCL_GENSEAMP_s;
typedef struct
{
uint8_t commStatus;
}BMCL_COMM_SEQ_s;
typedef enum
{
BMCL_COMM_SEQ_STATUS_0 , // not need to response
BMCL_COMM_SEQ_STATUS_1 , // need to response
BMCL_COMM_SEQ_STATUS_2
}BMCL_COMM_SEQ_STATUS;
typedef enum
{
BMCL_GENSEAMP_STA_TAKEN = 0,
BMCL_GENSEAMP_STA_GIVEN ,
}BMCL_GENSEAMP_STA;
typedef enum
{
BMCL_GENSEAMP_RESULT_ERR = -1,
BMCL_GENSEAMP_RESULT_OK,
BMCL_GENSEAMP_RESULT_NOT_GIVEN,
BMCL_GENSEAMP_RESULT_GET_GIVEN,
}BMCL_GENSEAMP_RESULT;
//Data remote sensing structure
//which stores motor board remote sensing data and is used for the data queue of internal protocols.
typedef struct
{
float data[10];
}BMCL_PROTOCOL_REMOTESEN;
extern BMCL_GENSEAMP_s bmcl_ahrs_CurAngArr;
extern BMCL_GENSEAMP_s bmcl_ahrs_TarAngArr;
extern BMCL_GENSEAMP_s bmcl_Calibration;
extern BMCL_GENSEAMP_s bmcl_Music;
extern BMCL_COMM_SEQ_s bmcl_comm_seq_1;
extern BMCL_PROTOCOL_REMOTESEN bmcl_protocol_reData ;
void BMCL_Init();
void BMCL_Genseamp_give( BMCL_GENSEAMP_s * s , uint32_t data );
int32_t BMCL_GenSemap_take( BMCL_GENSEAMP_s * s , uint32_t* data );
#endif
... ...
#ifndef __BMCL_DEVSPECIFIC_TEMPLATE_H__
#define __BMCL_DEVSPECIFIC_TEMPLATE_H__
#include "main.h"
#define BMCL_DEVSPECIFIC_SELECT_1_GPIO_PORT MOT_SELECT_1_GPIO_Port
#define BMCL_DEVSPECIFIC_SELECT_2_GPIO_PORT MOT_SELECT_2_GPIO_Port
#define BMCL_DEVSPECIFIC_SELECT_1_GPIO_PIN MOT_SELECT_1_Pin
#define BMCL_DEVSPECIFIC_SELECT_2_GPIO_PIN MOT_SELECT_2_Pin
#endif
... ...
/*
* @Date: 2023-12-11 18:07:11
* @LastEditTime: 2024-03-20 15:41:44
* @FilePath: \A2_Motor_Board_V1\Core\Inc\Project_Config.h
* @Description:
*/
#ifndef __PROJECT_CONFIG_FD3892FH9U2F9U2__
#define __PROJECT_CONFIG_FD3892FH9U2F9U2__
//###Pre Define
#define PROJECT_CONFIG_ENABLE 1
#define PROJECT_CONFIG_DISABLE 0
#define MOTOR_HOLDER_AXIS_PITCH 0
#define MOTOR_HOLDER_AXIS_ROLL 1
#define MOTOR_HOLDER_AXIS_YAW 2
//=========!!!!==========Debug COONFIG==========!!!!=========
/*
__ ___ ___ _ _ ___ _ _ ___
\ \ / /_\ | _ | \| |_ _| \| |/ __|
\ \/\/ / _ \| | .` || || .` | (_ |
\_/\_/_/ \_|_|_|_|\_|___|_|\_|\___|
The following functions must be turned off for normal operation!!!!!
*/
//-------IMU Debug Output CONFIG-------
#define IMU_DEBUG_OUTPUT PROJECT_CONFIG_DISABLE // Enable/Disable IMU Debug Output (Use VOFA+ JustFloat Format)
// !!!!!!! The following two options can only be enabled by choosing one of the two. <<<<<<
//-------Motor debugging frame debugging output CONFIG-------
#define FRAME_MOT_DEBUG_DBOUTPUT PROJECT_CONFIG_DISABLE // When it is set to Enable , The protocol only outputs the Motor debug Frame
//-------Motor debugging frame debugging output CONFIG-------
#define FRAME_MOT_TARGET_DBOUTPUT PROJECT_CONFIG_DISABLE // When it is set to Enable , The protocol only outputs the Motor TARGET Frame
// !!!!!!! Only For Debug. <<<<<<
//-------Motor debug - Sensor Align CONFIG-------
#define MOTOR_DEBUG_SENSOR_ALIGN PROJECT_CONFIG_ENABLE // When it is set to DISABLE , MUST SET EANGLE AND SENSOR DIRECTION
// !!!!!!! VoFA+ Debug Output. <<<<<<
#define MOT_VOFA_DEBUG_OUTPUT PROJECT_CONFIG_DISABLE // When it is set to Enable , The protocol only outputs the Motor TARGET Frame
//=======================UART COONFIG=======================
//-------FUNTION CONFIG-------
#define UART1_RX_FUNTION PROJECT_CONFIG_ENABLE // Enable/Disable UART1 RX FUNTION (Only for debugging , Prevent input from causing program delays )
#define UART1_TX_OPENDRAIN PROJECT_CONFIG_DISABLE
//-------IT BUFFER CONFIG-------
#define UART1_BUFF_RX_IT_LEN 128 //Buffer length, NEED to be a power of 2( 2^x )
//-------DMA BUFFER CONFIG-------
#define UART1_BUFF_TX_DMA_LEN 128
#define UART1_BUFF_RX_DMA_LEN 512
//-------UART L2 BUFFER CONFIG-------
#define UART1_L2_BUFF_RX_LEN 512
#define UART1_L2_BUFF_TX_LEN 128
//-------FEATURE CONFIG-------
#define UART1_FEATURE_CHARACTER_OUTPUT_RETURN PROJECT_CONFIG_DISABLE
//-------DEBUG CONFIG !!!Only For Debug-------
#define UART1_DMA_FREERTOS_SOUPPORT PROJECT_CONFIG_DISABLE
//=======================IMU READ/PROCESS COONFIG=======================
// //-------IMU READ CONFIG-------
// #define IMU_READ_FILTER_GYR_ON PROJECT_CONFIG_DISABLE //IMU Read Gyro Filter Switch
// #define IMU_READ_FILTER_ACC_ON PROJECT_CONFIG_ENABLE //IMU Read ACC Filter Switch
// //-------IMU RESLOVING CONFIG-------
// #define ACC_CORRECT_SW 1
//=======================MOTOR SPECIAL CONFIG===========================
#define MOTOR_BOARD_SELECT_AXIS MOTOR_HOLDER_AXIS_ROLL
#define MOTOR_BOARD_DEBUG_OR_TEST PROJECT_CONFIG_DISABLE
#define MOTOR_BOARD_SHUTDOWN PROJECT_CONFIG_DISABLE
#endif
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __DMA_H__ */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.h
* @brief This file contains all the function prototypes for
* the gpio.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GPIO_H__
#define __GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
#define SIGN1_ON LL_GPIO_SetOutputPin(SIGN1_LED_GPIO_Port, SIGN1_LED_Pin); //LED 点亮
#define SIGN1_OFF LL_GPIO_ResetOutputPin(SIGN1_LED_GPIO_Port, SIGN1_LED_Pin);
#define SIGN1_TAGO LL_GPIO_TogglePin(SIGN1_LED_GPIO_Port, SIGN1_LED_Pin); //LED 翻转
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.h
* @brief : Header for main.c file.
* This file contains the common defines of the application.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
#include "stm32f1xx_ll_dma.h"
#include "stm32f1xx_ll_spi.h"
#include "stm32f1xx_ll_tim.h"
#include "stm32f1xx_ll_usart.h"
#include "stm32f1xx_ll_rcc.h"
#include "stm32f1xx_ll_bus.h"
#include "stm32f1xx_ll_system.h"
#include "stm32f1xx_ll_exti.h"
#include "stm32f1xx_ll_cortex.h"
#include "stm32f1xx_ll_utils.h"
#include "stm32f1xx_ll_pwr.h"
#include "stm32f1xx_ll_gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/
#define SIGN1_LED_Pin LL_GPIO_PIN_1
#define SIGN1_LED_GPIO_Port GPIOA
#define MOT_SELECT_1_Pin LL_GPIO_PIN_2
#define MOT_SELECT_1_GPIO_Port GPIOA
#define MOT_SELECT_2_Pin LL_GPIO_PIN_4
#define MOT_SELECT_2_GPIO_Port GPIOA
#define MGE_SCK_Pin LL_GPIO_PIN_5
#define MGE_SCK_GPIO_Port GPIOA
#define MGE_MISO_Pin LL_GPIO_PIN_6
#define MGE_MISO_GPIO_Port GPIOA
#define MGE_MOSI_Pin LL_GPIO_PIN_7
#define MGE_MOSI_GPIO_Port GPIOA
#define MGE_CS_Pin LL_GPIO_PIN_8
#define MGE_CS_GPIO_Port GPIOA
#define UART_BUS_TX_Pin LL_GPIO_PIN_9
#define UART_BUS_TX_GPIO_Port GPIOA
#define UART_BUS_RX_Pin LL_GPIO_PIN_10
#define UART_BUS_RX_GPIO_Port GPIOA
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}
#endif
#endif /* __MAIN_H */
... ...
#ifndef __MONITOR_CONFIG_H_
#define __MONITOR_CONFIG_H_
//‾‾‾‾‾‾‾‾‾‾‾‾DONT MODIFY‾‾‾‾‾‾‾‾‾‾‾‾
#define MONITOR_CONFIG_ENABLE 1
#define MONITOR_CONFIG_DISABLE 0
//____________DONT MODIFY____________
//===============MONITOR FUNTION CONFIG===============
#define DEBUG_FRAME_LOAD MONITOR_CONFIG_ENABLE
//===============MONITOR PARAMETER CONFIG===============
#define CH_COUNT_CONFIG 15
#endif
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file spi.h
* @brief This file contains all the function prototypes for
* the spi.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPI_H__
#define __SPI_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_SPI1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __SPI_H__ */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32_assert.h
* @brief STM32 assert file.
******************************************************************************
* @attention
*
* Copyright (c) 2018 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_ASSERT_H
#define __STM32_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t *file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32_ASSERT_H */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_hal_conf.h
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* Copyright (c) 2017 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F1xx_HAL_CONF_H
#define __STM32F1xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
/*#define HAL_CAN_MODULE_ENABLED */
/*#define HAL_CAN_LEGACY_MODULE_ENABLED */
/*#define HAL_CEC_MODULE_ENABLED */
/*#define HAL_CORTEX_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_DAC_MODULE_ENABLED */
/*#define HAL_DMA_MODULE_ENABLED */
/*#define HAL_ETH_MODULE_ENABLED */
/*#define HAL_FLASH_MODULE_ENABLED */
/*#define HAL_GPIO_MODULE_ENABLED */
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_I2S_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_NOR_MODULE_ENABLED */
/*#define HAL_NAND_MODULE_ENABLED */
/*#define HAL_PCCARD_MODULE_ENABLED */
/*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_HCD_MODULE_ENABLED */
/*#define HAL_PWR_MODULE_ENABLED */
/*#define HAL_RCC_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SD_MODULE_ENABLED */
/*#define HAL_MMC_MODULE_ENABLED */
/*#define HAL_SDRAM_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_SRAM_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */
/*#define HAL_UART_MODULE_ENABLED */
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT 100U /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE 8000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE 40000U /*!< LSI Typical Value in Hz */
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature. */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 5000U /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 15U /*!< tick interrupt priority (lowest by default) */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#define USE_HAL_CAN_REGISTER_CALLBACKS 0U /* CAN register callback disabled */
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#define USE_HAL_PCCARD_REGISTER_CALLBACKS 0U /* PCCARD register callback disabled */
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1U */
/* ################## Ethernet peripheral configuration ##################### */
/* Section 1 : Ethernet peripheral configuration */
/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
#define MAC_ADDR0 2U
#define MAC_ADDR1 0U
#define MAC_ADDR2 0U
#define MAC_ADDR3 0U
#define MAC_ADDR4 0U
#define MAC_ADDR5 0U
/* Definition of the Ethernet driver buffers size and count */
#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
#define ETH_RXBUFNB 8U /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
#define ETH_TXBUFNB 4U /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
/* Section 2: PHY configuration section */
/* DP83848_PHY_ADDRESS Address*/
#define DP83848_PHY_ADDRESS 0x01U
/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
#define PHY_RESET_DELAY 0x000000FFU
/* PHY Configuration delay */
#define PHY_CONFIG_DELAY 0x00000FFFU
#define PHY_READ_TO 0x0000FFFFU
#define PHY_WRITE_TO 0x0000FFFFU
/* Section 3: Common PHY Registers */
#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
/* Section 4: Extended PHY Registers */
#define PHY_SR ((uint16_t)0x10U) /*!< PHY status register Offset */
#define PHY_SPEED_STATUS ((uint16_t)0x0002U) /*!< PHY Speed mask */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0004U) /*!< PHY Duplex mask */
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32f1xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32f1xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32f1xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32f1xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_ETH_MODULE_ENABLED
#include "stm32f1xx_hal_eth.h"
#endif /* HAL_ETH_MODULE_ENABLED */
#ifdef HAL_CAN_MODULE_ENABLED
#include "stm32f1xx_hal_can.h"
#endif /* HAL_CAN_MODULE_ENABLED */
#ifdef HAL_CAN_LEGACY_MODULE_ENABLED
#include "Legacy/stm32f1xx_hal_can_legacy.h"
#endif /* HAL_CAN_LEGACY_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED
#include "stm32f1xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32f1xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32f1xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32f1xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32f1xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32f1xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32f1xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32f1xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32f1xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32f1xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32f1xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32f1xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32f1xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_PCCARD_MODULE_ENABLED
#include "stm32f1xx_hal_pccard.h"
#endif /* HAL_PCCARD_MODULE_ENABLED */
#ifdef HAL_SD_MODULE_ENABLED
#include "stm32f1xx_hal_sd.h"
#endif /* HAL_SD_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32f1xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32f1xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32f1xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32f1xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32f1xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32f1xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32f1xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32f1xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32f1xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32f1xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
#ifdef HAL_MMC_MODULE_ENABLED
#include "stm32f1xx_hal_mmc.h"
#endif /* HAL_MMC_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function's parameters check.
* @param expr If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F1xx_HAL_CONF_H */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.h
* @brief This file contains the headers of the interrupt handlers.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F1xx_IT_H
#define __STM32F1xx_IT_H
#ifdef __cplusplus
extern "C" {
#endif
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Channel4_IRQHandler(void);
void DMA1_Channel5_IRQHandler(void);
void TIM4_IRQHandler(void);
void USART1_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
#ifdef __cplusplus
}
#endif
#endif /* __STM32F1xx_IT_H */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.h
* @brief This file contains all the function prototypes for
* the tim.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TIM_H__
#define __TIM_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
#include "stm32f1xx_hal_tim.h"
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
extern TIM_HandleTypeDef htim2_Self;
extern TIM_HandleTypeDef htim3_Self;
extern TIM_HandleTypeDef htim4_Self;
/* USER CODE END Private defines */
void MX_TIM2_Init(void);
void MX_TIM3_Init(void);
void MX_TIM4_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __TIM_H__ */
... ...
/*
* @Date: 2023-11-07 18:19:22
* @LastEditTime: 2024-02-01 15:08:59
* @FilePath: \IMU_T6_Single\Hardware\delay.h
* @Description:
*/
/*
::
:;J7, :, ::;7:
,ivYi, , ;LLLFS:
:iv7Yi :7ri;j5PL
,:ivYLvr ,ivrrirrY2X,
:;r@Wwz.7r: :ivu@kexianli.
:iL7::,:::iiirii:ii;::::,,irvF7rvvLujL7ur
ri::,:,::i:iiiiiii:i:irrv177JX7rYXqZEkvv17
;i:, , ::::iirrririi:i:::iiir2XXvii;L8OGJr71i
:,, ,,: ,::ir@mingyi.irii:i:::j1jri7ZBOS7ivv,
,::, ::rv77iiiriii:iii:i::,rvLq@huhao.Li
,, ,, ,:ir7ir::,:::i;ir:::i:i::rSGGYri712:
::: ,v7r:: ::rrv77:, ,, ,:i7rrii:::::, ir7ri7Lri
, 2OBBOi,iiir;r:: ,irriiii::,, ,iv7Luur:
,, i78MBBi,:,:::,:, :7FSL: ,iriii:::i::,,:rLqXv::
: iuMMP: :,:::,:ii;2GY7OBB0viiii:i:iii:i:::iJqL;::
, ::::i ,,,,, ::LuBBu BBBBBErii:i:i:i:i:i:i:r77ii
, : , ,,:::rruBZ1MBBqi, :,,,:::,::::::iiriri:
, ,,,,::::i: @arqiao. ,:,, ,:::ii;i7:
:, rjujLYLi ,,:::::,:::::::::,, ,:i,:,,,,,::i:iii
:: BBBBBBBBB0, ,,::: , ,:::::: , ,,,, ,,:::::::
i, , ,8BMMBBBBBBi ,,:,, ,,, , , , , , :,::ii::i::
: iZMOMOMBBM2::::::::::,,,, ,,,,,,:,,,::::i:irr:i:::,
i ,,:;u0MBMOG1L:::i:::::: ,,,::, ,,, ::::::i:i:iirii:i:i:
: ,iuUuuXUkFu7i:iii:i:::, :,:,: ::::::::i:i:::::iirr7iiri::
: :rk@Yizero.i:::::, ,:ii:::::::i:::::i::,::::iirrriiiri::,
: 5BMBBBBBBSr:,::rv2kuii:::iii::,:i:,, , ,,:,:i@petermu.,
, :r50EZ8MBBBBGOBBBZP7::::i::,:::::,: :,:,::i;rrririiii::
:jujYY7LS0ujJL7r::,::i::,::::::::::::::iirirrrrrrr:ii:
,: :@kevensun.:,:,,,::::i:i:::::,,::::::iir;ii;7v77;ii;i,
,,, ,,:,::::::i:iiiii:i::::,, ::::iiiir@xingjief.r;7:i,
, , ,,,:,,::::::::iiiiiiiiii:,:,:::::::::iiir;ri7vL77rrirri::
:,, , ::::::::i:::i:::i:i::,,,,,:,::i:i:::iir;@Secbone.ii:::
*/
/*
_______________ _________
\__ ___/\ \ / / _ \
| | \ Y / /_\ \
| | \ / | \
|____| \___/\____|__ /
\/
Time Management Agency
*/
/*************************************************
The Gun delay/time API Announce (us)
File name: tva.h
Author: c17
Description: Offer the general delay ways and time manager
Others: Need To Used Some API
Log: Last Update at 2023/12/7
*************************************************/
#ifndef __DELAY_H
#define __DELAY_H
// #include "stm32f4xx_ll_tim.h"
#include "stm32f1xx_ll_tim.h"
#include "stdint.h"
// #include "main.h"
#define TVA_USE_TIMER TIM4
#define TVA_USE_TIMER_US_PREUP 50000
#define TVA_FULLUP_MS_CUT_u32 (0xFFFFFFFF / TVA_USE_TIMER_US_PREUP - 1)
// #define TVA_FULLUP_MS_CUT_u32 100
#define TVA_FULLUP_US_u32 (TVA_FULLUP_MS_CUT_u32+1) * TVA_USE_TIMER_US_PREUP
extern volatile uint32_t tvaTimerUptime;
#define TVA_TIMER_IT_ACTION \
{ \
tvaTimerUptime++; \
if (tvaTimerUptime > TVA_FULLUP_MS_CUT_u32) /*Manual overFlow*/ \
{ \
tvaTimerUptime = 0; \
} \
}
static inline void tva_time_It_action(void)
{
tvaTimerUptime++;
if (tvaTimerUptime > TVA_FULLUP_MS_CUT_u32) // Manual overFlow
{
tvaTimerUptime = 0;
}
}
// Time Record Struct (us) //Overflow not tested!!
typedef struct
{
// uint32_t Now_Time; // Current Time - Temp
uint32_t Last_Time; // Last operation system running time
uint32_t Pre_Run_Time; // Last operation during time
uint32_t Run_Time_High; // superstratum System running time HighPart - extraordinary long (1000day+++)
// uint32_t Run_TIme_Low; // superstratum System running time LowPart
} TimeRec_s;
void delay_ms(uint16_t nms);
void delay_us(uint32_t nus);
void Delay(unsigned long delay_time);
float TimeFlash(TimeRec_s *time);
uint32_t TimeFlash_us(TimeRec_s *time);
#endif
//------------------End of File----------------------------
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.h
* @brief This file contains all the function prototypes for
* the usart.c file
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
#include "stdbool.h"
#include "Project_Config.h"
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
typedef enum
{
UART_TX_STA_OK = 0,
UART_TX_STA_TX_BUSY,
UART_TX_STA_TX_UNBUSY,
UART_TX_STA_DATALEN_TOOLONG,
} UART_TX_STA; // UART DMA Result
#define UART_PRECONFIG_ENABLE 1
#define UART_PRECONFIG_DISABLE 0
extern __IO uint8_t usart1_Tx_dma_buffer[UART1_BUFF_TX_DMA_LEN];
extern __IO uint8_t usart1_Rx_dma_buffer[UART1_BUFF_RX_DMA_LEN];
extern __IO int32_t usart1_TX_dma_BusySign;
extern __IO uint8_t uasrt1_TX_dma_NeedToNofSign;
extern __IO uint32_t usart1_Rx_dma_count ;
extern __IO uint32_t usart1_Rx_dma_VerFALLCount ;
extern __IO uint8_t usart1_rx_L2_buffer[UART1_L2_BUFF_RX_LEN];
extern __IO uint8_t usart1_tx_L2_buffer[UART1_L2_BUFF_TX_LEN];
#define UART1_TX_MODE_OPEN_DRAIN LL_GPIO_SetPinOutputType(UART_BUS_TX_GPIO_Port,UART_BUS_TX_Pin,LL_GPIO_OUTPUT_OPENDRAIN);
#define UART1_TX_MODE_PUSH_PULL LL_GPIO_SetPinOutputType(UART_BUS_TX_GPIO_Port,UART_BUS_TX_Pin,LL_GPIO_OUTPUT_PUSHPULL);
/*+++++++++++++++++++++++++++++++++++ UART Gen Define +++++++++++++++++++++++++++++++++++*/
typedef struct
{
uint16_t volatile Wd_Indx;
uint16_t volatile Rd_Indx;
uint16_t Mask;
uint8_t *pbuf;
} UartBuf;
typedef enum
{
UARTRX_STATUS_END = 1,
UARTRX_STATUS_NOTEND
} UARTRX_STATUS;
extern UartBuf Uart1Txbuf;
extern UartBuf Uart1Rxbuf;
/*+++++++++++++++++++++++++++++++++++ UART Gen Define +++++++++++++++++++++++++++++++++++*/
// uart reicer flag
#define b_uart_head 0x80
#define b_rx_over 0x40
/* USER CODE END Private defines */
void MX_USART1_UART_Init(void);
/* USER CODE BEGIN Prototypes */
/*+++++++++++++++++++++++++ UART1 DMA +++++++++++++++++++++++++++++*/
UART_TX_STA Uart1_Send_DMA_StartBuff(uint8_t *senddata, uint16_t datalen);
UART_TX_STA Uart1_Send_DMA_Start(uint8_t *senddata, uint16_t datalen);
bool Uart1_SendDMA_IsBusy(void);
/*+++++++++++++++++++++++++ UART Gen +++++++++++++++++++++++++++++*/
uint8_t UartBuf_RD(UartBuf *Ringbuf);
uint16_t UartBuf_Cnt(UartBuf *Ringbuf);
void UartBuf_WD(UartBuf *Ringbuf, uint8_t DataIn);
UARTRX_STATUS UartBuf_End_Check(UartBuf *Ringbuf);
UARTRX_STATUS UartBuf_End_Check_RC(UartBuf *Ringbuf);
int UartBuf_RD_MultBytes(UartBuf *Ringbuf, uint8_t *readbuff, uint32_t bufflen, uint32_t readlen);
int fputc(int ch, FILE *f);
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __USART_H__ */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.c
* @brief This file provides code for the configuration
* of all the requested memory to memory DMA transfers.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "dma.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure DMA */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/**
* Enable DMA controller clock
*/
void MX_DMA_Init(void)
{
/* Init with LL driver */
/* DMA controller clock enable */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
/* DMA interrupt init */
/* DMA1_Channel4_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel4_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(DMA1_Channel4_IRQn);
/* DMA1_Channel5_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel5_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(DMA1_Channel5_IRQn);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file gpio.c
* @brief This file provides code for the configuration
* of all used GPIO pins.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "gpio.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
void MX_GPIO_Init(void)
{
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOD);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
/**/
LL_GPIO_ResetOutputPin(SIGN1_LED_GPIO_Port, SIGN1_LED_Pin);
/**/
LL_GPIO_SetOutputPin(MGE_CS_GPIO_Port, MGE_CS_Pin);
/**/
GPIO_InitStruct.Pin = SIGN1_LED_Pin|MGE_CS_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = MOT_SELECT_1_Pin|MOT_SELECT_2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "dma.h"
#include "spi.h"
#include "tim.h"
#include "usart.h"
#include "gpio.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Project_Config.h"
#include "BMCL.h"
#include "BMCL_ParaLoadF1.h"
#include "monitor.h"
#include "tva.h"
#include "MGE_Hal.h"
#include "stdlib.h"
//#include "cmsis_gcc.h"
#include "OBS_MOT.h"
#include "motor.h"
#include "FOC.h"
#include "protocolV1_1.h"
#include "T_SpeedShape.h"
#include "BMCL_Config.h"
#include "Motor_Manage.h"
#include "buzzer.h"
#include "upgrade.h"
#include "ParaMge_F1.h"
//#include "IMU_Pubilc.h"
#include "FilterExt.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
extern bool frameGetSign;
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
void commander_run(void);
void Parse_Posturd(uint8_t *buff, uint32_t len);
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
// static float pitchVelTaget, rollVelTaget, yawVelTaget = 0;
// static float motAngP, motAngR, controlA = 0;
uint8_t firstIn = 1;
uint32_t RunCount = 0;
float PlanTarget;
// Roll trapezoidal velocity profile definition
TRAP_CURVE_s rollANGPlan = {0};
float rollANGPlan_Time = 0;
TimeRec_s rollANGPlan_TimeS = {0};
float rollPlanTarget = 0;
//============To F4 PROTOCOL DATA/BUFF GROUP============
#define TX_TO_MOT_BUFF_LEN 36
uint8_t protocol_Tx_buff[TX_TO_MOT_BUFF_LEN];
float protocol_data[4] = {0};
float yawF4BaktimePass = 0;
#define YAW_TO_F4_ANG_BAK_DIVTIME 0.002f // second
// BMCL Semap
uint32_t curAngArr_SRoute = 0X00;
uint32_t tarAngArr_SRoute = 0X00;
uint32_t calibration_SRoute = 0X00;
uint32_t Music_SRoute = 0X00;
// uint32_t calibration_Sequence = PROTOCOL_F_COMMSQR_DATA_00;
//============Self-stabilizing mode control About=============
// S S M quantity
// KFP kfp_ssmq = {0.02, 0, 0, 0, 0.01, 0.1} ;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
__enable_irq();
__set_FAULTMASK(0);
SCB->VTOR = FLASH_BASE | 0x1400;
// while(1)
// {
// SIGN1_TAGO;
// }
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_SPI1_Init();
MX_TIM2_Init();
MX_TIM3_Init();
MX_USART1_UART_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
// 磁编码器初始�?
mge_hal_Init();
// PWM通道,主要是先�?启开启�?�道
PWM_Init(); // Enable the PWM output channel of Timx
upgrade_check();
//CUT##-240724A201 电机基本初始化的示例 - Start -> 展示初始化流�?,�?要初始化哪些东西,以及有那些东西需要进行Load和Write
// TODO: 读取Flash,并标记状�?,相关初始化等外部协议进行处理
Para_Init();
// NOTE: BMCL 初始�?,�?要在硬件初始化之后第�?个调�?
BMCL_Init();
bmcl_Config_Init();
bmcl_config_mot_select = BMCL_CONFIG_MOT_SELECT_ROLL;
workMode = WORK_MODE_1;
#if MOTOR_BOARD_DEBUG_OR_TEST == PROJECT_CONFIG_ENABLE
// while (frameGetSign != true)
while (1)
{
RunCount++;
if(RunCount==6000000)
{
RunCount = 0;
SIGN1_TAGO;
}
}
#endif
// HAL_Delay(1000);
// BMCL_mot_Calibration = BMCL_CONFIG_MOT_CAL_STA_EMPTY;
// TEST#: 当Flash中没有参数时,模拟外部协议对电机进行初始化
if (BMCL_mot_Calibration == __PARAMGE_DEF_MOT_CALI_STA_BAD)
{
BMCL_PL_PreLoadALL();
BMCL_PL_WriteAll2ParaMge();
motor_Align_Sensor();
motor_Set_ZeroEAngleOffset(zeroElectricAngleOffset_Temp);
mge_Set_direction(mge_direction_Temp);
mge_Set_abOffset(offset_Temp);
if (motor_Calibration_Status != __PARAMGE_DEF_MOT_CALI_STA_GOOD) // flash只保存成功和失败两种情况
{
motor_Calibration_Status = __PARAMGE_DEF_MOT_CALI_STA_BAD;
}
BMCL_mot_Calibration = motor_Calibration_Status;
BMCL_PL_WriteAll2ParaMge();
paraMge_SaveALL();
}
if(BMCL_mot_Calibration == __PARAMGE_DEF_MOT_CALI_STA_GOOD)
{
BMCL_PL_LoadAll4ParaMge();
}
uint8_t i;
uint8_t motor_SelfTest_flag;
for(i=0;i<2;i++)
{
if(motor_start_SelfTest()==0)
{
Operation_Reply(PROTOCOL_F_FUNCTION_2_0X01);
motor_SelfTest_flag = 0;
break;
}else motor_SelfTest_flag = 1;
playMusic(MelodyQuit, sizeof(MelodyQuit));
}
HAL_Delay(500);
// BMCL_PL_PreLoadALL();
//CUT## 电机基本初始化的示例 - END
#if 0 // NOTE: flash参数保存测试程序 - 2407121053
__PARAMGE_TEMP_MOT dest,src;
memset(&dest, 0x00, sizeof(__PARAMGE_TEMP_MOT));
memset(&src, 0x00, sizeof(__PARAMGE_TEMP_MOT));
src.mge_absOffset=2.32;
src.mge_Calibration=BMCL_CONFIG_MGE_CAL_STA_CALED;
paraMge_WriteMOT( &src);
paraMge_SaveALL();
paraMge_ReadALL();
paraMge_GetMOT(&dest);
#endif
while (1)
{
// SIGN1_ON
if (firstIn)
{
playMusic(MelodyStart, sizeof(MelodyStart));
HAL_Delay(1500);
rollANGPlan_Time += TimeFlash(&rollANGPlan_TimeS);
trap_Curve_Init(&rollANGPlan, 400.0f, 800.0f, rollANGPlan_Time, TRAP_CURVE_CYCMODE_OFF, 0);
rollANGPlan.pos_Cur = mge_hal_GetAbsAngle_withFilter()*57.2957795130f;//弧度转角�?
trap_Curve_SetTarget(&rollANGPlan, 0);
firstIn = 0;
}
if((BMCL_mot_Calibration == __PARAMGE_DEF_MOT_CALI_STA_BAD||motor_SelfTest_flag)&&workMode == WORK_MODE_1)
{
Operation_Reply(PROTOCOL_F_FUNCTION_2_0XFF);
playMusic(MelodyQuit, sizeof(MelodyQuit));
SIGN1_TAGO;
HAL_Delay(1500);
}
if (BMCL_GenSemap_take(&bmcl_Music, &Music_SRoute) == BMCL_GENSEAMP_RESULT_GET_GIVEN)
{
switch (Music_SRoute)
{
case Start:
playMusic(MelodyStart, sizeof(MelodyStart));
break;
case Connect:
playMusic(MelodyConnect, sizeof(MelodyConnect));
break;
case Enter:
playMusic(MelodyEnter, sizeof(MelodyEnter));
break;
case Quit:
playMusic(MelodyQuit, sizeof(MelodyQuit));
break;
default:
break;
}
}
if (BMCL_GenSemap_take(&bmcl_Calibration, &calibration_SRoute) == BMCL_GENSEAMP_RESULT_GET_GIVEN)
{
motor_Align_Sensor();
}
if (BMCL_mot_Calibration == __PARAMGE_DEF_MOT_CALI_STA_GOOD && workMode == WORK_MODE_1)
{
trap_Curve_SetTarget(&rollANGPlan, PlanTarget);
rollANGPlan_Time += TimeFlash(&rollANGPlan_TimeS);
rollPlanTarget = trap_Curve_Update(&rollANGPlan, rollANGPlan_Time);
Target_Angle = rollPlanTarget / 57.2957795130f; // 角度转弧�?
close_Angle_Control_GenPID(Target_Angle); // 目标角度闭环控制
RunCount++;
}else if(workMode == WORK_MODE_4)
{
setPhaseVoltage(0, 0, _3PI_2);
}
// MOT_YandR_VelControl_Direct_GenPID_ErrIn(0);
// RunCount++;
if(RunCount==2000)
{
// DebugFrameLoad_F(0,motor_obs.actual_Angle);
// DebugFrameLoad_F(1,motor_obs.actual_Velocity);
// DebugFrameLoad_F(2,motor_obs.actual_Velocity_KPF);
// DebugFrameLoad_F(3,motor_obs.el_Angle);
// DebugFrameLoad_F(4,Target_Angle);
// Uart1_Send_DMA_StartBuff((uint8_t *)debugFrame.fdata, (uint16_t)(sizeof(float) * CH_COUNT + sizeof(uint8_t) * 4));
RunCount = 0;
SIGN1_TAGO;
}
}
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
// uint8_t readbuff[12];
// uint8_t readlen;
// void commander_run(void)
// {
// if ((UartBuf_End_Check(&Uart1Rxbuf) == UARTRX_STATUS_END) && (UartBuf_Cnt(&Uart1Rxbuf) > 0))
// {
// readlen = UartBuf_RD_MultBytes(&Uart1Rxbuf, readbuff, 128, 8); // read Cmd Len
// Parse_Posturd(readbuff, readlen);
// }
// }
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file spi.c
* @brief This file provides code for the configuration
* of the SPI instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "spi.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* SPI1 init function */
void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
LL_SPI_InitTypeDef SPI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
/**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = MGE_SCK_Pin|MGE_MOSI_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = MGE_MISO_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
LL_GPIO_Init(MGE_MISO_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN SPI1_Init 1 */
/* USER CODE END SPI1_Init 1 */
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_16BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.CRCPoly = 10;
LL_SPI_Init(SPI1, &SPI_InitStruct);
/* USER CODE BEGIN SPI1_Init 2 */
LL_SPI_Enable(SPI1);
/* USER CODE END SPI1_Init 2 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_hal_msp.c
* @brief This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */
/* USER CODE END Define */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */
/* USER CODE END Macro */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */
/* USER CODE END ExternalFunctions */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
*/
__HAL_AFIO_REMAP_SWJ_NOJTAG();
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file stm32f1xx_it.c
* @brief Interrupt Service Routines.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f1xx_it.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "Project_Config.h"
#include "usart.h"
#include "gpio.h"
#include "tva.h"
#include "protocolV1_1.h"
#include "string.h"
#include "BMCL.h"
#include "motor.h"
//#include "IMU_Pubilc.h"
#include "T_SpeedShape.h"
#include "BMCL_Config.h"
#include "ParaMge_F1.h"
#include "Motor_Manage.h"
#include "buzzer.h"
extern TimeRec_s buzzer_TimeS ;
extern uint32_t pastedTime;
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */
/* USER CODE END TD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
bool fstAttArr = false;
Pro_Parse_Result protocol_parse_result;
bool frameGetSign = false;
// extern TRAP_CURVE_s yawANGPlan ;
// extern KFP kfp_ssmq ;
extern KFP kfp_motAngP ;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/* External variables --------------------------------------------------------*/
/* USER CODE BEGIN EV */
/* USER CODE END EV */
/******************************************************************************/
/* Cortex-M3 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
* @brief This function handles Non maskable interrupt.
*/
void NMI_Handler(void)
{
/* USER CODE BEGIN NonMaskableInt_IRQn 0 */
/* USER CODE END NonMaskableInt_IRQn 0 */
/* USER CODE BEGIN NonMaskableInt_IRQn 1 */
while (1)
{
}
/* USER CODE END NonMaskableInt_IRQn 1 */
}
/**
* @brief This function handles Hard fault interrupt.
*/
void HardFault_Handler(void)
{
/* USER CODE BEGIN HardFault_IRQn 0 */
/* USER CODE END HardFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_HardFault_IRQn 0 */
/* USER CODE END W1_HardFault_IRQn 0 */
}
}
/**
* @brief This function handles Memory management fault.
*/
void MemManage_Handler(void)
{
/* USER CODE BEGIN MemoryManagement_IRQn 0 */
/* USER CODE END MemoryManagement_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
/* USER CODE END W1_MemoryManagement_IRQn 0 */
}
}
/**
* @brief This function handles Prefetch fault, memory access fault.
*/
void BusFault_Handler(void)
{
/* USER CODE BEGIN BusFault_IRQn 0 */
/* USER CODE END BusFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_BusFault_IRQn 0 */
/* USER CODE END W1_BusFault_IRQn 0 */
}
}
/**
* @brief This function handles Undefined instruction or illegal state.
*/
void UsageFault_Handler(void)
{
/* USER CODE BEGIN UsageFault_IRQn 0 */
/* USER CODE END UsageFault_IRQn 0 */
while (1)
{
/* USER CODE BEGIN W1_UsageFault_IRQn 0 */
/* USER CODE END W1_UsageFault_IRQn 0 */
}
}
/**
* @brief This function handles System service call via SWI instruction.
*/
void SVC_Handler(void)
{
/* USER CODE BEGIN SVCall_IRQn 0 */
/* USER CODE END SVCall_IRQn 0 */
/* USER CODE BEGIN SVCall_IRQn 1 */
/* USER CODE END SVCall_IRQn 1 */
}
/**
* @brief This function handles Debug monitor.
*/
void DebugMon_Handler(void)
{
/* USER CODE BEGIN DebugMonitor_IRQn 0 */
/* USER CODE END DebugMonitor_IRQn 0 */
/* USER CODE BEGIN DebugMonitor_IRQn 1 */
/* USER CODE END DebugMonitor_IRQn 1 */
}
/**
* @brief This function handles Pendable request for system service.
*/
void PendSV_Handler(void)
{
/* USER CODE BEGIN PendSV_IRQn 0 */
/* USER CODE END PendSV_IRQn 0 */
/* USER CODE BEGIN PendSV_IRQn 1 */
/* USER CODE END PendSV_IRQn 1 */
}
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
/* USER CODE END SysTick_IRQn 1 */
}
/******************************************************************************/
/* STM32F1xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f1xx.s). */
/******************************************************************************/
/**
* @brief This function handles DMA1 channel4 global interrupt.
*/
void DMA1_Channel4_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel4_IRQn 0 */
if (LL_DMA_IsActiveFlag_TC4(DMA1))
{
LL_DMA_ClearFlag_TC4(DMA1);
// UART1_TX_MODE_OPEN_DRAIN // UART TX GUAN BI !
usart1_TX_dma_BusySign = UART_TX_STA_TX_UNBUSY;
#if UART1_DMA_FREERTOS_SOUPPORT == PROJECT_CONFIG_ENABLE
if (uasrt1_TX_dma_NeedToNofSign)
{
vTaskNotifyGiveFromISR(cmdOutputTaskHandle, pdTRUE);
}
#endif
}
/* USER CODE END DMA1_Channel4_IRQn 0 */
/* USER CODE BEGIN DMA1_Channel4_IRQn 1 */
/* USER CODE END DMA1_Channel4_IRQn 1 */
}
/**
* @brief This function handles DMA1 channel5 global interrupt.
*/
void DMA1_Channel5_IRQHandler(void)
{
/* USER CODE BEGIN DMA1_Channel5_IRQn 0 */
if (LL_DMA_IsActiveFlag_TC5(DMA1))
{
LL_DMA_ClearFlag_TC5(DMA1);
}
/* USER CODE END DMA1_Channel5_IRQn 0 */
/* USER CODE BEGIN DMA1_Channel5_IRQn 1 */
/* USER CODE END DMA1_Channel5_IRQn 1 */
}
/**
* @brief This function handles TIM4 global interrupt.
*/
void TIM4_IRQHandler(void)
{
/* USER CODE BEGIN TIM4_IRQn 0 */
if (LL_TIM_IsActiveFlag_UPDATE(TIM4))
{
LL_TIM_ClearFlag_UPDATE(TIM4);
// tvaTimerUptime++;
// if (tvaTimerUptime > TVA_FULLUP_MS_CUT_u32) //Manual overFlow
// {
// tvaTimerUptime = 0;
// }
// TVA_TIMER_IT_ACTION
tva_time_It_action();
// playMusic_Ud(MelodyStart,sizeof(MelodyStart));
}
/* USER CODE END TIM4_IRQn 0 */
/* USER CODE BEGIN TIM4_IRQn 1 */
/* USER CODE END TIM4_IRQn 1 */
}
/**
* @brief This function handles USART1 global interrupt.
*/
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
// if( LL_USART_IsActiveFlag_RXNE(USART1) ){
// LL_USART_ClearFlag_RXNE(USART1);
// uint8_t Udatatmp = LL_USART_ReceiveData8(USART1);
// UartBuf_WD(&Uart1Rxbuf, Udatatmp);
// }
uint16_t count = 0;
uint32_t temp;
uint32_t temp2;
int judge = 0;
// ### IDLE PROCESS TIMES = 4碌s
/* Check for IDLE line interrupt */
if (LL_USART_IsActiveFlag_IDLE(USART1) != RESET)
{
// SIGN1_ON
temp = LL_DMA_GetDataLength(DMA1, LL_DMA_CHANNEL_5);
count = UART1_BUFF_RX_DMA_LEN - temp;
if ((count <= UART1_BUFF_RX_DMA_LEN)) // 闃叉鏁版嵁澶у皬鍑洪棶锟????
{
// SIGN1_UP;
memcpy((uint8_t *)usart1_rx_L2_buffer, (uint8_t *)usart1_Rx_dma_buffer, count); // 灏嗘暟鎹鍒跺埌鍐呴儴缂撳啿鍖轰腑-鍙互鐪佺暐鐩存帴瀵筊X DMA BUFFER杩涜澶勭悊
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_5);
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_5, UART1_BUFF_RX_DMA_LEN);
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_5);
protocol_parse_result = protocol_frame_parse((uint8_t *)usart1_rx_L2_buffer, count + 2); // 澶勭悊鏁版嵁
SIGN1_TAGO;
}
USART1_JUMP_P1:
LL_USART_ClearFlag_IDLE(USART1);
// SIGN1_OFF
}
/* Check for TC line interrupt */
if ( (LL_USART_IsEnabledIT_TC(USART1) != RESET) && (LL_USART_IsActiveFlag_TC(USART1) != RESET) )
{
SIGN1_ON
// UART1_TX_MODE_OPEN_DRAIN // UART TX GUAN BI !////此设备结束传输时,关闭tx(防止并联的串口设备短路)
// LL_USART_DisableIT_TC( USART1 );//关闭完成中断
LL_USART_ClearFlag_TC( USART1 );
SIGN1_OFF
}
/* USER CODE END USART1_IRQn 0 */
/* USER CODE BEGIN USART1_IRQn 1 */
/* USER CODE END USART1_IRQn 1 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
... ...
/**
******************************************************************************
* @file system_stm32f1xx.c
* @author MCD Application Team
* @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.
*
* 1. This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
* factors, AHB/APBx prescalers and Flash settings).
* This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the "startup_stm32f1xx_xx.s" file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
* 2. After each device reset the HSI (8 MHz) is used as system clock source.
* Then SystemInit() function is called, in "startup_stm32f1xx_xx.s" file, to
* configure the system clock before to branch to main program.
*
* 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depending on
* the product used), refer to "HSE_VALUE".
* When HSE is used as system clock source, directly or through PLL, and you
* are using different crystal you have to adapt the HSE value to your own
* configuration.
*
******************************************************************************
* @attention
*
* Copyright (c) 2017-2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/** @addtogroup CMSIS
* @{
*/
/** @addtogroup stm32f1xx_system
* @{
*/
/** @addtogroup STM32F1xx_System_Private_Includes
* @{
*/
#include "stm32f1xx.h"
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Defines
* @{
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE 8000000U /*!< Default value of the External oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
This value can be provided and adapted by the user application. */
#endif /* HSI_VALUE */
/*!< Uncomment the following line if you need to use external SRAM */
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/* #define DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/* Note: Following vector table addresses must be defined in line with linker
configuration. */
/*!< Uncomment the following line if you need to relocate the vector table
anywhere in Flash or Sram, else the vector table is kept at the automatic
remap of boot address selected */
/* #define USER_VECT_TAB_ADDRESS */
#if defined(USER_VECT_TAB_ADDRESS)
/*!< Uncomment the following line if you need to relocate your vector Table
in Sram else user remap will be done in Flash. */
/* #define VECT_TAB_SRAM */
#if defined(VECT_TAB_SRAM)
#define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#else
#define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field.
This value must be a multiple of 0x200. */
#define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */
#endif /* VECT_TAB_SRAM */
#endif /* USER_VECT_TAB_ADDRESS */
/******************************************************************************/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Macros
* @{
*/
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Variables
* @{
*/
/* This variable is updated in three ways:
1) by calling CMSIS function SystemCoreClockUpdate()
2) by calling HAL API function HAL_RCC_GetHCLKFreq()
3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency
Note: If you use this function to configure the system clock; then there
is no need to call the 2 first functions listed above, since SystemCoreClock
variable is updated automatically.
*/
uint32_t SystemCoreClock = 16000000;
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_FunctionPrototypes
* @{
*/
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
#ifdef DATA_IN_ExtSRAM
static void SystemInit_ExtMemCtl(void);
#endif /* DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/**
* @}
*/
/** @addtogroup STM32F1xx_System_Private_Functions
* @{
*/
/**
* @brief Setup the microcontroller system
* Initialize the Embedded Flash Interface, the PLL and update the
* SystemCoreClock variable.
* @note This function should be used only after reset.
* @param None
* @retval None
*/
void SystemInit (void)
{
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
#ifdef DATA_IN_ExtSRAM
SystemInit_ExtMemCtl();
#endif /* DATA_IN_ExtSRAM */
#endif
/* Configure the Vector Table location -------------------------------------*/
#if defined(USER_VECT_TAB_ADDRESS)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#endif /* USER_VECT_TAB_ADDRESS */
}
/**
* @brief Update SystemCoreClock variable according to Clock Register Values.
* The SystemCoreClock variable contains the core clock (HCLK), it can
* be used by the user application to setup the SysTick timer or configure
* other parameters.
*
* @note Each time the core clock (HCLK) changes, this function must be called
* to update SystemCoreClock variable value. Otherwise, any configuration
* based on this variable will be incorrect.
*
* @note - The system frequency computed by this function is not the real
* frequency in the chip. It is calculated based on the predefined
* constant and the selected clock source:
*
* - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
*
* - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
*
* - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**)
* or HSI_VALUE(*) multiplied by the PLL factors.
*
* (*) HSI_VALUE is a constant defined in stm32f1xx.h file (default value
* 8 MHz) but the real value may vary depending on the variations
* in voltage and temperature.
*
* (**) HSE_VALUE is a constant defined in stm32f1xx.h file (default value
* 8 MHz or 25 MHz, depending on the product used), user has to ensure
* that HSE_VALUE is same as the real frequency of the crystal used.
* Otherwise, this function may have wrong result.
*
* - The result of this function could be not correct when using fractional
* value for HSE crystal.
* @param None
* @retval None
*/
void SystemCoreClockUpdate (void)
{
uint32_t tmp = 0U, pllmull = 0U, pllsource = 0U;
#if defined(STM32F105xC) || defined(STM32F107xC)
uint32_t prediv1source = 0U, prediv1factor = 0U, prediv2factor = 0U, pll2mull = 0U;
#endif /* STM32F105xC */
#if defined(STM32F100xB) || defined(STM32F100xE)
uint32_t prediv1factor = 0U;
#endif /* STM32F100xB or STM32F100xE */
/* Get SYSCLK source -------------------------------------------------------*/
tmp = RCC->CFGR & RCC_CFGR_SWS;
switch (tmp)
{
case 0x00U: /* HSI used as system clock */
SystemCoreClock = HSI_VALUE;
break;
case 0x04U: /* HSE used as system clock */
SystemCoreClock = HSE_VALUE;
break;
case 0x08U: /* PLL used as system clock */
/* Get PLL clock source and multiplication factor ----------------------*/
pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
#if !defined(STM32F105xC) && !defined(STM32F107xC)
pllmull = ( pllmull >> 18U) + 2U;
if (pllsource == 0x00U)
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
}
else
{
#if defined(STM32F100xB) || defined(STM32F100xE)
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
#else
/* HSE selected as PLL clock entry */
if ((RCC->CFGR & RCC_CFGR_PLLXTPRE) != (uint32_t)RESET)
{/* HSE oscillator clock divided by 2 */
SystemCoreClock = (HSE_VALUE >> 1U) * pllmull;
}
else
{
SystemCoreClock = HSE_VALUE * pllmull;
}
#endif
}
#else
pllmull = pllmull >> 18U;
if (pllmull != 0x0DU)
{
pllmull += 2U;
}
else
{ /* PLL multiplication factor = PLL input clock * 6.5 */
pllmull = 13U / 2U;
}
if (pllsource == 0x00U)
{
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
}
else
{/* PREDIV1 selected as PLL clock entry */
/* Get PREDIV1 clock source and division factor */
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
if (prediv1source == 0U)
{
/* HSE oscillator clock selected as PREDIV1 clock entry */
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
}
else
{/* PLL2 clock selected as PREDIV1 clock entry */
/* Get PREDIV2 division factor and PLL2 multiplication factor */
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
pll2mull = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> 8U) + 2U;
SystemCoreClock = (((HSE_VALUE / prediv2factor) * pll2mull) / prediv1factor) * pllmull;
}
}
#endif /* STM32F105xC */
break;
default:
SystemCoreClock = HSI_VALUE;
break;
}
/* Compute HCLK clock frequency ----------------*/
/* Get HCLK prescaler */
tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4U)];
/* HCLK clock frequency */
SystemCoreClock >>= tmp;
}
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/**
* @brief Setup the external memory controller. Called in startup_stm32f1xx.s
* before jump to __main
* @param None
* @retval None
*/
#ifdef DATA_IN_ExtSRAM
/**
* @brief Setup the external memory controller.
* Called in startup_stm32f1xx_xx.s/.c before jump to main.
* This function configures the external SRAM mounted on STM3210E-EVAL
* board (STM32 High density devices). This SRAM will be used as program
* data memory (including heap and stack).
* @param None
* @retval None
*/
void SystemInit_ExtMemCtl(void)
{
__IO uint32_t tmpreg;
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
required, then adjust the Register Addresses */
/* Enable FSMC clock */
RCC->AHBENR = 0x00000114U;
/* Delay after an RCC peripheral clock enabling */
tmpreg = READ_BIT(RCC->AHBENR, RCC_AHBENR_FSMCEN);
/* Enable GPIOD, GPIOE, GPIOF and GPIOG clocks */
RCC->APB2ENR = 0x000001E0U;
/* Delay after an RCC peripheral clock enabling */
tmpreg = READ_BIT(RCC->APB2ENR, RCC_APB2ENR_IOPDEN);
(void)(tmpreg);
/* --------------- SRAM Data lines, NOE and NWE configuration ---------------*/
/*---------------- SRAM Address lines configuration -------------------------*/
/*---------------- NOE and NWE configuration --------------------------------*/
/*---------------- NE3 configuration ----------------------------------------*/
/*---------------- NBL0, NBL1 configuration ---------------------------------*/
GPIOD->CRL = 0x44BB44BBU;
GPIOD->CRH = 0xBBBBBBBBU;
GPIOE->CRL = 0xB44444BBU;
GPIOE->CRH = 0xBBBBBBBBU;
GPIOF->CRL = 0x44BBBBBBU;
GPIOF->CRH = 0xBBBB4444U;
GPIOG->CRL = 0x44BBBBBBU;
GPIOG->CRH = 0x444B4B44U;
/*---------------- FSMC Configuration ---------------------------------------*/
/*---------------- Enable FSMC Bank1_SRAM Bank ------------------------------*/
FSMC_Bank1->BTCR[4U] = 0x00001091U;
FSMC_Bank1->BTCR[5U] = 0x00110212U;
}
#endif /* DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file tim.c
* @brief This file provides code for the configuration
* of the TIM instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "tim.h"
/* USER CODE BEGIN 0 */
TIM_HandleTypeDef htim2_Self = {0};
TIM_HandleTypeDef htim3_Self = {0};
TIM_HandleTypeDef htim4_Self = {0};
/* USER CODE END 0 */
/* TIM2 init function */
void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
htim2_Self.Instance = TIM2;
/* USER CODE END TIM2_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_CENTER_DOWN;
TIM_InitStruct.Autoreload = 1600-LL_TIM_IC_FILTER_FDIV1_N2;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM2, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM2);
LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_OC_EnablePreload(TIM2, LL_TIM_CHANNEL_CH4);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
LL_TIM_OC_Init(TIM2, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH4);
LL_TIM_SetTriggerOutput(TIM2, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM2);
/* USER CODE BEGIN TIM2_Init 2 */
LL_TIM_EnableAllOutputs(TIM2);
LL_TIM_EnableCounter(TIM2);
/* USER CODE END TIM2_Init 2 */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
/**TIM2 GPIO Configuration
PA3 ------> TIM2_CH4
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
/* TIM3 init function */
void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
htim3_Self.Instance = TIM3;
/* USER CODE END TIM3_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
TIM_InitStruct.Prescaler = 0;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_CENTER_DOWN;
TIM_InitStruct.Autoreload = 1600-LL_TIM_IC_FILTER_FDIV1_N2;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM3, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM3);
LL_TIM_SetClockSource(TIM3, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH4);
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH4, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH4);
LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM3);
/* USER CODE BEGIN TIM3_Init 2 */
LL_TIM_EnableAllOutputs(TIM3);
LL_TIM_EnableCounter(TIM3);
/* USER CODE END TIM3_Init 2 */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
/**TIM3 GPIO Configuration
PB0 ------> TIM3_CH3
PB1 ------> TIM3_CH4
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_1;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* TIM4 init function */
void MX_TIM4_Init(void)
{
/* USER CODE BEGIN TIM4_Init 0 */
htim4_Self.Instance = TIM4;
/* USER CODE END TIM4_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM4);
/* TIM4 interrupt Init */
NVIC_SetPriority(TIM4_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(TIM4_IRQn);
/* USER CODE BEGIN TIM4_Init 1 */
/* USER CODE END TIM4_Init 1 */
TIM_InitStruct.Prescaler = 72-LL_TIM_IC_FILTER_FDIV1_N2;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 50000-LL_TIM_IC_FILTER_FDIV1_N2;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM4, &TIM_InitStruct);
LL_TIM_DisableARRPreload(TIM4);
LL_TIM_SetClockSource(TIM4, LL_TIM_CLOCKSOURCE_INTERNAL);
LL_TIM_SetTriggerOutput(TIM4, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM4);
/* USER CODE BEGIN TIM4_Init 2 */
LL_TIM_EnableIT_UPDATE(TIM4);
LL_TIM_EnableCounter(TIM4);
/* USER CODE END TIM4_Init 2 */
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
... ...
/*************************************************
The Gun delay/time API Implementation
Copyright ? not there is not such of right
File name: tva.c
Author: c17
Description: Offer the general delay ways and time manager (use Systick this time)
Others: Need To Used Some API
Log: Last Update at 2023/12/7
*************************************************/
#include "tva.h"
#include "stdbool.h"
// #include "stm32f10x_it.h"
// cycles per microsecond
// current uptime for 1kHz systick timer. will rollover after 49 days. hopefully we won't care.
volatile uint32_t tvaTimerUptime = 0;
volatile bool timeInt_Happen = 0;
/*************************\
************************************* API BASE implementation *****************************************************
\*************************/
// Return system uptime in microseconds (rollover in 70min)
uint32_t micros_10(void)
{
register uint32_t _RecMS, cycle_cnt;
do
{
_RecMS = tvaTimerUptime;
cycle_cnt = LL_TIM_GetCounter(TVA_USE_TIMER);
} while (_RecMS != tvaTimerUptime);
cycle_cnt = _RecMS * TVA_USE_TIMER_US_PREUP + cycle_cnt;
return cycle_cnt;
}
// // Return system uptime in nanoseconds (only return after millisecond) (rollover in 4second)
// uint32_t nanos(void)
// {
// register uint32_t ms, cycle_cnt;
// do {
// ms = tvaTimerUptime;
// cycle_cnt = LL_TIM_GetCounter(TIM9);
// } while (ms != tvaTimerUptime);
// return cycle_cnt * nanoPSC;
// }
// // Return system uptime in milliseconds (rollover in 49 days)
// uint32_t millis(void)
// {
// return cycle_cnt/1000;
// }
/******************************\
************************************* Top-level API implementation *****************************************************
\******************************/
/**
* @brief delay in ms
* @param nms the ms need to wait
*/
void delay_ms(uint16_t nms)
{
uint32_t t0 = micros_10();
while (micros_10() - t0 < nms * 1000)
;
}
/**
* @brief delay in us
* @param nms the us need to wait
*/
void delay_us(uint32_t nus)
{
uint32_t t0 = micros_10();
while (micros_10() - t0 < nus)
;
}
// 粗略延时
void Delay(unsigned long delay_time)
{
long i;
for (i = 0; i < delay_time; i++)
;
}
/**
* @brief Update each time run of the "time struct"
* @param time The "time struct" needs to be updated
* @return The elapsed time (in microseconds) from the last TimeFlash call to this one
* ##the pass time from last TimeFlash called to this time, in us
*/
float TimeFlash(TimeRec_s *time)
{
uint32_t now_time;
now_time = micros_10();
if (now_time < time->Last_Time)
{ // 时间溢出
// time->Pre_Run_Time = 0xFFFFFFFF - time->Last_Time + now_time;
time->Pre_Run_Time = TVA_FULLUP_US_u32 - time->Last_Time + now_time;
time->Run_Time_High++; // 溢出一次记录一次
}
else
{
time->Pre_Run_Time = now_time - time->Last_Time;
}
time->Last_Time = now_time;
return ((float)time->Pre_Run_Time) * 1e-6f;
}
/**
* @brief Update each time run of the "time struct"
* @param time The "time struct" needs to be updated
* @return The elapsed time (in microseconds) from the last TimeFlash call to this one
* ##the pass time from last TimeFlash called to this time, in us
*/
uint32_t TimeFlash_us(TimeRec_s *time)
{
uint32_t now_time;
now_time = micros_10();
if (now_time < time->Last_Time)
{ // 时间溢出
// time->Pre_Run_Time = 0xFFFFFFFF - time->Last_Time + now_time;
time->Pre_Run_Time = TVA_FULLUP_US_u32 - time->Last_Time + now_time;
time->Run_Time_High++; // 溢出一次记录一次
}
else
{
time->Pre_Run_Time = now_time - time->Last_Time;
}
time->Last_Time = now_time;
return time->Pre_Run_Time;
}
//------------------End of File----------------------------
... ...
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.c
* @brief This file provides code for the configuration
* of the USART instances.
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/* USER CODE BEGIN 0 */
#include <string.h>
#include "Project_Config.h"
/*+++++++++++++++++++++++++ UART1 DMA Data ++++++++++++++++++++++++++++++*/
__IO uint8_t usart1_Tx_dma_buffer[UART1_BUFF_TX_DMA_LEN];
__IO int32_t usart1_TX_dma_BusySign = UART_TX_STA_TX_UNBUSY;
__IO uint8_t uasrt1_TX_dma_NeedToNofSign = false;
__IO uint8_t usart1_Rx_dma_buffer[UART1_BUFF_RX_DMA_LEN];
__IO uint32_t usart1_Rx_dma_count = 1;
__IO uint32_t usart1_Rx_dma_VerFALLCount = 1;
__IO uint8_t usart1_rx_L2_buffer[UART1_L2_BUFF_RX_LEN];
__IO uint8_t usart1_tx_L2_buffer[UART1_L2_BUFF_TX_LEN];
/*++++++++++++++++++++++++++++++++++++++ Uart Gen Define +++++++++++++++++++++++++++++++++++*/
// UartBuf Uart1Txbuf ;
UartBuf Uart1Rxbuf ;
uint8_t uartRxStatus ;
unsigned char u1rx_buffer[UART1_BUFF_RX_IT_LEN];
/* USER CODE END 0 */
/* USART1 init function */
void MX_USART1_UART_Init(void)
{
/* USER CODE BEGIN USART1_Init 0 */
LL_DMA_DeInit(DMA1, LL_DMA_CHANNEL_4);
/* USER CODE END USART1_Init 0 */
LL_USART_InitTypeDef USART_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
*/
GPIO_InitStruct.Pin = UART_BUS_TX_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(UART_BUS_TX_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = UART_BUS_RX_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
LL_GPIO_Init(UART_BUS_RX_GPIO_Port, &GPIO_InitStruct);
/* USART1 DMA Init */
/* USART1_TX Init */
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_4, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PRIORITY_HIGH);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_4, LL_DMA_MDATAALIGN_BYTE);
/* USART1_RX Init */
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_5, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PRIORITY_LOW);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MODE_NORMAL);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_5, LL_DMA_MDATAALIGN_BYTE);
/* USART1 interrupt Init */
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_Init 1 */
/*_________ Self Add On DMA For UART1 TX _________ */
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_4); // Enable DMA TC IT
// LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_4);
// LL_DMA_DisableIT_DME(DMA1, LL_DMA_CHANNEL_4); // Disable Useless IT
LL_DMA_DisableIT_TE(DMA1, LL_DMA_CHANNEL_4);
LL_DMA_SetPeriphAddress(DMA1, LL_DMA_CHANNEL_4, LL_USART_DMA_GetRegAddr(USART1)); // Set The Peripheral Address
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_4, (uint32_t)usart1_Tx_dma_buffer); // Set The Memony Address
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, 0);
LL_USART_EnableDMAReq_TX(USART1); // Enable USART1 TX DMA Rqe
/*_________ Self Add On DMA For UART1 RX _________ */
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_5); // Enable DMA TC IT
// LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_5);
// LL_DMA_DisableIT_DME(DMA1, LL_DMA_CHANNEL_5); // Disable Useless IT
LL_DMA_DisableIT_TE(DMA1, LL_DMA_CHANNEL_5);
LL_DMA_SetPeriphAddress(DMA1, LL_DMA_CHANNEL_5, LL_USART_DMA_GetRegAddr(USART1)); // Set The Peripheral Address
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_5, (uint32_t)usart1_Rx_dma_buffer); // Set The Memony Address
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_5, UART1_BUFF_RX_DMA_LEN);
LL_DMA_EnableChannel(DMA1,LL_DMA_CHANNEL_5);
LL_USART_EnableDMAReq_RX(USART1); // Enable USART3 TX DMA Rqe
/* USER CODE END USART1_Init 1 */
USART_InitStruct.BaudRate = 115200;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART1, &USART_InitStruct);
LL_USART_ConfigAsyncMode(USART1);
LL_USART_Enable(USART1);
/* USER CODE BEGIN USART1_Init 2 */
LL_USART_DisableIT_RXNE(USART1);
LL_USART_EnableIT_IDLE(USART1);
LL_USART_ClearFlag_IDLE(USART1);
#if UART1_TX_OPENDRAIN == PROJECT_CONFIG_ENABLE
LL_GPIO_SetPinOutputType(GPIOA,LL_GPIO_PIN_9,LL_GPIO_OUTPUT_OPENDRAIN);
#endif
/*++++++++++++++++++++++++ Uart Gen Init +++++++++++++++++++++++++++*/
Uart1Rxbuf.Wd_Indx = 0;
Uart1Rxbuf.Rd_Indx = 0;
Uart1Rxbuf.Mask = UART1_BUFF_RX_IT_LEN - 1;
Uart1Rxbuf.pbuf = &u1rx_buffer[0];
/* USER CODE END USART1_Init 2 */
}
/* USER CODE BEGIN 1 */
//int fputc(int ch,FILE *f)
//{
// HAL_UART_Transmit(&USART1, (uint8_t *) &ch, 1, 0xFFFF);
// return ch;
//}
int fputc(int ch, FILE *f)
{
LL_USART_TransmitData8(USART1, (uint8_t) ch);
while (LL_USART_IsActiveFlag_TXE(USART1) == 0);
return ch;
}
/*++++++++++++++++++++++++++++++++++++++++++++++ UART Gen Part ++++++++++++++++++++++++++++++++++++++++*/
uint8_t UartBuf_RD(UartBuf *Ringbuf)
{
uint8_t temp;
temp = Ringbuf->pbuf[Ringbuf->Rd_Indx & Ringbuf->Mask];
Ringbuf->Rd_Indx++;
return temp;
}
int UartBuf_RD_MultBytes(UartBuf *Ringbuf, uint8_t *readbuff, uint32_t bufflen, uint32_t readlen)
{
uint32_t vauleLen, i;
vauleLen = UartBuf_Cnt(Ringbuf); // 澶氫綑锟?????????
if (UartBuf_Cnt(Ringbuf) < readlen)
readlen = vauleLen;
if (bufflen < readlen)
readlen = bufflen;
for (i = 0; i < readlen; i++)
{
readbuff[i] = UartBuf_RD(Ringbuf);
}
return readlen;
}
inline UARTRX_STATUS UartBuf_End_Check(UartBuf *Ringbuf)
{
if (Ringbuf->pbuf[(Ringbuf->Wd_Indx - 1) & Ringbuf->Mask] == '\n' &&
Ringbuf->pbuf[(Ringbuf->Wd_Indx - 2) & Ringbuf->Mask] == '\r')
{
return UARTRX_STATUS_END;
}
else
{
return UARTRX_STATUS_NOTEND;
}
}
inline UARTRX_STATUS UartBuf_End_Check_RC(UartBuf *Ringbuf)
{
if (Ringbuf->pbuf[(Ringbuf->Wd_Indx - 1) & Ringbuf->Mask] == 0x34 &&
Ringbuf->pbuf[(Ringbuf->Wd_Indx - 2) & Ringbuf->Mask] == 0x33)
{
return UARTRX_STATUS_END;
}
else
{
return UARTRX_STATUS_NOTEND;
}
}
inline void UartBuf_WD(UartBuf *Ringbuf, uint8_t DataIn)
{
Ringbuf->pbuf[Ringbuf->Wd_Indx & Ringbuf->Mask] = DataIn;
Ringbuf->Wd_Indx++;
}
inline uint16_t UartBuf_Cnt(UartBuf *Ringbuf)
{
return (Ringbuf->Wd_Indx - Ringbuf->Rd_Indx) & Ringbuf->Mask;
}
inline void UartBufClear(UartBuf *Ringbuf)
{
Ringbuf->Rd_Indx = Ringbuf->Wd_Indx;
}
/*++++++++++++++++++++++++++++++++++++++++++++++ UART1 DMA Part ++++++++++++++++++++++++++++++++++++++++*/
/**
* @brief UART1 TX StartSteam - With Buff(Data will copy to In-Built Buff frist before transimitting)
* @param senddata
* @param datalen
*/
UART_TX_STA Uart1_Send_DMA_StartBuff(uint8_t *senddata, uint16_t datalen)
{
if (datalen > UART1_BUFF_TX_DMA_LEN)
{
return UART_TX_STA_DATALEN_TOOLONG;
}
if (usart1_TX_dma_BusySign == UART_TX_STA_TX_BUSY)
{
return UART_TX_STA_TX_BUSY;
}
// The Uart1 is not busy , good to send data
#if UART1_DMA_FREERTOS_SOUPPORT == PROJECT_CONFIG_ENABLE
taskENTER_CRITICAL();
#endif
// SIGN1_ON
memcpy(usart1_Tx_dma_buffer, senddata, sizeof(uint8_t) * datalen);
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4);
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_4, (uint32_t)usart1_Tx_dma_buffer); // Set The Memony Address
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, datalen);
UART1_TX_MODE_PUSH_PULL // UART TX DI DONG!//此设备要传输时,打开tx
LL_USART_EnableIT_TC( USART1 );//打开完成中断
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_4);
usart1_TX_dma_BusySign = UART_TX_STA_TX_BUSY;//标志dma正忙
// SIGN1_OFF
#if UART1_DMA_FREERTOS_SOUPPORT == PROJECT_CONFIG_ENABLE
taskEXIT_CRITICAL();
#endif
return UART_TX_STA_OK;
}
/**
* @brief UART1 TX StartSteam - With Not Buff(Need To keep DMA Buff vaild while transimitting)
* @param senddata
* @param datalen
*/
UART_TX_STA Uart1_Send_DMA_Start(uint8_t *senddata, uint16_t datalen)
{
if (datalen > UART1_BUFF_TX_DMA_LEN)
{
return UART_TX_STA_DATALEN_TOOLONG;
}
if (usart1_TX_dma_BusySign == UART_TX_STA_TX_BUSY)
{
return UART_TX_STA_TX_BUSY;
}
#if UART1_DMA_FREERTOS_SOUPPORT == PROJECT_CONFIG_ENABLE
taskENTER_CRITICAL();
#endif
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_4);
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_CHANNEL_4, (uint32_t)senddata); // Set The Memony Address
LL_DMA_SetDataLength(DMA1, LL_DMA_CHANNEL_4, datalen);
UART1_TX_MODE_PUSH_PULL // UART TX DI DONG!
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_4);
usart1_TX_dma_BusySign = UART_TX_STA_TX_BUSY;
#if UART1_DMA_FREERTOS_SOUPPORT == PROJECT_CONFIG_ENABLE
taskEXIT_CRITICAL();
#endif
return UART_TX_STA_OK;
}
inline bool Uart1_SendDMA_IsBusy(void)
{
return (usart1_TX_dma_BusySign == UART_TX_STA_TX_BUSY) ? true : false;
}
/* USER CODE END 1 */
... ...
#include "IMU_Pubilc.h"
state_t curAttitude = {0};
state_t tagAttitude = {0};
\ No newline at end of file
... ...
/*
* @Date: 2023-11-07 18:19:22
* @LastEditTime: 2024-02-06 10:16:08
* @FilePath: \IMU_T6_Single\IMU_About\Inc\MPU_Pubilc.h
* @Description:
*/
#ifndef __PUBLIC_H
#define __PUBLIC_H
#include "stdint.h"
#include "sensors_types.h"
#include "Project_Config.h"
//+++++++++++++++++++++++++++++++++++++++++++++++++++++MPU6500 Special Define Start
#pragma region
//____________________________ Setting PreDefine
#define MPU6500_PISET_ACC_RANGE_2G 0
#define MPU6500_PISET_ACC_RANGE_4G 1
#define MPU6500_PISET_ACC_RANGE_8G 2
#define MPU6500_PISET_ACC_RANGE_16G 3
#define MPU6500_PSET_ACC_RANGE_2G_LSB 16384.0f
#define MPU6500_PSET_ACC_RANGE_4G_LSB 8192.0f
#define MPU6500_PSET_ACC_RANGE_8G_LSB 4096.0f
#define MPU6500_PSET_ACC_RANGE_16G_LSB 2048.0f
#define MPU6500_PISET_GYR_RANGE_200 0
#define MPU6500_PISET_GYR_RANGE_500 1
#define MPU6500_PISET_GYR_RANGE_1000 2
#define MPU6500_PISET_GYR_RANGE_2000 3
#define MPU6500_PSET_GYR_RANGE_200_LSB 131.0f
#define MPU6500_PSET_GYR_RANGE_500_LSB 65.6f
#define MPU6500_PSET_GYR_RANGE_1000_LSB 32.8f
#define MPU6500_PSET_GYR_RANGE_2000_LSB 16.4f
//============================ Setting Start
#define MPU6500_SET_ACC_RANGE MPU6500_PISET_ACC_RANGE_4G
#define MPU6500_SET_GYR_RANGE MPU6500_PISET_GYR_RANGE_2000
//============================ Setting End
#pragma endregion
//+++++++++++++++++++++++++++++++++++++++++++++++++++++MPU6500 Special Define End
//=================================MPU Holder Define
#define HOLDER_PITCH MOTOR_HOLDER_AXIS_PITCH
#define HOLDER_ROLL MOTOR_HOLDER_AXIS_ROLL
#define HOLDER_YAW MOTOR_HOLDER_AXIS_YAW
#define IMU_XAXIS 0
#define IMU_YAXIS 1
#define IMU_ZAXIS 2
//________________IMU_Sense_RAWData_Short
#define IMU_DATA_In_ACCX_u16 0
#define IMU_DATA_In_ACCY_u16 1
#define IMU_DATA_In_ACCZ_u16 2
#define IMU_DATA_In_Temp_u16 3
#define IMU_DATA_In_GYRX_u16 4
#define IMU_DATA_In_GYRY_u16 5
#define IMU_DATA_In_GYRZ_u16 6
typedef struct
{
uint16_t accl_origin_x_u16;
uint16_t accl_origin_y_u16;
uint16_t accl_origin_z_u16;
uint16_t temperature_raw;
uint16_t gyro_origin_x_u16;
uint16_t gyro_origin_y_u16;
uint16_t gyro_origin_z_u16;
uint16_t reserve;
}IMU_RAWDATAu16_X8;
typedef union
{
uint16_t data[8];
IMU_RAWDATAu16_X8 data_s;
}IMU_Sense_RAWData_Short;
//________________IMU_Sense_RAWData
typedef struct
{
float accl_origin_x;
float accl_origin_y;
float accl_origin_z;
float temperature_raw;
float gyro_origin_x;
float gyro_origin_y;
float gyro_origin_z;
float reserve;
}IMU_RAWDATA_X8;
typedef union
{
float data[8];
IMU_RAWDATA_X8 data_s;
}IMU_Sense_RAWData;
//________________IMU_Sense_Read_ResultData
typedef struct {
Axis3f accData;
Axis3f gyroData;
float temperature;
}IMU_Sense_ResData;
//==================IMU_CRETIFY
typedef struct
{
int16_t accelData500Hz[3];
float accelTCBias[3]; //加速计校准结果
float gyroRTBias[3];
float gyroTCBias[3]; //陀螺仪校准结果
float accelOneG ; //1G的加速度
int16_t* orientationMatrix; //方向校准矩阵
} IMU_CALIBRATE;
// extern IMU_Sense_RAWData senser_datas;
extern IMU_CALIBRATE imu_cali ; //MPU校准信息结构体
//==================IMU_AHRS Result
typedef struct
{
uint32_t timestamp; /*时间戳*/
float roll;
float pitch;
float yaw;
} attitude_t;
struct vec3_s
{
uint32_t timestamp; /*时间戳*/
float x;
float y;
float z;
};
typedef struct vec3_s point_t;
typedef struct vec3_s velocity_t;
typedef struct vec3_s acc_t;
typedef struct
{
attitude_t attitude;
// attitude_t attitude_2;
// quaternion_t attitudeQuaternion;
// point_t position;
// velocity_t velocity;
acc_t acc;
// bool isRCLocked;
} state_t;
// Add for Motor side
extern state_t curAttitude ;
extern state_t tagAttitude ;
#endif
... ...
/*
* @Date: 2023-11-16 09:48:59
* @LastEditTime: 2024-01-08 15:21:16
* @FilePath: \IMU_T6_Single\IMU_About\Inc\sensors_types.h
* @Description:
*/
#ifndef __SENSORS_TYPES_H
#define __SENSORS_TYPES_H
typedef union
{
struct
{
int16_t x;
int16_t y;
int16_t z;
};
int16_t axis[3];
} Axis3i16;
typedef union
{
struct
{
int32_t x;
int32_t y;
int32_t z;
};
int32_t axis[3];
} Axis3i32;
typedef union
{
struct
{
int64_t x;
int64_t y;
int64_t z;
};
int64_t axis[3];
} Axis3i64;
typedef union
{
struct
{
float x;
float y;
float z;
};
float axis[3];
} Axis3f;
#endif /* __SENSORS_TYPES_H */
... ...
#include "crc16ibm.h"
//#include "Hex_and_Dex.h"
#include "string.h"
//#include "dji_logger.h"
uint8_t Buff_Compare(uint8_t *buff_1,uint8_t* buff_2,uint8_t BuffSize)
{
int i = 0;
for(i=0;i<BuffSize;i++)
{
if(buff_1[i]!=buff_2[i])
return 0 ;
}
return 1;
}
/*
功能: crc16校验
参数: 要校验的数组地址,
传入的数组长度
返回值:16位的校验数据
*/
uint16_t crc16_ibm(uint8_t *ptr,uint16_t len)
{
uint8_t i;
uint16_t crc = 0x00;
if (len == 0)
{
len = 1;
}
while(len--)
{
crc ^= *ptr;
for(i = 0;i < 8;i++)
{
if (crc & 1)
{
crc >>= 1;
crc ^= 0xA001;
}
else
{
crc >>= 1;
}
}
ptr++;
}
return crc;
}
void u16_2_u8(uint16_t *data,uint8_t *a)
{
*a = (*data) >> 8;
*(a+1) = (*data) & 0xff;
}
uint8_t Frame_Check(uint8_t* frame)
{
if(0x5A==*frame && 0x5A==*(frame+1) && 0x77==*(frame+2)) //帧头正确
{
if(0x00==*(frame+11)&&0x23==*(frame+12)) //校验位正确
return 1;
}
return 0;
}
//判断帧头和帧尾
//5B 5B 76 00 13 6E 2D 3D 37 45 00 23
uint8_t Frame1_Check(uint8_t *checkBuf, uint32_t bufLength)
{
if (bufLength < 12) // 检查缓冲区长度是否小于12
{
return 0;
}
uint8_t CompareBuf[4][3] = {{0x5A, 0x5A, 0x77}, {0x5B, 0x5B, 0x77}, {0x6A, 0x6A, 0x77}, {0x6B, 0x6B, 0x77},};
int i, j;
for (i = 0; i < 3; i++) {
int match = 1;
for (j = 0; j < 3; j++) {
if (checkBuf[j] == CompareBuf[i][j]) {
match = 0;
break;
}
}
if(match) {
return 0;
}
}
// 判断长度位
if (checkBuf[3] > 0xff || checkBuf[4] > 0xff) {
// printf("-----1-----\r\n");
return 0;
}
// 判断应答位
if (checkBuf[5] != 0x00 && checkBuf[5] != 0x01) {
// printf("-----2-----\r\n");
return 0;
}
// 判断应答位
if (checkBuf[6] != 0x00) {
// printf("-----3-----\r\n");
return 0;
}
// 判断帧尾
if (checkBuf[bufLength - 2] == 0x00 && checkBuf[bufLength - 1] == 0x23) {
return 1;
} else {
// printf("-----4-----\r\n");
return 0;
}
}
//uint8_t Length(uint8_t* frame)
//{
// *(frame+3)
//}
/*
功能:将u8数据转为u16数据
参数:u16数据的地址
u8数组的首地址
*/
//void u8_2_u16(uint16_t* data,uint8_t* b)
//{
// *data = (*b)<<8;
// *data |= *(b+1);
//}
... ...
#ifndef __CRC16_IBM_H
#define __CRC16_IBM_H
#include "stm32f1xx.h"
//将两位的 u8 转为一位的 u16
//void u8_2_u16(uint16_t *value, uint8_t * buff);
void u16_2_u8(uint16_t *data,uint8_t *a);
uint8_t Buff_Compare(uint8_t *buff_1,uint8_t* buff_2,uint8_t BuffSize);
//crc16校验
uint16_t crc16_ibm(uint8_t *ptr,uint16_t len);
uint8_t Frame_Check(uint8_t* frame);
uint8_t Frame1_Check(uint8_t *checkBuf, uint32_t bufLength);
#endif
... ...
#include "string.h"
//#include "FreeRTOS.h"
//#include "FreeRTOSConfig.h"
//#include "task.h"
//#include "dji_sdk_config.h"
#include "usart.h"
#include "util_md5.h"
//#include "dji_typedef.h"
//#include "dji_upgrade.h"
#include "data_processing.h"
#include "upgrade.h"
#include "crc16ibm.h"
#include "data_frame.h"
#include "stmflash.h"
/*------------------数据帧------------*/
// 6A 6A 77 00 1B 01 00 69 54 54 33 53 45 4E 46 31 38 33 30 30 30 43 46 35 31 00 23
uint8_t SN_Reply[27] = {0x5B, 0x5B, 0x77, 0x00, 0x1B, 0x01, 0x00, 0x6F, 0x57,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x23};
uint8_t SN_Reply1[27] = {0x5B, 0x5B, 0x77, 0x00, 0x1B, 0x01, 0x00, 0x50, 0x56,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x23}; // 序列号回复
uint8_t Dev_SN_Reply[28] = {0x5B, 0x5B, 0x77, 0x00, 0x1C, 0x01, 0x00, 0x50, 0x56,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x23}; // 序列号回复
uint8_t Version_Return[16] = {0x5B, 0x5B, 0x77, 0x00, 0x0F, 0x00, 0x00, 0x53, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23}; // 版本返回
uint8_t Dev_Ver_Return[17] = {0x5B, 0x5B, 0x77, 0x00, 0x10, 0x00, 0x00, 0x50, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23}; // 版本返回
uint8_t ConnetReque[12] = {0x5A, 0x5A, 0x77, 0x00, 0x0C, 0x01, 0x00, 0x50, 0x51, 0x00, 0x00, 0x23}; // 连接帧
uint8_t ConntAnswer[12] = {0x5B, 0x5B, 0x77, 0x00, 0x0C, 0x00, 0x00, 0x50, 0x51, 0x73, 0x00, 0x23}; // 应答帧
uint8_t Ret1[12] = {0x5b,0x5b,0x77,0x00,0x0c,0x00,0x00,0x51,0x01,0x00,0x00,0x23};//操作成功
uint8_t Ret2[12] = {0x5b,0x5b,0x77,0x00,0x0c,0x00,0x00,0x51,0xff,0x00,0x00,0x23};//操作失败
///*------------------数据帧------------*/
//extern uint8_t devConnetState; // 设备握手成功标志
//// 数据帧解析
//uint8_t DataFrame_Analyse(uint8_t *frame, uint16_t len)
//{
// uint8_t result = 0;
// uint8_t Read_Sn_Buff[20] = {0};//序列号
//
// // 连接帧
// uint8_t connectBuff[] = {0x5a, 0x5a, 0x77, 0x00, 0x0c, 0x01, 0x00, 0x50, 0x51, 0x00, 0x00, 0x23};
// uint8_t versionBuff[] = {0x5a, 0x5a, 0x77, 0x00, 0x0c, 0x01, 0x00, 0x53, 0xf1, 0x00, 0x00, 0x23};
// printf("Frame_data:\n");
// for (int i = 0; i < len; i++)
// {
// printf("%02X ", frame[i]);
// }
// printf("\r\n");
// if (Frame1_Check(frame, len)) // 检查是否符合帧协议
// {
// if (Buff_Compare(frame, ConnetReque, 12)) // 接收到请求
// {
// printf("连接帧\r\n");
// devConnetState = 1;
//// UART_Write(UART_NUM_1, ConntAnswer, 12); // 发送应答帧
// }
// if (frame[7] == 0x50)
// {
// switch (frame[8]) // 判断功能位
// {
// case 0x55: { //版本号
// switch (frame[9]) // 判断功能位
// {
// case 0x00: //查询单设备
//// Version_Return[9] = USER_FIRMWARE_MAJOR_VERSION;
//// Version_Return[10] = USER_FIRMWARE_MINOR_VERSION;
//// Version_Return[11] = USER_FIRMWARE_MODIFY_VERSION;
//// Version_Return[12] = USER_FIRMWARE_DEBUG_VERSION;
//// UART_Write(UART_NUM_1, Version_Return, sizeof(Version_Return));
//// printf("Version: %d.%d.%d.%d\n", USER_FIRMWARE_MAJOR_VERSION, USER_FIRMWARE_MINOR_VERSION, USER_FIRMWARE_MODIFY_VERSION, USER_FIRMWARE_DEBUG_VERSION);
// break;
// case 0x01: //查询全设备
//// Dev_Ver_Return[9] = 0x73;
//// Dev_Ver_Return[10] = USER_FIRMWARE_MAJOR_VERSION;
//// Dev_Ver_Return[11] = USER_FIRMWARE_MINOR_VERSION;
//// Dev_Ver_Return[12] = USER_FIRMWARE_MODIFY_VERSION;
//// Dev_Ver_Return[13] = USER_FIRMWARE_DEBUG_VERSION;
//// UART_Write(UART_NUM_1, Dev_Ver_Return, sizeof(Dev_Ver_Return));
//// printf("Version: %d.%d.%d.%d\n", USER_FIRMWARE_MAJOR_VERSION, USER_FIRMWARE_MINOR_VERSION, USER_FIRMWARE_MODIFY_VERSION, USER_FIRMWARE_DEBUG_VERSION);
// break;
// }
// }break;
// case 0x56: { //序列号
//// Read_SN_FromFlash(Read_Sn_Buff,SN_LEN);
// printf("查询序列号\r\n");
// switch (frame[9]) // 判断功能位
// {
// case 0x00: { //查询单设备
// for (int i = 0; i < 16; i++)
// {
// SN_Reply1[9 + i] = Read_Sn_Buff[i];
// printf("%c", Read_Sn_Buff[i]);
// }
// printf("\r\n");
//// UART_Write(UART_NUM_1, SN_Reply1, sizeof(SN_Reply1));
// }break;
//
// case 0x01: { //查询全设备
// Dev_SN_Reply[9] = 0x27;
//
// for (int i = 0; i < 16; i++)
// {
// Dev_SN_Reply[10 + i] = Read_Sn_Buff[i];
// printf("%c", Read_Sn_Buff[i]);
// }
// printf("\r\n");
//// UART_Write(UART_NUM_1, Dev_SN_Reply, sizeof(Dev_SN_Reply));
// }break;
// }
// }break;
// }
// }
//
// if (frame[7] == 0x53)
// {
// switch (frame[8]) // 判断功能位
// {
// case 0xF1: { //版本号
//// Version_Return[9] = USER_FIRMWARE_MAJOR_VERSION;
//// Version_Return[10] = USER_FIRMWARE_MINOR_VERSION;
//// Version_Return[11] = USER_FIRMWARE_MODIFY_VERSION;
//// Version_Return[12] = USER_FIRMWARE_DEBUG_VERSION;
//// UART_Write(UART_NUM_1, Version_Return, sizeof(Version_Return));
//// printf("Version: %d.%d.%d.%d\n", USER_FIRMWARE_MAJOR_VERSION, USER_FIRMWARE_MINOR_VERSION, USER_FIRMWARE_MODIFY_VERSION, USER_FIRMWARE_DEBUG_VERSION);
// }break;
// }
// }
// if (frame[7] == 0xA1) // 升级功能
// {
// switch (frame[8]) // 判断功能位
// {
// case 0x01: {// 准备串口升级
// printf("准备串口升级\r\n");
// result = UpgradePreparation();
// if (result != 0)
// {
// AnswerUpgradeFrame(0x01, 0x01);
// }
// }break;
// case 0x02: {// 固件校验MD5校验码
// printf("固件校验MD5校验码\r\n");
// UpgradeFileMD5Code_Get(frame, len);
// }break;
// case 0x03: {// 开始发送文件
// printf("开始发送文件\r\n");
// AnswerUpgradeFrame(0x03, 0x00);
// }break;
// case 0x04: {// 结束文件传输
// printf("结束文件传输\r\n");
// AnswerUpgradeFrame(0x04, 0x00);
// UpgradeFile_MD5Create();
// }break;
// case 0xF1: {// 定长文件数据
// printf("定长文件数据\r\n");
// result = UpgradeFile_Write(frame, len);
// if (result != 0) // 传输出错,提前结束文件传输
// {
// printf("传输出错\r\n");
// }
// }break;
// default:
// break;
// }
// }
// }
//}
... ...
#ifndef __DATA_FRAME_H_
#define __DATA_FRAME_H_
#include "stm32f1xx.h"
#include "protocolV1_1.h"
#endif
... ...
/**
该文件从串口缓冲区中读取数据放入缓冲区后并进行帧合法判断,帧数据处理在其它任务
*/
#include "string.h"
//#include "FreeRTOS.h"
//#include "FreeRTOSConfig.h"
//#include "task.h"
//#include "dji_logger.h"
#include "usart.h"
#include "data_processing.h"
uint32_t countTims = 0;//连接的时间
uint32_t errorTimes = 0;//错误时间
/**
@brief 判断帧头格式
@parame no
@return no
*/
uint8_t Is_Frame_Head(uint8_t *headBuf)
{
if (headBuf[0] == 0x5b && headBuf[1] == 0x5b && headBuf[2] == 0x77) // 当前为通用协议
return 1;
else if (headBuf[0] == 0x5a && headBuf[1] == 0x5a && headBuf[2] == 0x77) // 收到连接帧
return 2;
else if (headBuf[0] == 0x6b && headBuf[1] == 0x6b && headBuf[2] == 0x77) // 当前为私有协议
return 3;
else if (headBuf[0] == 0x6a && headBuf[1] == 0x6a && headBuf[2] == 0x77) // 当前为私有协议
return 4;
return 0;
}
/**
* @brief 数据出队解析任务
* @param pvParam 缓存队列
* @param s_getFrame 结构体
*/
#if 1
void Data_Analysis(void *pvParam)//处理升级串口来的数据
{
int16_t getLen = 0; // 获取到的数据长度
int16_t readLen = 1; // 需要读取的读取长度
uint16_t datalen = 0; // 数据长度
uint8_t Byte[512] = {0}; // 数据缓存数组
t_queue_info *framehandle = (t_queue_info *)pvParam; // 强制类型转换为队列信息结构体指针
while(1)
{
getLen = 0;
memset(Byte, 0x00, sizeof(Byte)); // 清空数据缓存
// getLen = UART_Read(UART_NUM_1, Byte, readLen);//从串口缓冲区
if(getLen > 0)//获取到数据存放在环形缓冲区中
{
memcpy(&framehandle->frameinfo.buff[framehandle->frameinfo.count], Byte, getLen); // 数据存入缓存
framehandle->frameinfo.count += getLen; // 计数增加
if(datalen == 0)//当前帧未检查,开始检查
{
if(framehandle->frameinfo.count >= 5)//检查当前是否满足进行帧检查条件
{
if (Is_Frame_Head(framehandle->frameinfo.buff) == 0) // 检测帧头,帧头不对则将数据丢弃
{
printf("Discard the error header\r\n");
memcpy(&framehandle->frameinfo.buff[0], &framehandle->frameinfo.buff[1], framehandle->frameinfo.count);
framehandle->frameinfo.count--;
continue;
}else//帧头正常才进行帧长度计算
{
datalen = (framehandle->frameinfo.buff[3] * 256) + framehandle->frameinfo.buff[4];// 生成数据长度
if (datalen > 512)
goto error;
}
}
}
else
{
readLen = datalen - getLen - 5;//计算下一次读取的数据
if (readLen < 1)
readLen = 1;
if (framehandle->frameinfo.count >= datalen)
{
// 判断帧尾
if (framehandle->frameinfo.buff[datalen - 2] == 0x00 && framehandle->frameinfo.buff[datalen - 1] == 0x23)
{
printf("a frame\r\n");
framehandle->frameinfo.flag = 1;
datalen = 0;
readLen = 1;
countTims++;
}
else
goto error;
}
}
}
continue;//没有报错直接开始下一次循环
error:
{
printf("c = %d e = %d\r\n", countTims, errorTimes);
errorTimes++;
readLen = 1;
datalen = 0;
framehandle->frameinfo.count = 0;
memset(framehandle->frameinfo.buff, 0x00, sizeof(framehandle->frameinfo.buff));
framehandle->frameinfo.flag = 0;
}
}
}
#else
void Data_Analysis(void *pvParam)
{
int16_t getLen = 0; // 获取长度
uint16_t datalen = 0; // 数据长度
int16_t readLen = 1; // 读取长度
uint8_t Byte[512] = {0}; // 数据缓存数组
t_queue_info *framehandle = (t_queue_info *)pvParam; // 强制类型转换为队列信息结构体指针
printf("--------------Data_Analysis------------\r\n");
while (1)
{
getLen = 0;
memset(Byte, 0x00, sizeof(Byte)); // 清空数据缓存
if (framehandle->frameinfo.flag == 0) // 空闲状态
{
getLen = UART_Read(UART_NUM_1, Byte, readLen);//从串口缓冲区
if (getLen > 0) // 队列非空
{
memcpy(&framehandle->frameinfo.buff[framehandle->frameinfo.count], Byte, getLen); // 数据存入缓存
framehandle->frameinfo.count += getLen; // 计数增加
if (framehandle->frameinfo.count <= 5)
{
if (framehandle->frameinfo.count == 3)
{
// 检测帧头,帧头不对则将数据丢弃
if (Is_Frame_Head(framehandle->frameinfo.buff) == 0)
{
printf("------------Is_Frame_Head ok------------\r\n");
memcpy(&framehandle->frameinfo.buff[0], &framehandle->frameinfo.buff[1], 2);
framehandle->frameinfo.count--;
continue;
}
}
if (framehandle->frameinfo.count == 5)
{
// 生成数据长度
datalen = (framehandle->frameinfo.buff[3] * 256) + framehandle->frameinfo.buff[4];
if (datalen > 512)
goto errorloop;
}
}
else
{
readLen = datalen - getLen - 5;
if (readLen < 1)
readLen = 1;
if (framehandle->frameinfo.count >= datalen)
{
// 判断帧尾
if (framehandle->frameinfo.buff[datalen - 2] == 0x00 && framehandle->frameinfo.buff[datalen - 1] == 0x23)
{
printf("a frame\r\n");
framehandle->frameinfo.flag = 1;
datalen = 0;
readLen = 1;
countTims++;
// 清空缓存
// framehandle->frameinfo.count = 0;
// memset(framehandle->frameinfo.buff, 0x00, sizeof(framehandle->frameinfo.buff));
// framehandle->frameinfo.flag = 0;
}
else
goto errorloop;
}
}
}
}
// else
// {
// printf("c = %d e = %d\r\n", countTims, errorTimes);
// vTaskDelay(1000);
// }
continue;
errorloop:
printf("c = %d e = %d\r\n", countTims, errorTimes);
errorTimes++;
readLen = 1;
datalen = 0;
framehandle->frameinfo.count = 0;
memset(framehandle->frameinfo.buff, 0x00, sizeof(framehandle->frameinfo.buff));
framehandle->frameinfo.flag = 0;
}
}
#endif
/**
// * @brief 数据出队解析
// * @param 缓存队列
// * @param s_getFrame 结构体
// */
// void Data_Analysis(ringBuf_t* ringBuff,s_getFrame* framehandle)
//{
// int16_t getLen = 0;
// uint16_t datalen = 0;
// uint16_t readLen = 1;
// uint8_t Byte[512] = {0};
//
// while(1)
// {
// getLen = 0;
// memset(Byte,0x00,sizeof(Byte));
//
// if(framehandle->flag==0) //空闲状态
// getLen = ringBufRead(ringBuff,(char*)Byte,readLen); //读出队列, 获取到帧头和长度位之前每次读一个字节,获取长度位之后读取多个字节
//
// if(getLen > 0) //队列不为空
// {
// memcpy(&framehandle->buff[framehandle->count],Byte,getLen); //数据转存
//
// framehandle->count+=getLen; //计数增加
//
// if(framehandle->count<=5) //帧头和长度位检测
// {
// if(framehandle->count==3)
// {
// if(Is_Frame_Head(framehandle->buff)==0) //没接收到帧头
// {
// for(int8_t i=0;i<2;i++)
// framehandle->buff[i] = framehandle->buff[i+1]; //舍弃前一位数据
// framehandle->count--;
// continue;
// }
// }
//
// if(framehandle->count==5) //接收完长度位后生成长度位
// datalen = (framehandle->buff[3]*256)+framehandle->buff[4];
// }
// else
// {
// readLen = datalen - getLen - 5; //接收完长度位之后,更改读每次读队列的长度
//
// if(framehandle->count>=datalen)
// {
// if(framehandle->buff[datalen-2]==0x00&&framehandle->buff[datalen-1]==0x23)
// {
// countTims++;
//// framehandle->flag = 1; //接收标志 置 1 ,初步判断接收满一帧
// datalen = 0;
// readLen = 1;
// framehandle->count = 0;
// memset(framehandle->buff,0x00,sizeof(framehandle->buff));
// framehandle->flag = 0;
// }
// else //帧尾检测失败
// {
// errorTimes++;
// readLen = 1;
// datalen = 0;
// framehandle->count = 0;
// memset(framehandle->buff,0x00,sizeof(framehandle->buff));
// framehandle->flag = 0;
// }
// }
// }
//
// }
// else
// {
// vTaskDelay(100);
// }
// }
//}
... ...
#ifndef __DATA_PROCESSING_H_
#define __DATA_PROCESSING_H_
#include "stm32f1xx.h"
typedef struct {
uint8_t flag;
uint8_t buff[512];
uint16_t count;
} t_get_frame;
//ضϢ
typedef struct {
t_get_frame frameinfo;
} t_queue_info;
void Data_Analysis(void* pvParam);
extern uint32_t countTims ;
extern uint32_t errorTimes;
#endif
... ...
#ifndef __MY_TYPEDEF_H_
#define __MY_TYPEDEF_H_
#include "stm32f1xx.h"
typedef struct {
uint8_t majorVersion; /*!< The major version of firmware, the range is 0 ~ 99. */
uint8_t minorVersion; /*!< The minor version of firmware, the range is 0 ~ 99. */
uint8_t modifyVersion; /*!< The modify version of firmware, the range is 0 ~ 99. */
uint8_t debugVersion; /*!< The debug version of firmware, the range is 0 ~ 99. */
} T_FirmwareVersion;
///////////////////////////////////
typedef enum {
UPGRADE_END_STATE_SUCCESS = 1, /*!< Upgrade success. */
UPGRADE_END_STATE_UNKNOWN_ERROR = 2, /*!< Upgrade failure due to unknown reason. */
} E_UpgradeEndState;
typedef struct {
E_UpgradeEndState upgradeEndState; /*!< The upgrade end state */
} T_UpgradeEndInfo;
typedef struct {
uint32_t upgradeRebootKey;
T_UpgradeEndInfo upgradeEndInfo;
} T_UpgradeRebootParam;
typedef struct {
uint32_t fileSize; /*! The size of file. */
char fileName[256]; /*! The name of file. */
} T_UpgradeFileInfo;
typedef enum{
Uart_Port = 0,
Usb_Port,
} Port_t;
typedef enum{
T160 = 21,
T90,
T60,
T60S,
T30,
N3,
T30S
}E_Light;
typedef enum{
Upgrade_Stage_IDEL = 0,
Upgrade_Stage_Ready = 1,
Upgrade_Stage_GetMd5 = 2,
Upgrade_Stage_OnGoing = 3,
Upgrade_Stage_End = 4,
Upgrade_Stage_Reboot = 5,
Upgrade_Stage_Error = 6,
} E_UpgradeState;
typedef struct {
uint32_t state;
T_UpgradeEndInfo upgradeEndInfo;
uint32_t filesize;
uint8_t md5code[32];
}myUpgrade_t;
#endif
... ...