Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add support for steval esc002 v1 #110

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 131 additions & 16 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


//#define REF_F031
//#define STEVAL_ESC002V1
//#define NEUTRON_G071
//#define GEN_64K_G071
//#define PWM_ENABLE_G071
Expand Down Expand Up @@ -273,7 +274,14 @@
#define CURRENT_OFFSET 0
#define TARGET_VOLTAGE_DIVIDER 210
#define USE_SERIAL_TELEMETRY

#define USE_RGB_LED
#define LED_RED_PORT GPIOB
#define LED_RED_PIN LL_GPIO_PIN_8
#define LED_GREEN_PORT GPIOB
#define LED_GREEN_PIN LL_GPIO_PIN_5
#define LED_BLUE_PORT GPIOB
#define LED_BLUE_PIN LL_GPIO_PIN_3
#endif

#ifdef AM32REF_F051
Expand Down Expand Up @@ -479,6 +487,29 @@
#define USE_SERIAL_TELEMETRY
#endif

#ifdef STEVAL_ESC002V1
#define FILE_NAME "STEVAL_ESC002V1"
#define FIRMWARE_NAME "ESC002V1 "
#define DEAD_TIME 45
// uses the STSPIN32F0A
#define HARDWARE_GROUP_F031_C
#define TARGET_VOLTAGE_DIVIDER 152
#define MILLIVOLT_PER_AMP 24
// 3.3V * (R17 + 24k(=R23) / (R17 + 24k(=R23) + R15-24k(=R23)) = 0.175 V
#define CURRENT_OFFSET 175
#define TARGET_STALL_PROTECTION_INTERVAL 8000

#define INVERTED_COMPARATOR_OUTPUT

#define USE_RGB_LED
#define LED_RED_PORT GPIOA
#define LED_RED_PIN LL_GPIO_PIN_0
#define LED_GREEN_PORT GPIOA
#define LED_GREEN_PIN LL_GPIO_PIN_1
#define LED_BLUE_PORT GPIOA
#define LED_BLUE_PIN LL_GPIO_PIN_2

#endif

/********************************** defaults if not set ***************************/

Expand Down Expand Up @@ -740,16 +771,19 @@
#define DMA_HANDLE_TYPE_DEF hdma_tim3_ch1
#define IC_DMA_IRQ_NAME DMA1_Channel4_5_IRQn

// TIM1_CH3
#define PHASE_A_GPIO_LOW LL_GPIO_PIN_1
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_A_GPIO_PORT_HIGH GPIOA

// TIM1_CH2
#define PHASE_B_GPIO_LOW LL_GPIO_PIN_0
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_9
#define PHASE_B_GPIO_PORT_HIGH GPIOA

// TIM1_CH1
#define PHASE_C_GPIO_LOW LL_GPIO_PIN_7
#define PHASE_C_GPIO_PORT_LOW GPIOA
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_8
Expand All @@ -762,12 +796,8 @@

#endif



/************************************* G071 Hardware Groups **********************************/



#ifdef HARDWARE_GROUP_G0_A

#define MCU_G071
Expand Down Expand Up @@ -1071,16 +1101,19 @@
#define DMA_HANDLE_TYPE_DEF hdma_tim3_ch1
#define IC_DMA_IRQ_NAME DMA1_Channel1_IRQn

// TIM1_CH3
#define PHASE_A_GPIO_LOW LL_GPIO_PIN_1
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_A_GPIO_PORT_HIGH GPIOA

// TIM1_CH2
#define PHASE_B_GPIO_LOW LL_GPIO_PIN_0
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_9
#define PHASE_B_GPIO_PORT_HIGH GPIOA

// TIM1_CH1
#define PHASE_C_GPIO_LOW LL_GPIO_PIN_7
#define PHASE_C_GPIO_PORT_LOW GPIOA
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_8
Expand Down Expand Up @@ -1143,9 +1176,10 @@

#ifdef HARDWARE_GROUP_F031_A

#define MCU_F031
#define INTERVAL_TIMER TIM3
#define EXTI_TYPE_BAC
#define USE_TIMER_2_CHANNEL_3
#define MCU_F031

#define INPUT_PIN LL_GPIO_PIN_2
#define INPUT_PIN_PORT GPIOA
Expand Down Expand Up @@ -1181,8 +1215,9 @@
#define PHASE_B_LL_EXTI_LINE LL_EXTI_LINE_1
#define PHASE_C_LL_EXTI_LINE LL_EXTI_LINE_6

