XMC4500学习笔记

发布于 2022-09-10  1528 次阅读


1. Workflow of Embedded Programs

Step 1: Write the code

# include <stdio .h>
int main (int argc, char* argv[]) {
puts (" Hello ␣ World ");
return 0;
}

gcc -o helloworld helloworld .c

  • arm-non-eabi-gcc can compiling the start-up files, libraries and main.c into *.o files

=> *.o files are compiled but unlinked versions of your codes, not human readable.

  • arm-non-eabi-gcc can link all *.o files together into bin/main.elf.

=> *.elf files are compiled and linked programs, ready to execute on the architecture they are
build for.

  • arm-none-eabi-objdump can create the *.lst file.

=> *.lst file is a human-readable copy of parts of the *.elf file. What to put in here is set by options to objdump.

=> But usually it's section headers(where .data, .bss, etc. are located and how large they are), and disassembly of the .text section interleaved with the C instructions it was compiled from.

Step 3: Run the program

./ helloworld

2. Assembler

1. Instructions

  • Arithmetic instructions: ADD, SUB, MUL, DIV, NEG
  • Boolean instruction: NOT, AND, OR, EOR, BIC
  • Logical instructions: CMP, CMN, TST

2. RISC VS CISC

  • RISC: 除了load/store,没有其他访问内存的指令。指令固定长度,指令很多,但CPU很简单,时钟频率很高。
  • CISC: load/store被集成到各种指令中。指令长度可变,指令很少但CPU更复杂。
  • Thumb Mode: 如果我们跳转到一个偶数地址,后续指令被解释为ARM代码。如果我们跳转到一个奇数地址,指令被解码为Thumb。 Cortex-M只支持Thumb代码。

3. GNU Debugger

1. Cheatsheet

  • 到达函数foo()时停止执行 - break foo
  • 执行单行源代码/汇编代码 - step / stepi
  • 当变量Bytes被改变时停止执行 - watch Bytes
  • 暂时继续执行 - continue
  • 立即停止执行并显示当前处理的代码行 - Press Ctrl C
  • 删除2号断点 - delete 2
  • 改变布局,同时显示源代码和汇编程序 - layout split
  • 改变光标焦点以扫描命令历史而不是滚动源码 - focus cmd
  • 打印变量计数器/寄存器r3的值 - print counter / print $r3
  • 设置变量计数器为7 - set counter = 7
  • 检查地址为0x08000000的32位的十六进制值 - x /1wx 0x80000000
  • 每次执行停止时显示Bytes值 - display Bytes
  • 显示当前函数的局部变量 - info locals

2. Comparisons of Debug Methods