简体   繁体   English

使用 OpenOCD 和 arm-none-eabi-gdb 将二进制文件加载到 stm32f103c8t6

[英]Load binary into stm32f103c8t6 with OpenOCD and arm-none-eabi-gdb

I tried to load binary that is compiled from rust code, but it doesn't work.我试图加载从 Rust 代码编译的二进制文件,但它不起作用。

First, I downloaded Rust code from https://github.com/rust-embedded/discovery .首先,我从https://github.com/rust-embedded/discovery下载了 Rust 代码。 Then, I built it.然后,我建造了它。

# I am in the `src/05-led-roulette` directory
rustup target add thumbv7m-none-eabi
cargo build --target thumbv7m-none-eabi

It was successfully compiled.它已成功编译。

After that, I successfully connected with stm32f103c8t6 using OpenOCD.之后,我使用 OpenOCD 成功连接到 stm32f103c8t6。 Then, I run this command.然后,我运行这个命令。

arm-none-eabi-gdb -q target/thumbv7m-none-eabi/debug/led-roulette

But it seemed like it didn't finish reading.但是好像没读完。

Reading symbols from target/thumbv7m-none-eabi/debug/led-roulette...
(gdb)

(not done?!) (尚未完成?!)

After that, I tried load command, but it returned following sentences.之后,我尝试了load命令,但它返回了以下句子。

Start address 0x0, load size 0
Transfer rate: 0 bits in <1 sec.

I have no idea about why it doesn't work.我不知道为什么它不起作用。

Please help me.请帮我。

First see if your binary is good, then try telnet, then gdb.首先看看你的二进制文件是否好,然后尝试 telnet,然后是 gdb。 Rust also multiplies the odds of failure, so start with something simple: Rust 也会增加失败的几率,所以从一些简单的事情开始:

so.s so.s

.thumb
.globl _start
_start:
.word 0x20001000
.word reset
.thumb_func
reset:
    ldr r0,some_addr
    ldr r1,[r0]
    add r1,r1,#1
    str r1,[r0]
    b .
    .align
some_addr: .word 0x20000000

build it建造它

arm-none-eabi-as so.s -o so.o
arm-none-eabi-ld -Ttext=0x08000000 so.o -o so.elf
arm-none-eabi-objdump -D so.elf 
arm-none-eabi-objdump -D so.elf 

so.elf: file format elf32-littlearm so.elf:文件格式 elf32-littlearm

Disassembly of section .text: .text 节的反汇编:

08000000 <_start>: 8000000: 20001000 andcs r1, r0, r0 8000004: 08000009 stmdaeq r0, {r0, r3} 08000000 <_start>: 8000000: 20001000 andcs r1, r0, r0 8000004: 08000009 stmdaeq r0, {r0, r3}

