如果您最近才开始使用它,那么您还有很长一段时间后闪光灯会耗尽。您可能会遇到驱动器已满错误,只需拔下并重新插入电路板即可。我已经拥有这些东西多年了,还没有磨损闪光灯。并不是说它不能完成,它可以,但你不可能在那里,除非你写了一个快闪程序,把它弄坏了。
您将需要 openocd (或其他一些调试器,也许您的 IDE 提供了,我不使用这些,所以无法提供帮助)。 openocd 和 gnu 工具是微不足道的,所以要逐步完成。
从正确的目录,或者从 openocd 复制这些文件
openocd -f stlink-v2-1.cfg -f stm32f4x.cfg
(其中一个或两个可能依赖于它们包含的其他文件,可以将它们拉入或采取任何措施)。
应该以这样的方式结束,而不是退出到命令行
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
在另一个窗口中
telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
>
在该窗口中,您可以停止处理器
> halt
stm32f4x.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x61000000 pc: 0x080000b2 msp: 0x20000ff0
>
全尺寸手臂处理器您的入口点是一条指令,您只需
开始执行。 cortex-m 使用一个向量表,你不能只在那里分支。
.thumb_func
.global _start
_start:
stacktop: .word 0x20001000
.word reset
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.word hang
.thumb_func
reset:
bl notmain
b hang
.thumb_func
hang: b .
理论上你可以跳转到重置处理程序地址,但是链接描述文件需要在闪存中,任何依赖于位置的东西都不起作用。如果您依靠向量表来执行此操作,则可能不会设置您的堆栈指针。所以像这样的东西会起作用,是完整示例的一部分
sram.s
.cpu cortex-m0
.thumb
.thumb_func
.global _start
_start:
ldr r0,stacktop
mov sp,r0
bl notmain
b .
.align
stacktop: .word 0x20001000
.thumb_func
.globl PUT32
PUT32:
str r1,[r0]
bx lr
.thumb_func
.globl GET32
GET32:
ldr r0,[r0]
bx lr
notmain.c
void PUT32 ( unsigned int, unsigned int );
unsigned int GET32 ( unsigned int );
int notmain ( void )
{
unsigned int ra;
ra=GET32(0x20000400);
PUT32(0x20000404,ra);
PUT32(0x20000400,ra+1);
return(0);
}
sram.ld
MEMORY
{
rom : ORIGIN = 0x08000000, LENGTH = 0x1000
ram : ORIGIN = 0x20000000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > ram
.rodata : { *(.rodata*) } > ram
.bss : { *(.bss*) } > ram
}
基本上用 ram 替换 rom 引用。 (如果 gnu 可能比这个更复杂,那么你的链接器脚本,但它工作得很好,可以根据需要在此处添加一个 .data)。
arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m0 flash.s -o flash.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -mcpu=cortex-m0 -mthumb -c notmain.c -o notmain.o
arm-none-eabi-ld -o notmain.flash.elf -T flash.ld flash.o notmain.o
arm-none-eabi-objdump -D notmain.flash.elf > notmain.flash.list
arm-none-eabi-objcopy notmain.flash.elf notmain.flash.bin -O binary
arm-none-eabi-as --warn --fatal-warnings -mcpu=cortex-m0 sram.s -o sram.o
arm-none-eabi-ld -o notmain.sram.elf -T sram.ld sram.o notmain.o
arm-none-eabi-objdump -D notmain.sram.elf > notmain.sram.list
arm-none-eabi-objcopy notmain.sram.elf notmain.sram.hex -O ihex
arm-none-eabi-objcopy notmain.sram.elf notmain.sram.bin -O binary
我构建的程序的 flash 版本和 sram 版本。
所以现在我们将 telnet 连接到 openocd 服务器,处理器停止,让我们查看内存位置并更改它
> mdw 0x20000400
0x20000400: 7d7d5889
> mww 0x20000400 0x12345678
> mdw 0x20000400
0x20000400: 12345678
并运行我们新的基于 sram 的程序
> load_image /path/to/notmain.sram.elf
64 bytes written at address 0x20000000
downloaded 64 bytes in 0.008047s (7.767 KiB/s)
> resume 0x20000001
让它运行吧,脚本速度可能仍然很慢,但输入停止命令的时间肯定很多。
> halt
stm32f4x.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x41000000 pc: 0x20000008 msp: 0x20001000
> mdw 0x20000400 10
0x20000400: 12345679 12345678 ce879a24 fc4ba5c7 997e5367 9db9a851 40d5083f fbfbcff8
0x20000420: 035dce6b 65a7f13c
>
因此程序运行,程序读取 0x20000400 将其保存到 0x20000404 增量并将其保存到 0x20000400 并且它完成了所有这些操作。
> load_image /path/to/notmain.sram.elf
64 bytes written at address 0x20000000
downloaded 64 bytes in 0.008016s (7.797 KiB/s)
> resume 0x20000000
> halt
stm32f4x.cpu: target state: halted
target halted due to debug-request, current mode: Thread
xPSR: 0x41000000 pc: 0x20000008 msp: 0x20001000
> mdw 0x20000400 10
0x20000400: 1234567a 12345679 ce879a24 fc4ba5c7 997e5367 9db9a851 40d5083f fbfbcff8
0x20000420: 035dce6b 65a7f13c
>
所以我们不需要或起始地址为一个,就像您使用 BX 所做的那样,他们必须将地址直接推入电脑,和/或为我们做正确的事情。
如果您只修改链接描述文件以用 ram 替换 rom。
20000000 <_start>:
20000000: 20001000
20000004: 20000041
20000008: 20000047
2000000c: 20000047
20000010: 20000047
20000014: 20000047
20000018: 20000047
2000001c: 20000047
20000020: 20000047
20000024: 20000047
20000028: 20000047
2000002c: 20000047
20000030: 20000047
20000034: 20000047
20000038: 20000047
2000003c: 20000047
20000040 <reset>:
20000040: f000 f806 bl 20000050 <notmain>
20000044: e7ff b.n 20000046 <hang>
您可以使用 0x20000041 地址作为入口点(恢复 0x20000041),但您必须先处理堆栈指针。
通过这样做
> reg sp 0x20001000
sp (/32): 0x20001000
> reg sp
sp (/32): 0x20001000
> resume 0x20000041
请注意,论文上的 ram 比 rom 快,并且在您增加时钟频率时不需要等待状态,因此如果您确实增加时钟频率并仅在 ram 中调试,如果您有切换到闪存,它可能会失败不记得设置闪存等待状态...除此之外,如果您愿意,您可以整天在 ram 中开发的程序的空间要小得多。
一个不错的功能是您可以继续暂停和重新加载。我不知道在这个设备/调试器上,如果你打开缓存(如果不是全部,一些 cortex-m4 有一个缓存)你必须小心确保在更改程序时它是关闭的。写入内存是一个数据操作取指令是一个指令提取操作,如果你在 0x20000100 处执行一些指令并且它被缓存在 I 缓存中,它可能会落在指令缓存中。然后你停止使用调试器然后编写一个新程序,包括缓存中的地址(0x20000100),当你运行它时,我的缓存没有被刷新,所以你将混合运行缓存中的先前程序和数据中的新程序,这充其量是一场灾难。因此,要么在以这种方式运行时永远不要打开缓存,要么想出解决此问题的方法(在停止程序之前清除缓存,使用重置按钮在运行之间重置处理器、重启电源等)。