我写了一个简单的启动程序,从Nand Flash启动,然后将代码从Nand Flash搬到RAM中去执行,在RAM中进行UART初始化。可是最终运行时串口没有输出。
UART初始化:
int serial_init(void)
{
volatile struct mini2440_uart *uart = (volatile struct mini2440_uart *)MINI2440_UART0_BASE;
unsigned long reg = 0, pclk;
#ifdef UART_FIFO
/* FIFO enable, Tx/Rx FIFO clear */
uart->ufcon = 0x07;
#else
uart->ufcon = 0x0;
#endif
uart->umcon = 0x0;
/* Normal,No parity,1 stop,8 bit */
uart->ulcon = 0x03;
/*
* tx=level,rx=edge,disable timeout int.,enable rx error int.,
* normal,interrupt or polling
*/
uart->ucon = 0x0245;
pclk = get_pclk();
if (!pclk)
return -1;
/* value is calculated so : (int)(PCLK/(16*baudrate)) -1 */
reg = (int)(pclk / (16*BAUDRATE)) - 1;
uart->ubrdiv = reg;
pll_delay(100);
pll_delay(0x1000000);
leds(1);
PUTC('H');PUTC('e');PUTC('l');PUTC('l');PUTC('o');
// PUTS("serial init ok!!!\r\n");
leds(2);
return (0);
}
主程序:
start_code:
/*
* set the cpu to SVC32 mode
*/
mrs r0, cpsr
bic r0, r0, #0x1f
orr r0, r0, #0xd3
msr cpsr, r0
#define pWTCON 0x53000000
#define INTMSK 0x4a000008
#define INTSUBMSK 0x4a00001c
/* turn off watchdog */
ldr r0, =pWTCON
mov r1, #0x0
str r1, [r0]
/*
* mask all IRQs by setting all bits in the INTMR - default
*/
mov r1, #0xffffffff
ldr r0, =INTMSK
str r1, [r0]
ldr r1, =0x7ff
ldr r0, =INTSUBMSK
str r1, [r0]
ldr r0, =0x56000010 /* GPBCON */
ldr r1, =0x00015400 /* GPB 5,6,7,8 output */
str r1, [r0]
ldr r0, =0x56000014 /* GPBDAT */
mov r1, #0
mvn r1, r1, lsl #5
str r1, [r0]
bl cpu_init_crit
#define RELOC_ADDR 0x30000000
#define RELOC_OFF 0x30000000
adr lr, here
ldr r0, =RELOC_OFF
add lr, lr, r0
ldr r0, =RELOC_ADDR
b relocate_code
here:
ldr sp, =CONFIG_SYS_INIT_SP_ADDR
bic sp, sp, #7 /* 8-byte alignment */
bl debug
bl serial_init
adr r0, current
current:
bl after_relocate
我用LED灯调试,程序是执行到最后的,可是串口却无法输出。
我把代码改成从SDRAM中执行,其中也将代码搬运到SDRAM中较后的地方执行,串口却正常输出。
恳请大虾指点迷津。
完整代码下载:
http://pan.baidu.com/share/link?shareid=478415&uk=788634284
arm?uart?c C ARM
------解决方案--------------------