日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]首先明確一下我們的編程步驟。(1)、加電在nand_flash加載boot.s中4K以內的程序。這4k將自動拷貝到SRAM(片內RAM)執(zhí)行。(2)、我們需要用這4k的程序實現(xiàn)nand-flash中4K以后的程序的拷貝(當然,拷貝到SDRAM基址為

首先明確一下我們的編程步驟。


(1)、加電在nand_flash加載boot.s中4K以內的程序。這4k將自動拷貝到SRAM(片內RAM)執(zhí)行。


(2)、我們需要用這4k的程序實現(xiàn)nand-flash中4K以后的程序的拷貝(當然,拷貝到SDRAM基址為0x30000000處)繼續(xù)執(zhí)行(main.o部分的程序)。對于SDRAM的初始化和Watchdog的禁用已經在前一個實驗中使用到了,這里就不再詳細敘述。主要來看一下nand-flash的初始化和使用。



查閱一下s3c2440的空間布局。查看手冊圖Figure 5-1. S3C2440A Memory Map after Reset一目了然。



有8個banks— Total 8 memory banksSix memory banks for ROM, SRAM, etc.Remaining two memory banks for ROM, SRAM, SDRAM, etc .



每個bank擁有128M空間。當訪問bankx時,對應的地址范圍是128*n 到 128*(1+n)tq2440使用了64M的nand flash和64M的SDROMNAND Flash不對應任何bank,他是通過幾組寄存器來訪問的;上電以后,nand flash開始的4k數(shù)據被自動的復制到芯片內部一個稱為steppingstone的RAM上。steppingstore的映射地址為0,上面的4k完成初始化工作;SDRAM則使用bank6,起始位置為0x30000000



該實驗中我們將使用SDRAM的bank6實驗目的:


(1)、mem controller的原理和工作過程


(2)、bank的使用


(3)、nand flash的讀寫控制


(4)、啟動代碼流程分析



在實際編程中,uboot和vivi都是絕佳的參考源碼,我這里參考的是vivi的代碼。


vivi已經上傳到新浪共享:http://ishare.iask.sina.com.cn/f/11353581.html



datasheet上關于啟動原理的介紹:

Bank0:The data bus of BANK0 (nGCS0) should be configured with a width as one of 16-bit and 32-bit ones. Because theBANK0 works as the booting ROM bank (map to 0x0000_0000), the bus width of BANK0 should be determinedbefore the first ROM access, which will depend on the logic level of OM[1:0] at Reset.



下面小結一下對nand flash控制器的操作過程.


s3c2440對nandflash讀寫操作寄存器配置的流程:


s3c2440對nandflash讀寫操作寄存器配置的流程:


1.初始化


(1)NFCONT= (1<<0) //enable NAND flash controller


(2)NFCONT|= (1<<0)//chip disable


2.復位


(1)NFCONT&= ~(1<<1) //chip enable


(2)NFCMD= 0xff; //reset command


(3)while(!(NFSTAT& BUSY))等待NAND flashmemory ready to operate


3.讀函數(shù)


(1)NFCONT&= ~(1<<1)//chip enable


(2)NFSTAT|= (1<<2) //NAND_CLEAR_RB ,RnBtransition is detected


(3)NFCMD= 0; //READ0,讀上半葉


(4)//Write Address


NFADDR= i & 0xff;


NFADDR= (i >> 9) & 0xff;


NFADDR= (i >> 17) & 0xff;


NFADDR= (i >> 25) & 0xff;


(5)while(!(NFSTAT&(1<<0)) ); //NAND_DETECT_RB,等待NANDflash memory ready to operate


(6)*buf= (NFDATA & 0xff); //讀數(shù)據線


(7)NFCONT|= (1<<1)//chip disable



用到的nand flash初始化讀操作源碼:


1 /*在第一次實用NAND Flash前,復位一下NAND Flash */

2 void nand_flash_reset()

3 {

4 NAND_CHIP_ENABLE;

5 NFCMD = 0xff; //reset command

6 wait_idle();

7 }

8

9 /*初始化NAND Flash */

10 void nand_flash_init()

11 {

12 //vivi init

13 int i = 0;

14 NFCONF = ( (7<<12)|(7<<8)|(7<<4)|(0<<0) );

15 NFCONT = ( (1<<4)|(0<<1)|(1<<0) );// Active low CE Control

16 NFSTAT = (0x6);//RnB Clear

17 NFCMD = 0xff; //reset command

18 for(i = 0; i < 10; i++)

19 ;

20 wait_idle();

21 /*

22 //----------------------------------------------------------------

23 // following is the copy module

24 //----------------------------------------------------------------

25 NFCONT |= 0x2;//@ Flash Memory Chip Disable

26 //----------------------------------------------------------------

27 @ Flash Memory Chip Disable

28 @ get read to call C functions (for nand_read())

29 @ copy vivi to RAM

30 ldr r0, =VIVI_RAM_BASE

31 mov r1, #0x0

32 mov r2, #0x20000

33 bl nand_read_ll

34 //---------------------------------------------------------------

35 */

36 /*

37 NFCONT = (1<<0);

38 NAND_CHIP_DISABLE;

39 nand_flash_reset();

40 */

41 }

42

43 #define BUSY 1

44 inline void wait_idle(void)

45 {

46 while(!(NFSTAT & BUSY));

47 NFSTAT |= BUSY;

48 }

49

50 #define NAND_SECTOR_SIZE 512

51 #define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)

52

53 /* low level nand read function */

54 int nand_flash_read(unsigned char *buf, unsigned long start_addr, int size)

55 {

56 int i, j;

57

58 if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {

59 return -1; /* invalid alignment */

60 }

61

62 NAND_CHIP_ENABLE;

63

64 for(i=start_addr; i < (start_addr + size);) {

65 /*debug*/

66 (*(volatile unsigned long *)0x56000010) = 0x00015400;

67 (*(volatile unsigned long *)0x56000014) = 0x00000000;

68 /*debug*/

69 /* READ0 */

70 NAND_CLEAR_RB;

71 NFCMD = 0;

72

73 /* Write Address */

74 NFADDR = i & 0xff;

75 NFADDR = (i >> 9) & 0xff;

76 NFADDR = (i >> 17) & 0xff;

77 NFADDR = (i >> 25) & 0xff;

78

79 NAND_DETECT_RB;

80

81 for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

82 *buf = (NFDATA & 0xff);

83 buf++;

84 }

85 /*debug*/

86 if(i >= 512)

87 {

88 for(j = 0; j < 2048; j++)

89 ;

90 (*(volatile unsigned long *)0x56000014) &= (1 << 5) & (1 << 6);

91 for(j = 0; j < 2048; j++)

92 ;

93 }

94 /*debug*/

95 }

96 NAND_CHIP_DISABLE;

97 return 0;

98 }



