Parcourir la source

at32 demo板测试

Signed-off-by: kevin <huhui@sharkgulf.com>
kevin il y a 2 ans
Parent
commit
6d466a7a7c

+ 3 - 0
Applications/app/app.c

@@ -113,6 +113,9 @@ static void app_print_log(void) {
 	//sys_debug("Trq: %f-%f-%f\n", motor.controller.ramp_input_torque.target, motor.controller.ramp_input_torque.interpolation, motor.controller.ramp_input_torque.step);
 	sys_debug("FOC is %s, %d,%d, pwm:%s\n", mot_contrl_is_start(mot_contrl())?"start":"stop", motor.foc_start_cnt, motor.foc_stop_cnt, pwm_channel_is_enabled()?"start":"stop");
 	sys_debug("curr: %f,%f\n", mot_contrl()->dc_curr_calc, mot_contrl()->dc_curr_filted);
+	float phase_vol[3];
+	get_uvw_phases_raw(phase_vol);
+	sys_debug("phvol: %f,%f,%f\n", phase_vol[0], phase_vol[1], phase_vol[2]);
 	//F_debug();
 	//eCtrl_debug_log();
 	//sys_debug("enc err %d, %d\n", foc_observer_enc_errcount(), foc_observer_sensorless_stable());

+ 8 - 1
Applications/app/factory.h

@@ -2,7 +2,14 @@
 #define _FACTORY_H__
 #include "prot/can_message.h"
 
+#ifdef CONFIG_BOARD_MCXXX
 void can_process_factory_message(can_message_t *can_message);
 bool factory_is_running(void);
-
+#else
+static void can_process_factory_message(can_message_t *can_message){
+}
+static bool factory_is_running(void){
+	return false;
+}
+#endif
 #endif /* _FACTORY_H__ */

+ 97 - 227
Applications/bsp/at32/adc.c

@@ -5,61 +5,18 @@
 #include "math/fast_math.h"
 
 
-#ifdef CONFIG_BOARD_MCXXX
-#if (CONFIG_MC105_HW_VERSION==2)
-#define ADC01_NUM (8)
-#define ADC2_NUM 4
+#define ADC1_NUM 3
+#define ADC2_NUM 3
 
-#define MOS_TEMP_BUFF_IDX 0
-#define VREF5v_BUFF_IDX 1
-#define VBUS_I_BUFF_IDX 2
-#define U_VOL_BUFF_IDX 3
-#define V_VOL_BUFF_IDX 4
-#define W_VOL_BUFF_IDX 5
-#define VREF_BUFF_IDX 7
+#define U_VOL_BUFF_IDX 0
+#define V_VOL_BUFF_IDX 1
+#define W_VOL_BUFF_IDX 2
+#define VBUS_I_BUFF_IDX 3
+#define MOS_TEMP_BUFF_IDX 4
+#define VBUS_V_BUFF_IDX 5
 
-#define VBUS_V_BUFF_IDX 8
-#define ACC_V_BUFF_IDX 9
-#define THROTTLE_BUFF_IDX 10
-#define MOTOR_TEMP_BUFF_IDX 11
-
-#elif (CONFIG_MC105_HW_VERSION==3)
-#define ADC1_NUM 9
-#define ADC2_NUM 9
-
-#define MOS_TEMP_BUFF_IDX 0
-#define VBUS_V_BUFF_IDX 1
-
-#define MOTOR_TEMP_BUFF_IDX 2
-#define ACC_V_BUFF_IDX 3
-
-#define THROTTLE_BUFF_IDX 4
-#define VBUS_I_BUFF_IDX 5
-
-#define THROTTLE2_BUFF_IDX 6
-#define V_VOL_BUFF_IDX 7
-
-//zero chan            8
-#define W_VOL_BUFF_IDX 9
-
-#define VREF_BUFF_IDX   10
-//zero chan             11
-
-#define THROTTLE2_5V_BUFF_IDX 12
-#define THROTTLE_5V_BUFF_IDX 13
-
-#define U_VOL_BUFF_IDX 14
-//zero chan            15
-
-//zero chan            16
-#define VREF5v_BUFF_IDX 17
-
-#endif
-#endif
 #define REG_CHAN_NUM (ADC1_NUM + ADC2_NUM)
 u16 adc_buffer[REG_CHAN_NUM];
-float vref_adc = 1408.0f;
-float vref_5v_adc = 3095.0f;
 
 static void analog_gpio_init(gpio_type *gpiox, u32 pin) {
 	gpio_init_type gpio_init_struct = {0};
@@ -90,13 +47,76 @@ static void adc01_dma_init(void)
 	dma_init_struct.priority = DMA_PRIORITY_HIGH;
 	dma_init_struct.loop_mode_enable = TRUE;
 	dma_init(DMA1_CHANNEL1, &dma_init_struct);
-	
+	/* Flexible Mode Channel Cofig */
+  	dma_flexible_config(DMA1, FLEX_CHANNEL1, DMA_FLEXIBLE_ADC1);
 	dma_channel_enable(DMA1_CHANNEL1, TRUE);
 
 }
 
+static void adc_preempt_channel_set_samples(adc_type *adc_x, adc_channel_select_type adc_channel, adc_sampletime_select_type adc_sampletime)
+{
+  switch(adc_channel)
+  {
+    case ADC_CHANNEL_0:
+      adc_x->spt2_bit.cspt0 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_1:
+      adc_x->spt2_bit.cspt1 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_2:
+      adc_x->spt2_bit.cspt2 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_3:
+      adc_x->spt2_bit.cspt3 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_4:
+      adc_x->spt2_bit.cspt4 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_5:
+      adc_x->spt2_bit.cspt5 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_6:
+      adc_x->spt2_bit.cspt6 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_7:
+      adc_x->spt2_bit.cspt7 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_8:
+      adc_x->spt2_bit.cspt8 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_9:
+      adc_x->spt2_bit.cspt9 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_10:
+      adc_x->spt1_bit.cspt10 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_11:
+      adc_x->spt1_bit.cspt11 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_12:
+      adc_x->spt1_bit.cspt12 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_13:
+      adc_x->spt1_bit.cspt13 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_14:
+      adc_x->spt1_bit.cspt14 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_15:
+      adc_x->spt1_bit.cspt15 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_16:
+      adc_x->spt1_bit.cspt16 = adc_sampletime;
+      break;
+    case ADC_CHANNEL_17:
+      adc_x->spt1_bit.cspt17 = adc_sampletime;
+      break;
+    default:
+      break;
+  }
+}
 
-static void adc0_init(void){
+static void adc01_init(void){
 	adc_base_config_type adc_base_struct;
 	
 	/* adc clock configuration */
@@ -115,52 +135,38 @@ static void adc0_init(void){
 	adc_base_config(ADC2, &adc_base_struct);
 	
 	/* ordinary channel configuration */
-	adc_ordinary_channel_set(ADC1, MOS_TEMP_ADC_CHAN, 1, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, MOTOR_TEMP_ADC_CHAN, 2, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, THROTTLE_CHAN, 3, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, THROTTLE2_CHAN, 4, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, ZERO_ADC_CHAN, 5, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
-	adc_ordinary_channel_set(ADC1, ADC_CHANNEL_17, 6, ADC_REGCHAN_SAMPLE_TIME); //mcu内部vref
-	adc_ordinary_channel_set(ADC1, THROTTLE2_5V_CHAN, 7, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, U_VOL_ADC_CHAN, 8, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC1, ZERO_ADC_CHAN, 9, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
+	adc_ordinary_channel_set(ADC1, U_VOL_ADC_CHAN, 1, ADC_REGCHAN_SAMPLE_TIME);
+	adc_ordinary_channel_set(ADC1, W_VOL_ADC_CHAN, 2, ADC_REGCHAN_SAMPLE_TIME);
+	adc_ordinary_channel_set(ADC1, MOS_TEMP_ADC_CHAN, 3, ADC_REGCHAN_SAMPLE_TIME);
 	adc_ordinary_conversion_trigger_set(ADC1, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);
 
-	adc_ordinary_channel_set(ADC2, VBUS_V_CHAN, 1, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ACC_V_CHAN, 2, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, VBUS_I_CHAN, 3, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, V_VOL_ADC_CHAN, 4, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, W_VOL_ADC_CHAN, 5, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ZERO_ADC_CHAN, 6, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
-	adc_ordinary_channel_set(ADC2, THROTTLE_5V_CHAN, 7, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ZERO_ADC_CHAN, 8, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
-	adc_ordinary_channel_set(ADC2, DC5V_ADC_CHAN, 9, ADC_REGCHAN_SAMPLE_TIME);
+	adc_ordinary_channel_set(ADC2, V_VOL_ADC_CHAN, 1, ADC_REGCHAN_SAMPLE_TIME);
+	adc_ordinary_channel_set(ADC2, VBUS_I_CHAN, 2, ADC_REGCHAN_SAMPLE_TIME);
+	adc_ordinary_channel_set(ADC2, VBUS_V_CHAN, 3, ADC_REGCHAN_SAMPLE_TIME);
 	adc_ordinary_conversion_trigger_set(ADC2, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);
 
 
-	adc_preempt_channel_length_set(ADC1, 3);
-	adc_preempt_channel_set(ADC1, V_PHASE_I_CHAN, 1, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC1, V_PHASE_I_CHAN, 2, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC1, V_PHASE_I_CHAN, 3, ADC_INSERT_SAMPLE_TIME);
-	//adc_preempt_channel_set(ADC1, V_PHASE_I_CHAN, 4, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_length_set(ADC1, 1);
+	adc_preempt_channel_set(ADC1, U_PHASE_I_CHAN, 1, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_set_samples(ADC1, V_PHASE_I_CHAN, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_set_samples(ADC1, W_PHASE_I_CHAN, ADC_INSERT_SAMPLE_TIME);
 	/* adc prempt trigger source */
 	adc_preempt_conversion_trigger_set(ADC1, ADC12_PREEMPT_TRIG_TMR1CH4, TRUE);
 
-	adc_preempt_channel_length_set(ADC2, 3);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 1, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 2, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 3, ADC_INSERT_SAMPLE_TIME);
-	//adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 4, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_length_set(ADC2, 1);
+	adc_preempt_channel_set(ADC2, V_PHASE_I_CHAN, 1, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_set_samples(ADC2, U_PHASE_I_CHAN, ADC_INSERT_SAMPLE_TIME);
+	adc_preempt_channel_set_samples(ADC2, W_PHASE_I_CHAN, ADC_INSERT_SAMPLE_TIME);
 	/* adc prempt trigger source */
 	adc_preempt_conversion_trigger_set(ADC2, ADC12_PREEMPT_TRIG_TMR1CH4, TRUE);
 
 	/* select adc mster-slave mode */
 	adc_combine_mode_select(ADC_ORDINARY_SMLT_PREEMPT_SMLT_MODE);
 
-	adc_tempersensor_vintrv_enable(TRUE);
+	//adc_tempersensor_vintrv_enable(TRUE);
 
 	adc_dma_mode_enable(ADC1, TRUE);
-	adc_dma_mode_enable(ADC2, TRUE);
+	//adc_dma_mode_enable(ADC2, TRUE);
 
 	/* ADC enable and calibration */
 	adc_enable(ADC1, TRUE);
@@ -179,60 +185,12 @@ static void adc0_init(void){
 
 	adc_disable_ext_trigger();
 
-	adc_current_sample_config(0);
+	adc_current_sample_config(PHASE_AB);
 	
 	adc_ordinary_software_trigger_enable(ADC1, TRUE);
 }
 
-static void adc1_init(void){
-
-#if 0
-	adc_base_config_type adc_base_struct;
-	
-	/* adc clock configuration */
-	crm_periph_clock_enable(CRM_ADC2_PERIPH_CLOCK, TRUE);
-
-	adc_reset(ADC2);
-	adc_base_struct.sequence_mode = TRUE;
-	adc_base_struct.repeat_mode = TRUE;
-	adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;
-	adc_base_struct.ordinary_channel_length = ADC2_NUM;
-	adc_base_config(ADC2, &adc_base_struct);
-
-	/* ordinary channel configuration */
-	adc_ordinary_channel_set(ADC2, VBUS_V_CHAN, 1, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ACC_V_CHAN, 2, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, VBUS_I_CHAN, 3, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, V_VOL_ADC_CHAN, 4, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, W_VOL_ADC_CHAN, 5, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ZERO_ADC_CHAN, 6, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
-	adc_ordinary_channel_set(ADC2, THROTTLE_5V_CHAN, 7, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_channel_set(ADC2, ZERO_ADC_CHAN, 8, ADC_REGCHAN_SAMPLE_TIME); //insert zero vol
-	adc_ordinary_channel_set(ADC2, DC5V_ADC_CHAN, 9, ADC_REGCHAN_SAMPLE_TIME);
-	adc_ordinary_conversion_trigger_set(ADC2, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);
-
-	adc_preempt_channel_length_set(ADC2, 3);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 1, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 2, ADC_INSERT_SAMPLE_TIME);
-	adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 3, ADC_INSERT_SAMPLE_TIME);
-	//adc_preempt_channel_set(ADC2, W_PHASE_I_CHAN, 4, ADC_INSERT_SAMPLE_TIME);
-	/* adc prempt trigger source */
-	adc_preempt_conversion_trigger_set(ADC2, ADC12_PREEMPT_TRIG_TMR1CH4, TRUE);
-
-	adc_dma_mode_enable(ADC2, TRUE);
-	/* ADC enable and calibration */
-	adc_enable(ADC2, TRUE);
-	adc_calibration_init(ADC2);
-	while(adc_calibration_init_status_get(ADC2));
-	adc_calibration_start(ADC2);
-	while(adc_calibration_status_get(ADC2));
-#endif
-}
-
-
 static void adc_gpio_init(void) {
-
-	/* configure ADC pin, current sampling -- ADC_IN1(PA1) ADC_IN12(PC2) ADC_IN13(PC3) */
 #ifdef U_PHASE_ADC_GROUP
 	crm_periph_clock_enable(U_PHASE_ADC_RCU, TRUE);
 	analog_gpio_init(U_PHASE_ADC_GROUP, U_PHASE_ADC_PIN);
@@ -245,47 +203,14 @@ static void adc_gpio_init(void) {
 	crm_periph_clock_enable(W_PHASE_ADC_RCU, TRUE);
 	analog_gpio_init(W_PHASE_ADC_GROUP, W_PHASE_ADC_PIN);
 #endif
-
 #ifdef VBUS_V_ADC_GROUP
 	crm_periph_clock_enable(VBUS_V_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
 	analog_gpio_init(VBUS_V_ADC_GROUP, VBUS_V_ADC_PIN);
 #endif
-
 #ifdef VBUS_I_ADC_GROUP
 	crm_periph_clock_enable(VBUS_I_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
 	analog_gpio_init(VBUS_I_ADC_GROUP, VBUS_I_ADC_PIN);
 #endif
-
-
-#ifdef ACC_V_ADC_GROUP
-	crm_periph_clock_enable(ACC_V_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
-	analog_gpio_init(ACC_V_ADC_GROUP, ACC_V_ADC_PIN);
-#endif
-
-#ifdef THROTTLE_V_ADC_GROUP
-	crm_periph_clock_enable(THROTTLE_V_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
-	analog_gpio_init(THROTTLE_V_ADC_GROUP, THROTTLE_V_ADC_PIN);
-#endif
-#ifdef THROTTLE2_V_ADC_GROUP
-	crm_periph_clock_enable(THROTTLE2_V_ADC_RCU, TRUE);
-	analog_gpio_init(THROTTLE2_V_ADC_GROUP, THROTTLE2_V_ADC_PIN);
-#endif
-
-#ifdef THROTTLE_5V_ADC_GROUP
-	crm_periph_clock_enable(THROTTLE_5V_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
-	analog_gpio_init(THROTTLE_5V_ADC_GROUP, THROTTLE_5V_ADC_PIN);
-#endif
-#ifdef THROTTLE2_5V_ADC_GROUP
-	crm_periph_clock_enable(THROTTLE2_5V_ADC_RCU, TRUE);
-	/* configure ADC pin, bus voltage sampling -- ADC_IN0(PA0) */
-	analog_gpio_init(THROTTLE2_5V_ADC_GROUP, THROTTLE2_5V_ADC_PIN);
-#endif
-
 #ifdef U_VOL_ADC_GROUP
 	crm_periph_clock_enable(U_VOL_ADC_RCU, TRUE);
 	analog_gpio_init(U_VOL_ADC_GROUP,  U_VOL_ADC_PIN);
@@ -302,64 +227,37 @@ static void adc_gpio_init(void) {
 	crm_periph_clock_enable(MOS_TEMP_ADC_RCU, TRUE);
 	analog_gpio_init(MOS_TEMP_ADC_GROUP, MOS_TEMP_ADC_PIN);
 #endif
-#ifdef MOS_TEMP1_ADC_GROUP
-	crm_periph_clock_enable(MOS_TEMP1_ADC_RCU, TRUE);
-	analog_gpio_init(MOS_TEMP1_ADC_GROUP, MOS_TEMP1_ADC_PIN);
-#endif
-
-#ifdef MOTOR_TEMP_ADC_GROUP
-	crm_periph_clock_enable(MOTOR_TEMP_ADC_RCU, TRUE);
-	analog_gpio_init(MOTOR_TEMP_ADC_GROUP, MOTOR_TEMP_ADC_PIN);
-#endif
-
-#ifdef ZERO_ADC_GROUP
-	crm_periph_clock_enable(ZERO_ADC_RCU, TRUE);
-	analog_gpio_init(ZERO_ADC_GROUP, ZERO_ADC_PIN);
-#endif
 
 }
 
-void adc_init(void) {
+void adc_init(bool mot_ind) {
 	adc_gpio_init();
 	adc01_dma_init();
-	adc0_init();
-	adc1_init();
+	adc01_init();
 }
 
 void adc_set_vref_calc(float v) {
-	vref_adc = v;
 }
 
 void adc_set_5vref_calc(float v) {
-	vref_5v_adc = v;
 }
 
-#define VREF_COMP_LFP_CEOF (0.0001F)
+
 static float vref_compestion_filter = 1.0f;
-#define VREF_3V3_COMPESTION() (vref_adc/(float)adc_buffer[VREF_BUFF_IDX])
-void adc_3v3ref_filter(void) {
-	float value = VREF_3V3_COMPESTION();
-	LowPass_Filter(vref_compestion_filter, value, VREF_COMP_LFP_CEOF);
-}
+#define VREF_3V3_COMPESTION() (vref_compestion_filter)
 
 float adc_vref_compesion(void) {
 	return vref_compestion_filter;
 }
 
 static float vref_5v_compestion_filter = 1.0f;
-#define VREF_5V_COMPESTION() (vref_5v_adc/(float)adc_buffer[VREF5v_BUFF_IDX])
-void adc_5vref_filter(void) {
-	float value = VREF_5V_COMPESTION();
-	LowPass_Filter(vref_5v_compestion_filter, value, VREF_COMP_LFP_CEOF);
-}
+#define VREF_5V_COMPESTION() (vref_5v_compestion_filter)
 
 float adc_5vref_compesion(void) {
 	return vref_5v_compestion_filter;
 }
 
 void adc_vref_filter(void) {
-	adc_3v3ref_filter();
-	adc_5vref_filter();
 }
 
 u16 adc_get_vbus(void) {
@@ -367,47 +265,27 @@ u16 adc_get_vbus(void) {
 }
 
 u16 adc_get_acc(void) {
-#ifdef CONFIG_BOARD_MCXXX
-	return (float)adc_buffer[ACC_V_BUFF_IDX] * VREF_3V3_COMPESTION();
-#else
 	return adc_get_vbus();
-#endif
 }
 
 u16 adc_get_ibus(void) {
-#ifdef CONFIG_BOARD_MCXXX
 	return (float)adc_buffer[VBUS_I_BUFF_IDX] * VREF_5V_COMPESTION();
-#else
-	return 0;
-#endif
 }
 
 u16 adc_get_throttle(void) {
-	return adc_buffer[THROTTLE_BUFF_IDX] * VREF_3V3_COMPESTION();
+	return 0;
 }
 
 u16 adc_get_throttle2(void) {
-#ifdef THROTTLE2_BUFF_IDX
-	return adc_buffer[THROTTLE2_BUFF_IDX] * VREF_3V3_COMPESTION();
-#else
 	return adc_get_throttle();
-#endif
 }
 
 u16 adc_get_thro_5v(void) {
-#ifdef THROTTLE_5V_BUFF_IDX
-	return adc_buffer[THROTTLE_5V_BUFF_IDX] * VREF_3V3_COMPESTION();
-#else
 	return 0;
-#endif
 }
 
 u16 adc_get_thro2_5v(void) {
-#ifdef THROTTLE2_5V_BUFF_IDX
-	return adc_buffer[THROTTLE2_5V_BUFF_IDX] * VREF_3V3_COMPESTION();
-#else
 	return 0;
-#endif
 }
 
 void adc_get_uvw_phaseV(u16 *uvw) {
@@ -421,23 +299,15 @@ u16 adc_get_mos_temp(void) {
 }
 
 u16 adc_get_motor_temp(void) {
-	return adc_buffer[MOTOR_TEMP_BUFF_IDX];
+	return 0;
 }
 
 u16 adc_get_vref(void) {
-#ifdef CONFIG_BOARD_MCXXX
-	return adc_buffer[VREF_BUFF_IDX];
-#else
 	return 0;
-#endif
 }
 
 u16 adc_get_5v_ref(void) {
-#ifdef CONFIG_BOARD_MCXXX
-	return adc_buffer[VREF5v_BUFF_IDX];
-#else
 	return 0;
-#endif
 }
 
 void adc_start_convert(void) {

+ 19 - 16
Applications/bsp/at32/adc.h

@@ -16,34 +16,37 @@ inserted ADC 由timer0 ch3触发,
 #define ISQ3_OFFSET 15
 #define IL_OFFSET   20
 
-#define ADC_REGCHAN_SAMPLE_TIME ADC_SAMPLETIME_239_5
-#define ADC_INSERT_SAMPLE_TIME ADC_SAMPLETIME_28_5
+#define ADC_REGCHAN_SAMPLE_TIME ADC_SAMPLETIME_71_5
+#define ADC_INSERT_SAMPLE_TIME ADC_SAMPLETIME_1_5
 #define ADC_TRIGGER_PHASE ADC12_PREEMPT_TRIG_TMR1CH4
 
-#define PHASE_AB 0
-#define PHASE_AC 1
-#define PHASE_BC 2
-
-
 static void __inline adc_phase_current_read(u8 phases, s32 *v1, s32 *v2) {
-	*v1 = (s32)((float)((ADC1->pdt2_bit.pdt2 + ADC1->pdt3_bit.pdt3)/2.0f) * adc_5vref_compesion());
-	*v2 = (s32)((float)((ADC2->pdt2_bit.pdt2 + ADC2->pdt3_bit.pdt3)/2.0f) * adc_5vref_compesion());
+	*v1 = (s32)((float)(ADC1->pdt1_bit.pdt1) * adc_5vref_compesion());
+	*v2 = (s32)((float)(ADC2->pdt1_bit.pdt1) * adc_5vref_compesion());
 }
 
 
 static void __inline adc_current_sample_config(u8 phases) {
-	//ADC1->psq_bit.psn4 = V_PHASE_I_CHAN;
-	//ADC2->psq_bit.psn4 = W_PHASE_I_CHAN;
+	if (phases == PHASE_AB) {
+		ADC1->psq_bit.psn4 = U_PHASE_I_CHAN;
+		ADC2->psq_bit.psn4 = V_PHASE_I_CHAN;
+	}else if (phases == PHASE_AC) {
+		ADC1->psq_bit.psn4 = U_PHASE_I_CHAN;
+		ADC2->psq_bit.psn4 = W_PHASE_I_CHAN;
+	}else {
+		ADC1->psq_bit.psn4 = V_PHASE_I_CHAN;
+		ADC2->psq_bit.psn4 = W_PHASE_I_CHAN;
+	}
 }
 
 static void __inline adc_disable_ext_trigger(void) {   
-	//ADC1->ctrl2_bit.pcten = FALSE;
-	//ADC2->ctrl2_bit.pcten = FALSE;
+	ADC1->ctrl2_bit.pcten = FALSE;
+	ADC2->ctrl2_bit.pcten = FALSE;
 }
 
 static void __inline adc_enable_ext_trigger(void) {	
-	//ADC1->ctrl2_bit.pcten = TRUE;
-	//ADC2->ctrl2_bit.pcten = TRUE;
+	ADC1->ctrl2_bit.pcten = TRUE;
+	ADC2->ctrl2_bit.pcten = TRUE;
 }
 
 static __inline__ void adc_clear_irq_flags(void) {
@@ -56,7 +59,7 @@ static __inline__ void adc_clear_irq_flags(void) {
 #define adc_update_ext_trigger(trigger) \
 	adc_preempt_conversion_trigger_set(ADC1, trigger, TRUE)
 
-void adc_init(void);
+void adc_init(bool mot_ind);
 void adc_start_convert(void);
 void adc_stop_convert(void);
 u16 adc_get_vbus(void);

+ 29 - 13
Applications/bsp/at32/board_at32_mc.h

@@ -13,21 +13,22 @@
 #define CONFIG_STALL_MAX_TIME    3000   //ms, 超过最大堵转电流持续时间,判断堵转
 
 #define CONFIG_LADRC_OBSERVER
-//#define CONFIG_FORCE_HIGH_VOL_MODE
 #ifdef CONFIG_SENSORLESS_TOW_SAMPLES
 #define CONFIG_SENSORLESS_TS (FOC_CTRL_US/2.0f)
 #else
 #define CONFIG_SENSORLESS_TS FOC_CTRL_US
 #endif
 
-//#define CONFIG_FORCE_HIGH_VOL_MODE 1
+#define CONFIG_FORCE_HIGH_VOL_MODE 1
 
 #define SCHED_TIMER TMR5
 #define SCHED_TIMER_RCU CRM_TMR5_PERIPH_CLOCK
 #define SCHED_TIMER_IRQ TMR5_GLOBAL_IRQn
 #define SCHED_TIMER_IRQHandler TMR5_GLOBAL_IRQHandler
 
-#define PWM_DEAD_TIME_NS 400u
+#define CONFIG_THREE_SHUNT 
+
+#define PWM_DEAD_TIME_NS 300u
 #define PWM_TOFF_DELAY_MAX 240u
 #define PWM_TON_DELAY_MIN 200u
 #define HW_DEAD_TIME_NS  210u
@@ -123,7 +124,7 @@
 #define VBUS_V_ADC_PIN 				GPIO_PINS_7
 #define VBUS_V_ADC_RCU 				CRM_GPIOA_PERIPH_CLOCK
 #define VBUS_V_ADC_MODE 			GPIO_MODE_ANALOG
-#define VBUS_VOL_CEOF 				(ADC_REFERENCE_VOLTAGE*(3.9F + 180.0F)/ADC_FULL_MAX)
+#define VBUS_VOL_CEOF 				(ADC_REFERENCE_VOLTAGE*(1.39F + 18.0F)/ADC_FULL_MAX)
 
 #define VBUS_I_CHAN 				ADC_CHANNEL_3 //adc012
 #define VBUS_I_ADC_GROUP 			GPIOA
@@ -172,19 +173,34 @@
 #define W_VOL_ADC_RCU 				CRM_GPIOA_PERIPH_CLOCK
 #define W_VOL_ADC_MODE 				GPIO_MODE_ANALOG
 #define UVW_VOL_CEOF 				(ADC_REFERENCE_VOLTAGE*((37.4F + 3.9F)/3.9F)/ADC_FULL_MAX)
+#define PHASE_VOL_R (40*1000.0f)
+#define PHASE_VOL_R1 (1*1000.0f)
+#define PHASE_VOL_C1 (470e-9f) //470nF
+#define PHASE_VOL_Gain  ((PHASE_VOL_R + PHASE_VOL_R1)/PHASE_VOL_R1)
+#define Phase_Vol_LPF_R  ((PHASE_VOL_R * PHASE_VOL_R1)/(PHASE_VOL_R + PHASE_VOL_R1))
+#define PHASE_VOL_LPF_BAND  (1/(2*3.14F*Phase_Vol_LPF_R*PHASE_VOL_C1))
 
 /* 霍尔3线 */
-#define HALL1_PIN					GPIO_PINS_4
-#define HALL2_PIN					GPIO_PINS_5
-#define HALL3_PIN					GPIO_PINS_0
-#define HALL1_PIN_GROUP				GPIOB
-#define HALL2_PIN_GROUP				GPIOB
-#define HALL3_PIN_GROUP				GPIOB
-#define HALL1_PIN_RCU				CRM_GPIOB_PERIPH_CLOCK
-#define HALL2_PIN_RCU				CRM_GPIOB_PERIPH_CLOCK
-#define HALL3_PIN_RCU				CRM_GPIOB_PERIPH_CLOCK
+#define HALL_A_PIN					GPIO_PINS_4
+#define HALL_B_PIN					GPIO_PINS_5
+#define HALL_C_PIN					GPIO_PINS_0
+#define HALL_A_GROUP				GPIOB
+#define HALL_B_GROUP				GPIOB
+#define HALL_C_GROUP				GPIOB
+#define HALL_A_RCU					CRM_GPIOB_PERIPH_CLOCK
+#define HALL_B_RCU					CRM_GPIOB_PERIPH_CLOCK
+#define HALL_C_RCU					CRM_GPIOB_PERIPH_CLOCK
 #define HALL_TIMER 					TMR3
 #define HALL_TIMER_RCU				CRM_TMR3_PERIPH_CLOCK
+#define HALL_CAPTURE_IOMUX			TMR3_GMUX_0010
+#define HALL_TMR_IRQHandler			TMR3_GLOBAL_IRQHandler
+#define HALL_TMR_IRQn				TMR3_GLOBAL_IRQn
+
+#define	STATUS3_LED_GPIO_CRM_CLK	CRM_GPIOC_PERIPH_CLOCK
+#define	STATUS3_LED_PORT			GPIOC
+#define	STATUS3_LED_GPIO_PIN		GPIO_PINS_15
+
+#define CONFIG_BOARD_COM_UART 
 //#define CONFIG_DQ_STEP_RESPONSE
 
 #endif /*_BOARD_AT32_MC_H__ */

+ 0 - 1
Applications/bsp/at32/bsp.c

@@ -15,7 +15,6 @@ void bsp_init(void){
 	systick_open();
 	task_ticks_enable();
 	gpio_pin_init();
-	shark_uart_init(SHARK_UART0);
 }
 
 

+ 5 - 0
Applications/bsp/at32/bsp.h

@@ -31,5 +31,10 @@
 #define CONFIG_BOARD_MCXXX
 #define CONFIG_BOARD_NAME "MC105AT"
 #define CONFIG_MC105_HW_VERSION 3
+#elif defined (AT32_MC_DEMO)
+#define CONFIG_BOARD_MAX_VOLTAGE 60.0f
+#define CONFIG_BOARD_MIN_VOLTAGE 12.0f
+#include "bsp/at32/board_at32_mc.h"
+#define CONFIG_BOARD_NAME "AT32MC"
 #endif
 #endif /* __BSP_AT32_H__ */

+ 1 - 2
Applications/bsp/at32/fan_pwm.h

@@ -1,6 +1,5 @@
 #ifndef _FAN_PWM_H__
 #define _FAN_PWM_H__
-#include "bsp/bsp.h"
 #include "os/os_types.h"
 
 #define PWM_FREQ_HZ    200
@@ -16,7 +15,7 @@ bool fan_pwm_is_running(void);
 static void fan_pwm_init(void) {}
 static void fan_stop(void) {}
 static void fan_set_duty(u8 duty) {}
-bool fan_pwm_is_running(void){return false;}
+static bool fan_pwm_is_running(void){return false;}
 
 #endif
 #endif /* _FAN_PWM_H__ */

+ 13 - 61
Applications/bsp/at32/gpio.c

@@ -6,16 +6,6 @@
 * all pins used as gpio(in/out/irq) must be init&accessed here
 */
 
-void gpio_pin_init(void){
-	crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
-    crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
-	crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
-	crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE);
-	crm_periph_clock_enable(CRM_GPIOF_PERIPH_CLOCK, TRUE);
-	crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
-}
-
-
 void gpio_beep(u32 ms) {
 }
 
@@ -32,6 +22,16 @@ void at32_gpio_init(gpio_type *gpiox, gpio_mode_type mode, gpio_output_type otyp
 	gpio_init(gpiox, &gpio_init_struct);
 }
 
+void gpio_pin_init(void){
+	crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
+    crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
+	crm_periph_clock_enable(CRM_GPIOC_PERIPH_CLOCK, TRUE);
+	crm_periph_clock_enable(CRM_GPIOD_PERIPH_CLOCK, TRUE);
+	crm_periph_clock_enable(CRM_GPIOF_PERIPH_CLOCK, TRUE);
+	crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
+	gpio_bits_write(STATUS3_LED_PORT, STATUS3_LED_GPIO_PIN, TRUE);
+	at32_gpio_init(STATUS3_LED_PORT, GPIO_MODE_OUTPUT, GPIO_OUTPUT_PUSH_PULL, GPIO_PULL_NONE, STATUS3_LED_GPIO_PIN);
+}
 
 void gpio_mc_brk_init(void) {
 #ifdef GPIO_BRAKE_IN_GROUP
@@ -108,51 +108,13 @@ void gpio_led_init(void) {
 #endif
 }
 
-void gpio_brk_light_init(void) {
-#ifdef GPIO_BRAKE_LIGHT_OUT_GROUP
-	crm_periph_clock_enable(GPIO_BRAKE_LIGHT_OUT_RCU, TRUE);
-	at32_gpio_init(GPIO_BRAKE_LIGHT_OUT_GROUP, GPIO_BRAKE_LIGHT_OUT_MODE, GPIO_OUTPUT_PUSH_PULL, GPIO_PULL_NONE, GPIO_BRAKE_LIGHT_OUT_PIN);
-	gpio_bits_reset(GPIO_BRAKE_LIGHT_OUT_GROUP, GPIO_BRAKE_LIGHT_OUT_PIN);
-#endif
-}
-
-void gpio_board_id_init(void) {
-#ifdef BOOT_PIN_0_GROUP
-	at32_gpio_init(BOOT_PIN_0_GROUP, GPIO_MODE_INPUT, GPIO_OUTPUT_PUSH_PULL, GPIO_PULL_NONE, BOOT_PIN_0_PIN);
-	at32_gpio_init(BOOT_PIN_1_GROUP, GPIO_MODE_INPUT, GPIO_OUTPUT_PUSH_PULL, GPIO_PULL_NONE, BOOT_PIN_1_PIN);
-#endif
-}
-
-u8  gpio_hw_board_id(void) {
-	u8 id = CONFIG_MC105_VER3_ID1;
-#ifdef BOOT_PIN_0_GROUP
-	u8 b0 = gpio_input_data_bit_read(BOOT_PIN_0_GROUP, BOOT_PIN_0_PIN);
-	u8 b1 = gpio_input_data_bit_read(BOOT_PIN_1_GROUP, BOOT_PIN_1_PIN);
-	id = ((b1 << 1) | b0);
-#endif
-	return id;
-}
 
-static u8 _board_id = CONFIG_MC105_VER3_ID1;
 void mc_gpio_init(void) {
-	gpio_mlock_init();
-	gpio_mc_brk_init();
-	gpio_fan_det_init();
 	gpio_led_init();
-	gpio_brk_light_init();
-	gpio_board_id_init();
-	int count = 10;
-	do {
-		delay_ms(5);
-		_board_id = gpio_hw_board_id();
-		if (_board_id == CONFIG_MC105_VER3_ID2 || _board_id == CONFIG_MC105_VER3_ID1) {
-			break;
-		}
-	}while(count-- > 0);
 }
 
 u8  gpio_board_id(void) {
-	return _board_id;
+	return 0xFF;
 }
 
 void gpio_led_enable(bool enable) {
@@ -162,30 +124,20 @@ void gpio_led_enable(bool enable) {
 }
 
 void gpio_brk_light_enable(bool enable) {
-#ifdef GPIO_BRAKE_LIGHT_OUT_GROUP
-	gpio_bits_write(GPIO_BRAKE_LIGHT_OUT_GROUP, GPIO_BRAKE_LIGHT_OUT_PIN, enable?TRUE:FALSE);
-#endif
+
 }
 
 
 bool mc_get_gpio_brake(void) {
-	return gpio_input_data_bit_read(GPIO_BRAKE_IN_GROUP, GPIO_BRAKE_IN_PIN) == SET;
+	return false;
 }
 
 bool mc_get_gpio_brake1(void) {
-#ifdef GPIO_BRAKE1_IN_GROUP
-	return gpio_input_data_bit_read(GPIO_BRAKE1_IN_GROUP, GPIO_BRAKE1_IN_PIN) == SET;
-#else
 	return mc_get_gpio_brake();
-#endif
 }
 
 
 bool gpio_motor_locked(void) {
-#ifdef GPIO_MLOCK_IN_GROUP
-	return gpio_input_data_bit_read(GPIO_MLOCK_IN_GROUP, GPIO_MLOCK_IN_PIN) == RESET;
-#else
 	return false;
-#endif
 }
 

+ 74 - 0
Applications/bsp/at32/hall_tmr.c

@@ -0,0 +1,74 @@
+#include "bsp/bsp_driver.h"
+#include "libs/utils.h"
+#include "libs/logger.h"
+#include "hall_tmr.h"
+
+void hall_tmr_init(void) {
+	gpio_init_type gpio_init_struct = {0};
+	tmr_input_config_type tmr_input_config_struct;
+	
+	crm_periph_clock_enable(HALL_TIMER_RCU, TRUE);
+	crm_periph_clock_enable(HALL_A_RCU, TRUE);
+	crm_periph_clock_enable(HALL_B_RCU, TRUE);
+	crm_periph_clock_enable(HALL_C_RCU, TRUE);
+	
+	/* timer hall sensor pin Configuration */
+	gpio_default_para_init(&gpio_init_struct);
+	gpio_init_struct.gpio_pins = HALL_A_PIN;
+	gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
+	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_STRONGER;
+	gpio_init(HALL_A_GROUP, &gpio_init_struct);
+	
+	gpio_init_struct.gpio_pins = HALL_B_PIN;
+	gpio_init(HALL_B_GROUP, &gpio_init_struct);
+	
+	gpio_init_struct.gpio_pins = HALL_C_PIN;
+	gpio_init(HALL_C_GROUP, &gpio_init_struct);
+	
+	/* remap hall timer input pins */
+	gpio_pin_remap_config(HALL_CAPTURE_IOMUX, TRUE);
+	
+	/* timer hall interface configuration */
+	tmr_base_init(HALL_TIMER, 0xFFFF, 0);
+	tmr_cnt_dir_set(HALL_TIMER, TMR_COUNT_UP);
+	
+	/* config ti1 trc as input source */
+	tmr_input_default_para_init(&tmr_input_config_struct);
+	tmr_input_config_struct.input_channel_select = TMR_SELECT_CHANNEL_1;
+	tmr_input_config_struct.input_mapped_select = TMR_CC_CHANNEL_MAPPED_STI;
+	tmr_input_config_struct.input_polarity_select = TMR_INPUT_RISING_EDGE;
+	tmr_input_config_struct.input_filter_value = 0xF;
+	tmr_input_channel_init(HALL_TIMER, &tmr_input_config_struct, TMR_CHANNEL_INPUT_DIV_1);
+	
+	/* xor funtion enable */
+	tmr_channel1_input_select(HALL_TIMER, TMR_CHANEL1_2_3_CONNECTED_C1IRAW_XOR);
+	
+	/* select the tmr input trigger: C1INC */
+	tmr_trigger_input_select(HALL_TIMER, TMR_SUB_INPUT_SEL_C1INC);
+	
+	/* select the slave mode: reset mode */
+	tmr_sub_mode_select(HALL_TIMER, TMR_SUB_RESET_MODE);
+	
+	/* clear interrupt flag of hall timer */
+	tmr_flag_clear(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_OVF_FLAG);
+	
+	/* enable overflow flag of hall timer */
+	tmr_interrupt_enable(HALL_TIMER, TMR_TRIGGER_INT, TRUE);
+	
+	/* enable hall timer */
+	tmr_counter_enable(HALL_TIMER, TRUE);
+
+	nvic_irq_enable(HALL_TMR_IRQn, HALL_IRQ_PRIORITY, 0);
+}
+
+__weak void HALL_IRQHandler(void) {
+
+}
+void HALL_TMR_IRQHandler(void) {
+	 if (tmr_flag_get(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_C1_FLAG) != RESET) {
+	 	tmr_flag_clear(HALL_TIMER, TMR_TRIGGER_FLAG | TMR_C1_FLAG | TMR_OVF_FLAG);
+		HALL_IRQHandler();
+	 }
+}

+ 10 - 0
Applications/bsp/at32/hall_tmr.h

@@ -0,0 +1,10 @@
+#ifndef _HALL_TMR_H__
+#define _HALL_TMR_H__
+#include "bsp/bsp_driver.h"
+void hall_tmr_init(void);
+#define gpio_hall_a_value() (((HALL_A_GROUP->odt)&(HALL_A_PIN))!=0?1:0)
+#define gpio_hall_b_value() (((HALL_B_GROUP->odt)&(HALL_B_PIN))!=0?1:0)
+#define gpio_hall_c_value() (((HALL_C_GROUP->odt)&(HALL_C_PIN))!=0?1:0)
+
+#endif /* _HALL_TMR_H__ */
+

+ 0 - 4
Applications/bsp/at32/mc_irqs.c

@@ -86,10 +86,6 @@ __weak void ADC_IRQHandler(void) {
 
 }
 
-__weak void HALL_IRQHandler(void) {
-
-}
-
 __weak void ABI_I_IRQHandler(void) {
 
 }

+ 0 - 42
Applications/bsp/at32/pwm.c

@@ -42,49 +42,7 @@ void pwm_3phase_init(void){
 }
 
 void pwm_3phase_sides(bool hon, bool lon) {
-	if (hon && lon) {
-		return;
-	}
-	tmr_reset(MOS_PWM_TIMER);
-	crm_periph_clock_enable(PWM_CRM_CLK, TRUE);
-    pwm_gpio_init(PWM_U_P_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE, PWM_U_P_PIN);
-    pwm_gpio_init(PWM_V_P_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE,PWM_V_P_PIN);
-    pwm_gpio_init(PWM_W_P_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE,PWM_W_P_PIN);
-
-    pwm_gpio_init(PWM_U_N_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE,PWM_U_N_PIN);
-    pwm_gpio_init(PWM_V_N_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE,PWM_V_N_PIN);
-    pwm_gpio_init(PWM_W_N_GROUP,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_PULL_NONE,PWM_W_N_PIN);
-
-	sys_debug("pwm_3phase_sides\n");
-	/* 开上桥或者下桥之前先关闭下桥或者上桥 */
-	if (hon) {
-		_pwm_gpio_config();
-		_init_pwm_timer(false);
-		delay_us(10);
-		pwm_start();
-		pwm_update_duty(FOC_PWM_Half_Period-200, FOC_PWM_Half_Period-200, FOC_PWM_Half_Period-200);
-	}else if (lon) {
-		gpio_bits_write(PWM_U_P_GROUP, PWM_U_P_PIN, FALSE);
-		gpio_bits_write(PWM_V_P_GROUP, PWM_V_P_PIN, FALSE);
-		gpio_bits_write(PWM_W_P_GROUP, PWM_W_P_PIN, FALSE);
 
-		delay_us(10);
-		gpio_bits_write(PWM_U_N_GROUP, PWM_U_N_PIN, TRUE);
-		gpio_bits_write(PWM_V_N_GROUP, PWM_V_N_PIN, TRUE);
-		gpio_bits_write(PWM_W_N_GROUP, PWM_W_N_PIN, TRUE);
-	}else {
-#if 0		
-		gpio_bit_write(PWM_U_P_GROUP, PWM_U_P_PIN, RESET);
-		gpio_bit_write(PWM_V_P_GROUP, PWM_V_P_PIN, RESET);
-		gpio_bit_write(PWM_W_P_GROUP, PWM_W_P_PIN, RESET);
-
-		gpio_bit_write(PWM_U_N_GROUP, PWM_U_N_PIN, RESET);
-		gpio_bit_write(PWM_V_N_GROUP, PWM_V_N_PIN, RESET);
-		gpio_bit_write(PWM_W_N_GROUP, PWM_W_N_PIN, RESET);
-#else
-		pwm_3phase_init();
-#endif
-	}
 }
 
 static void _pwm_gpio_config(void)

+ 1 - 1
Applications/bsp/at32/pwm.h

@@ -23,7 +23,7 @@
 #define TIMxCCER_MASK_CP           ((uint16_t) TIMER_CHCTL2_CH0NP | TIMER_CHCTL2_CH1NP |TIMER_CHCTL2_CH2NP)
 #define pwm_enable_channel() {MOS_PWM_TIMER->cctrl |= TIMxCCER_MASK_CH012;}
 #define pwm_disable_channel() {MOS_PWM_TIMER->cctrl &= ~TIMxCCER_MASK_CH012;}
-
+#define pwm_channel_is_enabled() ((MOS_PWM_TIMER->cctrl & TIMxCCER_MASK_CH012) != 0)
 
 #define ch0_update_duty(duty) 	MOS_PWM_TIMER->c1dt = (uint32_t)duty
 #define ch1_update_duty(duty) 	MOS_PWM_TIMER->c2dt = (uint32_t)duty

+ 19 - 10
Applications/bsp/at32/uart.c

@@ -38,31 +38,25 @@ static u8 shark_uart0_rx_cache[SHARK_UART_RX_MEM_SIZE];
 
 static shark_uart_t _shark_uart[1];
 ///static bool uart_no_data = false;
-#if ENABLE_RX_DMA==1
-#define update_dma_w_pos(uart) circle_update_write_position(&uart->rx_queue, SHARK_UART_RX_MEM_SIZE - SHARK_UART0_rx_dma_ch->dtcnt)
-#else
-#define update_dma_w_pos(uart){}
-#endif
 
 // ================================================================================
 static usart_type *_uart_index(usart_type* com){
 	return SHARK_UART0;
 }
 
-__weak void shark_uart_on_frame_received(u8 *data, u16 lenght){
+__weak void handle_uart_can_frame(uint8_t *data, int len){
 
 }
 
-
 static bool shark_uart_on_rx_frame(shark_uart_t *uart)
 {
 	u16 crc0 = decode_u16(uart->rx_frame + uart->rx_length);
 	u16 crc1 = crc16_get(uart->rx_frame, uart->rx_length);
 
-	if (crc0 != crc1) {
+	if (crc0 != crc1 || uart->rx_length < 1) {
 		return false;
 	}
-	shark_uart_on_frame_received(uart->rx_frame, uart->rx_length);
+	handle_uart_can_frame(uart->rx_frame+1, uart->rx_length-1);
 	return true;
 }
 
@@ -225,11 +219,12 @@ static void shark_uart_rx_dma_init(shark_uart_t *uart){
 	dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE;
 	dma_init_struct.peripheral_inc_enable = FALSE;
 	dma_init_struct.priority = DMA_PRIORITY_MEDIUM;
-	dma_init_struct.loop_mode_enable = FALSE;
+	dma_init_struct.loop_mode_enable = TRUE;
 	dma_init(uart->rx_dma_ch, &dma_init_struct);	
 	/* config flexible dma for usart1 rx */
 	dma_flexible_config(SHARK_UART0_rx_dma, DMA_UART_RX_FLEX_CHANNEL, DMA_UART_RX_FLEX);
 	usart_dma_receiver_enable(uart->uart_com, TRUE);
+	dma_channel_enable(uart->rx_dma_ch, TRUE);
 }
 #endif
 static void shark_uart_pin_init(shark_uart_t *uart){
@@ -448,3 +443,17 @@ int fputc(int c, FILE *fp){
 	return 1;
 }
 
+int shark_uart_send_can_message(uint32_t efid, u8 *data, int len) {
+	shark_uart_t *uart = _shark_uart + SHARK_UART0;
+	u8 command = 38;
+	
+	shark_uart_tx_start(uart);
+	
+	shark_uart_tx_continue(uart, &command, sizeof(command));
+	
+	shark_uart_tx_continue(uart, &efid, sizeof(efid));
+	shark_uart_tx_continue(uart, data, len);
+	shark_uart_tx_end(uart);
+	return 0;
+}
+

+ 4 - 1
Applications/bsp/at32/uart.h

@@ -50,4 +50,7 @@ void shark_uart_write_bytes(uart_enum_t uart_no, u8 *buff, u16 size);
 void shark_uart_flush(void);
 bool shark_uart_timeout(void);
 void shark_uart_log(void);
-
+int shark_uart_send_can_message(uint32_t efid, u8 *data, int len);
+static __INLINE void shark_uart_can_init(void){
+	shark_uart_init(SHARK_UART0);
+}

+ 3 - 0
Applications/bsp/bsp.h

@@ -23,6 +23,9 @@
 #define ENCODER_MPS 1
 #define ENCODER_MT  2
 
+#define PHASE_AB 0
+#define PHASE_AC 1
+#define PHASE_BC 2
 
 #define MOTOR_BLUESHARK_NEW1  1//蓝鲨大功率电机,双I形
 #define MOTOR_BLUESHARK_NEW2  2//蓝鲨大功率电机,V形

+ 1 - 0
Applications/bsp/bsp_driver.h

@@ -25,6 +25,7 @@
 #include "bsp/at32/adc.h"
 #include "bsp/at32/fan_pwm.h"
 #include "bsp/at32/enc_intf.h"
+#include "bsp/at32/hall_tmr.h"
 #include "bsp/at32/sched_timer.h"
 #include "bsp/at32/uart.h"
 #elif defined N32G45X

+ 0 - 4
Applications/bsp/gd32/adc.h

@@ -26,10 +26,6 @@ inserted ADC 由timer0 ch3触发,
 #define ADC_TRIGGER_NONE  ADC0_1_2_EXTTRIG_INSERTED_NONE
 #define ADC_TRIGGER_VBUS ADC0_1_EXTTRIG_INSERTED_T1_CH0
 
-#define PHASE_AB 0
-#define PHASE_AC 1
-#define PHASE_BC 2
-
 #define ADC_RANK_CHANNEL(c)  ((c)<<ISQ3_OFFSET | (0)<<IL_OFFSET) 
 #define ADC_INS_RANK_4_CHANS(c1,c2,c3,c4) (((c1)<<ISQ0_OFFSET) | ((c2)<<ISQ1_OFFSET) | ((c3)<<ISQ2_OFFSET) | ((c4)<<ISQ3_OFFSET) | ((3)<<IL_OFFSET))
 #define INJ_CHAN_NUM 1

+ 1 - 1
Applications/bsp/gd32/fan_pwm.h

@@ -16,7 +16,7 @@ bool fan_pwm_is_running(void);
 static void fan_pwm_init(void) {}
 static void fan_stop(void) {}
 static void fan_set_duty(u8 duty) {}
-bool fan_pwm_is_running(void){return false;}
+static bool fan_pwm_is_running(void){return false;}
 
 #endif
 #endif /* _FAN_PWM_H__ */

+ 0 - 1
Applications/foc/commands.c

@@ -125,7 +125,6 @@ static void process_ext_command(foc_cmd_body_t *command) {
 		response[1] |= (mc_is_cruise_enabled()?2:1);
 		response[1] |= (mc_is_epm()?1:2) << 2;
 		response[1] |= m_4896<<4;
-
 		shark_can0_send_ext_message(0x1A024D43, response, sizeof(response));
 	}else if (command->ext_key == 0x1A05) {
 		u16 idc_lim = decode_u16((u8 *)command->data) / 10;

+ 205 - 0
Applications/foc/motor/current_2_3_shut.c

@@ -0,0 +1,205 @@
+#include <math.h>
+#include "bsp/bsp_driver.h"
+#include "foc/motor/current.h"
+#include "foc/core/controller.h"
+#include "foc/mc_error.h"
+#include "libs/utils.h"
+#include "libs/logger.h"
+#include "math/fast_math.h"
+current_samp_t g_cs;
+
+#define NB_OFFSET_SAMPLES 32
+#define SENSOR_SAMPLES 10000
+
+void phase_current_init(void) {
+	current_samp_t *cs = &g_cs;
+	cs->sample_count = NB_OFFSET_SAMPLES + 1;
+	cs->adc_ia = 0;
+	cs->adc_ib = 0;
+	cs->adc_ic = 0;
+}
+
+void phase_current_offset_calibrate(void){
+	g_cs.adc_offset_a = 0;
+	g_cs.adc_offset_b = 0;
+	g_cs.adc_offset_c = 0;
+
+	phase_current_init();
+	g_cs.c_phases = PHASE_AB;
+	g_cs.c_ignore_phase = IGNORE_NONE;
+	adc_current_sample_config(g_cs.c_phases);
+	g_cs.is_calibrating_offset = true;
+}
+
+void phase_current_calibrate_wait(void) {
+	while(g_cs.is_calibrating_offset || g_cs.is_calibrating_sensor) {
+		wdog_reload();
+	}
+	sys_debug("offset %d, %d, %d\n", g_cs.adc_offset_a, g_cs.adc_offset_b, g_cs.adc_offset_c);
+}
+
+void phase_current_sensor_start_calibrate(float calibrate_current) {
+	bool calibrate = false;
+	if (calibrate_current > 0) {
+		calibrate = true;
+		g_cs.sensor_samples_1 = 0;
+		g_cs.sensor_samples_2 = 0;
+		g_cs.sample_count = SENSOR_SAMPLES + 1;
+		g_cs.calibrate_current = calibrate_current;
+	}
+	
+	g_cs.is_calibrating_sensor = calibrate;
+}
+
+bool phase_current_sensor_do_calibrate(void) {
+	current_samp_t *cs = &g_cs;
+	if (!cs->is_calibrating_sensor) {
+		return false;
+	}
+	s32 phase_current1, phase_current2;
+	adc_phase_current_read(cs->c_phases, &phase_current1, &phase_current2);
+	if(cs->c_phases == PHASE_BC) {
+		if (cs->sample_count > 0) {
+			cs->sample_count--;
+			if (cs->sample_count <= SENSOR_SAMPLES) {
+				cs->sensor_samples_1 += (phase_current1 - cs->adc_offset_b);
+				cs->sensor_samples_2 += (phase_current2 - cs->adc_offset_c);
+			}
+		}else {
+			cs->sensor_samples_1 = cs->sensor_samples_1 / (float)SENSOR_SAMPLES;
+			cs->sensor_samples_2 = cs->sensor_samples_2 / (float)SENSOR_SAMPLES;
+			cs->sensor_k1 = g_cs.calibrate_current/cs->sensor_samples_1;
+			cs->sensor_k2 = g_cs.calibrate_current/cs->sensor_samples_2;
+			cs->sensor_k1 = ABS(cs->sensor_k1);
+			cs->sensor_k2 = ABS(cs->sensor_k2);
+			cs->is_calibrating_sensor = false;
+		}
+	}
+	return cs->is_calibrating_sensor;
+}
+
+bool phase_current_offset(void) {
+	current_samp_t *cs = &g_cs;
+	if (!cs->is_calibrating_offset) {
+		return false;
+	}
+	s32 phase_current1 = 0 , phase_current2 = 0;
+	adc_phase_current_read(cs->c_phases, &phase_current1, &phase_current2);
+	if (cs->sample_count == (NB_OFFSET_SAMPLES + 1)) {
+		cs->sample_count --;
+		return true;
+	}
+	if (cs->sample_count > 0) {
+		cs->sample_count--;
+		if (cs->c_phases == PHASE_AB && cs->sample_count >= 0) {
+			cs->adc_offset_a += phase_current1;
+			cs->adc_offset_b += phase_current2;
+			if (cs->sample_count == 0) {
+				cs->adc_offset_a = cs->adc_offset_a / NB_OFFSET_SAMPLES;
+				cs->adc_offset_b = cs->adc_offset_b / NB_OFFSET_SAMPLES;
+			}
+		}
+		if (cs->c_phases == PHASE_BC && cs->sample_count >= 0) {
+			cs->adc_offset_c += phase_current2;
+			//cs->adc_offset_b += phase_current1;
+			if (cs->sample_count == 0) {
+				cs->adc_offset_c = cs->adc_offset_c / NB_OFFSET_SAMPLES;
+				//cs->adc_offset_b = cs->adc_offset_b / NB_OFFSET_SAMPLES;
+			}
+		}
+	}else {
+		if (cs->c_phases == PHASE_AB) {
+			cs->c_phases = PHASE_BC;
+			phase_current_init();
+			adc_current_sample_config(cs->c_phases);
+		}else {
+			cs->is_calibrating_offset = false;
+		}
+
+	}
+	return true;
+}
+
+#define ADC_OFF_1 (ADC_FULL_MAX/2 + 100)
+#define ADC_OFF_2 (ADC_FULL_MAX/2 - 100)
+bool phase_curr_offset_check(void) {
+	if ((g_cs.adc_offset_a > ADC_OFF_1) || (g_cs.adc_offset_b > ADC_OFF_1) || (g_cs.adc_offset_c > ADC_OFF_1)) {
+		mc_crit_err_add_s16(FOC_CRIT_CURR_OFF_Err, MAX(g_cs.adc_offset_a, MAX(g_cs.adc_offset_c, g_cs.adc_offset_b)));
+		return true;
+	}
+	if ((g_cs.adc_offset_a < ADC_OFF_2) || (g_cs.adc_offset_b < ADC_OFF_2) || (g_cs.adc_offset_c < ADC_OFF_2)) {
+		mc_crit_err_add_s16(FOC_CRIT_CURR_OFF_Err, min(g_cs.adc_offset_a, min(g_cs.adc_offset_c, g_cs.adc_offset_b)));
+		return true;
+	}
+	return false;
+}
+
+void phase_current_get(float *iABC){
+	current_samp_t *cs = &g_cs;
+	s32 phase_current1, phase_current2;
+
+	adc_phase_current_read(cs->c_phases, &phase_current1, &phase_current2);
+
+	if (cs->c_phases == PHASE_AB) {
+		cs->adc_ia = (phase_current1 - cs->adc_offset_a);
+		cs->adc_ib = (phase_current2 - cs->adc_offset_b);
+		iABC[0] = -cs->adc_ia * ADC_TO_CURR_ceof;
+		iABC[1] = -cs->adc_ib * ADC_TO_CURR_ceof;
+		iABC[2] = -(iABC[0] + iABC[1]);
+	}else if (cs->c_phases == PHASE_BC) {
+		cs->adc_ib = (phase_current1 - cs->adc_offset_b);
+		cs->adc_ic = (phase_current2 - cs->adc_offset_c);
+		iABC[1] = -cs->adc_ib * ADC_TO_CURR_ceof;
+		iABC[2] = -cs->adc_ic * ADC_TO_CURR_ceof;
+		iABC[0] = -(iABC[1] + iABC[2]);
+	}else { //PHASE_AC
+		cs->adc_ia = (phase_current1 - cs->adc_offset_a);
+		cs->adc_ic = (phase_current2 - cs->adc_offset_c);
+		iABC[0] = -cs->adc_ia * ADC_TO_CURR_ceof;
+		iABC[2] = -cs->adc_ic * ADC_TO_CURR_ceof;
+		iABC[1] = -(iABC[0] + iABC[2]);
+	}
+}
+
+void phase_current_point(void *p){
+	foc_out_t *out = p;
+	current_samp_t *cs = &g_cs;
+#ifdef CONFIG_THREE_SHUNT
+	if (out->low_duty == out->duty[0]) {
+		if (out->mid_duty == out->duty[1]) {
+			cs->c_phases = PHASE_AB;
+		}else if (out->mid_duty == out->duty[2]) {
+			cs->c_phases = PHASE_AC;
+		}else {
+			//keep unchanged
+		}
+	}else if (out->low_duty == out->duty[1]) {
+		if (out->mid_duty == out->duty[0]) {
+			cs->c_phases = PHASE_AB;
+		}else if (out->mid_duty == out->duty[2]) {
+			cs->c_phases = PHASE_BC;
+		}else {
+			//keep unchanged
+		}
+	}else { // out->low_duty == out->duty[2]
+		if (out->mid_duty == out->duty[0]) {
+			cs->c_phases = PHASE_AC;
+		}else if (out->mid_duty == out->duty[1]) {
+			cs->c_phases = PHASE_BC;
+		}else {
+			//keep unchanged
+		}
+	}
+#else // two shunt
+	cs->c_phases = PHASE_AB;
+#endif
+	out->sample1 = FOC_PWM_Half_Period - 1;
+	out->sample2 = FOC_PWM_Half_Period + 1;
+	out->sample_phase = cs->c_phases;
+}
+
+void phase_current_adc_triger(void){
+	adc_enable_ext_trigger();
+}
+
+

+ 4 - 0
Applications/foc/motor/hall.c

@@ -175,7 +175,11 @@ void hall_init(void) {
 
 	if (!g_hall.inited) {
 		g_hall.inited = true;
+#ifdef HALL_TIMER
+		hall_tmr_init();
+#else
 		gpio_hall_init();
+#endif
 	}
 	hall_offset_dec_init();
 	hall_init_low_pos();

+ 8 - 0
Applications/foc/samples.c

@@ -122,7 +122,11 @@ float get_vbus_current(void) {
 }
 
 s16 get_motor_temp(void) {
+#ifdef MOTOR_TEMP_ADC_CHAN
 	return motor_temp.filted_value;
+#else
+	return 0;
+#endif
 }
 
 s16 get_mos_temp(void) {
@@ -130,7 +134,11 @@ s16 get_mos_temp(void) {
 }
 
 s16 get_motor_temp_raw(void) {
+#ifdef MOTOR_TEMP_ADC_CHAN
 	return motor_temp.value;
+#else
+	return 0;
+#endif
 }
 
 s16 get_mos_temp_raw(void) {

+ 4 - 2
Applications/libs/logger.c

@@ -4,6 +4,8 @@
 #include "logger.h"
 #include "os/os_task.h"
 #include "libs/utils.h"
+#include "prot/can_message.h"
+
 static uint32_t level_data[2];
 static char log_cache[128];
 //static co_queue_t log_queue = NULL;
@@ -89,12 +91,12 @@ int can_fputc(char c){
 	if (c == '\n'){ //don't send '\n'
 		if (log_index != 0){
 			frame_id.dest 	= 0x72;
-			shark_can0_send_message(frame_id.id, log_buffer, log_index);
+			can_send_message(frame_id.id, (u8 *)log_buffer, log_index, 0);
 		}
 		log_index = 0;
 	}else if (log_index == sizeof(log_buffer)){
 		frame_id.dest 	= 0x70;
-		shark_can0_send_message(frame_id.id, log_buffer, log_index);
+		can_send_message(frame_id.id, (u8 *)log_buffer, log_index, 0);
 		log_index = 0;
 		log_buffer[log_index++] = c;
 	}else{

+ 1 - 1
Applications/prot/can_foc_msg.c

@@ -105,7 +105,7 @@ void can_mcast_foc_status2(void) {
 		iDC = 0;
 	}
 	encode_s16(data + 6, (s16)(iDC*10));
-	shark_can0_send_message(get_indicator_can_id(0x7F), data, sizeof(data));
+	can_send_message(get_indicator_can_id(0x7F), data, sizeof(data), 0);
 }
 
 void can_report_mpta_values(u8 can) {

+ 23 - 1
Applications/prot/can_message.c

@@ -13,7 +13,9 @@ static void free_can_message(can_message_t *message);
 static can_message_t messages[MAX_CAN_MESSAGE];
 
 void can_message_init(void){
-#ifndef GD32_FOC_DEMO	
+#ifdef CONFIG_BOARD_COM_UART
+	shark_uart_can_init();
+#else
 	shark_can0_init();
 #endif
 }
@@ -37,7 +39,14 @@ static can_message_t *get_message_by_id(can_id_t id){
 
 
 s32 can_send_message(uint32_t can_id, u8 *data, int len, s32 timeout){
+#ifdef CONFIG_BOARD_COM_UART
+	can_id_t efid;
+	efid.id = can_id;
+	efid.total = efid.idx = 1;
+	return shark_uart_send_can_message(efid.id, data, len);
+#else
 	return shark_can0_send_message(can_id, data, len) == 0?CAN_SEND_SUCCESS:CAN_SEND_ERROR;
+#endif
 }
 
 static bool handle_can_ext_frame(u32 id, uint8_t *data, int len) {
@@ -118,6 +127,19 @@ void handle_can_frame(can_id_t id, uint8_t *data, int len){
 	}
 }
 
+#ifdef CONFIG_BOARD_COM_UART
+void handle_uart_can_frame(uint8_t *data, int len) {
+	can_id_t *can_id;
+	can_id = (can_id_t *)data;
+	handle_can_frame(*can_id, data+4, len-4);
+}
+
+int shark_can0_send_ext_message(uint32_t can_id, const void*buff, int len) {
+	return 0;//shark_uart_send_can_message(can_id, (u8 *)buff, len);
+}
+
+#endif
+
 static void can_process_message(can_message_t *message){
 	//sys_debug("can %x [%x -> %x], len = %d\n", message->key, message->src, message->dest, message->len);
 	if ((message->key & 0xFF) >= 0xF0) {

+ 1 - 1
Applications/prot/can_pc_message.c

@@ -88,6 +88,6 @@ void iap_send_data(uint8_t can, uint8_t *data, int len){
 	frame_id.dest = can;
 	frame_id.type 		= ptype_response;
 	
-	shark_can0_send_message(frame_id.id, data, len);
+	can_send_message(frame_id.id, data, len, 100);
 }
 

+ 797 - 0
Project/AT32_MC.uvprojx

@@ -0,0 +1,797 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
+
+  <SchemaVersion>2.1</SchemaVersion>
+
+  <Header>### uVision Project, (C) Keil Software</Header>
+
+  <Targets>
+    <Target>
+      <TargetName>AT32F413RC</TargetName>
+      <ToolsetNumber>0x4</ToolsetNumber>
+      <ToolsetName>ARM-ADS</ToolsetName>
+      <pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
+      <uAC6>0</uAC6>
+      <TargetOption>
+        <TargetCommonOption>
+          <Device>-AT32F413RCT7</Device>
+          <Vendor>ArteryTek</Vendor>
+          <PackID>ArteryTek.AT32F413_DFP.2.0.9</PackID>
+          <Cpu>IRAM(0x20000000,0x8000) IROM(0x08000000,0x40000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
+          <FlashUtilSpec></FlashUtilSpec>
+          <StartupFile></StartupFile>
+          <FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0AT32F413_256 -FS08000000 -FL040000 -FP0($$Device:-AT32F413RCT7$Flash\AT32F413_256.FLM))</FlashDriverDll>
+          <DeviceId>0</DeviceId>
+          <RegisterFile>$$Device:-AT32F413RCT7$Device\Include\at32f413.h</RegisterFile>
+          <MemoryEnv></MemoryEnv>
+          <Cmp></Cmp>
+          <Asm></Asm>
+          <Linker></Linker>
+          <OHString></OHString>
+          <InfinionOptionDll></InfinionOptionDll>
+          <SLE66CMisc></SLE66CMisc>
+          <SLE66AMisc></SLE66AMisc>
+          <SLE66LinkerMisc></SLE66LinkerMisc>
+          <SFDFile>$$Device:-AT32F413RCT7$SVD\AT32F413xx_v2.svd</SFDFile>
+          <bCustSvd>0</bCustSvd>
+          <UseEnv>0</UseEnv>
+          <BinPath></BinPath>
+          <IncludePath></IncludePath>
+          <LibPath></LibPath>
+          <RegisterFilePath></RegisterFilePath>
+          <DBRegisterFilePath></DBRegisterFilePath>
+          <TargetStatus>
+            <Error>0</Error>
+            <ExitCodeStop>0</ExitCodeStop>
+            <ButtonStop>0</ButtonStop>
+            <NotGenerated>0</NotGenerated>
+            <InvalidFlash>1</InvalidFlash>
+          </TargetStatus>
+          <OutputDirectory>.\Objects\</OutputDirectory>
+          <OutputName>AT32MC</OutputName>
+          <CreateExecutable>1</CreateExecutable>
+          <CreateLib>0</CreateLib>
+          <CreateHexFile>1</CreateHexFile>
+          <DebugInformation>1</DebugInformation>
+          <BrowseInformation>1</BrowseInformation>
+          <ListingPath>.\Listings\</ListingPath>
+          <HexFormatSelection>1</HexFormatSelection>
+          <Merge32K>0</Merge32K>
+          <CreateBatchFile>0</CreateBatchFile>
+          <BeforeCompile>
+            <RunUserProg1>0</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name></UserProg1Name>
+            <UserProg2Name></UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopU1X>0</nStopU1X>
+            <nStopU2X>0</nStopU2X>
+          </BeforeCompile>
+          <BeforeMake>
+            <RunUserProg1>1</RunUserProg1>
+            <RunUserProg2>0</RunUserProg2>
+            <UserProg1Name>SharkFwVersion gen ..\Applications\version.h  .\version_AT32_MC.cfg</UserProg1Name>
+            <UserProg2Name></UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopB1X>0</nStopB1X>
+            <nStopB2X>0</nStopB2X>
+          </BeforeMake>
+          <AfterMake>
+            <RunUserProg1>1</RunUserProg1>
+            <RunUserProg2>1</RunUserProg2>
+            <UserProg1Name>fromelf --bin --output ./Output/AT32MC.bin ./Objects/AT32MC.axf</UserProg1Name>
+            <UserProg2Name>SharkFwVersion copy  ./Output/AT32MC.bin</UserProg2Name>
+            <UserProg1Dos16Mode>0</UserProg1Dos16Mode>
+            <UserProg2Dos16Mode>0</UserProg2Dos16Mode>
+            <nStopA1X>0</nStopA1X>
+            <nStopA2X>0</nStopA2X>
+          </AfterMake>
+          <SelectedForBatchBuild>0</SelectedForBatchBuild>
+          <SVCSIdString></SVCSIdString>
+        </TargetCommonOption>
+        <CommonProperty>
+          <UseCPPCompiler>0</UseCPPCompiler>
+          <RVCTCodeConst>0</RVCTCodeConst>
+          <RVCTZI>0</RVCTZI>
+          <RVCTOtherData>0</RVCTOtherData>
+          <ModuleSelection>0</ModuleSelection>
+          <IncludeInBuild>1</IncludeInBuild>
+          <AlwaysBuild>0</AlwaysBuild>
+          <GenerateAssemblyFile>0</GenerateAssemblyFile>
+          <AssembleAssemblyFile>0</AssembleAssemblyFile>
+          <PublicsOnly>0</PublicsOnly>
+          <StopOnExitCode>3</StopOnExitCode>
+          <CustomArgument></CustomArgument>
+          <IncludeLibraryModules></IncludeLibraryModules>
+          <ComprImg>1</ComprImg>
+        </CommonProperty>
+        <DllOption>
+          <SimDllName>SARMCM3.DLL</SimDllName>
+          <SimDllArguments> -REMAP -MPU</SimDllArguments>
+          <SimDlgDll>DCM.DLL</SimDlgDll>
+          <SimDlgDllArguments>-pCM4</SimDlgDllArguments>
+          <TargetDllName>SARMCM3.DLL</TargetDllName>
+          <TargetDllArguments> -MPU</TargetDllArguments>
+          <TargetDlgDll>TCM.DLL</TargetDlgDll>
+          <TargetDlgDllArguments>-pCM4</TargetDlgDllArguments>
+        </DllOption>
+        <DebugOption>
+          <OPTHX>
+            <HexSelection>1</HexSelection>
+            <HexRangeLowAddress>0</HexRangeLowAddress>
+            <HexRangeHighAddress>0</HexRangeHighAddress>
+            <HexOffset>0</HexOffset>
+            <Oh166RecLen>16</Oh166RecLen>
+          </OPTHX>
+        </DebugOption>
+        <Utilities>
+          <Flash1>
+            <UseTargetDll>1</UseTargetDll>
+            <UseExternalTool>0</UseExternalTool>
+            <RunIndependent>0</RunIndependent>
+            <UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
+            <Capability>1</Capability>
+            <DriverSelection>4096</DriverSelection>
+          </Flash1>
+          <bUseTDR>1</bUseTDR>
+          <Flash2>BIN\UL2CM3.DLL</Flash2>
+          <Flash3></Flash3>
+          <Flash4></Flash4>
+          <pFcarmOut></pFcarmOut>
+          <pFcarmGrp></pFcarmGrp>
+          <pFcArmRoot></pFcArmRoot>
+          <FcArmLst>0</FcArmLst>
+        </Utilities>
+        <TargetArmAds>
+          <ArmAdsMisc>
+            <GenerateListings>0</GenerateListings>
+            <asHll>1</asHll>
+            <asAsm>1</asAsm>
+            <asMacX>1</asMacX>
+            <asSyms>1</asSyms>
+            <asFals>1</asFals>
+            <asDbgD>1</asDbgD>
+            <asForm>1</asForm>
+            <ldLst>0</ldLst>
+            <ldmm>1</ldmm>
+            <ldXref>1</ldXref>
+            <BigEnd>0</BigEnd>
+            <AdsALst>1</AdsALst>
+            <AdsACrf>1</AdsACrf>
+            <AdsANop>0</AdsANop>
+            <AdsANot>0</AdsANot>
+            <AdsLLst>1</AdsLLst>
+            <AdsLmap>1</AdsLmap>
+            <AdsLcgr>1</AdsLcgr>
+            <AdsLsym>1</AdsLsym>
+            <AdsLszi>1</AdsLszi>
+            <AdsLtoi>1</AdsLtoi>
+            <AdsLsun>1</AdsLsun>
+            <AdsLven>1</AdsLven>
+            <AdsLsxf>1</AdsLsxf>
+            <RvctClst>0</RvctClst>
+            <GenPPlst>0</GenPPlst>
+            <AdsCpuType>"Cortex-M4"</AdsCpuType>
+            <RvctDeviceName></RvctDeviceName>
+            <mOS>0</mOS>
+            <uocRom>0</uocRom>
+            <uocRam>0</uocRam>
+            <hadIROM>1</hadIROM>
+            <hadIRAM>1</hadIRAM>
+            <hadXRAM>0</hadXRAM>
+            <uocXRam>0</uocXRam>
+            <RvdsVP>2</RvdsVP>
+            <RvdsMve>0</RvdsMve>
+            <RvdsCdeCp>0</RvdsCdeCp>
+            <hadIRAM2>0</hadIRAM2>
+            <hadIROM2>0</hadIROM2>
+            <StupSel>8</StupSel>
+            <useUlib>1</useUlib>
+            <EndSel>0</EndSel>
+            <uLtcg>0</uLtcg>
+            <nSecure>0</nSecure>
+            <RoSelD>3</RoSelD>
+            <RwSelD>3</RwSelD>
+            <CodeSel>0</CodeSel>
+            <OptFeed>0</OptFeed>
+            <NoZi1>0</NoZi1>
+            <NoZi2>0</NoZi2>
+            <NoZi3>0</NoZi3>
+            <NoZi4>0</NoZi4>
+            <NoZi5>0</NoZi5>
+            <Ro1Chk>0</Ro1Chk>
+            <Ro2Chk>0</Ro2Chk>
+            <Ro3Chk>0</Ro3Chk>
+            <Ir1Chk>1</Ir1Chk>
+            <Ir2Chk>0</Ir2Chk>
+            <Ra1Chk>0</Ra1Chk>
+            <Ra2Chk>0</Ra2Chk>
+            <Ra3Chk>0</Ra3Chk>
+            <Im1Chk>1</Im1Chk>
+            <Im2Chk>0</Im2Chk>
+            <OnChipMemories>
+              <Ocm1>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm1>
+              <Ocm2>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm2>
+              <Ocm3>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm3>
+              <Ocm4>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm4>
+              <Ocm5>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm5>
+              <Ocm6>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </Ocm6>
+              <IRAM>
+                <Type>0</Type>
+                <StartAddress>0x20000000</StartAddress>
+                <Size>0x8000</Size>
+              </IRAM>
+              <IROM>
+                <Type>1</Type>
+                <StartAddress>0x8000000</StartAddress>
+                <Size>0x40000</Size>
+              </IROM>
+              <XRAM>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </XRAM>
+              <OCR_RVCT1>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT1>
+              <OCR_RVCT2>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT2>
+              <OCR_RVCT3>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT3>
+              <OCR_RVCT4>
+                <Type>1</Type>
+                <StartAddress>0x8002000</StartAddress>
+                <Size>0x40000</Size>
+              </OCR_RVCT4>
+              <OCR_RVCT5>
+                <Type>1</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT5>
+              <OCR_RVCT6>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT6>
+              <OCR_RVCT7>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT7>
+              <OCR_RVCT8>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT8>
+              <OCR_RVCT9>
+                <Type>0</Type>
+                <StartAddress>0x20000000</StartAddress>
+                <Size>0x8000</Size>
+              </OCR_RVCT9>
+              <OCR_RVCT10>
+                <Type>0</Type>
+                <StartAddress>0x0</StartAddress>
+                <Size>0x0</Size>
+              </OCR_RVCT10>
+            </OnChipMemories>
+            <RvctStartVector></RvctStartVector>
+          </ArmAdsMisc>
+          <Cads>
+            <interw>1</interw>
+            <Optim>2</Optim>
+            <oTime>1</oTime>
+            <SplitLS>0</SplitLS>
+            <OneElfS>1</OneElfS>
+            <Strict>0</Strict>
+            <EnumInt>0</EnumInt>
+            <PlainCh>0</PlainCh>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <wLevel>2</wLevel>
+            <uThumb>0</uThumb>
+            <uSurpInc>0</uSurpInc>
+            <uC99>1</uC99>
+            <uGnu>1</uGnu>
+            <useXO>0</useXO>
+            <v6Lang>3</v6Lang>
+            <v6LangP>3</v6LangP>
+            <vShortEn>1</vShortEn>
+            <vShortWch>1</vShortWch>
+            <v6Lto>0</v6Lto>
+            <v6WtE>0</v6WtE>
+            <v6Rtti>0</v6Rtti>
+            <VariousControls>
+              <MiscControls></MiscControls>
+              <Define>AT32F413RCT7,USE_STDPERIPH_DRIVER,AT32_MC_DEMO,CONFIG_CAN_IAP,CONFIG_USE_ENCODER_HALL</Define>
+              <Undefine></Undefine>
+              <IncludePath>..\Librarys\CMSIS\Include,..\Librarys\CMSIS\AT32,..\Librarys\AT32F41x_Drivers\inc,..\Applications</IncludePath>
+            </VariousControls>
+          </Cads>
+          <Aads>
+            <interw>1</interw>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <thumb>0</thumb>
+            <SplitLS>0</SplitLS>
+            <SwStkChk>0</SwStkChk>
+            <NoWarn>0</NoWarn>
+            <uSurpInc>0</uSurpInc>
+            <useXO>0</useXO>
+            <ClangAsOpt>1</ClangAsOpt>
+            <VariousControls>
+              <MiscControls></MiscControls>
+              <Define></Define>
+              <Undefine></Undefine>
+              <IncludePath></IncludePath>
+            </VariousControls>
+          </Aads>
+          <LDads>
+            <umfTarg>1</umfTarg>
+            <Ropi>0</Ropi>
+            <Rwpi>0</Rwpi>
+            <noStLib>0</noStLib>
+            <RepFail>1</RepFail>
+            <useFile>0</useFile>
+            <TextAddressRange>0x08000000</TextAddressRange>
+            <DataAddressRange>0x20000000</DataAddressRange>
+            <pXoBase></pXoBase>
+            <ScatterFile></ScatterFile>
+            <IncludeLibs></IncludeLibs>
+            <IncludeLibsPath></IncludeLibsPath>
+            <Misc></Misc>
+            <LinkerInputFile></LinkerInputFile>
+            <DisabledWarnings></DisabledWarnings>
+          </LDads>
+        </TargetArmAds>
+      </TargetOption>
+      <Groups>
+        <Group>
+          <GroupName>Application</GroupName>
+          <Files>
+            <File>
+              <FileName>main.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\main.c</FilePath>
+            </File>
+            <File>
+              <FileName>app.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\app\app.c</FilePath>
+            </File>
+            <File>
+              <FileName>nv_storage.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\app\nv_storage.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Foc</GroupName>
+          <Files>
+            <File>
+              <FileName>commands.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\commands.c</FilePath>
+            </File>
+            <File>
+              <FileName>samples.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\samples.c</FilePath>
+            </File>
+            <File>
+              <FileName>svpwm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\svpwm.c</FilePath>
+            </File>
+            <File>
+              <FileName>mc_error.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\mc_error.c</FilePath>
+            </File>
+            <File>
+              <FileName>limit.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\limit.c</FilePath>
+            </File>
+            <File>
+              <FileName>smo_observer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\smo_observer.c</FilePath>
+            </File>
+            <File>
+              <FileName>foc_observer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\foc_observer.c</FilePath>
+            </File>
+            <File>
+              <FileName>adrc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\adrc.c</FilePath>
+            </File>
+            <File>
+              <FileName>F_Calc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\F_Calc.c</FilePath>
+            </File>
+            <File>
+              <FileName>ladrc_observer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\ladrc_observer.c</FilePath>
+            </File>
+            <File>
+              <FileName>controller.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\controller.c</FilePath>
+            </File>
+            <File>
+              <FileName>foc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\foc.c</FilePath>
+            </File>
+            <File>
+              <FileName>etcs.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\core\etcs.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Motor</GroupName>
+          <Files>
+            <File>
+              <FileName>motor.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\motor.c</FilePath>
+            </File>
+            <File>
+              <FileName>ntc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\ntc.c</FilePath>
+            </File>
+            <File>
+              <FileName>motor_param.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\motor_param.c</FilePath>
+            </File>
+            <File>
+              <FileName>throttle.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\throttle.c</FilePath>
+            </File>
+            <File>
+              <FileName>mot_params_ind.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\mot_params_ind.c</FilePath>
+            </File>
+            <File>
+              <FileName>mc_config.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\mc_config.c</FilePath>
+            </File>
+            <File>
+              <FileName>current_2_3_shut.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\current_2_3_shut.c</FilePath>
+            </File>
+            <File>
+              <FileName>hall.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\foc\motor\hall.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Proto</GroupName>
+          <Files>
+            <File>
+              <FileName>can_message.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\prot\can_message.c</FilePath>
+            </File>
+            <File>
+              <FileName>can_pc_message.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\prot\can_pc_message.c</FilePath>
+            </File>
+            <File>
+              <FileName>can_foc_msg.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\prot\can_foc_msg.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Math</GroupName>
+          <Files>
+            <File>
+              <FileName>fast_math.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\math\fast_math.c</FilePath>
+            </File>
+            <File>
+              <FileName>sin_table.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\math\sin_table.c</FilePath>
+            </File>
+            <File>
+              <FileName>arm_cortexM4lf_math.lib</FileName>
+              <FileType>4</FileType>
+              <FilePath>..\Applications\math\arm_cortexM4lf_math.lib</FilePath>
+            </File>
+            <File>
+              <FileName>Fir.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\math\Fir.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>BSP</GroupName>
+          <Files>
+            <File>
+              <FileName>sched_timer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\sched_timer.c</FilePath>
+            </File>
+            <File>
+              <FileName>delay.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\delay.c</FilePath>
+            </File>
+            <File>
+              <FileName>adc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\adc.c</FilePath>
+            </File>
+            <File>
+              <FileName>bsp.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\bsp.c</FilePath>
+            </File>
+            <File>
+              <FileName>fmc_flash.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\fmc_flash.c</FilePath>
+            </File>
+            <File>
+              <FileName>gpio.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\gpio.c</FilePath>
+            </File>
+            <File>
+              <FileName>mc_irqs.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\mc_irqs.c</FilePath>
+            </File>
+            <File>
+              <FileName>pwm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\pwm.c</FilePath>
+            </File>
+            <File>
+              <FileName>uart.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\uart.c</FilePath>
+            </File>
+            <File>
+              <FileName>hall_tmr.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\bsp\at32\hall_tmr.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>Libs</GroupName>
+          <Files>
+            <File>
+              <FileName>circle_buffer.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\libs\circle_buffer.c</FilePath>
+            </File>
+            <File>
+              <FileName>logger.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\libs\logger.c</FilePath>
+            </File>
+            <File>
+              <FileName>crc16.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\libs\crc16.c</FilePath>
+            </File>
+            <File>
+              <FileName>byte_queue.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\libs\byte_queue.c</FilePath>
+            </File>
+            <File>
+              <FileName>time_measure.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\libs\time_measure.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>OS</GroupName>
+          <Files>
+            <File>
+              <FileName>heap_4.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\os\heap_4.c</FilePath>
+            </File>
+            <File>
+              <FileName>queue.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\os\queue.c</FilePath>
+            </File>
+            <File>
+              <FileName>os_task.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Applications\os\os_task.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>AT32F4xx_Drivers</GroupName>
+          <Files>
+            <File>
+              <FileName>at32f413_acc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_acc.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_adc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_adc.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_bpr.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_bpr.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_can.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_can.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_debug.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_debug.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_dma.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_dma.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_exint.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_exint.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_flash.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_flash.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_gpio.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_gpio.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_i2c.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_i2c.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_misc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_misc.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_pwc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_pwc.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_rtc.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_rtc.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_tmr.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_tmr.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_usart.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_usart.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_wdt.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_wdt.c</FilePath>
+            </File>
+            <File>
+              <FileName>at32f413_crm.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\AT32F41x_Drivers\src\at32f413_crm.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+        <Group>
+          <GroupName>StartUp</GroupName>
+          <Files>
+            <File>
+              <FileName>startup_at32f413.s</FileName>
+              <FileType>2</FileType>
+              <FilePath>..\Librarys\CMSIS\AT32\startup\mdk\startup_at32f413.s</FilePath>
+            </File>
+            <File>
+              <FileName>system_at32f413.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Librarys\CMSIS\AT32\system_at32f413.c</FilePath>
+            </File>
+          </Files>
+        </Group>
+      </Groups>
+    </Target>
+  </Targets>
+
+  <RTE>
+    <apis/>
+    <components/>
+    <files/>
+  </RTE>
+
+  <LayerInfo>
+    <Layers>
+      <Layer>
+        <LayName>&lt;Project Info&gt;</LayName>
+        <LayDesc></LayDesc>
+        <LayUrl></LayUrl>
+        <LayKeys></LayKeys>
+        <LayCat></LayCat>
+        <LayLic></LayLic>
+        <LayTarg>0</LayTarg>
+        <LayPrjMark>1</LayPrjMark>
+      </Layer>
+    </Layers>
+  </LayerInfo>
+
+</Project>

+ 1 - 1
Project/MC124.uvoptx

@@ -73,7 +73,7 @@
         <LExpSel>0</LExpSel>
       </OPTXL>
       <OPTFL>
-        <tvExp>0</tvExp>
+        <tvExp>1</tvExp>
         <tvExpOptDlg>0</tvExpOptDlg>
         <IsCurrentTarget>1</IsCurrentTarget>
       </OPTFL>

+ 3 - 0
Project/version_AT32_MC.cfg

@@ -0,0 +1,3 @@
+project: AT32MC
+version: 01
+debug: 1