Skip to content

Commit

Permalink
Ensure everything is stopped when entering the bootloader
Browse files Browse the repository at this point in the history
While we're at it, ensure the primary ISR is stopped when entering the
bootloader or when an assertion failure occurs.
  • Loading branch information
jpieper committed Jul 24, 2023
1 parent 3759121 commit c72fc7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion fw/board_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,9 @@ class BoardDebug::Impl {
}

if (cmd_text == "flash") {
// TODO: Get the USART and direction pin from our config.
// Ensure everything is stopped!
MoteusEnsureOff();

MultiplexBootloader(multiplex_protocol_->config()->id, USART1, GPIOA, 8);
// We should never get here.
MJ_ASSERT(false);
Expand Down
9 changes: 1 addition & 8 deletions fw/moteus_assert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ extern "C" {
void mbed_die(void) {
// We want to ensure the motor controller is disabled and flash an
// LED which exists.
gpio_t power;
gpio_init_out(&power, moteus::g_hw_pins.drv8323_hiz);
gpio_write(&power, 0);

// Also, disable the DRV8323 entirely, because, hey, why not.
gpio_t enable;
gpio_init_out(&enable, moteus::g_hw_pins.drv8323_enable);
gpio_write(&enable, 0);
moteus::MoteusEnsureOff();

gpio_t led;
gpio_init_out(&led, moteus::g_hw_pins.debug_led1);
Expand Down
18 changes: 18 additions & 0 deletions fw/moteus_hw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,22 @@ MoteusHwPins FindHardwarePins(FamilyAndVersion fv) {
return result;
}

void MoteusEnsureOff() {
gpio_t power;
gpio_init_out(&power, moteus::g_hw_pins.drv8323_hiz);
gpio_write(&power, 0);

// Also, disable the DRV8323 entirely, because, hey, why not.
gpio_t enable;
gpio_init_out(&enable, moteus::g_hw_pins.drv8323_enable);
gpio_write(&enable, 0);

// We want to ensure that our primary interrupt is not running.
// Which one it is could vary, so just turn them all off.
NVIC_DisableIRQ(TIM2_IRQn);
NVIC_DisableIRQ(TIM3_IRQn);
NVIC_DisableIRQ(TIM4_IRQn);
NVIC_DisableIRQ(TIM5_IRQn);
}

}
3 changes: 3 additions & 0 deletions fw/moteus_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,7 @@ MoteusHwPins FindHardwarePins(FamilyAndVersion);

extern MoteusHwPins g_hw_pins;

// Ensure the DRV8323 is turned off.
void MoteusEnsureOff();

}

0 comments on commit c72fc7f

Please sign in to comment.