08000008 : 8000008: 4802 ldr r0, [pc, #8] ; 08000008:8000008:4802 ldr r0,[pc,#8]; (8000014 <some_addr>) 800000a: 6801 ldr r1, [r0, #0] 800000c: 3101 adds r1, #1 800000e: 6001 str r1, [r0, #0] 8000010: e7fe bn 8000010 <reset+0x8> 8000012: 46c0 nop ; (8000014 <some_addr>) 800000a: 6801 ldr r1, [r0, #0] 800000c: 3101 添加 r1, #1 800000e: 6001 str r1, [r0, #0]: 8007000100000010010010000010 46c0 nop ; (mov r8, r8) (移动 r8, r8)

08000014 <some_addr>: 8000014: 20000000 andcs r0, r0, r0 08000014 <some_addr>: 8000014: 20000000 andcs r0, r0, r0

for small programs (Read the st documentation) this can be based at address 0x08000000 or 0x00000000 for this part.对于小程序(阅读 st 文档),这部分可以基于地址 0x08000000 或 0x00000000。 0x08000000 is preferred. 0x08000000 是首选。 The vector table must be first in this case ignore the disassembly just look at the values向量表必须首先在这种情况下忽略反汇编只看值

 8000000:   20001000    andcs   r1, r0, r0
 8000004:   08000009    stmdaeq r0, {r0, r3}

The 0x08000009 is the reset address ORRed with one. 0x08000009 是复位地址 ORRed 为 1。 so 0x08000008 |所以 0x08000008 | 1 is 0x08000009. 1 是 0x08000009。 So that will at least boot and try to fetch code without a fault.这样至少可以启动并尝试获取代码而不会出错。

This code simply reads the word at address 0x20000000 and increments it, sram is not affected by a reset so we can keep resetting and seeing that value increment.这段代码只是读取地址 0x20000000 处的字并递增它,sram 不受复位影响,因此我们可以继续复位并看到该值递增。

using whatever configs you have and interface, I combine the openocd one for the st part into a single file and carry that with the project along with ones for the various interfaces (stlinks of different versions and jlink).使用您拥有的任何配置和接口,我将 st 部分的 openocd 组合到一个文件中,并将其与项目以及各种接口(不同版本的 stlinks 和 jlink)的配置一起携带。

openocd -f jlink.cfg -f target.cfg 

Open On-Chip Debugger 0.9.0 (2019-04-28-23:34)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : JLink SWD mode enabled
swd
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
cortex_m reset_config sysresetreq
Info : J-Link ARM-OB STM32 compiled Jun 30 2009 11:14:15
Info : J-Link caps 0x88ea5833
Info : J-Link hw version 70000
Info : J-Link hw type J-Link
Info : J-Link max mem block 15344
Info : J-Link configuration
Info : USB-Address: 0x0
Info : Kickstart power on JTAG-pin 19: 0x0
Info : Vref = 3.300 TCK = 1 TDI = 1 TDO = 1 TMS = 1 SRST = 1 TRST = 1
Info : J-Link JTAG Interface ready
Info : clock speed 1000 kHz
Info : SWD IDCODE 0x1ba01477
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

If you don't see the watchpoints line if it returns to the console, it didn't work.如果返回到控制台后您没有看到观察点行,则说明它不起作用。

In another window在另一个窗口

telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
>

Now let's stop the chip and write our program.现在让我们停止芯片并编写我们的程序。 The psr, pc, etc values may be different depending than mine depending on what you had running. psr、pc 等值可能与我的不同,具体取决于您运行的内容。

> reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000010 msp: 0x20001000
> flash write_image erase so.elf
auto erase enabled
device id = 0x20036410
flash size = 64kbytes
wrote 1024 bytes from file so.elf in 0.437883s (2.284 KiB/s)

Let's read it and see that it is there, should match the words from the disassembly让我们阅读它,看看它在那里,应该与反汇编中的单词相匹配

> mdw 0x08000000 20
0x08000000: 20001000 08000009 5000f04f 31016801 e7fe6001 ffffffff ffffffff ffffffff 
0x08000020: ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff 
0x08000040: ffffffff ffffffff ffffffff ffffffff 

Assume this is random garbage and that is fine so long as we see it increment.假设这是随机垃圾,只要我们看到它增加就可以了。

> mdw 0x20000000
0x20000000: 2e006816 
> reset
> halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000012 msp: 0x20001000
> mdw 0x20000000
0x20000000: 2e006817 

So the value incremented if you do a reset, then do a halt (not a reset halt in one command) then dump that memory location it should keep incrementing every time.因此,如果您执行重置,则该值会增加,然后执行暂停(不是在一个命令中重置暂停),然后转储该内存位置,它应该每次都保持增加。

Now you can choose to take the gdb path (I don't have a use for gdb so don't have one installed) with this binary or examine your rust binary by first examining the vector table to see it is correct, without at least the reset vector being correct then you will fault and not run any code on the processor.现在你可以选择使用这个二进制文件来获取 gdb 路径(我没有使用 gdb,所以没有安装)或者通过首先检查向量表来检查你的 rust 二进制文件以查看它是否正确,至少没有重置向量是正确的,那么你会出错并且不会在处理器上运行任何代码。 Can flash it using telnet or you can try gdb.可以使用 telnet 刷新它,或者您可以尝试 gdb。

If gdb is having a problem with the file then perhaps you are using the wrong file.如果 gdb 对文件有问题,那么您可能使用了错误的文件。 or the file is incorrectly built.或者文件构建不正确。 did you try a simple program in that repository?您是否在该存储库中尝试过一个简单的程序? can you make a minimal program from that repository, an empty entry function or an infinite loop or a counter that counts forever?你能从那个存储库中制作一个最小的程序,一个空的入口函数或一个无限循环或一个永远计数的计数器吗?

Is this truly a gdb problem?这真的是gdb问题吗? Is this an openocd problem?这是一个openocd问题吗? Is this a Rust tools problem?这是 Rust 工具的问题吗? Is this a Rust binary problem?这是 Rust 二进制问题吗? Is this a bug in the docs and you are pointing gdb at the wrong file problem?这是文档中的错误并且您将 gdb 指向错误的文件问题吗? If the above works then openocd works, binutils at least works, the debugger/hardware works, it eliminates those and then becomes is this a rust thing, a gdb thing, using the wrong file thing, or something else?如果以上工作,那么 openocd 工作,binutils 至少工作,调试器/硬件工作,它消除了那些,然后变成这是一个生锈的东西,一个 gdb 的东西,使用错误的文件的东西,还是别的什么?

After connecting openocd with the board don't forget to connect the debugger arm-none-eabi-gdb with openocd .openocd与开发板连接openocd ,不要忘记将调试器arm-none-eabi-gdbopenocd

> arm-none-eabi-gdb -se target/thumbv7em-none-eabi/release/your_binary
(gdb) target remote localhost:3333

If all is OK in the terminal console where openocd is running you will see the message:如果在运行openocd的终端控制台中openocd正常,您将看到以下消息:

accepting 'gdb' connection on tcp/3333`

and you should be able to start debugging.你应该可以开始调试了。

To optimize connection setup you may create/update the .gdbinit file with the content:要优化连接设置,您可以使用以下内容创建/更新.gdbinit文件:

target remote localhost:3333

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过arm-none-eabi-gdb命令连接到GDB服务器 - Unable to connect to the GDB server through arm-none-eabi-gdb command 通过 openocd 和 gdb 调试 stm32f407 时,Rust 调试不会在断点处停止 - Rust debugging doesn't stop at the breakpoints when debugging stm32f407 via openocd and gdb STM32F103串口发送时钟信号抖动问题(Bluepill) - Jitter Problem on Sending Clock Signal over Serial on STM32F103 (Bluepill) 使用Rust创建一个静态库以将其链接到arm-none-eabi C代码固件 - Creating a static library with Rust to link it to an arm-none-eabi C code firmware 如何将 stm32f3discovery API 传递给 function? - How to pass a stm32f3discovery API into a function? 通过 OpenOCD 刷新不允许嵌入式程序运行,但是使用 GDB 和 OpenOCD 桥运行运行正常 - Flashing via OpenOCD does not allow the embedded program to run, however running using GDB with an OpenOCD bridge works fine 为什么我的 LED(stm32f3-discovery board)在应用延迟后不发光? - Why is my led(stm32f3-discovery board) is not glowing after applying delay? 如何从stm32f30x中的cortex-m-rt获取中断重新导出以运行 - How to get the interrupt reexport from cortex-m-rt in stm32f30x to run 在 bluepill 开发板上使用 stm32f1xx_hal 对 GPIO Output 进行外设初始化 - Peripheral Initialisation of GPIO Output with stm32f1xx_hal on bluepill development board 使用STM32f1xx_hal板条箱时借入移动值错误 - Borrow of moved value error when using the STM32f1xx_hal crate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM