|
|
|
|
@@ -65,7 +65,7 @@
|
|
|
|
|
* @brief system clock config program
|
|
|
|
|
* @note the system clock is configured as follow:
|
|
|
|
|
* system clock (sclk) = hext / 2 * pll_mult
|
|
|
|
|
* system clock source = pll (hext)
|
|
|
|
|
* system clock source = HEXT_VALUE
|
|
|
|
|
* - hext = HEXT_VALUE
|
|
|
|
|
* - sclk = 200000000
|
|
|
|
|
* - ahbdiv = 1
|
|
|
|
|
@@ -182,9 +182,6 @@ void wk_periph_clock_config(void)
|
|
|
|
|
|
|
|
|
|
/* enable can1 periph clock */
|
|
|
|
|
crm_periph_clock_enable(CRM_CAN1_PERIPH_CLOCK, TRUE);
|
|
|
|
|
|
|
|
|
|
/* enable pwc periph clock */
|
|
|
|
|
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -217,9 +214,17 @@ void wk_nvic_config(void)
|
|
|
|
|
*/
|
|
|
|
|
void wk_gpio_config(void)
|
|
|
|
|
{
|
|
|
|
|
/* add user code begin gpio_config 0 */
|
|
|
|
|
|
|
|
|
|
/* add user code end gpio_config 0 */
|
|
|
|
|
|
|
|
|
|
gpio_init_type gpio_init_struct;
|
|
|
|
|
gpio_default_para_init(&gpio_init_struct);
|
|
|
|
|
|
|
|
|
|
/* add user code begin 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_3 | GPIO_PINS_4 | GPIO_PINS_5 | GPIO_PINS_6;
|
|
|
|
|
@@ -235,46 +240,10 @@ void wk_gpio_config(void)
|
|
|
|
|
gpio_init_struct.gpio_pins = GPIO_PINS_15;
|
|
|
|
|
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
|
|
|
|
|
gpio_init(GPIOB, &gpio_init_struct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief init pwc function.
|
|
|
|
|
* @param none
|
|
|
|
|
* @retval none
|
|
|
|
|
*/
|
|
|
|
|
void wk_pwc_init(void)
|
|
|
|
|
{
|
|
|
|
|
/* add user code begin pwc_init 0 */
|
|
|
|
|
/* add user code begin gpio_config 2 */
|
|
|
|
|
|
|
|
|
|
/* add user code end pwc_init 0 */
|
|
|
|
|
|
|
|
|
|
exint_init_type exint_init_struct;
|
|
|
|
|
|
|
|
|
|
/* add user code begin pwc_init 1 */
|
|
|
|
|
|
|
|
|
|
/* add user code end pwc_init 1 */
|
|
|
|
|
|
|
|
|
|
/* set the threshold voltage*/
|
|
|
|
|
pwc_pvm_level_select(PWC_PVM_VOLTAGE_2V8);
|
|
|
|
|
/* enable power voltage monitor */
|
|
|
|
|
pwc_power_voltage_monitor_enable(TRUE);
|
|
|
|
|
|
|
|
|
|
exint_default_para_init(&exint_init_struct);
|
|
|
|
|
exint_init_struct.line_enable = TRUE;
|
|
|
|
|
exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
|
|
|
|
|
exint_init_struct.line_select = EXINT_LINE_16;
|
|
|
|
|
exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE;
|
|
|
|
|
exint_init(&exint_init_struct);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Users need to configure PWC interrupt functions according to the actual application.
|
|
|
|
|
* 1. Add the user's interrupt handler code into the below function in the at32f413_int.c file.
|
|
|
|
|
* --void PVM_IRQHandler (void)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* add user code begin pwc_init 2 */
|
|
|
|
|
|
|
|
|
|
/* add user code end pwc_init 2 */
|
|
|
|
|
/* add user code end gpio_config 2 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -379,7 +348,7 @@ void wk_tmr1_init(void)
|
|
|
|
|
gpio_init(GPIOA, &gpio_init_struct);
|
|
|
|
|
|
|
|
|
|
/* configure counter settings */
|
|
|
|
|
tmr_base_init(TMR1, 65535, 0);
|
|
|
|
|
tmr_base_init(TMR1, 999, 499);
|
|
|
|
|
tmr_cnt_dir_set(TMR1, TMR_COUNT_UP);
|
|
|
|
|
tmr_clock_source_div_set(TMR1, TMR_CLOCK_DIV1);
|
|
|
|
|
tmr_repetition_counter_set(TMR1, 0);
|
|
|
|
|
@@ -389,30 +358,37 @@ void wk_tmr1_init(void)
|
|
|
|
|
tmr_sub_sync_mode_set(TMR1, FALSE);
|
|
|
|
|
tmr_primary_mode_select(TMR1, TMR_PRIMARY_SEL_RESET);
|
|
|
|
|
|
|
|
|
|
/* configure overflow event */
|
|
|
|
|
tmr_overflow_event_disable(TMR1, TRUE);
|
|
|
|
|
|
|
|
|
|
/* configure channel 1 output settings */
|
|
|
|
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
|
|
|
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
|
|
|
|
tmr_output_struct.oc_output_state = TRUE;
|
|
|
|
|
tmr_output_struct.occ_output_state = TRUE;
|
|
|
|
|
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.oc_idle_state = TRUE;
|
|
|
|
|
tmr_output_struct.occ_idle_state = FALSE;
|
|
|
|
|
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_1, &tmr_output_struct);
|
|
|
|
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 0);
|
|
|
|
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_1, 500);
|
|
|
|
|
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
|
|
|
|
|
|
|
|
|
|
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_1, FALSE);
|
|
|
|
|
|
|
|
|
|
/* configure channel 2 output settings */
|
|
|
|
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_OFF;
|
|
|
|
|
tmr_output_struct.oc_mode = TMR_OUTPUT_CONTROL_PWM_MODE_A;
|
|
|
|
|
tmr_output_struct.oc_output_state = TRUE;
|
|
|
|
|
tmr_output_struct.occ_output_state = TRUE;
|
|
|
|
|
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.oc_idle_state = TRUE;
|
|
|
|
|
tmr_output_struct.occ_idle_state = FALSE;
|
|
|
|
|
tmr_output_channel_config(TMR1, TMR_SELECT_CHANNEL_2, &tmr_output_struct);
|
|
|
|
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 0);
|
|
|
|
|
tmr_channel_value_set(TMR1, TMR_SELECT_CHANNEL_2, 500);
|
|
|
|
|
tmr_output_channel_buffer_enable(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
|
|
|
|
|
|
|
|
|
|
tmr_output_channel_immediately_set(TMR1, TMR_SELECT_CHANNEL_2, FALSE);
|
|
|
|
|
|
|
|
|
|
/* configure break and dead-time settings */
|
|
|
|
|
tmr_brkdt_struct.brk_enable = FALSE;
|
|
|
|
|
tmr_brkdt_struct.auto_output_enable = FALSE;
|
|
|
|
|
|