Skip to content

Commit

Permalink
In-circuit debugging (#1560)
Browse files Browse the repository at this point in the history
* openocd script and readme

* do not disable SWD on boot
  • Loading branch information
robbederks committed Aug 5, 2023
1 parent 130092e commit d2d207b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions board/debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# In-circuit debugging using openocd and gdb

## Hardware
Connect an ST-Link V2 programmer to the SWD pins on the board. The pins that need to be connected are:
- GND
- VTref
- SWDIO
- SWCLK
- NRST

Make sure you're using a genuine one for boards that do not have a 3.3V panda power rail. For example, the tres runs at 1.8V, which is not supported by the clones.

## Openocd
Install openocd. For Ubuntu 20.04, the one in the package manager works fine: `sudo apt install openocd`.

To run, use `./debug_f4.sh (TODO)` or `./debug_h7.sh` depending on the panda.

## GDB
You need `gdb-multiarch`.

Once openocd is running, you can connect from gdb as follows:
```
$ gdb-multiarch
(gdb) target ext :3333
```
To reset and break, use `monitor reset halt`.
3 changes: 3 additions & 0 deletions board/debug/debug_h7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e

sudo openocd -f "interface/stlink.cfg" -c "transport select hla_swd" -f "target/stm32h7x.cfg" -c "init"
2 changes: 1 addition & 1 deletion board/stm32h7/stm32h7_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ separate IRQs for RX and TX.

void early_gpio_float(void) {
RCC->AHB4ENR = RCC_AHB4ENR_GPIOAEN | RCC_AHB4ENR_GPIOBEN | RCC_AHB4ENR_GPIOCEN | RCC_AHB4ENR_GPIODEN | RCC_AHB4ENR_GPIOEEN | RCC_AHB4ENR_GPIOFEN | RCC_AHB4ENR_GPIOGEN | RCC_AHB4ENR_GPIOHEN;
GPIOA->MODER = 0; GPIOB->MODER = 0; GPIOC->MODER = 0; GPIOD->MODER = 0; GPIOE->MODER = 0; GPIOF->MODER = 0; GPIOG->MODER = 0; GPIOH->MODER = 0;
GPIOA->MODER = 0xAB000000; GPIOB->MODER = 0; GPIOC->MODER = 0; GPIOD->MODER = 0; GPIOE->MODER = 0; GPIOF->MODER = 0; GPIOG->MODER = 0; GPIOH->MODER = 0;
GPIOA->ODR = 0; GPIOB->ODR = 0; GPIOC->ODR = 0; GPIOD->ODR = 0; GPIOE->ODR = 0; GPIOF->ODR = 0; GPIOG->ODR = 0; GPIOH->ODR = 0;
GPIOA->PUPDR = 0; GPIOB->PUPDR = 0; GPIOC->PUPDR = 0; GPIOD->PUPDR = 0; GPIOE->PUPDR = 0; GPIOF->PUPDR = 0; GPIOG->PUPDR = 0; GPIOH->PUPDR = 0;
}

0 comments on commit d2d207b

Please sign in to comment.