#define EXTI_IRQ1_NAME EXTI0_1_IRQn
#define EXTI_IRQ2_NAME EXTI4_15_IRQn
#define EXTI_IRQA_NAME EXTI0_1_IRQn
#define EXTI_IRQB_NAME EXTI0_1_IRQn
#define EXTI_IRQC_NAME EXTI4_15_IRQn

#define PHASE_A_GPIO_LOW LL_GPIO_PIN_14
#define PHASE_A_GPIO_PORT_LOW GPIOB
Expand All @@ -1199,18 +1234,23 @@
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_C_GPIO_PORT_HIGH GPIOA

#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_2

#define CURRENT_SENSE_ADC_PIN LL_GPIO_PIN_5
#define VOLTAGE_SENSE_ADC_PIN LL_GPIO_PIN_7

#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_5
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_7


#endif


#ifdef HARDWARE_GROUP_F031_B

#define MCU_F031
#define INTERVAL_TIMER TIM3
#define USE_TIMER_2_CHANNEL_3

#define INPUT_PIN LL_GPIO_PIN_2
#define IC_TIMER_CHANNEL LL_TIM_CHANNEL_CH3
#define IC_TIMER_REGISTER TIM2
Expand Down Expand Up @@ -1245,32 +1285,111 @@
#define PHASE_B_LL_EXTI_LINE LL_EXTI_LINE_1
#define PHASE_C_LL_EXTI_LINE LL_EXTI_LINE_5

#define EXTI_IRQ1_NAME EXTI0_1_IRQn
#define EXTI_IRQ2_NAME EXTI4_15_IRQn
#define EXTI_IRQA_NAME EXTI0_1_IRQn
#define EXTI_IRQB_NAME EXTI0_1_IRQn
#define EXTI_IRQC_NAME EXTI4_15_IRQn

// TIM CH2
#define PHASE_A_GPIO_LOW LL_GPIO_PIN_14
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_9
#define PHASE_A_GPIO_PORT_HIGH GPIOA

// TIM CH1
#define PHASE_B_GPIO_LOW LL_GPIO_PIN_13
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_8
#define PHASE_B_GPIO_PORT_HIGH GPIOA

// TIM CH3
#define PHASE_C_GPIO_LOW LL_GPIO_PIN_15
#define PHASE_C_GPIO_PORT_LOW GPIOB
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_10
#define PHASE_C_GPIO_PORT_HIGH GPIOA

#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_2

#define CURRENT_SENSE_ADC_PIN LL_GPIO_PIN_3
#define VOLTAGE_SENSE_ADC_PIN LL_GPIO_PIN_4

#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_3
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_4

#endif


#ifdef HARDWARE_GROUP_F031_C

#define MCU_F031
#define INTERVAL_TIMER TIM2
#define EXTI_TYPE_BAC
#define USE_TIMER_3_CHANNEL_1

#define INPUT_PIN LL_GPIO_PIN_6
#define INPUT_PIN_PORT GPIOA
#define IC_TIMER_CHANNEL LL_TIM_CHANNEL_CH1
#define IC_TIMER_REGISTER TIM3
#define IC_TIMER_POINTER htim3
#define INPUT_DMA_CHANNEL LL_DMA_CHANNEL_4
#define DMA_HANDLE_TYPE_DEF hdma_tim3_ch1
#define IC_DMA_IRQ_NAME DMA1_Channel4_5_IRQn

// Phase W/3 (LSW/LS3, HSW/HS3) TIM1_CH3
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_LOW LL_GPIO_PIN_15
#define PHASE_A_GPIO_PORT_HIGH GPIOA
#define PHASE_A_GPIO_HIGH LL_GPIO_PIN_10

// Phase V/2 (LSV/LS2, HSV/HS2) TIM1_CH2
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_LOW LL_GPIO_PIN_14
#define PHASE_B_GPIO_PORT_HIGH GPIOA
#define PHASE_B_GPIO_HIGH LL_GPIO_PIN_9

// Phase U/1 (LSU/LS1, HSU/HS1) TIM1_CH1
#define PHASE_C_GPIO_PORT_LOW GPIOB
#define PHASE_C_GPIO_LOW LL_GPIO_PIN_13
#define PHASE_C_GPIO_PORT_HIGH GPIOA
#define PHASE_C_GPIO_HIGH LL_GPIO_PIN_8

