10

我正在尝试在我的 Beagleboard-xm rev 上运行一个“hello world”类型的程序。C,通过从程序集中调用 Cputs函数。

到目前为止,我一直将其用作参考:http ://wiki.osdev.org/ARM_Beagleboard

这是我到目前为止所拥有的,但没有输出。

你好ç

volatile unsigned int * const UART3DR = (unsigned int *)0x49020000;

void puts(const char *s) {
  while(*s != '\0') { 
    *UART3DR = (unsigned int)(*s); 
    s++; 
  }
}

void hello() {
  puts("Hello, Beagleboard!\n");
}

引导程序

.global start
start:
   ldr sp, =stack_bottom
   bl hello
   b .

链接器.ld

ENTRY(start)

MEMORY
{
    ram : ORIGIN = 0x80200000, LENGTH = 0x10000
}

SECTIONS
{
    .hello : { hello.o(.text) } > ram
    .text : { *(.text) } > ram
    .data : { *(.data) } > ram
    .bss : { *(.bss) } > ram
     . = . + 0x5000; /* 4kB of stack memory */
    stack_bottom = .;

}

生成文件

ARMGNU = arm-linux-gnueabi

AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding

boot.bin: boot.asm
   $(ARMGNU)-as boot.asm -o boot.o
   $(ARMGNU)-gcc-4.6 -c $(COPS) hello.c -o hello.o
   $(ARMGNU)-ld -T linker.ld hello.o boot.o -o boot.elf
   $(ARMGNU)-objdump -D boot.elf > boot.list
   $(ARMGNU)-objcopy boot.elf -O srec boot.srec
   $(ARMGNU)-objcopy boot.elf -O binary boot.bin

像这样只使用 asm 文件。

.equ UART3.BASE,        0x49020000
start:
   ldr r0,=UART3.BASE
   mov r1,#'c'

以下是一些 Beagleboard/minicom 相关信息:http ://paste.ubuntu.com/829072/

任何指针?:)


我也试过

void hello() {
  *UART3DR = 'c';
}

我正在使用 minicom 并通过 ymodem 发送文件,然后我尝试使用以下命令运行它:

go 0x80200000

minicom 中的硬件和软件控制流程已关闭。

4

3 回答 3

3

那应该对你有用。这是我从很久以前挖出来的一些代码,今晚没有在 beagleboard 上尝试,只是确保它已编译,它曾经工作过......

启动.s:

    .code 32

.globl _start
_start:

    bl main
hang: b hang

.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

.globl GET32
GET32:
    ldr r0,[r0]
    bx lr

你好ç :

extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
void uart_send ( unsigned char x )
{
    while((GET32(0x49020014)&0x20)==0x00) continue;
    PUT32(0x49020000,x);
}
void hexstring ( unsigned int d )
{
    //unsigned int ra;
    unsigned int rb;
    unsigned int rc;

    rb=32;
    while(1)
    {
        rb-=4;
        rc=(d>>rb)&0xF;
        if(rc>9) rc+=0x37; else rc+=0x30;
        uart_send(rc);
        if(rb==0) break;
    }
    uart_send(0x0D);
    uart_send(0x0A);
}
int main ( void )
{
    hexstring(0x12345678);
    return(0);
}

memmap(链接描述文件):

MEMORY
{
    ram : ORIGIN = 0x82000000, LENGTH = 256K
}

SECTIONS
{
    ROM : { startup.o } > ram
}

生成文件:

CROSS_COMPILE = arm-none-eabi

AOPS = --warn --fatal-warnings 
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding 

all : hello.bin

hello.bin : startup.o hello.o memmap
    $(CROSS_COMPILE)-ld startup.o hello.o -T memmap -o hello.elf  
    $(CROSS_COMPILE)-objdump -D hello.elf > hello.list
    $(CROSS_COMPILE)-objcopy hello.elf -O binary hello.bin

startup.o : startup.s
    $(CROSS_COMPILE)-as $(AOPS) startup.s -o startup.o

hello.o : hello.c 
    $(CROSS_COMPILE)-gcc -c $(COPS) hello.c -o hello.o

clean :
    rm -f *.o
    rm -f *.elf
    rm -f *.bin
    rm -f *.list

看起来我只是将堆栈指针留在了引导加载程序所在的位置。同样,就像您一样,假设引导加载程序已初始化串行端口。

我假设你有串行端口访问工作,你看到 uboot 并且你可以输入命令以便将此程序(xmodem 或其他)下载到板 ram 中?如果你不能这样做,那么可能是你没有正确连接到串口。beagleboards 的串口很乱,可能需要自己制作电缆。

于 2012-02-05T08:53:08.890 回答
2

您不能只是盲目地将一串字符写入 UART - 您需要检查每个字符的状态 - 它适用于单字符示例,因为 UART 总是为第一个字符做好准备,但对于第二个和您需要轮询的后续字符(或者更好的是使用 ISR,但让我们在运行之前先走)。

这里有一些很好的示例代码:http: //hardwarefreak.wordpress.com/2011/08/30/some-experience-with-the-beagleboard-xm-part-2/

于 2012-02-04T18:19:33.867 回答
2

我没有足够的重复评论..但我的回答

无论哪种方式都有效。现在奇怪的是,我可以使用 uart_send('c') 打印单个字符,但不能打印字符串 print_string(char *str){ while (*str != '\0') uart_send (*str++); } print_string("测试"); . 对此有什么想法吗?

是:

您在输出缓冲区中的写入速度更快,因为 UART 能够发送。因此,在发送新字符之前,您必须检查输出缓冲区是否为空。

我已经在我的博客(http://hardwarefreak.wordpress.com/2011/08/30/some-experience-with-the-beagleboard-xm-part-2/)的代码中做到了这一点

于 2012-02-06T13:57:21.410 回答