#define M_G_U GPIOA
#define M_G_V GPIOA
#define M_G_W GPIOB
#define M_G_P_U GPIO_PIN_6
#define M_G_P_V GPIO_PIN_7
#define M_G_P_W GPIO_PIN_0
#define M_G_UN GPIOA
#define M_G_VN GPIOA
#define M_G_WN GPIOA
#define M_G_P_UN GPIO_PIN_3
#define M_G_P_VN GPIO_PIN_4
#define M_G_P_WN GPIO_PIN_5
#define M_G_FAULT GPIOB
#define M_G_P_FAULT GPIO_PIN_1
#define M_G_SLEEP GPIOB
#define M_G_P_SLEEP GPIO_PIN_2
#define H_G_A GPIOA
#define H_G_B GPIOA
#define H_G_C GPIOA
#define H_G_P_A GPIO_PIN_0
#define H_G_P_B GPIO_PIN_1
#define H_G_P_C GPIO_PIN_2
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_AF);
timer_parameter_struct timer_initpara;
timer_oc_parameter_struct timer_ocintpara;
gpio_init(M_G_U, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, M_G_P_U);
gpio_init(M_G_V, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, M_G_P_V);
gpio_init(M_G_W, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, M_G_P_W);
gpio_init(M_G_UN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, M_G_P_UN);
gpio_init(M_G_VN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, M_G_P_VN);
gpio_init(M_G_WN, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, M_G_P_WN);
gpio_init(M_G_FAULT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, M_G_P_FAULT);
gpio_init(M_G_SLEEP, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, M_G_P_SLEEP);
gpio_bit_reset(M_G_UN, M_G_P_UN);
gpio_bit_reset(M_G_VN, M_G_P_VN);
gpio_bit_reset(M_G_VN, M_G_P_WN);
gpio_bit_set(M_G_FAULT, M_G_P_FAULT);
gpio_bit_set(M_G_SLEEP, M_G_P_SLEEP);
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
// timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 1 - 1;
timer_initpara.period = 5000 - 1;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER2, &timer_initpara);
// timer_channel_output_struct_para_init(&timer_ocintpara);
timer_ocintpara.ocidlestate = TIMER_CCX_ENABLE;
timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
timer_ocintpara.outputstate = TIMER_OC_IDLE_STATE_LOW;
timer_ocintpara.ocnidlestate = TIMER_CCXN_DISABLE;
timer_ocintpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;
timer_ocintpara.outputnstate = TIMER_OCN_IDLE_STATE_LOW;
timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
timer_channel_output_config(TIMER2, TIMER_CH_1, &timer_ocintpara);
timer_channel_output_config(TIMER2, TIMER_CH_2, &timer_ocintpara);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 2500 - 1);
timer_channel_output_mode_config(TIMER2, TIMER_CH_0, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 2500 - 1);
timer_channel_output_mode_config(TIMER2, TIMER_CH_1, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, 2500 - 1);
timer_channel_output_mode_config(TIMER2, TIMER_CH_2, TIMER_OC_MODE_PWM0);
timer_channel_output_shadow_config(TIMER2, TIMER_CH_2, TIMER_OC_SHADOW_DISABLE);
timer_channel_output_fast_config(TIMER2, TIMER_CH_0, TIMER_OC_FAST_ENABLE);
timer_channel_output_clear_config(TIMER2, TIMER_CH_0, TIMER_OC_CLEAR_ENABLE);
timer_channel_output_polarity_config(TIMER2, TIMER_CH_0, TIMER_OC_POLARITY_HIGH);
timer_channel_output_state_config(TIMER2, TIMER_CH_0, TIMER_CCX_ENABLE);
timer_automatic_output_enable(TIMER2);
timer_primary_output_config(TIMER2, ENABLE);
timer_auto_reload_shadow_enable(TIMER2);
timer_enable(TIMER2);
gpio_init(H_G_A, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, H_G_P_A);
gpio_init(H_G_B, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, H_G_P_B);
gpio_init(H_G_C, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, H_G_P_C);
|