diff --git a/src/drivers/interface/motors.h b/src/drivers/interface/motors.h index e480123dd..c4c0ee238 100644 --- a/src/drivers/interface/motors.h +++ b/src/drivers/interface/motors.h @@ -223,6 +223,7 @@ typedef struct uint32_t gpioPowerswitchPerif; GPIO_TypeDef* gpioPowerswitchPort; uint16_t gpioPowerswitchPin; + bool hasPC15ESCReset; uint32_t timPerif; TIM_TypeDef* tim; uint16_t timPolarity; diff --git a/src/drivers/src/motors.c b/src/drivers/src/motors.c index 4336153e1..36f5ba532 100644 --- a/src/drivers/src/motors.c +++ b/src/drivers/src/motors.c @@ -224,6 +224,20 @@ void motorsInit(const MotorPerifDef** motorMapSelect) DEBUG_PRINT("Using %s motor driver\n", motorMap[0]->drvType == BRUSHED ? "brushed" : "brushless"); + if (motorMap[MOTOR_M1]->hasPC15ESCReset) + { + MOTORS_RCC_GPIO_CMD(RCC_AHB1Periph_GPIOC, ENABLE); + // Configure the GPIO for CF-BL ESC RST + GPIO_StructInit(&GPIO_InitStructure); + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; + GPIO_Init(GPIOC, &GPIO_InitStructure); + // Hold reset for all CF-BL ESC:s by pulling low. + GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_RESET); + } + for (i = 0; i < NBR_OF_MOTORS; i++) { //Clock the gpio and the timers @@ -243,16 +257,6 @@ void motorsInit(const MotorPerifDef** motorMapSelect) GPIO_WriteBit(motorMap[i]->gpioPowerswitchPort, motorMap[i]->gpioPowerswitchPin, 1); } - // Configure the GPIO for CF-BL ESC RST - GPIO_StructInit(&GPIO_InitStructure); - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; - GPIO_Init(GPIOC, &GPIO_InitStructure); - // Hold reset for all CF-BL ESC:s by pulling low. - GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_RESET); - // Configure the GPIO for the timer output GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = MOTORS_GPIO_MODE; @@ -283,9 +287,11 @@ void motorsInit(const MotorPerifDef** motorMapSelect) motorMap[i]->ocInit(motorMap[i]->tim, &TIM_OCInitStructure); motorMap[i]->preloadConfig(motorMap[i]->tim, TIM_OCPreload_Enable); } + #ifdef CONFIG_MOTORS_ESC_PROTOCOL_DSHOT motorsDshotDMASetup(); #endif + // Start the timers for (i = 0; i < NBR_OF_MOTORS; i++) { @@ -296,9 +302,12 @@ void motorsInit(const MotorPerifDef** motorMapSelect) // Output zero power motorsStop(); - // Release reset for all CF-BL ESC:s after motor signal is activated - GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_SET); + if (motorMap[MOTOR_M1]->hasPC15ESCReset) + { + // Release reset for all CF-BL ESC:s after motor signal is activated + GPIO_WriteBit(GPIOC, GPIO_Pin_15, Bit_SET); + } } void motorsDeInit(const MotorPerifDef** motorMapSelect) diff --git a/src/drivers/src/motors_def.c b/src/drivers/src/motors_def.c index d9ef9658c..1694067a6 100644 --- a/src/drivers/src/motors_def.c +++ b/src/drivers/src/motors_def.c @@ -378,9 +378,7 @@ static const MotorPerifDef MOTORS_PA1_TIM2_CH2_BRUSHLESS_OD = .gpioPinSource = GPIO_PinSource1, .gpioOType = GPIO_OType_OD, .gpioAF = GPIO_AF_TIM2, - .gpioPowerswitchPerif = RCC_AHB1Periph_GPIOA, - .gpioPowerswitchPort = GPIOA, - .gpioPowerswitchPin = GPIO_Pin_0, + .hasPC15ESCReset = true, .timPerif = RCC_APB1Periph_TIM2, .tim = TIM2, .timPolarity = TIM_OCPolarity_High, @@ -408,9 +406,7 @@ static const MotorPerifDef MOTORS_PB11_TIM2_CH4_BRUSHLESS_OD = .gpioPinSource = GPIO_PinSource11, .gpioOType = GPIO_OType_OD, .gpioAF = GPIO_AF_TIM2, - .gpioPowerswitchPerif = RCC_AHB1Periph_GPIOB, - .gpioPowerswitchPort = GPIOB, - .gpioPowerswitchPin = GPIO_Pin_12, + .hasPC15ESCReset = true, .timPerif = RCC_APB1Periph_TIM2, .tim = TIM2, .timPolarity = TIM_OCPolarity_High, @@ -438,9 +434,7 @@ static const MotorPerifDef MOTORS_PB11_TIM2_CH4_BRUSHLESS_OD = .gpioPinSource = GPIO_PinSource15, .gpioOType = GPIO_OType_OD, .gpioAF = GPIO_AF_TIM2, - .gpioPowerswitchPerif = RCC_AHB1Periph_GPIOC, - .gpioPowerswitchPort = GPIOC, - .gpioPowerswitchPin = GPIO_Pin_8, + .hasPC15ESCReset = true, .timPerif = RCC_APB1Periph_TIM2, .tim = TIM2, .timPolarity = TIM_OCPolarity_High, @@ -469,9 +463,7 @@ static const MotorPerifDef MOTORS_PB10_TIM2_CH3_BRUSHLESS_OD = .gpioPinSource = GPIO_PinSource10, .gpioOType = GPIO_OType_OD, .gpioAF = GPIO_AF_TIM2, - .gpioPowerswitchPerif = RCC_AHB1Periph_GPIOC, - .gpioPowerswitchPort = GPIOC, - .gpioPowerswitchPin = GPIO_Pin_15, + .hasPC15ESCReset = true, .timPerif = RCC_APB1Periph_TIM2, .tim = TIM2, .timPolarity = TIM_OCPolarity_High,