暂存
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
# dot files
|
# dot files
|
||||||
/.vscode/launch.json
|
|
||||||
/.settings
|
/.settings
|
||||||
/.eide/log
|
/.eide/log
|
||||||
/.eide.usr.ctx.json
|
/.eide.usr.ctx.json
|
||||||
|
|||||||
19
.vscode/launch.json
vendored
Normal file
19
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"type": "cortex-debug",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "openocd",
|
||||||
|
"servertype": "openocd",
|
||||||
|
"executable": "build\\BC3D\\BC3D.elf",
|
||||||
|
"runToEntryPoint": "main",
|
||||||
|
"configFiles": [
|
||||||
|
"interface/cmsis-dap.cfg",
|
||||||
|
"target/at32f413xx.cfg"
|
||||||
|
],
|
||||||
|
"toolchainPrefix": "arm-none-eabi",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
44
BC3D.ATWP
44
BC3D.ATWP
@@ -18,6 +18,14 @@
|
|||||||
<ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/>
|
<ParametersSub name="RSAW" value="CAN_RSAW_1TQ"/>
|
||||||
</Parameters>
|
</Parameters>
|
||||||
</CAN1>
|
</CAN1>
|
||||||
|
<CRM>
|
||||||
|
<Mode>
|
||||||
|
<ModeSub name="HEXT" value="HEXT-External-Oscillator"/>
|
||||||
|
</Mode>
|
||||||
|
<Parameters>
|
||||||
|
<ParametersSub name="HEXT" value="HEXT_CRYSTAL"/>
|
||||||
|
</Parameters>
|
||||||
|
</CRM>
|
||||||
<DEBUG>
|
<DEBUG>
|
||||||
<Mode>
|
<Mode>
|
||||||
<ModeSub name="Debug interface" value="SWD"/>
|
<ModeSub name="Debug interface" value="SWD"/>
|
||||||
@@ -39,14 +47,6 @@
|
|||||||
<ModeSub name="Activated" value="TRUE"/>
|
<ModeSub name="Activated" value="TRUE"/>
|
||||||
</Mode>
|
</Mode>
|
||||||
</TMR3>
|
</TMR3>
|
||||||
<TMR9>
|
|
||||||
<Mode>
|
|
||||||
<ModeSub name="Channel2 mode" value="Output_CH2"/>
|
|
||||||
<ModeSub name="Subordinate mode" value="Clock Mode"/>
|
|
||||||
<ModeSub name="Sub-mode input selection" value="SubModeInput_IS2"/>
|
|
||||||
<ModeSub name="Activated" value="TRUE"/>
|
|
||||||
</Mode>
|
|
||||||
</TMR9>
|
|
||||||
<TMR10>
|
<TMR10>
|
||||||
<Mode>
|
<Mode>
|
||||||
<ModeSub name="Channel1 mode" value="Output_without_pin"/>
|
<ModeSub name="Channel1 mode" value="Output_without_pin"/>
|
||||||
@@ -75,12 +75,6 @@
|
|||||||
<USART2_IRQHandler>0;0;0</USART2_IRQHandler>
|
<USART2_IRQHandler>0;0;0</USART2_IRQHandler>
|
||||||
</NVIC>
|
</NVIC>
|
||||||
<GPIO>
|
<GPIO>
|
||||||
<Signal SignalName="GPIO_Input" PinName="PB10">
|
|
||||||
<Parameters name="Label" value="SW_IN2"/>
|
|
||||||
</Signal>
|
|
||||||
<Signal SignalName="GPIO_Input" PinName="PB11">
|
|
||||||
<Parameters name="Label" value="SW_IN1"/>
|
|
||||||
</Signal>
|
|
||||||
<Signal SignalName="GPIO_Output" PinName="PB12">
|
<Signal SignalName="GPIO_Output" PinName="PB12">
|
||||||
<Parameters name="Label" value="MODE2"/>
|
<Parameters name="Label" value="MODE2"/>
|
||||||
</Signal>
|
</Signal>
|
||||||
@@ -90,22 +84,22 @@
|
|||||||
<Signal SignalName="GPIO_Output" PinName="PB14">
|
<Signal SignalName="GPIO_Output" PinName="PB14">
|
||||||
<Parameters name="Label" value="MODE0"/>
|
<Parameters name="Label" value="MODE0"/>
|
||||||
</Signal>
|
</Signal>
|
||||||
<Signal SignalName="TMR9_CH2" PinName="PB15">
|
<Signal SignalName="GPIO_Output" PinName="PB15">
|
||||||
<Parameters name="Label" value="STEP"/>
|
<Parameters name="Label" value="CLK"/>
|
||||||
</Signal>
|
</Signal>
|
||||||
<Signal SignalName="GPIO_Output" PinName="PA8">
|
<Signal SignalName="GPIO_Output" PinName="PA8">
|
||||||
<Parameters name="Label" value="DIR"/>
|
<Parameters name="Label" value="DIR"/>
|
||||||
</Signal>
|
</Signal>
|
||||||
<Signal SignalName="GPIO_Analog" PinName="PA9">
|
<Signal SignalName="GPIO_Output" PinName="PA9">
|
||||||
<Parameters name="Label" value="EN"/>
|
<Parameters name="Label" value="EN"/>
|
||||||
</Signal>
|
</Signal>
|
||||||
</GPIO>
|
</GPIO>
|
||||||
<ClockConfiguration>
|
<ClockConfiguration>
|
||||||
<rtcsel>0</rtcsel>
|
<rtcsel>0</rtcsel>
|
||||||
<hext>8.000000</hext>
|
<hext>16.000000</hext>
|
||||||
<pllhextdiv>0</pllhextdiv>
|
<pllhextdiv>1</pllhextdiv>
|
||||||
<pllrcs>1</pllrcs>
|
<pllrcs>0</pllrcs>
|
||||||
<pllmult>50</pllmult>
|
<pllmult>25</pllmult>
|
||||||
<sclkselect>1</sclkselect>
|
<sclkselect>1</sclkselect>
|
||||||
<ahbdiv>1</ahbdiv>
|
<ahbdiv>1</ahbdiv>
|
||||||
<apb1div>2</apb1div>
|
<apb1div>2</apb1div>
|
||||||
@@ -118,6 +112,8 @@
|
|||||||
<adcdiv>4</adcdiv>
|
<adcdiv>4</adcdiv>
|
||||||
</ClockConfiguration>
|
</ClockConfiguration>
|
||||||
<PINInfo>
|
<PINInfo>
|
||||||
|
<PinSub pinname="PD0/HEXT_IN" signalname="CRM_HEXT_IN" signaltype="2"/>
|
||||||
|
<PinSub pinname="PD1/HEXT_OUT" signalname="CRM_HEXT_OUT" signaltype="2"/>
|
||||||
<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="PA5" signalname="EXINT5" signaltype="3"/>
|
<PinSub pinname="PA5" signalname="EXINT5" signaltype="3"/>
|
||||||
@@ -128,9 +124,9 @@
|
|||||||
<PinSub pinname="PB12" signalname="GPIO_Output" signaltype="3"/>
|
<PinSub pinname="PB12" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<PinSub pinname="PB13" signalname="GPIO_Output" signaltype="3"/>
|
<PinSub pinname="PB13" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<PinSub pinname="PB14" signalname="GPIO_Output" signaltype="3"/>
|
<PinSub pinname="PB14" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<PinSub pinname="PB15" signalname="TMR9_CH2" signaltype="2"/>
|
<PinSub pinname="PB15" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<PinSub pinname="PA8" signalname="GPIO_Output" signaltype="3"/>
|
<PinSub pinname="PA8" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<PinSub pinname="PA9" signalname="GPIO_Analog" signaltype="3"/>
|
<PinSub pinname="PA9" signalname="GPIO_Output" signaltype="3"/>
|
||||||
<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="PB8" signalname="CAN1_RX" signaltype="2"/>
|
<PinSub pinname="PB8" signalname="CAN1_RX" signaltype="2"/>
|
||||||
@@ -143,7 +139,7 @@
|
|||||||
<KeepUserCode>true</KeepUserCode>
|
<KeepUserCode>true</KeepUserCode>
|
||||||
<MinHeapSize>0x200</MinHeapSize>
|
<MinHeapSize>0x200</MinHeapSize>
|
||||||
<MinStackSize>0x400</MinStackSize>
|
<MinStackSize>0x400</MinStackSize>
|
||||||
<UseFirmware>true</UseFirmware>
|
<UseFirmware>false</UseFirmware>
|
||||||
<PackageVersion>V2.1.3</PackageVersion>
|
<PackageVersion>V2.1.3</PackageVersion>
|
||||||
</ProjectInfomation>
|
</ProjectInfomation>
|
||||||
</Root>
|
</Root>
|
||||||
|
|||||||
41
app/by_stepper.c
Normal file
41
app/by_stepper.c
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include "by_stepper.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <dwt_delay.h>
|
||||||
|
#include "by_debug.h"
|
||||||
|
|
||||||
|
// TODO 是否增加一个动作列表?一般都比较简单吧
|
||||||
|
|
||||||
|
struct by_stepper_t {
|
||||||
|
uint8_t dir;
|
||||||
|
stepper_speed_t speed;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_stepper_t by_stepper;
|
||||||
|
|
||||||
|
void by_stepper_init(void)
|
||||||
|
{
|
||||||
|
memset(&by_stepper, 0x00, sizeof(by_stepper));
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_stepper_set_dir(uint8_t dir)
|
||||||
|
{
|
||||||
|
by_stepper.dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_stepper_set_speed(stepper_speed_t speed)
|
||||||
|
{
|
||||||
|
by_stepper.speed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_stepper_run(void)
|
||||||
|
{
|
||||||
|
// 根据预设条件发送脉冲
|
||||||
|
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
||||||
|
gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
||||||
|
DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
void by_stepper_stop(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
10
app/by_stepper.h
Normal file
10
app/by_stepper.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "at32f413.h"
|
||||||
|
|
||||||
|
typedef enum stepper_speed_t {
|
||||||
|
STEPPER_SPEED_DIV0 = 0,
|
||||||
|
STEPPER_SPEED_DIV2 = 2,
|
||||||
|
STEPPER_SPEED_DIV4 = 4,
|
||||||
|
STEPPER_SPEED_DIV8 = 8,
|
||||||
|
STEPPER_SPEED_DIV16 = 16,
|
||||||
|
STEPPER_SPEED_DIV32 = 32
|
||||||
|
} stepper_speed_t;
|
||||||
@@ -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
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -56,18 +56,14 @@ extern "C" {
|
|||||||
/* add user code end exported macro */
|
/* add user code end exported macro */
|
||||||
|
|
||||||
/* Private defines -------------------------------------------------------------*/
|
/* Private defines -------------------------------------------------------------*/
|
||||||
#define SW_IN2_PIN GPIO_PINS_10
|
|
||||||
#define SW_IN2_GPIO_PORT GPIOB
|
|
||||||
#define SW_IN1_PIN GPIO_PINS_11
|
|
||||||
#define SW_IN1_GPIO_PORT GPIOB
|
|
||||||
#define MODE2_PIN GPIO_PINS_12
|
#define MODE2_PIN GPIO_PINS_12
|
||||||
#define MODE2_GPIO_PORT GPIOB
|
#define MODE2_GPIO_PORT GPIOB
|
||||||
#define MODE1_PIN GPIO_PINS_13
|
#define MODE1_PIN GPIO_PINS_13
|
||||||
#define MODE1_GPIO_PORT GPIOB
|
#define MODE1_GPIO_PORT GPIOB
|
||||||
#define MODE0_PIN GPIO_PINS_14
|
#define MODE0_PIN GPIO_PINS_14
|
||||||
#define MODE0_GPIO_PORT GPIOB
|
#define MODE0_GPIO_PORT GPIOB
|
||||||
#define STEP_PIN GPIO_PINS_15
|
#define CLK_PIN GPIO_PINS_15
|
||||||
#define STEP_GPIO_PORT GPIOB
|
#define CLK_GPIO_PORT GPIOB
|
||||||
#define DIR_PIN GPIO_PINS_8
|
#define DIR_PIN GPIO_PINS_8
|
||||||
#define DIR_GPIO_PORT GPIOA
|
#define DIR_GPIO_PORT GPIOA
|
||||||
#define EN_PIN GPIO_PINS_9
|
#define EN_PIN GPIO_PINS_9
|
||||||
@@ -104,9 +100,6 @@ extern "C" {
|
|||||||
/* init tmr3 function. */
|
/* init tmr3 function. */
|
||||||
void wk_tmr3_init(void);
|
void wk_tmr3_init(void);
|
||||||
|
|
||||||
/* init tmr9 function. */
|
|
||||||
void wk_tmr9_init(void);
|
|
||||||
|
|
||||||
/* init tmr10 function. */
|
/* init tmr10 function. */
|
||||||
void wk_tmr10_init(void);
|
void wk_tmr10_init(void);
|
||||||
|
|
||||||
|
|||||||
@@ -64,8 +64,9 @@
|
|||||||
/**
|
/**
|
||||||
* @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
|
||||||
* - sclk = 200000000
|
* - sclk = 200000000
|
||||||
* - ahbdiv = 1
|
* - ahbdiv = 1
|
||||||
* - ahbclk = 200000000
|
* - ahbclk = 200000000
|
||||||
@@ -73,7 +74,7 @@
|
|||||||
* - apb1clk = 100000000
|
* - apb1clk = 100000000
|
||||||
* - apb2div = 2
|
* - apb2div = 2
|
||||||
* - apb2clk = 100000000
|
* - apb2clk = 100000000
|
||||||
* - pll_mult = 50
|
* - pll_mult = 25
|
||||||
* - pll_range = GT72MHZ (greater than 72 mhz)
|
* - pll_range = GT72MHZ (greater than 72 mhz)
|
||||||
* @param none
|
* @param none
|
||||||
* @retval none
|
* @retval none
|
||||||
@@ -91,6 +92,14 @@ void wk_system_clock_config(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* enable hext */
|
||||||
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_HEXT, TRUE);
|
||||||
|
|
||||||
|
/* wait till hext is ready */
|
||||||
|
while(crm_hext_stable_wait() == ERROR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/* enable hick */
|
/* enable hick */
|
||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
|
||||||
|
|
||||||
@@ -100,7 +109,7 @@ void wk_system_clock_config(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* config pll clock resource */
|
/* config pll clock resource */
|
||||||
crm_pll_config(CRM_PLL_SOURCE_HICK, CRM_PLL_MULT_50, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
|
crm_pll_config(CRM_PLL_SOURCE_HEXT_DIV, CRM_PLL_MULT_25, CRM_PLL_OUTPUT_RANGE_GT72MHZ);
|
||||||
|
|
||||||
/* enable pll */
|
/* enable pll */
|
||||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
||||||
@@ -153,12 +162,12 @@ 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 gpiod periph clock */
|
||||||
|
crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
/* enable tmr1 periph clock */
|
/* enable tmr1 periph clock */
|
||||||
crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
|
crm_periph_clock_enable(CRM_TMR1_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
/* enable tmr9 periph clock */
|
|
||||||
crm_periph_clock_enable(CRM_TMR9_PERIPH_CLOCK, TRUE);
|
|
||||||
|
|
||||||
/* enable tmr10 periph clock */
|
/* enable tmr10 periph clock */
|
||||||
crm_periph_clock_enable(CRM_TMR10_PERIPH_CLOCK, TRUE);
|
crm_periph_clock_enable(CRM_TMR10_PERIPH_CLOCK, TRUE);
|
||||||
|
|
||||||
@@ -213,33 +222,27 @@ void wk_gpio_config(void)
|
|||||||
|
|
||||||
/* gpio input config */
|
/* gpio input config */
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
|
||||||
gpio_init_struct.gpio_pins = SW_IN2_PIN | SW_IN1_PIN;
|
gpio_init_struct.gpio_pins = GPIO_PINS_10 | GPIO_PINS_11;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
/* gpio output config */
|
/* gpio output config */
|
||||||
gpio_bits_reset(GPIOB, MODE2_PIN | MODE1_PIN | MODE0_PIN);
|
gpio_bits_reset(GPIOB, MODE2_PIN | MODE1_PIN | MODE0_PIN | CLK_PIN);
|
||||||
gpio_bits_reset(DIR_GPIO_PORT, DIR_PIN);
|
gpio_bits_reset(GPIOA, DIR_PIN | EN_PIN);
|
||||||
|
|
||||||
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 = MODE2_PIN | MODE1_PIN | MODE0_PIN;
|
gpio_init_struct.gpio_pins = MODE2_PIN | MODE1_PIN | MODE0_PIN | CLK_PIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(GPIOB, &gpio_init_struct);
|
gpio_init(GPIOB, &gpio_init_struct);
|
||||||
|
|
||||||
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 = DIR_PIN;
|
gpio_init_struct.gpio_pins = DIR_PIN | EN_PIN;
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
||||||
gpio_init(DIR_GPIO_PORT, &gpio_init_struct);
|
gpio_init(GPIOA, &gpio_init_struct);
|
||||||
|
|
||||||
/* gpio analog config */
|
|
||||||
gpio_init_struct.gpio_mode = GPIO_MODE_ANALOG;
|
|
||||||
gpio_init_struct.gpio_pins = EN_PIN;
|
|
||||||
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
||||||
gpio_init(EN_GPIO_PORT, &gpio_init_struct);
|
|
||||||
|
|
||||||
/* add user code begin gpio_config 2 */
|
/* add user code begin gpio_config 2 */
|
||||||
|
|
||||||
@@ -436,67 +439,6 @@ void wk_tmr3_init(void)
|
|||||||
/* add user code end tmr3_init 2 */
|
/* add user code end tmr3_init 2 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief init tmr9 function.
|
|
||||||
* @param none
|
|
||||||
* @retval none
|
|
||||||
*/
|
|
||||||
void wk_tmr9_init(void)
|
|
||||||
{
|
|
||||||
/* add user code begin tmr9_init 0 */
|
|
||||||
|
|
||||||
/* add user code end tmr9_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 tmr9_init 1 */
|
|
||||||
|
|
||||||
/* add user code end tmr9_init 1 */
|
|
||||||
|
|
||||||
/* configure the CH2 pin */
|
|
||||||
gpio_init_struct.gpio_pins = STEP_PIN;
|
|
||||||
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(STEP_GPIO_PORT, &gpio_init_struct);
|
|
||||||
|
|
||||||
/* GPIO PIN remap */
|
|
||||||
gpio_pin_remap_config(TMR9_GMUX, TRUE);
|
|
||||||
|
|
||||||
/* configure counter settings */
|
|
||||||
tmr_base_init(TMR9, 65535, 0);
|
|
||||||
tmr_cnt_dir_set(TMR9, TMR_COUNT_UP);
|
|
||||||
tmr_clock_source_div_set(TMR9, TMR_CLOCK_DIV1);
|
|
||||||
tmr_period_buffer_enable(TMR9, FALSE);
|
|
||||||
|
|
||||||
/* configure sub-mode */
|
|
||||||
tmr_sub_mode_select(TMR9, TMR_SUB_EXTERNAL_CLOCK_MODE_A);
|
|
||||||
|
|
||||||
/* configure sub-mode input */
|
|
||||||
tmr_trigger_input_select(TMR9, TMR_SUB_INPUT_SEL_IS2);
|
|
||||||
|
|
||||||
/* 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(TMR9, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
|
||||||
tmr_channel_value_set(TMR9, TMR_SELECT_CHANNEL_2, 0);
|
|
||||||
tmr_output_channel_buffer_enable(TMR9, TMR_SELECT_CHANNEL_2, FALSE);
|
|
||||||
|
|
||||||
tmr_counter_enable(TMR9, TRUE);
|
|
||||||
|
|
||||||
/* add user code begin tmr9_init 2 */
|
|
||||||
|
|
||||||
/* add user code end tmr9_init 2 */
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief init tmr10 function.
|
* @brief init tmr10 function.
|
||||||
* @param none
|
* @param none
|
||||||
|
|||||||
@@ -29,7 +29,10 @@
|
|||||||
|
|
||||||
/* private includes ----------------------------------------------------------*/
|
/* private includes ----------------------------------------------------------*/
|
||||||
/* add user code begin private includes */
|
/* add user code begin private includes */
|
||||||
|
#include "dwt_delay.h"
|
||||||
|
|
||||||
#include "by_debug.h"
|
#include "by_debug.h"
|
||||||
|
#include "by_can.h"
|
||||||
/* add user code end private includes */
|
/* add user code end private includes */
|
||||||
|
|
||||||
/* private typedef -----------------------------------------------------------*/
|
/* private typedef -----------------------------------------------------------*/
|
||||||
@@ -97,9 +100,6 @@ int main(void)
|
|||||||
/* init tmr3 function. */
|
/* init tmr3 function. */
|
||||||
wk_tmr3_init();
|
wk_tmr3_init();
|
||||||
|
|
||||||
/* init tmr9 function. */
|
|
||||||
wk_tmr9_init();
|
|
||||||
|
|
||||||
/* init tmr10 function. */
|
/* init tmr10 function. */
|
||||||
wk_tmr10_init();
|
wk_tmr10_init();
|
||||||
|
|
||||||
@@ -110,12 +110,22 @@ int main(void)
|
|||||||
wk_gpio_config();
|
wk_gpio_config();
|
||||||
|
|
||||||
/* add user code begin 2 */
|
/* add user code begin 2 */
|
||||||
|
DWT_Init();
|
||||||
|
|
||||||
LOGD("hello world");
|
LOGD("hello world");
|
||||||
|
|
||||||
|
gpio_bits_write(GPIOB, GPIO_PINS_12, FALSE); // MODE2
|
||||||
|
gpio_bits_write(GPIOB, GPIO_PINS_13, TRUE); // MODE1
|
||||||
|
gpio_bits_write(GPIOB, GPIO_PINS_14, TRUE); // MODE0
|
||||||
|
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
||||||
|
gpio_bits_write(GPIOA, GPIO_PINS_8, TRUE); // DIR
|
||||||
|
gpio_bits_write(GPIOB, GPIO_PINS_15, TRUE); // CLK
|
||||||
/* add user code end 2 */
|
/* add user code end 2 */
|
||||||
|
|
||||||
while (1) {
|
while(1)
|
||||||
|
{
|
||||||
/* add user code begin 3 */
|
/* add user code begin 3 */
|
||||||
|
DWT_Delay(40);
|
||||||
/* add user code end 3 */
|
/* add user code end 3 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user