如何在linux上使用stlink-tools通过gdb远程调试STM32代码?

问题描述 投票:0回答:1

在Linux上,使用

stlink-tools
,我有一个STM32板,它运行必须调试的代码。如何进行?

该代码是在主机(x86 PC)上构建的,并使用

gcc-arm-none-eabi
用于 STM32 目标(arm):

>> sudo apt-get install gcc-arm-none-eabi
>> make VERBOSE=1
/usr/bin/arm-none-eabi-gcc  ... -g -O0 ... -o blink01.c.o -c blink01.c
/usr/bin/arm-none-eabi-gcc ... -g -O0 blink01.c.o -o blink01.elf

然后剥离以减少二进制文件的大小:

>> /usr/bin/arm-none-eabi-objcopy -O binary blink01.elf blink01.bin

然后使用STM工具将简化后的二进制文件烧录到STM32板:

>> sudo apt install stlink-tools
>> st-flash write blink01.bin 0x08000000
...
INFO common.c: Flash written and verified! jolly good!

然后在一个终端中运行gdbserver:

>> st-util
st-util
INFO common.c: F303 high density: 64 KiB SRAM, 512 KiB flash in at least 2 KiB pages.
INFO gdb-server.c: Listening at *:4242...

在另一个终端中,运行(注意在带有调试符号的主机上使用.elf,在没有符号的目标上使用.bin,因为根据我在某处读到的文档,它应该以这种方式工作):

>> sudo apt-get install gdb-arm-none-eabi
>> gdb-multiarch
(gdb) set remote exec-file /blink01.bin
(gdb) file blink01.elf
Reading symbols from blink01.elf...
(gdb) target extended-remote localhost:4242
Remote debugging using localhost:4242
0x00000000 in ?? ()

符号似乎搞砸了

0x00000000 in ??
:没有可用的堆栈,可以设置断点,但在运行时永远不会被击中
gdb
。似乎无法使用符号:如何解决这个问题?

编辑

主持人:

>> uname -a
Linux yoda 6.5.0-4-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.10-1 (2023-11-03) x86_64 GNU/Linux
>> arm-none-eabi-gcc --version
arm-none-eabi-gcc (15:12.2.rel1-1) 12.2.1 20221205
>> gdb-multiarch --version
GNU gdb (Debian 13.2-1) 13.2

编辑

禁用看门狗我确实让 gdb 工作得更好(符号和堆栈正常)

>> git diff
diff --git a/src/blink01.c b/src/blink01.c
index 1fba10e..86f23f5 100644
--- a/src/blink01.c
+++ b/src/blink01.c
@@ -169,6 +169,17 @@ void main(void) {
   GPIOA->BSRR |= GPIO_BSRR_BR_5; /* BR: Bit Reset. */
+
+#ifdef DEBUG
+  #define DBGMCU_APB1_FZ ( * ( ( volatile unsigned long * ) 0xE0042008 ) )
+  DBGMCU_APB1_FZ |= DBGMCU_APB1_FZ_DBG_IWDG_STOP;
+  DBGMCU_APB1_FZ |= DBGMCU_APB1_FZ_DBG_WWDG_STOP;
+#endif
 #endif
 

但是 gdb 不会在断点处停止,我无法列出。有知道为什么吗?

(gdb) file blink01.elf
Reading symbols from blink01.elf...
(gdb) b vBlink
Breakpoint 1 at 0x8002f4c
(gdb) target extended-remote localhost:4242
Remote debugging using localhost:4242
Note: automatically using hardware breakpoints for read-only addresses.
0x08002750 in xPortStartScheduler ()
(gdb) bt
#0  0x08002750 in xPortStartScheduler ()
#1  0x08000b9c in vTaskStartScheduler ()
#2  0x08003042 in main ()
(gdb) l
1   ../../../../../../../../../newlib/libc/machine/arm/memcpy-armv7m.S: No such file or directory.
arm stm32 cross-compiling
1个回答
0
投票

stm 32 板中的调试器使用和入门视频 https://www.youtube.com/watch?v=iUJE7uW-h90&t=1101s

© www.soinside.com 2019 - 2024. All rights reserved.