Compare commits

...

12 Commits

Author SHA1 Message Date
bmy
5003e2df6f pref: 增加自检闪灯动作 2024-08-03 12:28:58 +08:00
bmy
f2caaae8c8 pref: 为三个方向设置独立的标志位
保证移动距离完整,防止下发某一方向速度指令时,导致其他方向无法正常退出距离控制模式的问题
2024-07-28 16:24:31 +08:00
bmy
73b2e1a7e9 更新轴距标定值 2024-07-05 08:15:05 +08:00
bmy
dc858825ed feat: 增加转塔电机接口 2024-06-14 17:43:50 +08:00
bmy
26ae090e72 fix: 修改灯条与蜂鸣器输出 2024-06-05 11:11:47 +08:00
bmy
02b2b3ccc9 fix: 修改上次提交注释和测试代码 2024-06-05 10:47:54 +08:00
bmy
fc62db026b feat: 移植到 BC2C 新板 2024-06-05 01:05:23 +08:00
bmy
92395b9bb7 feat: 增加灯条与蜂鸣器接口 2024-06-02 18:25:28 +08:00
bmy
1ddec6d054 Merge branch 'main' of http://git.brisky.space/btl143/BC1C-firmware 2024-06-02 17:29:50 +08:00
bmy
0517164e42 feat: 接口更新 2024-06-02 17:01:35 +08:00
bmy
e7ffb29a69 Merge branch 'main' of http://81.70.22.205/btl143/BC1C-firmware 2024-05-19 16:07:33 +08:00
bmy
9abfdc4243 暂存 2024-05-19 16:07:29 +08:00
16 changed files with 433 additions and 669 deletions

View File

@@ -0,0 +1,29 @@
{
"version": 5,
"beforeBuildTasks": [],
"afterBuildTasks": [],
"global": {
"$float-abi-type": "softfp",
"output-debug-info": "enable",
"misc-control": "--specs=nosys.specs --specs=nano.specs"
},
"c/cpp-compiler": {
"language-c": "c11",
"language-cpp": "c++11",
"optimization": "level-debug",
"warnings": "all-warnings",
"one-elf-section-per-function": true,
"one-elf-section-per-data": true,
"C_FLAGS": "",
"CXX_FLAGS": ""
},
"asm-compiler": {
"ASM_FLAGS": ""
},
"linker": {
"output-format": "elf",
"remove-unused-input-sections": true,
"LD_FLAGS": "",
"LIB_FLAGS": "-lm"
}
}

View File

@@ -0,0 +1,31 @@
##########################################################################################
# Append Compiler Options For Source Files
#
# syntax:
# <your matcher expr>: <your compiler command>
#
# examples:
# 'main.cpp': --cpp11 -Og ...
# 'src/*.c': -gnu -O2 ...
# 'src/lib/**/*.cpp': --cpp11 -Os ...
# '!Application/*.c': -O0
# '**/*.c': -O2 -gnu ...
#
# For more syntax, please refer to: https://www.npmjs.com/package/micromatch
#
##########################################################################################
version: '1.0'
#
# for source files with filesystem paths
#
files:
# './test/**/*.c': --c99
#
# for source files with virtual paths
#
virtualPathFiles:
# 'virtual_folder/**/*.c': --c99

View File

