Skip to content

Commit

Permalink
Merge pull request #1391 from bitcraze/tobba/bolt_m4_not_running
Browse files Browse the repository at this point in the history
Fixed CF-BL and Bolt M4 PC15 conflict resulting in that Bolt M4 didn't spin.
  • Loading branch information
tobbeanton committed Jul 3, 2024
2 parents 079f02e + 0237009 commit ec6a792
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/drivers/interface/motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 21 additions & 12 deletions src/drivers/src/motors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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++)
{
Expand All @@ -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)
Expand Down
16 changes: 4 additions & 12 deletions src/drivers/src/motors_def.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ec6a792

Please sign in to comment.