在sram執(zhí)行的啟動匯編代碼:


1 @----------------------------------------------------

2 @ boot.s

3 @ yeven @2010.20.28

4 @----------------------------------------------------

5 .text

6 .global _start

7 _start:

8 ldr sp,=4096

9 bl disable_wd @關閉看門狗

10 bl memsetup @初始化SDRAM

11 bl nand_flash_init @初始化nand-flash

12

13 @下面調用 nand_flash_read,它需要三個參數(shù):目標地址,源地址,數(shù)據長度

14 ldr r0,=0x30000000 @SDRAM新的起始位置

15 mov r1,#4096 @main.o在nand-flash中的偏移,即數(shù)據起始位置

16 mov r2,#1024 @復制長度

17 bl nand_flash_read @調用vivi代碼中的拷貝函數(shù)

18

19

20 bl led_on_s

21 ldr pc, = set_sp @設置堆棧,進入main.o執(zhí)行

22 set_sp:

23 ldr sp,=0x34000000 @設置堆棧棧頂指針

24 ldr lr,=halt_loop @設置主函數(shù)返回地址

25 ldr pc,=main @執(zhí)行主函數(shù)

26

27 halt_loop:

28 b halt_loop

29

30 led_on_s:

31 ldr r0,=0x56000010

32 mov r1,#0x00000400

33 str r1,[r0]

34 ldr r0,=0x56000014

35 mov r1,#0x00000000

36 str r1,[r0]


主函數(shù)執(zhí)行代碼,這一段將在sdram-0x30000000執(zhí)行.他只是不停的閃燈:



1 /*

2 * mem-con.c yeven @2010.10.27

3 * learn to use the sdram,control the memory and memory map

4 * the main program locate at boot.s

5 * we just light the four leds to test the result.

6 */

7

8 //Register for the led

9 #define GPBCON (*(volatile unsigned long *)0x56000010)

10 #define GPBDAT (*(volatile unsigned long *)0x56000014)

11

12 //led-data register value(GPB5-GPB8)

13 #define LED0_ON (1 << (5*2))

14 #define LED1_ON (1 << (6*2))

15 #define LED2_ON (1 << (7*2))

16 #define LED3_ON (1 << (8*2))

17 #define GPB_ON(n) (~(1 << n))

18 #define GPB_OFF(n) (1 << n)

19

20 void delayms(unsigned int n)

21 {

22 int i = 0;

23 for(i = 0; i < 10240*n; i++)

24 ;

25 }

26

27 int main()

28 {

29 GPBCON |= (LED0_ON | LED1_ON | LED2_ON | LED3_ON); //led0-4

30 wh

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