@@ -1,11 +1,9 @@
{ {
"name": "BC1C", "name": "BC2C",
"type": "ARM", "type": "ARM",
"dependenceList": [], "dependenceList": [],
"srcDirs": [ "srcDirs": [
".eide/deps",
"3rd-part", "3rd-part",
"middlewares",
"app", "app",
"libraries/drivers", "libraries/drivers",
"project", "project",
@@ -23,7 +21,7 @@
"uid": "4b98bd91695978f42b405679968f1016" "uid": "4b98bd91695978f42b405679968f1016"
}, },
"targets": { "targets": {
"BC1C": { "BC2C": {
"excludeList": [ "excludeList": [
"project/MDK_V5", "project/MDK_V5",
"libraries/cmsis/cm4/device_support/startup/iar", "libraries/cmsis/cm4/device_support/startup/iar",
@@ -33,7 +31,7 @@
"compileConfig": { "compileConfig": {
"cpuType": "Cortex-M4", "cpuType": "Cortex-M4",
"floatingPointHardware": "single", "floatingPointHardware": "single",
"scatterFilePath": "${workspaceFolder}\\libraries\\cmsis\\cm4\\device_support\\startup\\gcc\\linker\\AT32F403AxC_FLASH.ld", "scatterFilePath": "${workspaceFolder}\\libraries\\cmsis\\cm4\\device_support\\startup\\gcc\\linker\\AT32F403AxG_FLASH.ld",
"useCustomScatterFile": true, "useCustomScatterFile": true,
"storageLayout": { "storageLayout": {
"RAM": [], "RAM": [],
@@ -69,14 +67,12 @@
"libraries/cmsis/cm4/device_support", "libraries/cmsis/cm4/device_support",
"project/inc", "project/inc",
".cmsis/include", ".cmsis/include",
".eide/deps",
"3rd-part/dwt_delay", "3rd-part/dwt_delay",
"3rd-part/lwprintf", "3rd-part/lwprintf",
"app", "app",
"3rd-part/lwrb" "3rd-part/lwrb"
], ],
"libList": [], "libList": [],
"sourceDirList": [],
"defineList": [ "defineList": [
"AT32F403ARCT7", "AT32F403ARCT7",
"USE_STDPERIPH_DRIVER", "USE_STDPERIPH_DRIVER",
@@ -85,5 +81,5 @@
} }
} }
}, },
"version": "3.3" "version": "3.4"
} }

View File

@@ -1,3 +1,3 @@
{ {
"sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\BC1C\\compile_commands.json" "sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\BC2C\\compile_commands.json"
} }

View File

@@ -2,8 +2,8 @@
<Root> <Root>
<MCUInfo> <MCUInfo>
<MCUSerials>AT32F403A</MCUSerials> <MCUSerials>AT32F403A</MCUSerials>
<MCUName>AT32F403ARCT7</MCUName> <MCUName>AT32F403ACGT7</MCUName>
<MCUPackage>LQFP64</MCUPackage> <MCUPackage>LQFP48</MCUPackage>
</MCUInfo> </MCUInfo>
<CAN1> <CAN1>
<Mode> <Mode>
@@ -11,9 +11,9 @@
</Mode> </Mode>
<Parameters> <Parameters>
<ParametersSub name="BaudRate" value="500"/> <ParametersSub name="BaudRate" value="500"/>
<ParametersSub name="Sample_Point" value="90.0"/> <ParametersSub name="Sample_Point" value="87.5"/>
<ParametersSub name="BaudRate_Division" value="24"/> <ParametersSub name="BaudRate_Division" value="30"/>
<ParametersSub name="BTS1" value="CAN_BTS1_8TQ"/> <ParametersSub name="BTS1" value="CAN_BTS1_6TQ"/>
<ParametersSub name="BTS2" value="CAN_BTS2_1TQ"/> <ParametersSub name="BTS2" value="CAN_BTS2_1TQ"/>
<ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/> <ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/>
</Parameters> </Parameters>
@@ -24,9 +24,9 @@
</Mode> </Mode>
<Parameters> <Parameters>
<ParametersSub name="BaudRate" value="500"/> <ParametersSub name="BaudRate" value="500"/>
<ParametersSub name="Sample_Point" value="90.0"/> <ParametersSub name="Sample_Point" value="87.5"/>
<ParametersSub name="BaudRate_Division" value="24"/> <ParametersSub name="BaudRate_Division" value="30"/>
<ParametersSub name="BTS1" value="CAN_BTS1_8TQ"/> <ParametersSub name="BTS1" value="CAN_BTS1_6TQ"/>
<ParametersSub name="BTS2" value="CAN_BTS2_1TQ"/> <ParametersSub name="BTS2" value="CAN_BTS2_1TQ"/>
<ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/> <ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/>
</Parameters> </Parameters>
@@ -55,24 +55,6 @@
<ModeSub name="Debug interface" value="SWD"/> <ModeSub name="Debug interface" value="SWD"/>
</Mode> </Mode>
</DEBUG> </DEBUG>
<I2C1>
<Mode>
<ModeSub name="I2C" value="I2C"/>
</Mode>
<Parameters>
<ParametersSub name="DualAddressMode" value="DISABLE"/>
<ParametersSub name="GeneralCallMode" value="FALSE"/>
</Parameters>
</I2C1>
<I2C2>
<Mode>
<ModeSub name="I2C" value="I2C"/>
</Mode>
<Parameters>
<ParametersSub name="DualAddressMode" value="DISABLE"/>
<ParametersSub name="GeneralCallMode" value="FALSE"/>
</Parameters>
</I2C2>
<TMR6> <TMR6>
<Mode> <Mode>
<ModeSub name="Activated" value="TRUE"/> <ModeSub name="Activated" value="TRUE"/>
@@ -84,10 +66,6 @@
</TMR6> </TMR6>
<TMR8> <TMR8>
<Mode> <Mode>
<ModeSub name="Channel1 mode" value="Output_CH1"/>
<ModeSub name="Channel2 mode" value="Output_CH2"/>
<ModeSub name="Channel3 mode" value="Output_CH3"/>
<ModeSub name="Channel4 mode" value="Output_CH4"/>
<ModeSub name="Activated" value="TRUE"/> <ModeSub name="Activated" value="TRUE"/>
</Mode> </Mode>
<Parameters> <Parameters>
@@ -95,24 +73,6 @@
<ParametersSub name="Period" value="2399"/> <ParametersSub name="Period" value="2399"/>
</Parameters> </Parameters>
</TMR8> </TMR8>
<TMR11>
<Mode>
<ModeSub name="Channel1 mode" value="Output_CH1"/>
<ModeSub name="Activated" value="TRUE"/>
</Mode>
<Parameters>
<ParametersSub name="DividerValue" value="99"/>
<ParametersSub name="Period" value="2399"/>
<ParametersSub name="OCMode_1" value="TMR_OUTPUT_CONTROL_PWM_MODE_A"/>
</Parameters>
</TMR11>
<TMR12>
<Mode>
<ModeSub name="Channel1 mode" value="Output_CH1"/>
<ModeSub name="Channel2 mode" value="Output_CH2"/>
<ModeSub name="Activated" value="TRUE"/>
</Mode>
</TMR12>
<USART1> <USART1>
<Mode> <Mode>
<ModeSub name="Mode" value="Asynchronous"/> <ModeSub name="Mode" value="Asynchronous"/>
@@ -130,18 +90,12 @@
</USART3> </USART3>
<NVIC> <NVIC>
<SysTick_Handler>0;0;0</SysTick_Handler> <SysTick_Handler>0;0;0</SysTick_Handler>
<PVM_IRQHandler>0;0;0</PVM_IRQHandler>
<FLASH_IRQHandler>0;0;0</FLASH_IRQHandler> <FLASH_IRQHandler>0;0;0</FLASH_IRQHandler>
<CRM_IRQHandler>0;0;0</CRM_IRQHandler> <CRM_IRQHandler>0;0;0</CRM_IRQHandler>
<USBFS_H_CAN1_TX_IRQHandler>0;0;0</USBFS_H_CAN1_TX_IRQHandler> <USBFS_H_CAN1_TX_IRQHandler>0;0;0</USBFS_H_CAN1_TX_IRQHandler>
<USBFS_L_CAN1_RX0_IRQHandler>1;0;0</USBFS_L_CAN1_RX0_IRQHandler> <USBFS_L_CAN1_RX0_IRQHandler>1;0;0</USBFS_L_CAN1_RX0_IRQHandler>
<CAN1_RX1_IRQHandler>0;0;0</CAN1_RX1_IRQHandler> <CAN1_RX1_IRQHandler>0;0;0</CAN1_RX1_IRQHandler>
<CAN1_SE_IRQHandler>0;0;0</CAN1_SE_IRQHandler> <CAN1_SE_IRQHandler>0;0;0</CAN1_SE_IRQHandler>
<TMR1_TRG_HALL_TMR11_IRQHandler>0;0;0</TMR1_TRG_HALL_TMR11_IRQHandler>
<I2C1_EVT_IRQHandler>0;0;0</I2C1_EVT_IRQHandler>
<I2C1_ERR_IRQHandler>0;0;0</I2C1_ERR_IRQHandler>
<I2C2_EVT_IRQHandler>0;0;0</I2C2_EVT_IRQHandler>
<I2C2_ERR_IRQHandler>0;0;0</I2C2_ERR_IRQHandler>
<USART1_IRQHandler>1;1;0</USART1_IRQHandler> <USART1_IRQHandler>1;1;0</USART1_IRQHandler>
<USART2_IRQHandler>1;1;0</USART2_IRQHandler> <USART2_IRQHandler>1;1;0</USART2_IRQHandler>
<USART3_IRQHandler>1;1;0</USART3_IRQHandler> <USART3_IRQHandler>1;1;0</USART3_IRQHandler>
@@ -157,11 +111,11 @@
</NVIC> </NVIC>
<ClockConfiguration> <ClockConfiguration>
<rtcsel>0</rtcsel> <rtcsel>0</rtcsel>
<hext>8.000000</hext> <hext>16.000000</hext>
<hextdiv>2</hextdiv> <hextdiv>2</hextdiv>
<pllhextdiv>0</pllhextdiv> <pllhextdiv>1</pllhextdiv>
<pllrcs>1</pllrcs> <pllrcs>0</pllrcs>
<pllmult>60</pllmult> <pllmult>30</pllmult>
<sclkselect>1</sclkselect> <sclkselect>1</sclkselect>
<ahbdiv>1</ahbdiv> <ahbdiv>1</ahbdiv>
<apb1div>2</apb1div> <apb1div>2</apb1div>
@@ -176,44 +130,23 @@
<PINInfo> <PINInfo>
<PinSub pinname="PD0/HEXT_IN" signalname="CRM_HEXT_IN" signaltype="2"/> <PinSub pinname="PD0/HEXT_IN" signalname="CRM_HEXT_IN" signaltype="2"/>
<PinSub pinname="PD1/HEXT_OUT" signalname="CRM_HEXT_OUT" signaltype="2"/> <PinSub pinname="PD1/HEXT_OUT" signalname="CRM_HEXT_OUT" signaltype="2"/>
<PinSub pinname="PC0" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PC1" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PC2" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PC3" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PA2" signalname="USART2_TX" signaltype="2"/> <PinSub pinname="PA2" signalname="USART2_TX" signaltype="2"/>
<PinSub pinname="PA3" signalname="USART2_RX" signaltype="2"/> <PinSub pinname="PA3" signalname="USART2_RX" signaltype="2"/>
<PinSub pinname="PA4" signalname="GPIO_Input" signaltype="3"/> <PinSub pinname="PB10" signalname="USART3_TX" signaltype="2"/>
<PinSub pinname="PA5" signalname="GPIO_Input" signaltype="3"/> <PinSub pinname="PB11" signalname="USART3_RX" signaltype="2"/>
<PinSub pinname="PA6" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PA7" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PB10" signalname="I2C2_SCL" signaltype="2"/>
<PinSub pinname="PB11" signalname="I2C2_SDA" signaltype="2"/>
<PinSub pinname="PB12" signalname="CAN2_RX" signaltype="2"/> <PinSub pinname="PB12" signalname="CAN2_RX" signaltype="2"/>
<PinSub pinname="PB13" signalname="CAN2_TX" signaltype="2"/> <PinSub pinname="PB13" signalname="CAN2_TX" signaltype="2"/>
<PinSub pinname="PB14" signalname="TMR12_CH1" signaltype="2"/>
<PinSub pinname="PB15" signalname="TMR12_CH2" signaltype="2"/>
<PinSub pinname="PC6" signalname="TMR8_CH1" signaltype="2"/>
<PinSub pinname="PC7" signalname="TMR8_CH2" signaltype="2"/>
<PinSub pinname="PC8" signalname="TMR8_CH3" signaltype="2"/>
<PinSub pinname="PC9" signalname="TMR8_CH4" signaltype="2"/>
<PinSub pinname="PA9" signalname="USART1_TX" signaltype="2"/> <PinSub pinname="PA9" signalname="USART1_TX" signaltype="2"/>
<PinSub pinname="PA10" signalname="USART1_RX" signaltype="2"/> <PinSub pinname="PA10" signalname="USART1_RX" signaltype="2"/>
<PinSub pinname="PA11" signalname="CAN1_RX" signaltype="2"/> <PinSub pinname="PA11" signalname="CAN1_RX" signaltype="2"/>
<PinSub pinname="PA12" signalname="CAN1_TX" signaltype="2"/> <PinSub pinname="PA12" signalname="CAN1_TX" signaltype="2"/>
<PinSub pinname="PA13" signalname="DEBUG_JTMS_SWDIO" signaltype="2"/> <PinSub pinname="PA13" signalname="DEBUG_JTMS_SWDIO" signaltype="2"/>
<PinSub pinname="PA14" signalname="DEBUG_JTCK_SWCLK" signaltype="2"/> <PinSub pinname="PA14" signalname="DEBUG_JTCK_SWCLK" signaltype="2"/>
<PinSub pinname="PC10" signalname="USART3_TX" signaltype="2"/> <PinSub pinname="PB6" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PC11" signalname="USART3_RX" signaltype="2"/> <PinSub pinname="PB7" signalname="GPIO_Output" signaltype="3"/>
<PinSub pinname="PD2" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PB3" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PB4" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PB5" signalname="GPIO_Input" signaltype="3"/>
<PinSub pinname="PB6" signalname="I2C1_SCL" signaltype="2"/>
<PinSub pinname="PB7" signalname="I2C1_SDA" signaltype="2"/>
<PinSub pinname="PB9" signalname="TMR11_CH1" signaltype="3"/>
</PINInfo> </PINInfo>
<ProjectInfomation> <ProjectInfomation>
<ProjectName>BC1C</ProjectName> <ProjectName>BC2C</ProjectName>
<ProjectLocation>C:/Users/ForgotDoge/Desktop/BC2024/firmware</ProjectLocation> <ProjectLocation>C:/Users/ForgotDoge/Desktop/BC2024/firmware</ProjectLocation>
<ToolchainIDE>MDK_V5</ToolchainIDE> <ToolchainIDE>MDK_V5</ToolchainIDE>
<KeepUserCode>true</KeepUserCode> <KeepUserCode>true</KeepUserCode>

View File

@@ -31,7 +31,7 @@
"titleBar.activeBackground": "#693002", "titleBar.activeBackground": "#693002",
"titleBar.activeForeground": "#FFF9F4" "titleBar.activeForeground": "#FFF9F4"
}, },
"cortex-debug.variableUseNaturalFormat": true "cortex-debug.variableUseNaturalFormat": false
}, },
"extensions": { "extensions": {
} }

