weixin_44954297 2020-01-07 14:45 采纳率: 0%
浏览 276

友善之臂mini2440 运行uart裸板程序失败

用的板子是友善之臂mini2440,自己学习韦东山的一期视频,在写uart裸板程序时发现怎么都无法实现功能

s3c2440.h

/* GPIO寄存器 */
#define GPBCON              (*(volatile unsigned int*)0x56000010)
#define GPGCON              (*(volatile unsigned int*)0x56000060)
#define GPHCON              (*(volatile unsigned int*)0x56000070)


#define GPBDAT              (*(volatile unsigned int*)0x56000014)
#define GPGDAT              (*(volatile unsigned int*)0x56000064)

#define GPHUP               (*(volatile unsigned int*)0x56000078)

/* UART寄存器 */
#define UCON0               (*(volatile unsigned int*)0x50000004)
#define UBRDIV0             (*(volatile unsigned int*)0x50000004)
#define ULCON0              (*(volatile unsigned int*)0x50000028)
#define UTRSTAT0            (*(volatile unsigned int*)0x50000010)
#define UTXH0               (*(volatile unsigned char*)0x50000020)
#define URXH0               (*(volatile unsigned char*)0x50000024)
#define UFCON0              (*(volatile unsigned int*)0x50000008)
#define UMCON0              (*(volatile unsigned int*)0x5000000C)

#define UCON1               (*(volatile unsigned int*)0x50004004)
#define UBRDIV1             (*(volatile unsigned int*)0x50004028)
#define ULCON1              (*(volatile unsigned int*)0x50004000)
#define UTRSTAT1            (*(volatile unsigned int*)0x50004010)
#define UTXH1               (*(volatile unsigned char*)0x50004020)
#define URXH1               (*(volatile unsigned char*)0x50004024)
#define UFCON1              (*(volatile unsigned int*)0x50004008)
#define UMCON1              (*(volatile unsigned int*)0x5000400C)

uart.h

#ifndef _UART_H
#define _UART_H

void uart0_init();

int putchar(int c);

int getchar(void);

int puts(const char *s);
#endif

uart.c

#include "s3c2440.h"


/* 设置引脚用于串口 */
void uart0_init()
{

    GPHCON &= ~((3<<8)|(3<<10));    //清空GPH2,GPH3
    GPHCON |= ((2<<8)|(2<<10));     //GPH4,GPH5用于TXD1,RXD1
    GPHUP &= ~((1<<4)|(1<<5));      //使能内部上拉
    UFCON0  = 0x00;                 //不使用FIFO
    UMCON0  = 0x00;                 //不使用流控
    ULCON0 = 0x00000003;            //设置数据格式8n1:8位数据位,无校验位,1停止位
    UCON0 = 0x00000005;             //PCLK,中断/查询模式
    UBRDIV0 = 26;                   //设置波特率 115200

}


int putchar(int c)
{
    while(!(UTRSTAT0) & (1<<2))
    UTXH0 = (unsigned char)c;
}

int getchar(void)
{
    while(!(UTRSTAT0) & (1<<0))
    return URXH0;
}

int puts(const char *s)
{
    while(*s)
    {
        putchar(*s);
        s++;
    }
}

main.c

#include "s3c2440.h"
#include "uart.h"

int main(void)
{
    unsigned char c;
    uart0_init();
    puts("hello,world!\n");

    while(1)
    {
        c = getchar();
        putchar(c);
    }
    return 0;
}

start.S

.text
.global _start

_start:
    /*设置内存:sp 栈*/
    ldr sp,=4096 /*nand启动*/

    /* 关闭看门狗 */
    ldr r0, =0x53000000 
    ldr r1, =0
    str r1, [r0]

    /* 设置CPU工作于异步模式 */
    mrc  p15,0,r0,c1,c0,0 
    orr  r0,r0,#0xc0000000 //R1_nF:OR:R1_iA 
    mcr  p15,0,r0,c1,c0,0 

    /* 设置MPLL,FCLK */
    /* CLKDIVN(0x4c000014) = 0x5 */
    ldr r0, =0x4c000014
    ldr r1, =0x5            /* HCLK = FCLK/4 = 100 MHz , PCLK = HCLK/2 = 50MHz */
    str r1, [r0]



    /* 设置MPLLCON(0x4c000004) = (92<<12)|(1<<4)|(1<<0)     FCLK = 400 MHz*/
    ldr r0, =0x4c000004
    ldr r1, =(92<<12)|(1<<4)|(1<<0)
    str r1,[r0]

    /*调用main*/
    bl main

halt:
    b halt

Makefile

all:
    arm-linux-gcc -c -o uart.o uart.c
    arm-linux-gcc -c -o main.o main.c
    arm-linux-gcc -c -o start.o start.S
    arm-linux-ld -Ttext 0 start.o uart.o main.o -o uart.elf
    arm-linux-objcopy -O binary -S uart.elf uart.bin
    arm-linux-objdump -D uart.elf > uart.dis

clean:
    rm *.bin *.o *.elf *.dis

程序写完后扔到虚拟机里编译生成.bin文件,之后用友善之臂自己编写的下载工具进行烧写
图片说明

之后选择nand启动,连接串口,并没有看到返回字符串hello,world!

特来请教

  • 写回答

1条回答 默认 最新

  • HockerF 2020-01-07 16:54
    关注

    不好意思,居然被禁言了,总之仔细比对 程序,管脚,上位机的配置。

    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)