Skip to content

Commit

Permalink
Fixed CF-BL and Bolt M4 PC15 conflict
Browse files Browse the repository at this point in the history
The CF-BL used PC15 for all ESC-Reset and Bolt M4 uses it for
it's ESC enable MOSFET. hasPC15ESCReset variable was intruduced
to separate the configurations during init.
  • Loading branch information
tobbeanton committed Jul 3, 2024
1 parent 079f02e commit 348174d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 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
35 changes: 22 additions & 13 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,22 +287,27 @@ 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++)
{
TIM_Cmd(motorMap[i]->tim, ENABLE);
TIM_Cmd(motorMap[MOTOR_M1]->tim, ENABLE);
}

isInit = true;

// 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[0]->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 348174d

Please sign in to comment.