// Phase W/3
#define PHASE_A_EXTI_PORT GPIOB
#define PHASE_A_EXTI_PIN LL_GPIO_PIN_1
#define PHASE_A_EXTI_LINE EXTI_IMR_MR1_Pos
#define PHASE_A_LL_EXTI_LINE LL_EXTI_LINE_1
#define SYSCFG_EXTI_PORTA LL_SYSCFG_EXTI_PORTB
#define SYSCFG_EXTI_LINEA LL_SYSCFG_EXTI_LINE1

// Phase V/2
#define PHASE_B_EXTI_PORT GPIOF
#define PHASE_B_EXTI_PIN LL_GPIO_PIN_0
#define PHASE_B_EXTI_LINE EXTI_IMR_MR0_Pos
#define PHASE_B_LL_EXTI_LINE LL_EXTI_LINE_0
#define SYSCFG_EXTI_PORTB LL_SYSCFG_EXTI_PORTF
#define SYSCFG_EXTI_LINEB LL_SYSCFG_EXTI_LINE0

// Phase U/1
#define PHASE_C_EXTI_PORT GPIOF
#define PHASE_C_EXTI_PIN LL_GPIO_PIN_1
#define PHASE_C_EXTI_LINE EXTI_IMR_MR1_Pos
#define PHASE_C_LL_EXTI_LINE LL_EXTI_LINE_1
#define SYSCFG_EXTI_PORTC LL_SYSCFG_EXTI_PORTF
#define SYSCFG_EXTI_LINEC LL_SYSCFG_EXTI_LINE1

#define EXTI_IRQA_NAME EXTI0_1_IRQn
#define EXTI_IRQB_NAME EXTI0_1_IRQn
#define EXTI_IRQC_NAME EXTI0_1_IRQn

#define ADC_DMA_CHANNEL LL_DMA_CHANNEL_1

#define VOLTAGE_SENSE_ADC_PIN LL_GPIO_PIN_3
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_3

#define CURRENT_SENSE_ADC_PIN LL_GPIO_PIN_4
#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_4

#endif

/*************************************l431******************************************************/

#ifdef HARDWARE_GROUP_L4_A

#define MCU_L431
Expand Down Expand Up @@ -1312,9 +1431,6 @@

#endif




/************************************ MCU COMMON PERIPHERALS **********************************************/

#ifdef MCU_F051
Expand Down Expand Up @@ -1365,7 +1481,6 @@
#ifdef MCU_F031
#define CPU_FREQUENCY_MHZ 48
#define EEPROM_START_ADD (uint32_t)0x08007C00
#define INTERVAL_TIMER TIM3
#define TEN_KHZ_TIMER TIM16
#define UTILITY_TIMER TIM17
#define COM_TIMER TIM14
Expand Down
6 changes: 5 additions & 1 deletion Mcu/f031/Inc/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void MX_DMA_Init(void);
void MX_TIM14_Init(void);
void MX_TIM16_Init(void);
void MX_TIM1_Init(void);
void MX_TIM3_Init(void);
void MX_TIM_Interval_Init(void);
void MX_TIM17_Init(void);
void MX_IWDG_Init(void);
//void MX_ADC_Init(void);
Expand All @@ -32,3 +32,7 @@ void TEN_KHZ_Timer_Init(void);
//static void MX_TIM16_Init2(void);
void UN_GPIO_Init(void);
void UN_TIM_Init(void);

#ifdef USE_RGB_LED
void LED_GPIO_init(void);
#endif
3 changes: 2 additions & 1 deletion Mcu/f031/Inc/stm32f0xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ void SysTick_Handler(void);
void DMA1_Channel2_3_IRQHandler(void);
void DMA1_Channel4_5_IRQHandler(void);
void TIM2_IRQHandler(void);
void TIM3_IRQHandler(void);
void TIM14_IRQHandler(void);
void TIM16_IRQHandler(void);
/* USER CODE BEGIN EFP */


void TIM2_IRQHandler(void);
void EXTI0_1_IRQHandler(void);
void EXTI2_3_IRQHandler(void);
void EXTI4_15_IRQHandler(void);
void DMA1_Channel4_5_IRQHandler(void);
void DMA1_Channel1_IRQHandler(void);
/* USER CODE END EFP */
Expand Down
Loading