View File

@@ -3,6 +3,7 @@
#include "lwprintf.h" #include "lwprintf.h"
#include "by_frame.h" #include "by_frame.h"
#include "by_motion.h" #include "by_motion.h"
#include "by_can.h"
void by_messy_init(void) void by_messy_init(void)
{ {
@@ -12,6 +13,9 @@ void by_messy_init(void)
void by_messy_loop(void) void by_messy_loop(void)
{ {
uint8_t cmd = 0; uint8_t cmd = 0;
uint8_t buff_t_u8[8] = {0};
uint16_t buff_t_u16[4] = {0};
float buff_t_f[2] = {0};
uint32_t buff[BY_FRAME_DATA_NUM] = {0}; uint32_t buff[BY_FRAME_DATA_NUM] = {0};
if (!by_frame_parse(&cmd, buff)) { if (!by_frame_parse(&cmd, buff)) {
@@ -21,50 +25,146 @@ void by_messy_loop(void)
switch (cmd) { switch (cmd) {
case 0x31: // 设置速度 x case 0x31: // 设置速度 x
memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x)); memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x));
by_motion_set_mode(0); by_motion_set_mode_x(0);
break; break;
case 0x32: // 设置速度 y case 0x32: // 设置速度 y
memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y)); memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y));
by_motion_set_mode(0); by_motion_set_mode_y(0);
break; break;
case 0x33: // 设置速度 omega case 0x33: // 设置速度 omega
memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w)); memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w));
by_motion_set_mode(0); by_motion_set_mode_w(0);
break; break;
case 0x34: // 设置移动距离 x case 0x34: // 设置移动距离 x
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x)); memcpy(&motion_speed_struct.v_x, buff, sizeof(motion_speed_struct.v_x));
by_motion_set_mode(1); by_motion_set_mode_x(1);
motion_time_struct.t_x += buff[1]; motion_time_struct.t_x += buff[1];
break; break;
case 0x35: // 设置移动距离 y case 0x35: // 设置移动距离 y
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y)); memcpy(&motion_speed_struct.v_y, buff, sizeof(motion_speed_struct.v_y));
by_motion_set_mode(1); by_motion_set_mode_y(1);
motion_time_struct.t_y += buff[1]; motion_time_struct.t_y += buff[1];
break; break;
case 0x36: // 设置旋转角度 omega case 0x36: // 设置旋转角度 omega
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w)); memcpy(&motion_speed_struct.v_w, buff, sizeof(motion_speed_struct.v_w));
by_motion_set_mode(1); by_motion_set_mode_w(1);
motion_time_struct.t_w += buff[1]; motion_time_struct.t_w += buff[1];
break; break;
case 0x41: // 设置转台 x 轴复位 case 0x41: // 设置转台 x 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
buff_t_u8[0] = 0;
buff_t_u8[1] = 1; // 复位模式下速度设置无效
buff_t_f[0] = 0.0;
memcpy(&buff_t_u8[2], &buff_t_f[0], sizeof(buff_t_f[0]));
by_can_send_stdd(0x008, buff_t_u8, 1, 100);
break; break;
case 0x42: // 设置转台 z 轴复位 case 0x42: // 设置转台 z 轴复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
buff_t_u8[0] = 0;
buff_t_u8[1] = 5; // 设置复位速度 5
by_can_send_stdd(0x008, buff_t_u8, 1, 100);
break; break;
case 0x43: // 设置转台末端执行器复位 case 0x43: // 设置转台末端执行器复位
by_frame_send(cmd, buff); // 正确接收后直接返回原文 by_frame_send(cmd, buff); // 正确接收后直接返回原文
buff_t_u8[0] = 0;
by_can_send_stdd(0x009, buff_t_u8, 1, 100);
break;
case 0x44: // 设置 x 轴位置 (增量)
by_frame_send(cmd, buff);
buff_t_u8[0] = 1; // 增量模式
buff_t_u8[1] = (uint8_t)(buff[0] & 0xFF); // 拷贝设置速度
memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
by_can_send_stdd(0x006, buff_t_u8, 8, 100);
break;
case 0x46: // 设置 z 轴位置 (增量)
by_frame_send(cmd, buff);
buff_t_u8[0] = 1; // 增量模式
buff_t_u8[1] = (uint8_t)(buff[0] & 0xFF); // 拷贝设置速度
memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
by_can_send_stdd(0x008, buff_t_u8, 8, 100);
break;
case 0x47: // 设置 x 轴位置 (绝对)
by_frame_send(cmd, buff);
buff_t_u8[0] = 0; // 位置模式
buff_t_u8[1] = (uint8_t)(buff[0] & 0xFF); // 拷贝设置速度
memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
by_can_send_stdd(0x006, buff_t_u8, 8, 100);
break;
case 0x49: // 设置 z 轴位置 (绝对)
by_frame_send(cmd, buff);
buff_t_u8[0] = 0; // 增量模式
buff_t_u8[1] = (uint8_t)(buff[0] & 0xFF); // 拷贝设置速度
memcpy(&buff_t_u8[2], &buff[1], sizeof(float)); // 拷贝设置距离
by_can_send_stdd(0x008, buff_t_u8, 8, 100);
break;
case 0x50: // 设置夹爪摇臂角度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x009, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x51: // 设置夹爪角度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x00A, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x52: // 设置摄像头角度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x00B, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x53: // 设置顶端抓取机构角度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x00C, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x54: // 设置托盘角度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x00D, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x55: // 设置转轴速度
by_frame_send(cmd, buff);
memcpy(buff_t_f, buff, sizeof(float));
buff_t_u16[0] = (int16_t)(buff_t_f[0]);
by_can_send_stdd(0x00E, (uint8_t *)&buff_t_u16, 2, 100);
break;
case 0x61: // 设置闪灯
by_frame_send(cmd, buff);
memcpy(buff_t_u8, buff, sizeof(buff[1]));
gpio_bits_write(GPIOB, GPIO_PINS_6, buff_t_u8[0] ? TRUE : FALSE); // 灯条
break;
case 0x62: // 设置蜂鸣器
by_frame_send(cmd, buff);
memcpy(buff_t_u8, buff, sizeof(buff[1]));
gpio_bits_write(GPIOB, GPIO_PINS_7, buff_t_u8[0] ? TRUE : FALSE); // 灯条
break; break;
default: default:

