暂存
This commit is contained in:
@@ -64,8 +64,9 @@
|
||||
/**
|
||||
* @brief system clock config program
|
||||
* @note the system clock is configured as follow:
|
||||
* system clock (sclk) = hick / 12 * pll_mult
|
||||
* system clock source = HICK_VALUE
|
||||
* system clock (sclk) = hext / 2 * pll_mult
|
||||
* system clock source = HEXT_VALUE
|
||||
* - hext = HEXT_VALUE
|
||||
* - sclk = 200000000
|
||||
* - ahbdiv = 1
|
||||
* - ahbclk = 200000000
|
||||
@@ -73,7 +74,7 @@
|
||||
* - apb1clk = 100000000
|
||||
* - apb2div = 2
|
||||
* - apb2clk = 100000000
|
||||
* - pll_mult = 50
|
||||
* - pll_mult = 25
|
||||
* - pll_range = GT72MHZ (greater than 72 mhz)
|
||||
* @param 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 */
|
||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_HICK, TRUE);
|
||||
|
||||
@@ -100,7 +109,7 @@ void wk_system_clock_config(void)
|
||||
}
|
||||
|
||||
/* 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 */
|
||||
crm_clock_source_enable(CRM_CLOCK_SOURCE_PLL, TRUE);
|
||||
@@ -153,12 +162,12 @@ void wk_periph_clock_config(void)
|
||||
/* enable gpiob periph clock */
|
||||
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 */
|
||||
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 */
|
||||
crm_periph_clock_enable(CRM_TMR10_PERIPH_CLOCK, TRUE);
|
||||
|
||||
@@ -213,33 +222,27 @@ void wk_gpio_config(void)
|
||||
|
||||
/* gpio input config */
|
||||
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(GPIOB, &gpio_init_struct);
|
||||
|
||||
/* gpio output config */
|
||||
gpio_bits_reset(GPIOB, MODE2_PIN | MODE1_PIN | MODE0_PIN);
|
||||
gpio_bits_reset(DIR_GPIO_PORT, DIR_PIN);
|
||||
gpio_bits_reset(GPIOB, MODE2_PIN | MODE1_PIN | MODE0_PIN | CLK_PIN);
|
||||
gpio_bits_reset(GPIOA, DIR_PIN | EN_PIN);
|
||||
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
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(GPIOB, &gpio_init_struct);
|
||||
|
||||
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
|
||||
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
|
||||
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(DIR_GPIO_PORT, &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);
|
||||
gpio_init(GPIOA, &gpio_init_struct);
|
||||
|
||||
/* add user code begin gpio_config 2 */
|
||||
|
||||
@@ -436,67 +439,6 @@ void wk_tmr3_init(void)
|
||||
/* 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.
|
||||
* @param none
|
||||
|
||||
@@ -29,7 +29,10 @@
|
||||
|
||||
/* private includes ----------------------------------------------------------*/
|
||||
/* add user code begin private includes */
|
||||
#include "dwt_delay.h"
|
||||
|
||||
#include "by_debug.h"
|
||||
#include "by_can.h"
|
||||
/* add user code end private includes */
|
||||
|
||||
/* private typedef -----------------------------------------------------------*/
|
||||
@@ -63,59 +66,66 @@
|
||||
/* add user code end 0 */
|
||||
|
||||
/**
|
||||
* @brief main function.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
* @brief main function.
|
||||
* @param none
|
||||
* @retval none
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* add user code begin 1 */
|
||||
/* add user code begin 1 */
|
||||
by_debug_init();
|
||||
/* add user code end 1 */
|
||||
|
||||
/* system clock config. */
|
||||
wk_system_clock_config();
|
||||
/* system clock config. */
|
||||
wk_system_clock_config();
|
||||
|
||||
/* config periph clock. */
|
||||
wk_periph_clock_config();
|
||||
/* config periph clock. */
|
||||
wk_periph_clock_config();
|
||||
|
||||
/* init debug function. */
|
||||
wk_debug_config();
|
||||
/* init debug function. */
|
||||
wk_debug_config();
|
||||
|
||||
/* nvic config. */
|
||||
wk_nvic_config();
|
||||
/* nvic config. */
|
||||
wk_nvic_config();
|
||||
|
||||
/* init usart2 function. */
|
||||
wk_usart2_init();
|
||||
/* init usart2 function. */
|
||||
wk_usart2_init();
|
||||
|
||||
/* init exint function. */
|
||||
wk_exint_config();
|
||||
/* init exint function. */
|
||||
wk_exint_config();
|
||||
|
||||
/* init tmr1 function. */
|
||||
wk_tmr1_init();
|
||||
/* init tmr1 function. */
|
||||
wk_tmr1_init();
|
||||
|
||||
/* init tmr3 function. */
|
||||
wk_tmr3_init();
|
||||
/* init tmr3 function. */
|
||||
wk_tmr3_init();
|
||||
|
||||
/* init tmr9 function. */
|
||||
wk_tmr9_init();
|
||||
/* init tmr10 function. */
|
||||
wk_tmr10_init();
|
||||
|
||||
/* init tmr10 function. */
|
||||
wk_tmr10_init();
|
||||
/* init can1 function. */
|
||||
wk_can1_init();
|
||||
|
||||
/* init can1 function. */
|
||||
wk_can1_init();
|
||||
/* init gpio function. */
|
||||
wk_gpio_config();
|
||||
|
||||
/* init gpio function. */
|
||||
wk_gpio_config();
|
||||
/* add user code begin 2 */
|
||||
DWT_Init();
|
||||
|
||||
/* add user code begin 2 */
|
||||
LOGD("hello world");
|
||||
/* add user code end 2 */
|
||||
|
||||
while (1) {
|
||||
/* add user code begin 3 */
|
||||
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 */
|
||||
|
||||
while(1)
|
||||
{
|
||||
/* add user code begin 3 */
|
||||
DWT_Delay(40);
|
||||
/* add user code end 3 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user