ååã¯ãQEMU ï¼ã¿ã¼ã²ãã㯠STM32F4-Discoveryï¼ã§åãããELFãã¡ã¤ã«ããã¤ããªãã¡ã¤ã«ï¼ãããã°æ
å ±ãã·ã³ãã«æ
å ±ãåé¤ãããï¼ã«å¤æãã¦ããã®ãã¤ããªãã¡ã¤ã«ã§ELFãã¡ã¤ã«ãåæ§ç¯ãã¾ããã
ä»åã¯ããã®ELFãã¡ã¤ã«ï¼ãããã°æ
å ±ãã·ã³ãã«æ
å ±ãªãï¼ã QEMU ã§åããã¦ããããã¨æãã¾ãã
ããã§ã¯ããã£ã¦ããã¾ãã
åèæç®
STM32F4 ã®ããã¥ã¢ã«
STM32F4 ã®ããã¥ã¢ã«
ä¸è¨ãªã³ã¯ã®ããã¥ã¡ã³ãâãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ãããã¥ã¡ã³ãâããã°ã©ãã³ã°ããã¥ã¢ã«ãªã©ãåç
§ãã¦ãã ãããæè¿ã¯ãããã¥ã¢ã«ãæ¥æ¬èªåããã¦ãã¦ãã¨ã¦ã便å©ã§ãã
デザイン/サポート | STM32, STM8ファミリはSTの32bit/8bit汎用マイクロコントローラ製品
GDBã®ããã¥ã¢ã«
è±èªã§ãããéã§ããæ¥æ¬èªããã¥ã¢ã«ã¸ã®ãªã³ã¯ãããã¾ããããå°ãå¤ãã£ãã§ãã
GDB Documentation
ã¯ããã«
ãQEMUãåãããã®è¨äºä¸è¦§ã§ããè¯ãã£ããåèã«ãã¦ãã ããã
QEMUãåããã®è¨äºä¸è¦§
ããã§ã¯ããã£ã¦ããã¾ãï¼
ã³ãã³ãã©ã¤ã³ã§QEMUãåããã¦GDBã§ãããã°ãã
第1åã第2å ã§ãQEMU ãåãããã¨ãã¯ãEclipseï¼ç·åéçºç°å¢ï¼IDEï¼ ã使ãã¾ããã
ä»åã¯ããããã°æ
å ±ãã·ã³ãã«æ
å ±ã®ç¡ããã¤ããªãã¡ã¤ã«ã§åããã®ã§ãã¾ãã¯ãã³ãã³ãã©ã¤ã³ã® GDB ã使ããQEMU ãã³ãã³ãã©ã¤ã³ã§åããã¾ãã
ãããã°æ
å ±ã®ããé常ã®ELFãã¡ã¤ã«ã使ã£ã¦ã³ãã³ãã©ã¤ã³ã§QEMUã¨GDBãåãã
ã¾ãã¯ãç°å¢ãæ£ãããã¨ã確èªãããã®ã§ãæ®éã® ELFãã¡ã¤ã«ã使ãã¾ãã
ã³ãã³ãã©ã¤ã³ã§ãQEMU ãèµ·åãã¾ããåºæ¬çã«ã¯ãInterface 2022å¹´ 7æå· ã«æ¸ããã¦ããéãã§ãããã-Sï¼èµ·åãã¦ããã«åæ¢ããï¼ãã¨ã--image stm32f4discovery_sample.elfï¼ãã¼ãããELFãã¡ã¤ã«ï¼ãã追å ãã¦ãã¾ãã
$ qemu-system-gnuarmeclipse -S --verbose --board STM32F4-Discovery --mcu STM32F407VG --image stm32f4discovery_sample.elf --gdb tcp::1234 -d unimp,guest_errors --semihosting-config enable=on,target=native --semihosting-cmdline stm32f4discovery_sample
QEMU ãèµ·åãããã次ã¯ãGDB ãå®è¡ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample.elf
(gdb) target remote :1234
ãã㧠GDBå´ãããããã°ãåºæ¥ã¾ããä»åã¯ã確èªãªã®ã§ãcï¼ç¶ç¶å®è¡ï¼ãå
¥åãã¦ãLED ãç¹æ»
ãã¦ãããã¨ï¼ã¨ LED ã®ãã°åºåï¼ã確èªãã¦ãçµäºãã¾ãã
åç´ã«objcopyã§ä½æããELFãã¡ã¤ã«ã§QEMUã¨GDBãåãã
ã¾ãã¯ãåå å®æ½ãã以ä¸ã®ã³ãã³ãã§ãåç´ã« objcopy ã§ä½æãã ELFãã¡ã¤ã«ã使ãã¾ãã
$ arm-none-eabi-objcopy -I binary -O elf32-little --change-section-address .data=0x08000000 stm32f4discovery_sample_objcopy.bin stm32f4discovery_sample_objcopy.elf
ã¾ããå
ã»ã©ã¯ãè©ä¾¡ãã¼ãã® LED ãããã¿ã³ã¹ã¤ããã表示ãããããã«èµ·åãã¾ããããä»å㯠LED ãç¹æ»
ããã ãã§ããã®ã§ãã°ã©ãã£ãã¯ã¯ OFFï¼--nographicï¼ã«ãã¾ãã
$ qemu-system-gnuarmeclipse -S --nographic --verbose --board STM32F4-Discovery --mcu STM32F407VG --image stm32f4discovery_sample.elf --gdb tcp::1234 -d unimp,guest_errors --semihosting-config enable=on,target=native --semihosting-cmdline stm32f4discovery_sample
QEMU ãèµ·åãããã次ã¯ãGDB ãå®è¡ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample.elf
(gdb) target remote :1234
åãã¾ããããéã¢ã»ã³ãã«ããThumbå½ä»¤ãèªèãã¦ããªãã®ã§ãå¥ã®å½ä»¤ã«è¦ãã¦ãã¾ããLED ãç¹æ»
ãã¦ãããã°ã表示ããã¦ããã®ã§ãåä½ã¨ãã¦ã¯æ£ããããã§ãã
bin2elf.shã§ä½æããELFãã¡ã¤ã«ã§QEMUã¨GDBãåãã
次ã¯ä»¥ä¸ã®ããã« bin2elf.sh ã§ãä½æãã ELFãã¡ã¤ã«ã使ãã¾ãã
$ ./bin2elf.sh stm32f4discovery_sample_objcopy.bin stm32f4discovery_sample_bin2elf.elf 0x08000000
QEMU ãèµ·åãã¾ãã
$ qemu-system-gnuarmeclipse -S --nographic --verbose --board STM32F4-Discovery --mcu STM32F407VG --image stm32f4discovery_sample_bin2elf.elf --gdb tcp::1234 -d unimp,guest_errors --semihosting-config enable=on,target=native --semihosting-cmdline stm32f4discovery_sample
QEMU ãèµ·åãããã次ã¯ãGDB ãå®è¡ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample_bin2elf.elf
(gdb) target remote :1234
ä»åº¦ã¯ãéã¢ã»ã³ãã«ããThumbå½ä»¤ãèªèãã¦ãã¦ãæ£ãã表示ããã¦ãã¾ãã
bin2elf_entry.shã§ä½æããELFãã¡ã¤ã«ã§QEMUã¨GDBãåãã
次ã¯ä»¥ä¸ã®ããã« bin2elf_entry.sh ã§ãä½æãã ELFãã¡ã¤ã«ã使ãã¾ãã
$ ./bin2elf_entry.sh stm32f4discovery_sample_objcopy.bin stm32f4discovery_sample_bin2elf_entry.elf 0x08000000 0x8000cf5
QEMU ãèµ·åãã¾ãã
$ qemu-system-gnuarmeclipse -S --nographic --verbose --board STM32F4-Discovery --mcu STM32F407VG --image stm32f4discovery_sample_bin2elf_entry.elf --gdb tcp::1234 -d unimp,guest_errors --semihosting-config enable=on,target=native --semihosting-cmdline stm32f4discovery_sample
QEMU ãèµ·åãããã次ã¯ãGDB ãå®è¡ãã¾ãã
$ arm-none-eabi-gdb stm32f4discovery_sample_bin2elf_entry.elf
(gdb) target remote :1234
ã¨ã³ããªãã¤ã³ããè¨å®ãã ELFãã¡ã¤ã«ã«ã¤ãã¦ããéã¢ã»ã³ãã«ããThumbå½ä»¤ãèªèãã¦ãã¦ãæ£ãã表示ããã¦ãã¾ãã
Eclipseã使ã£ã¦QEMUã§ãã¤ããªããæ§ç¯ããELFãã¡ã¤ã«ããããã°ãã
ã³ãã³ãã©ã¤ã³ã® QEMU 㨠GDB ã使ã£ã¦åä½ããããã¨ãåºæ¥ãã®ã§ãEclipse ã使ã£ã¦ããããã°æ
å ±ã®ç¡ã ELFãã¡ã¤ã«ã®ãããã°ããã£ã¦ã¿ã¾ãã
ELFãã¡ã¤ã«ã¯ãæå¾ã«ä½¿ã£ããã¨ã³ããªãã¤ã³ããè¨å®ãã ELFãã¡ã¤ã«ã使ãã¾ãã
æ°ããããã¸ã§ã¯ããä½ãã¾ãã
第1åã§è©³ãã説æããã®ã§ãããã§ã¯ãéãã¨ããã ãã詳ãã説æãã¾ãã
daisuke20240310.hatenablog.com
ãstm32f4discovery_sampleãã¨ããããã¸ã§ã¯ããéãã¦ãç¶æ
ããããã¾ããããFileâNewâProjectãã¯ãªãã¯ãã¾ãã
ããã¸ã§ã¯ãã®ä½æã¨è¨å®
C/C++ã®C Projectãé¸æãã¦Nextãã¯ãªãã¯ãã¾ãã
Project name ã¯ããstm32f4discovery_binaryãã¨ãã¦ãProject type ã¯ãEmpty Projectããé¸ã³ãToolchains ã¯ãArm Cross GCCããé¸æãã¦ãNext ãã¯ãªãã¯ãã¾ãã
ä½åããNext ãæ¼ãã¨ãFinish ãåºãã®ã§ã¯ãªãã¯ãã¾ãã
ããã¨ãè¤æ°ã®ããã¸ã§ã¯ããè¦ãã¦ããç¶æ
ããããã¾ãããä»åä½æãããstm32f4discovery_binaryãããã¸ã§ã¯ã以å¤ã¯éãã¦ããã¾ãï¼ä»ã®ããã¸ã§ã¯ãã®å½±é¿ããªãããã«ã¨æã£ã¦éãããã¨ã«ãã¾ããï¼ã
ã½ã¼ã¹ã¯ç¡ãæ³å®ãªã®ã§ãã¤ã³ãã¼ãã¯ããã«ãããã¸ã§ã¯ãã®è¨å®ãè¡ãã¾ãã
ProjectâProperties ãéãã¾ãã
C/C++ Build ã® Settings ãã¯ãªãã¯ãã¾ããTargetProcessor ãã¯ãªãã¯ãã¦ãArm family ã cortex-m4 ãé¸æãã¾ããFloat ABI 㯠QEMU ã FPU ã«å¯¾å¿ãã¦ããªããããLibrary (soft) ãé¸æãã¾ãã
ããã¾ã§ã¯åãã§ããªã³ã«ã¹ã¯ãªããã¯ç¡ãã®ã§ãæå®ãã¾ããã
GNU Arm Cross C Linker ã® Miscellaneous ãéãã¦ãå³ä¸ã® Other linker flags ã«ã-specs=nosys.specs -specs=nano.specs -specs=rdimon.specs -lc -lrdimon ã¨å
¥åãã¾ãã
ãã«ãããªãã®ã§ãBuild Tools Path ã®å
¥åã¯ä¸è¦ã§ããå®äºããããApply and Close ãã¯ãªãã¯ãã¾ãã
ãããã°ã®è¨å®
ç¶ãã¦ããããã°ã®è¨å®ã§ãã
RunâDebug Configurations... ãã¯ãªãã¯ãã¾ãã
左㮠GDB QEMU Debuggin ãããã«ã¯ãªãã¯ãã¾ããããã¨ããstm32f4discovery_binary Debugãã¨ããé
ç®ãããä¸ã«ä½ããã¾ãã
Mainã¿ãã® C/C++ Application ã¯ãBrowse... ãã¯ãªãã¯ãã¦ãstm32f4discovery_sample_bin2elf_entry.elf ãæå®ãã¦ãã ããã
ãã«ãã¯ããªãã®ã§ãDisable auto build ã«ãã§ãã¯ãå
¥ãã¦ãApply ãã¯ãªãã¯ãã¾ãã
次ã¯ãDebugger ã¿ãã§ãã
QEMU ã¾ã§ã®ãã¹ãæå®ãã¦ãBoard name ã«ãSTM32F4-Discoveryããå
¥åããDevice name ã«ãSTM32F407VGããå
¥åãã¾ãï¼ç§ã®å ´åã¯å
¨ã¦å
¥åæ¸ã¿ã§ããï¼ã
è©ä¾¡ãã¼ãã®ã°ã©ãã£ãã¯ã¯ä¸è¦ãªã®ã§ãDo not open graphic windows ã«ãã§ãã¯ãå
¥ãã¦ããã¾ãã
æå¾ã« GDB ã¾ã§ã®ãã«ãã¹ãæå®ãã¦ãApply ãã¯ãªãã¯ãã¾ãã
ãã¨ãèµ·åãã¦ãããã« Run ãã¦ã»ãããªãã®ã§ãStart ã¿ãã®ä¸çªä¸ã«ãã Continue ã®ãã§ãã¯ãå¤ãã¦ããã¾ãã
ãããã°ãã
ã§ã¯ãå®éã«åããã¦ããã¾ããè«ã¢ã¤ã³ã³ãæ¼ãã¦ããããã°ãéå§ãã¾ãã
ã½ã¼ã¹ã³ã¼ããç¡ããããä¸ã®ãããªç»é¢ã«ãªãã¨æãã¾ããPreferences... ãã¯ãªãã¯ãã¾ãã
Source Not Found ã¨æ¸ããã¦ããã¨ããããNever ã«ãã§ãã¯ãå
¥ãã¦ï¼å
ã»ã©ã®ãããªç»é¢ãæ¯ååºãã¨é¢åãªã®ã§ï¼ãApply and Close ãã¯ãªãã¯ãã¾ãã
WindowâShow View ãã¯ãªãã¯ãã¦ãDisassemblyãDebugger ConsoleãRegisters ãéãã¾ãããã®ãããªç»é¢ã«ãªãã¨æãã¾ãã
Disassembly ã¯ããªãã 0çªå°ã表示ãã¦ãã¾ãããPCã¬ã¸ã¹ã¿ãè¦ãã¨ãã¨ã³ããªãã¤ã³ãï¼0x08000cf4ï¼ã«ãã¾ãã
Debugger Console ã«ãsiãã¨å
¥åãã¦ãªã¿ã¼ã³ãã¾ããä¸åº¦ãã¹ãããå®è¡ããã¨ãæ£ãã表示ããã¾ãã
ãsiãã¨å
¥åãã¦ããªã¿ã¼ã³ããã ãã§ãéã¢ã»ã³ãã«ã¨ã¬ã¸ã¹ã¿ã®å¤ãè¦ããã®ã§ãã³ãã³ãã©ã¤ã³ã® GDB ãã楽ã§ããããã¼ã«ãã¼ã®ã¹ãããã¤ã³å®è¡ããã¹ããããªã¼ãã¼ã¯ä½¿ããªãã®ã§æ³¨æã§ãã
ãcãã¨ãªã¿ã¼ã³ãæ¼ãã¨ãå®è¡ãå§ã¾ã£ã¦ãLED ãç¹æ»
ãããã°ã表示ããã¾ããæ£ããåä½ãã¦ããããã§ãã
ãããã«
ä»åã¯ããããã°æ
å ±ãã·ã³ãã«æ
å ±ããªã ELFãã¡ã¤ã«ããGDB ã Eclipse ã§ãããã°ãã¾ãããGDB ã¯ãé常ã«å¤ãã®æ©è½ãããã®ã§ããããã試ãã¦ã¿ããã¨æãã¾ãã
次å以éã¯ãQEMU ã®ã½ã¼ã¹ã³ã¼ããå¤æ´ããã«ããã¦ãQEMU ã®åããå¤ãã¦ã¿ããã¨æãã¾ãã
æå¾ã«ãªãã¾ããããã¨ã³ã¸ãã¢ã°ã«ã¼ãã®ã©ã³ãã³ã°ã«åå ä¸ã§ãã
æ°æ¥½ã«ãããã¨ãããããé¡ããããã¾ãð
ä»åã¯ä»¥ä¸ã§ãï¼
æå¾ã¾ã§ãèªã¿ããã ãããããã¨ããããã¾ããã