GPIO 访问 SWD 接口的心得体会

2019-12-10 18:20发布

本帖最后由 helislayer 于 2016-6-23 22:30 编辑

最近写了些用 GPIO 访问 swd 的程序来玩。记录一下体会:

1)ARM Debug Interface Architecture Specification 这个是 ARM
给的规范,初学不要去读。用这个上手极其困难。这个规范讲了
太多细节,很多常识性的东西没有讲。例如我一直疑惑 turn around
的时候是谁驱动 swclk,应该是 host 但是没有说。这个规范比较
适合已经把底层跑通了,看细节某个寄存器如何用的。适合做 ARM
的厂家不适合作为程序员来写个 swd 访问的程序。

2)上手收建议这个:EFM32: Programming Internal Flash
Over the Serial Wire Debug Interface。
这个手册是从如何写 SWD 接口程序的,虽然不是 STM32 的,
但是比较清楚,例如我前面的疑惑就讲很明白。这个手册也不长。
我上传上来了。

3)那个 SWD 接口其实就是和 SPI 非常像,基本上可以理解为
MOSI 和 MISO 合并成一根线SWD-IO。中间有软件协议上下文来
协商谁来驱动这根线。这个转换需要一个 clock, 就是 turn around。

4) 那个 SWD 的 CLK 就是 SPI CLK, 永远由 host 来驱动。

5)target 永远再上升沿采集和放新的数据。这个意味着 host 从
target 读数的时候是在下降沿读比较方便。

6)思路和攻略大概是这样,要先写个底层的接口可以 reset。
就是发一堆 1 (50 以上) 和 中间发一个 0xE79E 再发 50 多个 1.
0xE79E 就是说老子要用 SWD 而不是 JTAG。

7)接下来就要写 读写 AP 和 DP 的寄存器。每种一共 4 个地址很简单。
这个 DP 就是调试接口的硬件。这个 AP 就是一个访问周边外设和内存
的硬件接口。因为 ARM 的外设都是影射到内存地址的,所以可以访问
任意内存地址就可以刷程序和调试了。

8)访问内存需要通过 AP。就是先写访问内存的地址到一个地址寄存器,
然后通过另外一个数据寄存器读写内存。

大概就是这样,我先在也就只是做到这一步。



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
98条回答
sanger
2019-12-21 14:14
本帖最后由 helislayer 于 2017-2-10 21:19 编辑
sanger 发表于 2017-2-10 16:27
编译有报错,你看是什么问题

"/opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-as" -mcpu=cortex- ...


我编译没有错啊。有几个 warning 但是不影响生成最后的结果。
你 arm-none-eabi-gcc 是直接执行就可以了吗?

原来 makefile 里面都没有提到 -as, 你自己改过 makefile 吗?


STM32F103VHB6_RevZ_Demo1]$ make
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o main.o main.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o stm32f10x_it.o stm32f10x_it.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_adc.o lib/src/stm32f10x_adc.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_bkp.o lib/src/stm32f10x_bkp.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_can.o lib/src/stm32f10x_can.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_dma.o lib/src/stm32f10x_dma.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_exti.o lib/src/stm32f10x_exti.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_flash.o lib/src/stm32f10x_flash.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_gpio.o lib/src/stm32f10x_gpio.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_i2c.o lib/src/stm32f10x_i2c.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_iwdg.o lib/src/stm32f10x_iwdg.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_lib.o lib/src/stm32f10x_lib.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_nvic.o lib/src/stm32f10x_nvic.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_pwr.o lib/src/stm32f10x_pwr.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_rcc.o lib/src/stm32f10x_rcc.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_rtc.o lib/src/stm32f10x_rtc.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_spi.o lib/src/stm32f10x_spi.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_systick.o lib/src/stm32f10x_systick.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_tim.o lib/src/stm32f10x_tim.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_tim1.o lib/src/stm32f10x_tim1.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_usart.o lib/src/stm32f10x_usart.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_wwdg.o lib/src/stm32f10x_wwdg.c
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -c  -o lib/src/cortexm3_macro.o lib/src/cortexm3_macro.s
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -Wall -g -O0 -I . -I lib/inc   -c -o lib/src/stm32f10x_vector.o lib/src/stm32f10x_vector.c
lib/src/stm32f10x_vector.c:111:3: warning: taking address of expression of type 'void'
   &_estack,            // The initial stack pointer
   ^
lib/src/stm32f10x_vector.c:174:3: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
   (unsigned short)0xF108F85F //this is a workaround for boot in RAM mode.
   ^
lib/src/stm32f10x_vector.c:174:3: note: (near initialization for 'g_pfnVectors[66]')
arm-none-eabi-ar cr lib/libstm32.a lib/src/stm32f10x_adc.o lib/src/stm32f10x_bkp.o lib/src/stm32f10x_can.o lib/src/stm32f10x_dma.o lib/src/stm32f10x_exti.o lib/src/stm32f10x_flash.o lib/src/stm32f10x_gpio.o lib/src/stm32f10x_i2c.o lib/src/stm32f10x_iwdg.o lib/src/stm32f10x_lib.o lib/src/stm32f10x_nvic.o lib/src/stm32f10x_pwr.o lib/src/stm32f10x_rcc.o lib/src/stm32f10x_rtc.o lib/src/stm32f10x_spi.o lib/src/stm32f10x_systick.o lib/src/stm32f10x_tim.o lib/src/stm32f10x_tim1.o lib/src/stm32f10x_usart.o lib/src/stm32f10x_wwdg.o lib/src/cortexm3_macro.o lib/src/stm32f10x_vector.o
arm-none-eabi-gcc -Wl,--gc-sections,-Map=main.elf.map,-cref,-u,Reset_Handler -I . -I lib/inc -L lib -T stm32.ld main.o stm32f10x_it.o lib/libstm32.a --output main.elf
arm-none-eabi-objcopy -O binary main.elf main.bin

一周热门 更多>