学习ARM7芯片stm32时,裸机程序开发可以很方便的根据库函数在工程模板上进行开发,而ARM9主要是移植Linux开发,很少有裸机程序开发,因此在玩S3C2440希望最终形成一个keil环境下的模板。用的淘宝上的JZ2440v2板子,因为是裸机程序开发其他板子都一样。
S3C2440.s是keil自动生成的启动文件,其他都是按stm32库函数模板写的,技术很差,自学娱乐,若有需求可自行改动。
main.c文件:
#include "S3C2440Reg.h"
#include "S3C2440Init.h"
#include "led.h"
#include "uart.h"
void delay(int t)
{
int a,b;
for(a=0;a
#ifndef __S3C2440REG_H
#define __S3C2440REG_H
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned int uint32;
typedef signed int int32;
typedef float fp32;
typedef double fp64;
/* WOTCH DOG register */
#define WTCON (*(volatile unsigned long *)0x53000000)
/* SDRAM regisers */
#define MEM_CTL_BASE 0x48000000
#define SDRAM_BASE 0x30000000
/* NAND Flash registers */
#define NFCONF (*(volatile unsigned int *)0x4e000000)
#define NFCMD (*(volatile unsigned char *)0x4e000004)
#define NFADDR (*(volatile unsigned char *)0x4e000008)
#define NFDATA (*(volatile unsigned char *)0x4e00000c)
#define NFSTAT (*(volatile unsigned char *)0x4e000010)
/*GPIO registers*/
#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)
#define GPFCON (*(volatile unsigned long *)0x56000050)
#define GPFDAT (*(volatile unsigned long *)0x56000054)
#define GPFUP (*(volatile unsigned long *)0x56000058)
#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGDAT (*(volatile unsigned long *)0x56000064)
#define GPGUP (*(volatile unsigned long *)0x56000068)
#define GPHCON (*(volatile unsigned long *)0x56000070)
#define GPHDAT (*(volatile unsigned long *)0x56000074)
#define GPHUP (*(volatile unsigned long *)0x56000078)
/*UART registers*/
#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UFCON0 (*(volatile unsigned long *)0x50000008)
#define UMCON0 (*(volatile unsigned long *)0x5000000c)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UTXH0 (*(volatile unsigned char *)0x50000020)
#define URXH0 (*(volatile unsigned char *)0x50000024)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028)
/*interrupt registes*/
#define SRCPND (*(volatile unsigned long *)0x4A000000)
#define INTMOD (*(volatile unsigned long *)0x4A000004)
#define INTMSK (*(volatile unsigned long *)0x4A000008)
#define PRIORITY (*(volatile unsigned long *)0x4A00000c)
#define INTPND (*(volatile unsigned long *)0x4A000010)
#define INTOFFSET (*(volatile unsigned long *)0x4A000014)
#define SUBSRCPND (*(volatile unsigned long *)0x4A000018)
#define INTSUBMSK (*(volatile unsigned long *)0x4A00001c)
/*external interrupt registers*/
#define EINTMASK (*(volatile unsigned long *)0x560000a4)
#define EINTPEND (*(volatile unsigned long *)0x560000a8)
/*clock registers*/
#define LOCKTIME (*(volatile unsigned long *)0x4c000000)
#define MPLLCON (*(volatile unsigned long *)0x4c000004)
#define UPLLCON (*(volatile unsigned long *)0x4c000008)
#define CLKCON (*(volatile unsigned long *)0x4c00000c)
#define CLKSLOW (*(volatile unsigned long *)0x4c000010)
#define CLKDIVN (*(volatile unsigned long *)0x4c000014)
/*PWM & Timer registers*/
#define TCFG0 (*(volatile unsigned long *)0x51000000)
#define TCFG1 (*(volatile unsigned long *)0x51000004)
#define TCON (*(volatile unsigned long *)0x51000008)
#define TCNTB0 (*(volatile unsigned long *)0x5100000c)
#define TCMPB0 (*(volatile unsigned long *)0x51000010)
#define TCNTO0 (*(volatile unsigned long *)0x51000014)
#define GSTATUS1 (*(volatile unsigned long *)0x560000B0)
#endif
#ifndef __S3C2440Init_H
#define __S3C2440Init_H
/* Main clock */
#define FIN (12000000)
#define FCLK 400000000
#define HCLK (FCLK/4)
#define PCLK (HCLK/2)
/* USB clock */
#define UCLK 48000000
/* BUSWIDTH : 16,32 */
#define BUSWIDTH (32)
/*64MB
* 0x30000000 ~ 0x30ffffff : Download Area (16MB) Cacheable
* 0x31000000 ~ 0x33feffff : Non-Cacheable Area
* 0x33ff0000 ~ 0x33ff47ff : Heap & RW Area
* 0x33ff4800 ~ 0x33ff7fff : FIQ ~ User Stack Area
* 0x33ff8000 ~ 0x33fffeff : Not Useed Area
* 0x33ffff00 ~ 0x33ffffff : Exception & ISR Vector Table
*/
#define _RAM_STARTADDRESS 0x30000000
#define _ISR_STARTADDRESS 0x33ffff00
#define _MMUTT_STARTADDRESS 0x33ff8000
#define _STACK_BASEADDRESS 0x33ff8000
#define _NONCACHE_STARTADDRESS 0x31000000
/*USB Device Options */
#define USBDMA 1
#define USBDMA_DEMAND 0 /* the downloadFileSize should be (64*n) */
#define BULK_PKT_SIZE 64
#define UPDATE_REFRESH(IN_HCLK) ( rREFRESH = (rREFRESH & ~(0x7ff)) | 2049-(U32)((float)IN_HCLK*7.8/1000000) )
/* CLKSEL0/1 Clock selection value define */
#define CLK_HCLK (3)
#define CLK_PCLK (4)
#define CLK_DCLK (5)
#define MEGA (1000000)
#include "S3C2440Reg.h"
void disable_watch_dog(void);
#endif
#include "uart.h"
#define UART_CLK PCLK // UART0ʱÖÓÉèÖÃ
#define UART_BAUD_RATE 115200 // ²¨ÌØÂÊÉèÖÃ
#define UART_BRD ((UART_CLK / (UART_BAUD_RATE * 16)) - 1)
//#define TXD0READY (1<<2)
//#define RXD0READY (1)
/*
* ³õʼ»¯UART0
* 115200,8N1,ÎÞÁ÷¿Ø
*/
void uart0_init(void)
{
GPHCON |= 0xa0; // GPH2,GPH3ÓÃ×÷TXD0,RXD0
GPHUP = 0x0c; // GPH2,GPH3ÄÚ²¿ÉÏÀ
ULCON0 = 0x03; // 8N1
UCON0 = 0x05; // ²éѯ·½Ê½,UARTʱÖÓΪPCLK
UFCON0 = 0x00; // ²»Ê¹ÓÃFIFO
UMCON0 = 0x00; // ²»Ê¹ÓÃÁ÷¿Ø
UBRDIV0 = UART_BRD; // ²¨ÌØÂÊ115200
}
/*
* ·¢ËÍÒ»¸ö×Ö·û
*/
void uart0SendData(unsigned char ch)
{
//Ö±µ½·¢ËÍ»º³åÇøÊý¾ÝÒÑÈ«²¿·¢³ö
while (!(UTRSTAT0 & 0x4));
UTXH0 = ch;
}
/*
* ·¢ËÍÒ»¸ö×Ö·û´®
*/
void uart0SendString(unsigned char *str)
{
while(0!=*str)
{
uart0SendData(*str);
str++;
}
}
/*
* ½ÓÊÕÒ»¸ö×Ö·û
*/
unsigned char uart0ReceiveData(void)
{
//Ö±µ½½ÓÊÕ»º³åÇøÓÐÊý¾Ý
while (!(UTRSTAT0 & 0x1));
return URXH0;
}
硬件上:nCTS0--->GPH0,nRTS0--->GPH1,TXD0--->GPH2,RXD0--->GPH3
查询S3C2440用户手册,相关串口控制寄存器设置如下:
因此,ULCON0 = 0x03; //8位传输,无校验,一位停止位
因此,UCON0 = 0x05; //选择PCLK作为串口时钟,发送和接收都是中断或者查询模式(polling mode)
因此,UFCON0 = 0x00;//不使用FIFO,每个UART通道包含了两个64-byte的FIFO队列用于接收器和发送器,可以存储更多数。
因此,UMCON0 = 0x00;//不使用流控,只需要接Rxd0和Txd0,不用接nCTS0和nRTS0
状态寄存器
最终代码连接:http://download.csdn.net/detail/tiandawangliang/9549257