View File

@@ -5,8 +5,8 @@
#include "by_debug.h" #include "by_debug.h"
#include "by_can.h" #include "by_can.h"
#define D_X (0.18f) // 底盘 Y 轴上两轮中心的间距 #define D_X (0.25f) // 底盘 Y 轴上两轮中心的间距
#define D_Y (0.25f) // 底盘 X 轴上两轮中心的间距 #define D_Y (0.28f) // 底盘 X 轴上两轮中心的间距
#define RX_RY ((D_X + D_Y) / 2.f) #define RX_RY ((D_X + D_Y) / 2.f)
/********************************************** /**********************************************
@@ -19,6 +19,12 @@
/*** 控制模式 ***/ /*** 控制模式 ***/
uint8_t control_mode = 0; // 0-速度模式 1-位置模式 uint8_t control_mode = 0; // 0-速度模式 1-位置模式
struct by_motion_mode_struct {
uint8_t x;
uint8_t y;
uint8_t w;
} by_motion_mode = {0,0,0};
/*** 位置控制 ***/ /*** 位置控制 ***/
uint8_t control_timer = 0; // 位置控制定时器状态 uint8_t control_timer = 0; // 位置控制定时器状态
uint32_t control_timer_cnt = 0; // 位置控制计数 uint32_t control_timer_cnt = 0; // 位置控制计数
@@ -55,8 +61,8 @@ void by_motion_update_speed(void)
v_wheel[3] = speed->v_x - speed->v_y - RX_RY * speed->v_w; v_wheel[3] = speed->v_x - speed->v_y - RX_RY * speed->v_w;
// 根据安装方式调整轮子方向 // 根据安装方式调整轮子方向
v_wheel[1] *= -1; v_wheel[1] *= -1.0f;
v_wheel[2] *= -1; v_wheel[2] *= -1.0f;
for (uint8_t i = 0; i < 4; i++) { for (uint8_t i = 0; i < 4; i++) {
motion_speed_data[i] = (int16_t)v_wheel[i]; motion_speed_data[i] = (int16_t)v_wheel[i];
@@ -74,20 +80,38 @@ void by_motion_update_speed(void)
*/ */
void by_motion_loop(void) void by_motion_loop(void)
{ {
if (control_mode == 0) { // 速度控制模式 if (by_motion_mode.x == 0) {
memset(&motion_time_struct, 0, sizeof(motion_time_struct)); motion_time_struct.t_x = 0;
} else { // 位置控制模式 } else if (by_motion_mode.x == 1 && motion_time_struct.t_x == 0) {
if (0 == motion_time_struct.t_x) { motion_speed_struct.v_x = 0;
motion_speed_struct.v_x = 0;
}
if (0 == motion_time_struct.t_y) {
motion_speed_struct.v_y = 0;
}
if (0 == motion_time_struct.t_w) {
motion_speed_struct.v_w = 0;
}
} }
if (by_motion_mode.y == 0) {
motion_time_struct.t_y = 0;
} else if (by_motion_mode.y == 1 && motion_time_struct.t_y == 0) {
motion_speed_struct.v_y = 0;
}
if (by_motion_mode.w == 0) {
motion_time_struct.t_w = 0;
} else if (by_motion_mode.w == 1 && motion_time_struct.t_w == 0) {
motion_speed_struct.v_w = 0;
}
// if (control_mode == 0) { // 速度控制模式
// memset(&motion_time_struct, 0, sizeof(motion_time_struct));
// } else { // 位置控制模式
// if (0 == motion_time_struct.t_x) {
// motion_speed_struct.v_x = 0;
// }
// if (0 == motion_time_struct.t_y) {
// motion_speed_struct.v_y = 0;
// }
// if (0 == motion_time_struct.t_w) {
// motion_speed_struct.v_w = 0;
// }
// }
if ((motion_speed_struct.v_x != motion_speed_struct_last.v_x) || (motion_speed_struct.v_y != motion_speed_struct_last.v_y) || (motion_speed_struct.v_w != motion_speed_struct_last.v_w)) { if ((motion_speed_struct.v_x != motion_speed_struct_last.v_x) || (motion_speed_struct.v_y != motion_speed_struct_last.v_y) || (motion_speed_struct.v_w != motion_speed_struct_last.v_w)) {
by_motion_update_speed(); by_motion_update_speed();
memcpy(&motion_speed_struct_last, &motion_speed_struct, sizeof(motion_speed_type)); memcpy(&motion_speed_struct_last, &motion_speed_struct, sizeof(motion_speed_type));
@@ -100,29 +124,62 @@ void by_motion_loop(void)
*/ */
void by_motion_timer_handle(void) void by_motion_timer_handle(void)
{ {
if (control_mode == 0) { // if (control_mode == 0) {
// motion_time_struct.t_x = 0;
// motion_time_struct.t_y = 0;
// motion_time_struct.t_w = 0;
// } else {
// if (motion_time_struct.t_x > 0) {
// motion_time_struct.t_x--;
// }
// if (motion_time_struct.t_y > 0) {
// motion_time_struct.t_y--;
// }
// if (motion_time_struct.t_w > 0) {
// motion_time_struct.t_w--;
// }
// }
if (by_motion_mode.x == 0) {
motion_time_struct.t_x = 0; motion_time_struct.t_x = 0;
} else if(motion_time_struct.t_x > 0) {
motion_time_struct.t_x--;
}
if(by_motion_mode.y == 0) {
motion_time_struct.t_y = 0; motion_time_struct.t_y = 0;
} else if(motion_time_struct.t_y > 0) {
motion_time_struct.t_y--;
}
if(by_motion_mode.w == 0) {
motion_time_struct.t_w = 0; motion_time_struct.t_w = 0;
} else { } else if(motion_time_struct.t_w > 0) {
if (motion_time_struct.t_x > 0) { motion_time_struct.t_w--;
motion_time_struct.t_x--;
}
if (motion_time_struct.t_y > 0) {
motion_time_struct.t_y--;
}
if (motion_time_struct.t_w > 0) {
motion_time_struct.t_w--;
}
} }
} }
/** // /**
* @brief 设置电机控制模式 // * @brief 设置电机控制模式
* // *
* @param mode 0-速度模式 1-位置模式 // * @param mode 0-速度模式 1-位置模式
*/ // */
void by_motion_set_mode(uint8_t mode) // void by_motion_set_mode(uint8_t mode)
// {
// control_mode = mode;
// }
void by_motion_set_mode_x(uint8_t mode)
{ {
control_mode = mode; by_motion_mode.x = mode;
}
void by_motion_set_mode_y(uint8_t mode)
{
by_motion_mode.y = mode;
}
void by_motion_set_mode_w(uint8_t mode)
{
by_motion_mode.w = mode;
} }

View File

@@ -20,7 +20,10 @@ extern void by_motion_update_speed(void);
extern void by_motion_loop(void); extern void by_motion_loop(void);
extern void by_motion_set_mode(uint8_t mode); extern void by_motion_set_mode(uint8_t mode);
extern void by_motion_timer_handle(void); extern void by_motion_timer_handle(void);
extern void by_motion_set_mode(uint8_t mode); // extern void by_motion_set_mode(uint8_t mode);
extern void by_motion_set_mode_x(uint8_t mode);
extern void by_motion_set_mode_y(uint8_t mode);
extern void by_motion_set_mode_w(uint8_t mode);
extern motion_speed_type motion_speed_struct; extern motion_speed_type motion_speed_struct;
extern motion_time_type motion_time_struct; extern motion_time_type motion_time_struct;

View File

@@ -17,7 +17,7 @@
<dwHighDateTime>0</dwHighDateTime> <dwHighDateTime>0</dwHighDateTime>
</DaveTm> </DaveTm>
<Target> <Target>
<TargetName>BC1C</TargetName> <TargetName>BC2C</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<TargetOption> <TargetOption>

View File

@@ -4,22 +4,22 @@
<Header>### uVision Project, (C) Keil Software</Header> <Header>### uVision Project, (C) Keil Software</Header>
<Targets> <Targets>
<Target> <Target>
<TargetName>BC1C</TargetName> <TargetName>BC2C</TargetName>
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed> <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
<uAC6>0</uAC6> <uAC6>0</uAC6>
<TargetOption> <TargetOption>
<TargetCommonOption> <TargetCommonOption>
<Device>-AT32F403ARCT7</Device> <Device>-AT32F403ACGT7</Device>
<Vendor>ArteryTek</Vendor> <Vendor>ArteryTek</Vendor>
<PackID>ArteryTek.AT32F403A_407_DFP.2.1.5</PackID> <PackID>ArteryTek.AT32F403A_407_DFP.2.1.5</PackID>
<Cpu>IRAM(0x20000000,0x6000000) IROM(0x08000000,0x10000000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu> <Cpu>IRAM(0x20000000,0x6000000) IROM(0x08000000,0x40000000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
<FlashUtilSpec/> <FlashUtilSpec/>
<StartupFile/> <StartupFile/>
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F403A_256 -FS08000000 -FL0400000 -FP0($$Device:-AT32F403ARCT7$Flash\AT32F403A_256.FLM))</FlashDriverDll> <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F403A_1024 -FS08000000 -FL1000000 -FP0($$Device:-AT32F403ACGT7$Flash\AT32F403A_1024.FLM))</FlashDriverDll>
<DeviceId>0</DeviceId> <DeviceId>0</DeviceId>
<RegisterFile>$$Device:-AT32F403ARCT7$Device\Include\at32f403a_407.h</RegisterFile> <RegisterFile>$$Device:-AT32F403ACGT7$Device\Include\at32f403a_407.h</RegisterFile>
<MemoryEnv/> <MemoryEnv/>
<Cmp/> <Cmp/>
<Asm/> <Asm/>
@@ -29,7 +29,7 @@
<SLE66CMisc/> <SLE66CMisc/>
<SLE66AMisc/> <SLE66AMisc/>
<SLE66LinkerMisc/> <SLE66LinkerMisc/>
<SFDFile>$$Device:-AT32F403ARCT7$SVD\AT32F403Axx_v2.svd</SFDFile> <SFDFile>$$Device:-AT32F403ACGT7$SVD\AT32F403Axx_v2.svd</SFDFile>
<bCustSvd>0</bCustSvd> <bCustSvd>0</bCustSvd>
<UseEnv>0</UseEnv> <UseEnv>0</UseEnv>
<BinPath/> <BinPath/>
@@ -45,7 +45,7 @@
<InvalidFlash>1</InvalidFlash> <InvalidFlash>1</InvalidFlash>
</TargetStatus> </TargetStatus>
<OutputDirectory>.\objects\</OutputDirectory> <OutputDirectory>.\objects\</OutputDirectory>
<OutputName>BC1C</OutputName> <OutputName>BC2C</OutputName>
<CreateExecutable>1</CreateExecutable> <CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib> <CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile> <CreateHexFile>1</CreateHexFile>
@@ -247,7 +247,7 @@
<IROM> <IROM>
<Type>1</Type> <Type>1</Type>
<StartAddress>0x8000000</StartAddress> <StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size> <Size>0x100000</Size>
</IROM> </IROM>
<XRAM> <XRAM>
<Type>0</Type> <Type>0</Type>
@@ -272,7 +272,7 @@
<OCR_RVCT4> <OCR_RVCT4>
<Type>1</Type> <Type>1</Type>
<StartAddress>0x8000000</StartAddress> <StartAddress>0x8000000</StartAddress>
<Size>0x40000</Size> <Size>0x100000</Size>
</OCR_RVCT4> </OCR_RVCT4>
<OCR_RVCT5> <OCR_RVCT5>
<Type>1</Type> <Type>1</Type>
@@ -333,7 +333,7 @@
<v6Rtti>0</v6Rtti> <v6Rtti>0</v6Rtti>
<VariousControls> <VariousControls>
<MiscControls/> <MiscControls/>
<Define>AT32F403ARCT7,USE_STDPERIPH_DRIVER,AT_START_F403A_V1</Define> <Define>AT32F403ACGT7,USE_STDPERIPH_DRIVER,AT_START_F403A_V1</Define>
<Undefine/> <Undefine/>
<IncludePath>..\..\libraries\drivers\inc;..\..\libraries\cmsis\cm4\core_support;..\..\libraries\cmsis\cm4\device_support;..\inc</IncludePath> <IncludePath>..\..\libraries\drivers\inc;..\..\libraries\cmsis\cm4\core_support;..\..\libraries\cmsis\cm4\device_support;..\inc</IncludePath>
</VariousControls> </VariousControls>
@@ -399,11 +399,6 @@
<Group> <Group>
<GroupName>firmware</GroupName> <GroupName>firmware</GroupName>
<Files> <Files>
<File>
<FileName>at32f403a_407_adc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_adc.c</FilePath>
</File>
<File> <File>
<FileName>at32f403a_407_can.c</FileName> <FileName>at32f403a_407_can.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -419,11 +414,6 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_debug.c</FilePath> <FilePath>..\..\libraries\drivers\src\at32f403a_407_debug.c</FilePath>
</File> </File>
<File>
<FileName>at32f403a_407_exint.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_exint.c</FilePath>
</File>
<File> <File>
<FileName>at32f403a_407_flash.c</FileName> <FileName>at32f403a_407_flash.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -434,11 +424,6 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_gpio.c</FilePath> <FilePath>..\..\libraries\drivers\src\at32f403a_407_gpio.c</FilePath>
</File> </File>
<File>
<FileName>at32f403a_407_i2c.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_i2c.c</FilePath>
</File>
<File> <File>
<FileName>at32f403a_407_misc.c</FileName> <FileName>at32f403a_407_misc.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
@@ -449,21 +434,11 @@
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_pwc.c</FilePath> <FilePath>..\..\libraries\drivers\src\at32f403a_407_pwc.c</FilePath>
</File> </File>
<File>
<FileName>at32f403a_407_tmr.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_tmr.c</FilePath>
</File>
<File> <File>
<FileName>at32f403a_407_usart.c</FileName> <FileName>at32f403a_407_usart.c</FileName>
<FileType>1</FileType> <FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_usart.c</FilePath> <FilePath>..\..\libraries\drivers\src\at32f403a_407_usart.c</FilePath>
</File> </File>
<File>
<FileName>at32f403a_407_crc.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\libraries\drivers\src\at32f403a_407_crc.c</FilePath>
</File>
</Files> </Files>
</Group> </Group>
<Group> <Group>
@@ -492,7 +467,7 @@
<LayerInfo> <LayerInfo>
<Layers> <Layers>
<Layer> <Layer>
<LayName>BC1C</LayName> <LayName>BC2C</LayName>
<LayTarg>0</LayTarg> <LayTarg>0</LayTarg>
<LayPrjMark>1</LayPrjMark> <LayPrjMark>1</LayPrjMark>
</Layer> </Layer>

View File

@@ -39,7 +39,7 @@ extern "C" {
* *
*/ */
#if !defined HEXT_VALUE #if !defined HEXT_VALUE
#define HEXT_VALUE ((uint32_t)8000000) /*!< value of the high speed exernal crystal in hz */ #define HEXT_VALUE ((uint32_t)16000000) /*!< value of the high speed exernal crystal in hz */
#endif #endif
/** /**
@@ -64,7 +64,7 @@ extern "C" {
/*#define EXINT_MODULE_ENABLED--------------------*/ /*#define EXINT_MODULE_ENABLED--------------------*/
#define FLASH_MODULE_ENABLED #define FLASH_MODULE_ENABLED
#define GPIO_MODULE_ENABLED #define GPIO_MODULE_ENABLED
#define I2C_MODULE_ENABLED /*#define I2C_MODULE_ENABLED----------------------*/
#define MISC_MODULE_ENABLED #define MISC_MODULE_ENABLED
#define PWC_MODULE_ENABLED #define PWC_MODULE_ENABLED
/*#define RTC_MODULE_ENABLED----------------------*/ /*#define RTC_MODULE_ENABLED----------------------*/

View File

@@ -71,12 +71,6 @@ extern "C" {
/* init gpio function. */ /* init gpio function. */
void wk_gpio_config(void); void wk_gpio_config(void);
/* init i2c1 function. */
void wk_i2c1_init(void);
/* init i2c2 function. */
void wk_i2c2_init(void);
/* init can1 function. */ /* init can1 function. */
void wk_can1_init(void); void wk_can1_init(void);
@@ -98,12 +92,6 @@ extern "C" {
/* init tmr8 function. */ /* init tmr8 function. */
void wk_tmr8_init(void); void wk_tmr8_init(void);
/* init tmr11 function. */
void wk_tmr11_init(void);
/* init tmr12 function. */
void wk_tmr12_init(void);
/* init crc function. */ /* init crc function. */
void wk_crc_init(void); void wk_crc_init(void);

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file at32f403a_407_int.c * @file at32f403a_407_int.c
* @brief main interrupt service routines. * @brief main interrupt service routines.
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
/* includes ------------------------------------------------------------------*/ /* includes ------------------------------------------------------------------*/
@@ -70,10 +70,10 @@
/* add user code end external variables */ /* add user code end external variables */
/** /**
* @brief this function handles nmi exception. * @brief this function handles nmi exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void NMI_Handler(void) void NMI_Handler(void)
{ {
/* add user code begin NonMaskableInt_IRQ 0 */ /* add user code begin NonMaskableInt_IRQ 0 */
@@ -86,17 +86,18 @@ void NMI_Handler(void)
} }
/** /**
* @brief this function handles hard fault exception. * @brief this function handles hard fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
/* add user code begin HardFault_IRQ 0 */ /* add user code begin HardFault_IRQ 0 */
/* add user code end HardFault_IRQ 0 */ /* add user code end HardFault_IRQ 0 */
/* go to infinite loop when hard fault exception occurs */ /* go to infinite loop when hard fault exception occurs */
while (1) { while (1)
{
/* add user code begin W1_HardFault_IRQ 0 */ /* add user code begin W1_HardFault_IRQ 0 */
/* add user code end W1_HardFault_IRQ 0 */ /* add user code end W1_HardFault_IRQ 0 */
@@ -104,17 +105,18 @@ void HardFault_Handler(void)
} }
/** /**
* @brief this function handles memory manage exception. * @brief this function handles memory manage exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void MemManage_Handler(void) void MemManage_Handler(void)
{ {
/* add user code begin MemoryManagement_IRQ 0 */ /* add user code begin MemoryManagement_IRQ 0 */
/* add user code end MemoryManagement_IRQ 0 */ /* add user code end MemoryManagement_IRQ 0 */
/* go to infinite loop when memory manage exception occurs */ /* go to infinite loop when memory manage exception occurs */
while (1) { while (1)
{
/* add user code begin W1_MemoryManagement_IRQ 0 */ /* add user code begin W1_MemoryManagement_IRQ 0 */
/* add user code end W1_MemoryManagement_IRQ 0 */ /* add user code end W1_MemoryManagement_IRQ 0 */
@@ -122,17 +124,18 @@ void MemManage_Handler(void)
} }
/** /**
* @brief this function handles bus fault exception. * @brief this function handles bus fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void BusFault_Handler(void) void BusFault_Handler(void)
{ {
/* add user code begin BusFault_IRQ 0 */ /* add user code begin BusFault_IRQ 0 */
/* add user code end BusFault_IRQ 0 */ /* add user code end BusFault_IRQ 0 */
/* go to infinite loop when bus fault exception occurs */ /* go to infinite loop when bus fault exception occurs */
while (1) { while (1)
{
/* add user code begin W1_BusFault_IRQ 0 */ /* add user code begin W1_BusFault_IRQ 0 */
/* add user code end W1_BusFault_IRQ 0 */ /* add user code end W1_BusFault_IRQ 0 */
@@ -140,17 +143,18 @@ void BusFault_Handler(void)
} }
/** /**
* @brief this function handles usage fault exception. * @brief this function handles usage fault exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void UsageFault_Handler(void) void UsageFault_Handler(void)
{ {
/* add user code begin UsageFault_IRQ 0 */ /* add user code begin UsageFault_IRQ 0 */
/* add user code end UsageFault_IRQ 0 */ /* add user code end UsageFault_IRQ 0 */
/* go to infinite loop when usage fault exception occurs */ /* go to infinite loop when usage fault exception occurs */
while (1) { while (1)
{
/* add user code begin W1_UsageFault_IRQ 0 */ /* add user code begin W1_UsageFault_IRQ 0 */
/* add user code end W1_UsageFault_IRQ 0 */ /* add user code end W1_UsageFault_IRQ 0 */
@@ -158,10 +162,10 @@ void UsageFault_Handler(void)
} }
/** /**
* @brief this function handles svcall exception. * @brief this function handles svcall exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void SVC_Handler(void) void SVC_Handler(void)
{ {
/* add user code begin SVCall_IRQ 0 */ /* add user code begin SVCall_IRQ 0 */
@@ -173,10 +177,10 @@ void SVC_Handler(void)
} }
/** /**
* @brief this function handles debug monitor exception. * @brief this function handles debug monitor exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void DebugMon_Handler(void) void DebugMon_Handler(void)
{ {
/* add user code begin DebugMonitor_IRQ 0 */ /* add user code begin DebugMonitor_IRQ 0 */
@@ -188,10 +192,10 @@ void DebugMon_Handler(void)
} }
/** /**
* @brief this function handles pendsv_handler exception. * @brief this function handles pendsv_handler exception.
* @param none * @param none
* @retval none * @retval none
*/ */
void PendSV_Handler(void) void PendSV_Handler(void)
{ {
/* add user code begin PendSV_IRQ 0 */ /* add user code begin PendSV_IRQ 0 */
@@ -203,10 +207,10 @@ void PendSV_Handler(void)
} }
/** /**
* @brief this function handles USB Low Priority or CAN1 RX0 handler. * @brief this function handles USB Low Priority or CAN1 RX0 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void USBFS_L_CAN1_RX0_IRQHandler(void) void USBFS_L_CAN1_RX0_IRQHandler(void)
{ {
/* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */ /* add user code begin USBFS_L_CAN1_RX0_IRQ 0 */
@@ -223,10 +227,10 @@ void USBFS_L_CAN1_RX0_IRQHandler(void)
} }
/** /**
* @brief this function handles USART1 handler. * @brief this function handles USART1 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void USART1_IRQHandler(void) void USART1_IRQHandler(void)
{ {
/* add user code begin USART1_IRQ 0 */ /* add user code begin USART1_IRQ 0 */
@@ -241,10 +245,10 @@ void USART1_IRQHandler(void)
} }
/** /**
* @brief this function handles USART2 handler. * @brief this function handles USART2 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void USART2_IRQHandler(void) void USART2_IRQHandler(void)
{ {
/* add user code begin USART2_IRQ 0 */ /* add user code begin USART2_IRQ 0 */
@@ -262,10 +266,10 @@ void USART2_IRQHandler(void)
} }
/** /**
* @brief this function handles USART3 handler. * @brief this function handles USART3 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void USART3_IRQHandler(void) void USART3_IRQHandler(void)
{ {
/* add user code begin USART3_IRQ 0 */ /* add user code begin USART3_IRQ 0 */
@@ -281,10 +285,10 @@ void USART3_IRQHandler(void)
} }
/** /**
* @brief this function handles TMR6 handler. * @brief this function handles TMR6 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void TMR6_GLOBAL_IRQHandler(void) void TMR6_GLOBAL_IRQHandler(void)
{ {
/* add user code begin TMR6_GLOBAL_IRQ 0 */ /* add user code begin TMR6_GLOBAL_IRQ 0 */
@@ -299,10 +303,10 @@ void TMR6_GLOBAL_IRQHandler(void)
} }
/** /**
* @brief this function handles CAN2 RX0 handler. * @brief this function handles CAN2 RX0 handler.
* @param none * @param none
* @retval none * @retval none
*/ */
void CAN2_RX0_IRQHandler(void) void CAN2_RX0_IRQHandler(void)
{ {
/* add user code begin CAN2_RX0_IRQ 0 */ /* add user code begin CAN2_RX0_IRQ 0 */

View File

@@ -1,27 +1,27 @@
/* add user code begin Header */ /* add user code begin Header */
/** /**
************************************************************************** **************************************************************************
* @file at32f403a_407_wk_config.c * @file at32f403a_407_wk_config.c
* @brief work bench config program * @brief work bench config program
************************************************************************** **************************************************************************
* Copyright notice & Disclaimer * Copyright notice & Disclaimer
* *
* The software Board Support Package (BSP) that is made available to * The software Board Support Package (BSP) that is made available to
* download from Artery official website is the copyrighted work of Artery. * download from Artery official website is the copyrighted work of Artery.
* Artery authorizes customers to use, copy, and distribute the BSP * Artery authorizes customers to use, copy, and distribute the BSP
* software and its related documentation for the purpose of design and * software and its related documentation for the purpose of design and
* development in conjunction with Artery microcontrollers. Use of the * development in conjunction with Artery microcontrollers. Use of the
* software is governed by this copyright notice and the following disclaimer. * software is governed by this copyright notice and the following disclaimer.
* *
* THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES, * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
* GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS, * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
* TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
* STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS, * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
* INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
* *
************************************************************************** **************************************************************************
*/ */
/* add user code end Header */ /* add user code end Header */
#include "at32f403a_407_wk_config.h" #include "at32f403a_407_wk_config.h"
@@ -64,8 +64,8 @@
/** /**
* @brief system clock config program * @brief system clock config program
* @note the system clock is configured as follow: * @note the system clock is configured as follow:
* system clock (sclk) = hick / 12 * pll_mult * system clock (sclk) = hext / 2 * pll_mult
* system clock source = HICK_VALUE * system clock source = HEXT_VALUE
* - hext = HEXT_VALUE * - hext = HEXT_VALUE
* - sclk = 240000000 * - sclk = 240000000
* - ahbdiv = 1 * - ahbdiv = 1
@@ -74,7 +74,7 @@
* - apb1clk = 120000000 * - apb1clk = 120000000
* - apb2div = 2 * - apb2div = 2
* - apb2clk = 120000000 * - apb2clk = 120000000
* - pll_mult = 60 * - pll_mult = 30
* - pll_range = GT72MHZ (greater than 72 mhz) * - pll_range = GT72MHZ (greater than 72 mhz)
* @param none * @param none
* @retval none * @retval none
@@ -109,7 +109,10 @@ void wk_system_clock_config(void)
} }
/* config pll clock resource */ /* config pll clock resource */
crm_pll_config(CRM_PLL_SOURCE_HICK, CRM_PLL_MULT_60, CRM_PLL_OUTPUT_RANGE_GT72MHZ); crm_pll_config(CRM_PLL_SOURCE_HEXT_DIV, CRM_PLL_MULT_30, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
/* config hext division */
crm_hext_clock_div_set(CRM_HEXT_DIV_2);
/* enable pll */ /* enable pll */
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE); crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
@@ -165,9 +168,6 @@ void wk_periph_clock_config(void)
/* enable gpiob periph clock */ /* enable gpiob periph clock */
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
/* enable gpioc periph clock */
crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
/* enable gpiod periph clock */ /* enable gpiod periph clock */
crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE);
@@ -177,27 +177,15 @@ void wk_periph_clock_config(void)
/* enable usart1 periph clock */ /* enable usart1 periph clock */
crm_periph_clock_enable(CRM_USART1_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_USART1_PERIPH_CLOCK, TRUE);
/* enable tmr11 periph clock */
crm_periph_clock_enable(CRM_TMR11_PERIPH_CLOCK, TRUE);
/* enable tmr6 periph clock */ /* enable tmr6 periph clock */
crm_periph_clock_enable(CRM_TMR6_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_TMR6_PERIPH_CLOCK, TRUE);
/* enable tmr12 periph clock */
crm_periph_clock_enable(CRM_TMR12_PERIPH_CLOCK, TRUE);
/* enable usart2 periph clock */ /* enable usart2 periph clock */
crm_periph_clock_enable(CRM_USART2_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_USART2_PERIPH_CLOCK, TRUE);
/* enable usart3 periph clock */ /* enable usart3 periph clock */
crm_periph_clock_enable(CRM_USART3_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_USART3_PERIPH_CLOCK, TRUE);
/* enable i2c1 periph clock */
crm_periph_clock_enable(CRM_I2C1_PERIPH_CLOCK, TRUE);
/* enable i2c2 periph clock */
crm_periph_clock_enable(CRM_I2C2_PERIPH_CLOCK, TRUE);
/* enable can1 periph clock */ /* enable can1 periph clock */
crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE); crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE);
@@ -251,133 +239,21 @@ void wk_gpio_config(void)
/* add user code end gpio_config 1 */ /* add user code end gpio_config 1 */
/* gpio input config */
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_4 | GPIO_PINS_5 | GPIO_PINS_6 | GPIO_PINS_7;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOA, &gpio_init_struct);
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_2;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOD, &gpio_init_struct);
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_3 | GPIO_PINS_4 | GPIO_PINS_5;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
/* gpio output config */ /* gpio output config */
gpio_bits_reset(GPIOC, GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3); gpio_bits_reset(GPIOB, GPIO_PINS_6 | GPIO_PINS_7);
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL; gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT; gpio_init_struct.gpio_mode = GPIO_MODE_OUTPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 | GPIO_PINS_2 | GPIO_PINS_3; gpio_init_struct.gpio_pins = GPIO_PINS_6 | GPIO_PINS_7;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOC, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
/* add user code begin gpio_config 2 */ /* add user code begin gpio_config 2 */
/* add user code end gpio_config 2 */ /* add user code end gpio_config 2 */
} }
/**
* @brief init i2c1 function.
* @param none
* @retval none
*/
void wk_i2c1_init(void)
{
/* add user code begin i2c1_init 0 */
/* add user code end i2c1_init 0 */
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin i2c1_init 1 */
/* add user code end i2c1_init 1 */
/* configure the SCL pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = GPIO_PINS_6;
gpio_init(GPIOB, &gpio_init_struct);
/* configure the SDA pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = GPIO_PINS_7;
gpio_init(GPIOB, &gpio_init_struct);
i2c_init(I2C1, I2C_FSMODE_DUTY_2_1, 100000);
i2c_own_address1_set(I2C1, I2C_ADDRESS_MODE_7BIT, 0x0);
i2c_ack_enable(I2C1, TRUE);
i2c_clock_stretch_enable(I2C1, TRUE);
i2c_general_call_enable(I2C1, FALSE);
i2c_enable(I2C1, TRUE);
/* add user code begin i2c1_init 2 */
/* add user code end i2c1_init 2 */
}
/**
* @brief init i2c2 function.
* @param none
* @retval none
*/
void wk_i2c2_init(void)
{
/* add user code begin i2c2_init 0 */
/* add user code end i2c2_init 0 */
gpio_init_type gpio_init_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin i2c2_init 1 */
/* add user code end i2c2_init 1 */
/* configure the SCL pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = GPIO_PINS_10;
gpio_init(GPIOB, &gpio_init_struct);
/* configure the SDA pin */
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init_struct.gpio_pins = GPIO_PINS_11;
gpio_init(GPIOB, &gpio_init_struct);
i2c_init(I2C2, I2C_FSMODE_DUTY_2_1, 100000);
i2c_own_address1_set(I2C2, I2C_ADDRESS_MODE_7BIT, 0x0);
i2c_ack_enable(I2C2, TRUE);
i2c_clock_stretch_enable(I2C2, TRUE);
i2c_general_call_enable(I2C2, FALSE);
i2c_enable(I2C2, TRUE);
/* add user code begin i2c2_init 2 */
/* add user code end i2c2_init 2 */
}
/** /**
* @brief init usart1 function * @brief init usart1 function
* @param none * @param none
@@ -516,7 +392,7 @@ void wk_usart3_init(void)
gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_10; gpio_init_struct.gpio_pins = GPIO_PINS_10;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOC, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
/* configure the RX pin */ /* configure the RX pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE; gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
@@ -524,9 +400,7 @@ void wk_usart3_init(void)
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT; gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_11; gpio_init_struct.gpio_pins = GPIO_PINS_11;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOC, &gpio_init_struct); gpio_init(GPIOB, &gpio_init_struct);
gpio_pin_remap_config(USART3_GMUX_0001, TRUE);
/* configure param */ /* configure param */
usart_init(USART3, 115200, USART_DATA_8BITS, USART_STOP_1_BIT); usart_init(USART3, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
@@ -600,48 +474,11 @@ void wk_tmr8_init(void)
/* add user code end tmr8_init 0 */ /* add user code end tmr8_init 0 */
gpio_init_type gpio_init_struct;
tmr_output_config_type tmr_output_struct;
tmr_brkdt_config_type tmr_brkdt_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin tmr8_init 1 */ /* add user code begin tmr8_init 1 */
/* add user code end tmr8_init 1 */ /* add user code end tmr8_init 1 */
/* configure the CH1 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_6;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOC, &gpio_init_struct);
/* configure the CH2 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_7;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOC, &gpio_init_struct);
/* configure the CH3 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_8;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOC, &gpio_init_struct);
/* configure the CH4 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_9;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOC, &gpio_init_struct);
/* configure counter settings */ /* configure counter settings */
tmr_base_init(TMR8, 2399, 1999); tmr_base_init(TMR8, 2399, 1999);
tmr_cnt_dir_set(TMR8, TMR_COUNT_UP); tmr_cnt_dir_set(TMR8, TMR_COUNT_UP);
@@ -653,67 +490,6 @@ void wk_tmr8_init(void)
tmr_sub_sync_mode_set(TMR8, FALSE); tmr_sub_sync_mode_set(TMR8, FALSE);
tmr_primary_mode_select(TMR8, TMR_PRIMARY_SEL_RESET); tmr_primary_mode_select(TMR8, TMR_PRIMARY_SEL_RESET);
/* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_1, 0);
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_1, FALSE);
/* configure channel 2 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_2, 0);
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_2, FALSE);
/* configure channel 3 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_3, &tmr_output_struct);
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_3, 0);
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_3, FALSE);
/* configure channel 4 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR8, TMR_SELECT_CHANNEL_4, &tmr_output_struct);
tmr_channel_value_set(TMR8, TMR_SELECT_CHANNEL_4, 0);
tmr_output_channel_buffer_enable(TMR8, TMR_SELECT_CHANNEL_4, FALSE);
/* configure break and dead-time settings */
tmr_brkdt_struct.brk_enable = FALSE;
tmr_brkdt_struct.auto_output_enable = FALSE;
tmr_brkdt_struct.brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW;
tmr_brkdt_struct.fcsoen_state = FALSE;
tmr_brkdt_struct.fcsodis_state = FALSE;
tmr_brkdt_struct.wp_level = TMR_WP_OFF;
tmr_brkdt_struct.deadtime = 0;
tmr_brkdt_config(TMR8, &tmr_brkdt_struct);
tmr_output_enable(TMR8, TRUE);
tmr_counter_enable(TMR8, TRUE); tmr_counter_enable(TMR8, TRUE);
/* add user code begin tmr8_init 2 */ /* add user code begin tmr8_init 2 */
@@ -721,132 +497,6 @@ void wk_tmr8_init(void)
/* add user code end tmr8_init 2 */ /* add user code end tmr8_init 2 */
} }
/**
* @brief init tmr11 function.
* @param none
* @retval none
*/
void wk_tmr11_init(void)
{
/* add user code begin tmr11_init 0 */
/* add user code end tmr11_init 0 */
gpio_init_type gpio_init_struct;
tmr_output_config_type tmr_output_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin tmr11_init 1 */
/* add user code end tmr11_init 1 */
/* configure the CH1 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_9;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOB, &gpio_init_struct);
/* configure counter settings */
tmr_base_init(TMR11, 2399, 99);
tmr_cnt_dir_set(TMR11, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR11, TMR_CLOCK_DIV1);
tmr_period_buffer_enable(TMR11, FALSE);
/* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR11, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR11, TMR_SELECT_CHANNEL_1, 0);
tmr_output_channel_buffer_enable(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
tmr_output_channel_immediately_set(TMR11, TMR_SELECT_CHANNEL_1, FALSE);
tmr_counter_enable(TMR11, TRUE);
/* add user code begin tmr11_init 2 */
/* add user code end tmr11_init 2 */
}
/**
* @brief init tmr12 function.
* @param none
* @retval none
*/
void wk_tmr12_init(void)
{
/* add user code begin tmr12_init 0 */
/* add user code end tmr12_init 0 */
gpio_init_type gpio_init_struct;
tmr_output_config_type tmr_output_struct;
gpio_default_para_init(&gpio_init_struct);
/* add user code begin tmr12_init 1 */
/* add user code end tmr12_init 1 */
/* configure the CH1 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_14;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOB, &gpio_init_struct);
/* configure the CH2 pin */
gpio_init_struct.gpio_pins = GPIO_PINS_15;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
gpio_init(GPIOB, &gpio_init_struct);
/* configure counter settings */
tmr_base_init(TMR12, 65535, 0);
tmr_cnt_dir_set(TMR12, TMR_COUNT_UP);
tmr_clock_source_div_set(TMR12, TMR_CLOCK_DIV1);
tmr_period_buffer_enable(TMR12, FALSE);
/* configure channel 1 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_1, 0);
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_1, FALSE);
/* configure channel 2 output settings */
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
tmr_output_struct.oc_output_state = TRUE;
tmr_output_struct.occ_output_state = FALSE;
tmr_output_struct.oc_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.occ_polarity = TMR_OUTPUT_ACTIVE_HIGH;
tmr_output_struct.oc_idle_state = FALSE;
tmr_output_struct.occ_idle_state = FALSE;
tmr_output_channel_config(TMR12, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
tmr_channel_value_set(TMR12, TMR_SELECT_CHANNEL_2, 0);
tmr_output_channel_buffer_enable(TMR12, TMR_SELECT_CHANNEL_2, FALSE);
tmr_counter_enable(TMR12, TRUE);
/* add user code begin tmr12_init 2 */
/* add user code end tmr12_init 2 */
}
/** /**
* @brief init can1 function. * @brief init can1 function.
* @param none * @param none
@@ -900,9 +550,9 @@ void wk_can1_init(void)
/*can_baudrate_setting-------------------------------------------------------------*/ /*can_baudrate_setting-------------------------------------------------------------*/
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ can_baudrate_struct.baudrate_div = 30; /*value: 1~0xFFF*/
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ can_baudrate_struct.bts1_size = CAN_BTS1_6TQ; /*value: 1~16*/
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
can_baudrate_set(CAN1, &can_baudrate_struct); can_baudrate_set(CAN1, &can_baudrate_struct);
@@ -989,9 +639,9 @@ void wk_can2_init(void)
/*can_baudrate_setting-------------------------------------------------------------*/ /*can_baudrate_setting-------------------------------------------------------------*/
/*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/ /*set baudrate = pclk/(baudrate_div *(1 + bts1_size + bts2_size))------------------*/
can_baudrate_struct.baudrate_div = 24; /*value: 1~0xFFF*/ can_baudrate_struct.baudrate_div = 30; /*value: 1~0xFFF*/
can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/ can_baudrate_struct.rsaw_size = CAN_RSAW_1TQ; /*value: 1~4*/
can_baudrate_struct.bts1_size = CAN_BTS1_8TQ; /*value: 1~16*/ can_baudrate_struct.bts1_size = CAN_BTS1_6TQ; /*value: 1~16*/
can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/ can_baudrate_struct.bts2_size = CAN_BTS2_1TQ; /*value: 1~8*/
can_baudrate_set(CAN2, &can_baudrate_struct); can_baudrate_set(CAN2, &can_baudrate_struct);

View File

@@ -100,24 +100,12 @@ int main(void)
/* init usart3 function. */ /* init usart3 function. */
wk_usart3_init(); wk_usart3_init();
/* init i2c1 function. */
wk_i2c1_init();
/* init i2c2 function. */
wk_i2c2_init();
/* init tmr6 function. */ /* init tmr6 function. */
wk_tmr6_init(); wk_tmr6_init();
/* init tmr8 function. */ /* init tmr8 function. */
wk_tmr8_init(); wk_tmr8_init();
/* init tmr11 function. */
wk_tmr11_init();
/* init tmr12 function. */
wk_tmr12_init();
/* init can1 function. */ /* init can1 function. */
wk_can1_init(); wk_can1_init();
@@ -148,6 +136,16 @@ int main(void)
by_messy_init(); by_messy_init();
LOGD("frame init done"); LOGD("frame init done");
/* self test */
gpio_bits_write(GPIOB, GPIO_PINS_6, FALSE); // 灯条
gpio_bits_write(GPIOB, GPIO_PINS_7, FALSE); // 蜂鸣器
for (uint8_t i = 0; i < 4; i++) {
gpio_bits_write(GPIOB, GPIO_PINS_6, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_6)); // 灯条
gpio_bits_write(GPIOB, GPIO_PINS_7, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_7)); // 蜂鸣器
DWT_Delay(100000);
}
LOGI("init done"); LOGI("init done");
/* add user code end 2 */ /* add user code end 2 */