Skip to content

Commit edb3207

Browse files
authored
fix(motor): estop release causes z to drop (#737)
* duplicated code, brake gpio already defined in initialize_rev_specific_pins.c * RQA-2170 disengage Z motors whenever estop is activated * use callback * use rising edge (when estop releases) and no need for delay
1 parent e14239b commit edb3207

9 files changed

+53
-22
lines changed

gripper/firmware/motor_hardware_shared.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "motor_hardware.h"
22
#include "system_stm32g4xx.h"
33

4-
54
static motor_interrupt_callback timer_callback = NULL;
65
static z_encoder_overflow_callback z_enc_overflow_callback = NULL;
76
static brushed_motor_interrupt_callback brushed_timer_callback = NULL;
@@ -214,3 +213,12 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef* htim) {
214213
}
215214

216215

216+
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
217+
if (GPIO_Pin == ESTOP_IN_PIN) {
218+
#if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a'
219+
HAL_GPIO_WritePin(EBRAKE_PORT, EBRAKE_PIN, GPIO_PIN_RESET);
220+
#endif
221+
// this keeps the motor disengaged when estop is released
222+
HAL_GPIO_WritePin(Z_MOT_ENABLE_PORT, Z_MOT_ENABLE_PIN, GPIO_PIN_RESET);
223+
}
224+
}

gripper/firmware/stm32g4xx_it.c

+10
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ void TIM7_IRQHandler(void) {
198198
call_motor_handler();
199199
}
200200

201+
/**
202+
* @brief This function handles EXTI line[15:10] interrupts.
203+
*/
204+
__attribute__((section(".ccmram")))
205+
void EXTI15_10_IRQHandler(void) {
206+
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_10)) {
207+
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_10);
208+
}
209+
}
210+
201211
extern void xPortSysTickHandler(void);
202212
void SysTick_Handler(void) {
203213
HAL_IncTick();

gripper/firmware/stm32g4xx_it.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void TIM3_IRQHandler(void);
4848
void TIM7_IRQHandler(void);
4949
void TIM8_CC_IRQHandler(void);
5050
void TIM8_UP_IRQHandler(void);
51+
void EXTI15_10_IRQHandler(void);
5152

5253
#ifdef __cplusplus
5354
}

gripper/firmware/utility_gpio.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ static void estop_input_gpio_init() {
6868
/*Configure GPIO pin EStopin : PA10 */
6969
GPIO_InitTypeDef GPIO_InitStruct = {0};
7070
GPIO_InitStruct.Pin = ESTOP_IN_PIN;
71-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
71+
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
7272
GPIO_InitStruct.Pull = GPIO_NOPULL;
7373
HAL_GPIO_Init(ESTOP_IN_PORT, &GPIO_InitStruct);
74+
75+
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 6, 0);
76+
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
7477
}
7578

7679
static void tool_detect_gpio_init(void) {

head/firmware/motor_hardware.h

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern TIM_HandleTypeDef htim3;
1414

1515
typedef void (*motor_interrupt_callback)();
1616
typedef void (*encoder_overflow_callback)(int32_t);
17+
1718
HAL_StatusTypeDef initialize_spi(SPI_HandleTypeDef* hspi);
1819
void initialize_timer(motor_interrupt_callback callback,
1920
encoder_overflow_callback left_enc_overflow_callback,

head/firmware/motor_hardware_common.c

+14
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) {
334334
}
335335
}
336336

337+
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
338+
// disengage motor whenever estop is engaged
339+
if (GPIO_Pin == GPIO_PIN_4) {
340+
#if PCBA_PRIMARY_REVISION != 'b' && PCBA_PRIMARY_REVISION != 'a'
341+
// right & left brake
342+
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0 | GPIO_PIN_5, GPIO_PIN_RESET);
343+
#endif
344+
345+
// disable both left and right enable pins
346+
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET);
347+
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_11, GPIO_PIN_RESET);
348+
}
349+
}
350+
337351
void initialize_timer(motor_interrupt_callback callback,
338352
encoder_overflow_callback l_f_callback,
339353
encoder_overflow_callback r_f_callback) {

head/firmware/stm32g4xx_it.c

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ void FDCAN1_IT0_IRQHandler(void) {
144144
HAL_FDCAN_IRQHandler(can_get_device_handle());
145145
}
146146

147+
/**
148+
* @brief This function handles EXTI line4 interrupt.
149+
*/
150+
void EXTI4_IRQHandler(void) {
151+
if (__HAL_GPIO_EXTI_GET_IT(GPIO_PIN_4)) {
152+
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
153+
}
154+
}
155+
147156
/**
148157
* @brief This function handles TIM7 global interrupt.
149158
*/

head/firmware/stm32g4xx_it.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void PendSV_Handler(void);
4242
void SysTick_Handler(void);
4343
void DMA1_Channel2_IRQHandler(void);
4444
void DMA1_Channel3_IRQHandler(void);
45+
void EXTI4_IRQHandler(void);
4546

4647
#ifdef __cplusplus
4748
}

head/firmware/utility_hardware.c

+4-20
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,15 @@ void estop_input_gpio_init() {
6262
/*Configure GPIO pin EStopin : PB4 */
6363
GPIO_InitTypeDef GPIO_InitStruct = {0};
6464
GPIO_InitStruct.Pin = GPIO_PIN_4;
65-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
65+
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
6666
GPIO_InitStruct.Pull = GPIO_NOPULL;
6767
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
68-
}
6968

70-
void ebrake_gpio_init() {
71-
__HAL_RCC_GPIOB_CLK_ENABLE();
72-
// left brake PB0
73-
// right brake PB5
74-
GPIO_InitTypeDef GPIO_InitStruct = {0};
75-
GPIO_InitStruct.Pin = GPIO_PIN_0;
76-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
77-
GPIO_InitStruct.Pull = GPIO_NOPULL;
78-
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
79-
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
80-
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
81-
82-
83-
GPIO_InitStruct.Pin = GPIO_PIN_5;
84-
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
85-
86-
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
69+
HAL_NVIC_SetPriority(EXTI4_IRQn, 6, 0);
70+
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
8771
}
8872

73+
8974
void carrier_detect_gpio_init() {
9075
// Z/left: PC5
9176
// A/right: PB2
@@ -109,7 +94,6 @@ void carrier_detect_gpio_init() {
10994
}
11095

11196
void utility_gpio_init() {
112-
ebrake_gpio_init();
11397
carrier_detect_gpio_init();
11498
limit_switch_gpio_init();
11599
estop_input_gpio_init();

0 commit comments

Comments
 (0)