zoukankan      html  css  js  c++  java
  • EKLM3S8962之LED

    1、新建工程

    image

    2、添加头文件

    拷贝自C:\StellarisWare\inc

    3、添加startup_gcc.c

    拷贝自C:\StellarisWare\boards\ek-lm3s8962\hello\startup_gcc.c

    4、添加main.c

    1 #include "../Include/lm3s8962.h"
    2 #include "../Include/hw_gpio.h"
    3 #define DEBUG (1)
    4 #define PF0_LED (0)
    5 #define LED_OUT (GPIO_PORTF_DATA_BITS_R[1])
    6 void led_init(void)
    7 {
    8 /* PORTF时钟使能 */
    9 SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
    10 /* 写0x1ACCE551到GPIOLOCK解锁GPIOCR寄存器 */
    11 GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;
    12 /* 当GPIOCR的指定位为1时,写GPIOAFSEL位有效 */
    13 GPIO_PORTF_CR_R |= (1 << PF0_LED);
    14 /* PF0为GPIO模式 */
    15 GPIO_PORTF_AFSEL_R &= ~(1 << PF0_LED);
    16 /* PF0为输出 */
    17 GPIO_PORTF_DIR_R |= (1 << PF0_LED);
    18 /* PF0禁止输出开漏 */
    19 GPIO_PORTF_ODR_R &= ~(1 << PF0_LED);
    20 /* PF0数字输入输出使能 */
    21 GPIO_PORTF_DEN_R |= (1 << PF0_LED);
    22 /* PF0 8mA驱动输出使能 */
    23 GPIO_PORTF_DR8R_R |= (1 << PF0_LED);
    24 /* 仅对PF0写数据 */
    25 /* 注意GPIO_PORTF_DATA_BITS_R为volatile unsigned long型*/
    26 /* 因此对地址0x40025000+0x004的操作为GPIO_PORTF_DATA_BITS_R[1]*/
    27 LED_OUT = 0;
    28 }
    29 void delay(unsigned long i)
    30 {
    31 while(i--);
    32 }
    33  int main(void)
    34 {
    35 led_init();
    36 while(1)
    37 {
    38 delay(500000);
    39 LED_OUT = 1;
    40 delay(500000);
    41 LED_OUT = 0;

    42 }
    43 return 0;
    44 }
    45

    5、添加连接脚本文件lm3s8962-rom.ld

    1 OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
    2 MEMORY
    3 {
    4 FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
    5 SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
    6 }
    7 SECTIONS
    8 {
    9 .text :
    10 {
    11 _text = .;
    12 KEEP(*(.isr_vector))
    13 *(.text*)
    14 _etext = .;
    15 } > FLASH
    16 .rodata :
    17 {
    18 _rodata = .;
    19 *(.rodata*)
    20 _erodata = .;
    21 } > FLASH
    22 .data : AT(ADDR(.rodata) + SIZEOF(.rodata))
    23 {
    24 _data = .;
    25 *(vtable)
    26 *(.data*)
    27 _edata = .;
    28 } > SRAM
    29 .bss :
    30 {
    31 _bss = .;
    32 *(.bss*)
    33 *(COMMON)
    34 _ebss = .;
    35 } > SRAM
    36 }
    37  

    并在工程中设置

    image

    6、编译成功

    image

    7、使用OpenOCD进行调试

    7.1、OpenOCD安装

    下载地址:

    http://www.freddiechopin.info/index.php/en/download/category/4-openocd

    运行openocd-0.4.0.zip中的openocd.msi进行安装。

    image

    7.2、为Stellaris Evaluation Board安装libusb驱动

    下载地址:

    http://sourceforge.net/projects/libusb-win32/

    解压libusb-win32-bin-1.2.2.0.zip到C:\

    运行C:\libusb-win32-bin-1.2.2.0\bin\inf-wizard.exe

    image

    image

    image

    为Stellaris Evaluation Board (Interface 1)安装ftdichip官方驱动,因为Stellaris Evaluation Board (Interface 1)

    是用来提供USB转串口的。

    image

    7.3、为EK-LM3S8962编写OpenOCD配置文件

    7.3.1、参考C:\Program Files\OpenOCD\0.4.0\interface\luminary-lm3s811.cfg

    新建C:\Program Files\OpenOCD\0.4.0\interface\luminary-lm3s8962.cfg

    1 interface ft2232
    2 ft2232_device_desc "Stellaris Evaluation Board"
    3 ft2232_layout evb_lm3s811
    4 ft2232_vid_pid 0x0403 0xbcd8

    7.3.2、参考C:\Program Files\OpenOCD\0.4.0\target\lm3s811.cfg

    新建C:\Program Files\OpenOCD\0.4.0\target\lm3s8962.cfg

    1 # Script for TI/Luminary Stellaris LM3S8962
    2
    3  if { [info exists CHIPNAME] } {
    4 set _CHIPNAME $CHIPNAME
    5 } else {
    6 set _CHIPNAME lm3s8962
    7 }
    8
    9  if { [info exists CPUTAPID ] } {
    10 set _CPUTAPID $CPUTAPID
    11 } else {
    12 set _CPUTAPID 0x3ba00477
    13 }
    14
    15 #jtag scan chain
    16 jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 1 -irmask 0xf -expected-id $_CPUTAPID
    17
    18 # the luminary variant causes a software reset rather than asserting SRST
    19 # this stops the debug registers from being cleared
    20 # this will be fixed in later revisions of silicon
    21  set _TARGETNAME $_CHIPNAME.cpu
    22 target create $_TARGETNAME cortex_m3 -chain-position $_CHIPNAME.cpu -variant lm3s
    23
    24 # 8k working area at base of ram, not backed up
    25 $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size 0x2000
    26
    27 #flash configuration
    28  set _FLASHNAME $_CHIPNAME.flash
    29 flash bank $_FLASHNAME stellaris 0 0 0 0 $_TARGETNAME
    30  

    7.3.3、参考C:\Program Files\OpenOCD\0.4.0\board\ek-lm3s811.cfg

    新建C:\Program Files\OpenOCD\0.4.0\board\ek-lm3s8962.cfg

    1 #
    2 # TI/Luminary Stellaris LM3S8962 Evaluation Kits
    3 #
    4
    5 # include the FT2232 interface config for on-board JTAG interface
    6 source [find interface/luminary-lm3s8962.cfg]
    7
    8 # include the target config
    9 source [find target/lm3s8962.cfg]
    10
    11 # jtag speed
    12 jtag_khz 500
    13
    14 jtag_nsrst_delay 100
    15
    16 #LM3S811 Evaluation Board has only srst
    17 reset_config srst_only
    18
    19 #Daemon Configuration
    20 #TCP/IP Ports
    21 telnet_port 4444
    22 gdb_port 3333
    23  

    7.4、在Eclipse中使用GDB Hardware Debugging连接OpenOCD进行调试

    image

    设置gdb和端口

    image

    image

    image

    运行OpenOCD

    image

    开始调试

    image

    image

    程序下载

  • 相关阅读:
    InterLockedIncrement and InterLockedDecrement
    bzoj2763
    bzoj1922
    bzoj1705
    bzoj1040
    bzoj3039
    bzoj1801
    bzoj2565
    bzoj1976
    一类最小割bzoj2127,bzoj2132 bzoj3438
  • 原文地址:https://www.cnblogs.com/arci/p/1949821.html
Copyright © 2011-2022 走看看