日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mini2440 裸机编程 -led

發布時間:2025/6/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mini2440 裸机编程 -led 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? 又重新做回了嵌入式,想把以前學到的東西從頭復習一下。首先從裸機編程開始。

本系列使用的硬件環境是友善之臂的 mini2440,百問網的OpenJtag,所有程序在 linux gcc下編譯, 具體硬件設置? 軟件環境搭建可見openjtag 文檔:

編譯器使用友善之臂的 4.4.3 。編譯器配置 /etc/profile:


[plain]?view plaincopyprint?
  • PATH="$PATH:/opt/FriendlyARM/toolschain/4.4.3/bin"??
  • export?PATH??
  • ???? 注意如果在 /etc/provile 里面修改了編譯器 之后,只是 source /etc/profile 還是不夠的,無法調整所用編譯器路徑。 正確做法是 先 source /etc/environment? 然后再 source /etc/profile


    第一個程序是 led 燈控制:

    開頭 匯編 文件:

    [plain]?view plaincopyprint?
  • @******************************************************************************??
  • @?File£ocrt0.S??
  • @?1|?ü£oí¨1y?ü×aè?C3ìDò??
  • @******************************************************************************??
  • ??
  • #define??PXT????????????????????????????0x12??
  • ??
  • .text??
  • .global?_start??
  • _start:??
  • ????????????ldr?????r0,?=0x53000000?????@?disable?WATCHDOG??
  • ????????????mov?????r1,?#0x0???????????????????????
  • ????????????str???r1,?[r0]??????????????@???
  • ??
  • ????????????ldr?????sp,?=1024*4?????????@?stack?pointer?point?to?4K??
  • ??
  • ????????????bl??????main??????????????????
  • halt_loop:??
  • ????????????b???????halt_loop??

  • 主函數文件:

    [cpp]?view plaincopyprint?
  • #define?GPBCON??????(*(volatile?unsigned?long?*)0x56000010)??
  • #define?GPBDAT??????(*(volatile?unsigned?long?*)0x56000014)??
  • ??
  • #define?GPB5_out????(1<<(5*2))??
  • #define?GPB6_out????(1<<(6*2))??
  • #define?GPB7_out????(1<<(7*2))??
  • #define?GPB8_out????(1<<(8*2))??
  • ??
  • void??wait(unsigned?long?dly)??
  • {??
  • ????for(;?dly?>?0;?dly--);??
  • }??
  • ??
  • int?main(void)??
  • {??
  • ????unsigned?long?i?=?0;??
  • ??????
  • ????GPBCON?=?GPB5_out|GPB6_out|GPB7_out|GPB8_out;?????
  • ??
  • ????while(1){??
  • ????????wait(100000);??
  • ????????GPBDAT?=?(1<<?(?(i%4)?+?5)?);???
  • ????????if(++i?==?16)??
  • ????????????i?=?0;??
  • ????}??
  • ??
  • ????return?0;??
  • }??

  • 這個程序實現的功能是點亮led 燈,并實現流水效果。其中高電平熄滅 led 燈。


    鏈接腳本把兩個文件鏈接成一個獨立的二進制文件: ( 使用開始的 4K 字節內存)


    [plain]?view plaincopyprint?
  • SECTIONS?{??
  • ????????.?=?0x00000000;??
  • ????????.text??????????:???{?*(.text)?}??
  • ????????.rodata?ALIGN(4)?:?{*(.rodata)}??
  • ????????.data?ALIGN(4)?:?{?*(.data)?}??
  • ????????.bss?ALIGN(4)??:?{?*(.bss)??*(COMMON)?}??
  • }??

  • Makefile 腳本

    [plain]?view plaincopyprint?
  • CFLAGS??:=?-Wall?-Wstrict-prototypes?-g?-fomit-frame-pointer?-ffreestanding??
  • all?:?crt0.S??leds.c??
  • ????????arm-linux-gcc?$(CFLAGS)?-c?-o?crt0.o?crt0.S??
  • ????????arm-linux-gcc?$(CFLAGS)?-c?-o?leds.o?leds.c??
  • ????????arm-linux-ld?-Tleds.lds??crt0.o?leds.o?-o?leds_elf??
  • ????????arm-linux-objcopy?-O?binary?-S?leds_elf?leds.bin??
  • ????????arm-linux-objdump?-D?-m?arm??leds_elf?>?leds.dis??
  • clean:??
  • ????????rm?-f???leds.dis?leds.bin?leds_elf?*.o??


  • 首先運行腳本openocd.sh

    [plain]?view plaincopyprint?
  • openocd?-f?/etc/openocd/interface/openjtag.cfg?-f?/etc/openocd/target/samsung_s3c2440.cfg??
  • 保持開啟不退出狀態。

    然后另開啟一個終端啟動 elf 文件調試

    [plain]?view plaincopyprint?
  • arm-linux-gdb?-x?gdb.init?leds_elf??

  • 其中 gdb.init 文件內容:

    [plain]?view plaincopyprint?
  • target?remote?127.0.0.1:3333??
  • monitor?halt??
  • monitor?arm920t?cp15?2?0??
  • monitor?step???
  • load??

  • 此時就可以像調試普通程序一樣調試這個裸機程序。


    工程文件地址:




    有一點特別需要注意:

    ? ?匯編語言文件開頭的位置標號必須是?_start: ?如果是其它的則會導致 OpenJtag 無法識別,load 之后 用si指令執行導致 PC指針到未知的位置!!。


    總結

    以上是生活随笔為你收集整理的mini2440 裸机编程 -led的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。