OK6410裸机调试笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24815615/article/details/55260675

1.如果使用JLINK或openjtag记得关注DBGSEL引脚电平,引脚位置在原理图中能搜到

2.使用openocd的时间,记得打开系统的Telnet

展开阅读全文

请教,关于OK6410 NAND Flash 裸机调试

10-09

开发板是256MB/2G Nand flash。Nand flash型号:K9GAG08U0D 。我是看 “伟东山ok6410(裸机调试部分)”的视频。前面的还算没多大问题,但到NAND Flash这部分就出问题,nand.c文件代码修改多次和参照别的代码还是不行,到copy2ddr获取的数据有问题,不知道是Nand flash初始化参数出错还是什么问题。用linux编译,j-link烧写,nand启动。请教大神要怎么修改rnrn代码:rnnand.crnrn[code=c]#define MEM_SYS_CFG (*((volatile unsigned long *)0x7E00F120))rn#define NFCONF (*((volatile unsigned long *)0x70200000))rn#define NFCONT (*((volatile unsigned long *)0x70200004))rn#define NFCMMD (*((volatile unsigned long *)0x70200008))rn#define NFADDR (*((volatile unsigned long *)0x7020000C))rn#define NFDATA (*((volatile unsigned char *)0x70200010))rn#define NFSTAT (*((volatile unsigned long *)0x70200028))rnrnvoid nand_select(void)rnrn NFCONT &= ~(1<<1);rnrnrnvoid nand_deselect(void)rnrn NFCONT |= (1<<1);rnrnrnrnvoid nand_cmd(unsigned char cmd)rnrn NFCMMD = cmd;rnrnrnvoid nand_addr(unsigned char addr)rnrn NFADDR = addr;rnrnrnunsigned char nand_get_data(void)rnrn return NFDATA;rnrnrnvoid nand_send_data(unsigned char data)rnrn NFDATA = data;rnrnrnvoid wait_ready(void)rnrn while ((NFSTAT & 0x1) == 0);rnrnrnvoid nand_reset(void)rnrn /* 选中 */rn nand_select();rn rn /* 发出0xff命令 */rn nand_cmd(0xff);rnrn /* 等待就绪 */rn wait_ready();rn rn /* 取消选中 */rn nand_deselect();rnrnrnvoid nand_init(void)rnrn /* 让xm0csn2用作nand flash cs0 片选引脚 */rn MEM_SYS_CFG &= ~(1<<1);rnrn /* 设置时间参数 */rn#define TACLS 0rn#define TWRPH0 1rn#define TWRPH1 0rn NFCONF &= ~((1<<30) | (7<<12) | (7<<8) | (7<<4));rn NFCONF |= ((TACLS<<12) | (TWRPH0<<8) | (TWRPH1<<4));rnrn /* 使能nand flash controller */rn NFCONT |= 1;rn NFCONT &= ~(1<<16); /* 森止soft lock */rnrn nand_reset();rnrnrnvoid nand_send_addr(unsigned int addr)rnrn#if 0 rn unsigned int page = addr / 2048;rnrn /* 这两个地址表示从页内哪里开始 */rn nand_addr(addr & 0xff);rn nand_addr((addr >> 8) & 0xff);rnrn /* 下面三个地址表示哪一页 */rn nand_addr(page & 0xff);rn nand_addr((page >> 8) & 0xff);rn nand_addr((page >> 16) & 0xff);rn#elsern nand_addr(addr & 0xff); /* a0~a7 */rn nand_addr((addr >> 8) & 0x1f); /* 程序的角度: a8~a12 */rnrn nand_addr((addr >> 13) & 0xff); /* 程序的角度: a13~a20 */rn nand_addr((addr >> 21) & 0xff); /* 程序的角度: a21~a28 */rn nand_addr((addr >> 29) & 0x7); /* 程序的角度: a29~ */rn rn#endifrnrnrnint nand_read(unsigned int nand_start, unsigned int ddr_start, unsigned int len)rnrn unsigned int addr = nand_start;rn int i = nand_start % 4096;//nand_start % 2048;rn int count = 0;rn unsigned char *dest = (unsigned char *)ddr_start;rn rn /* 选中芯片 */rn nand_select();rnrn while (count < len)rn rn /* 发出命令0x00 */rn nand_cmd(0x00);rnrn /* 发出地址 */rn nand_send_addr(addr);rnrn /* 发出命令0x30 */rn nand_cmd(0x30);rnrn /* 等待就绪 */rn wait_ready();rnrn /* 读数据 */rn for (; i < 4096 && count < len; i++)rn rn dest[count++] = nand_get_data();rn addr++; rn rnrn i = 0; rn rnrn /* 取消片选 */rn nand_deselect();rn return 0;rnrnrnint copy2ddr(unsigned int nand_start, unsigned int ddr_start, unsigned int len)rnrn int ret;rn rn /* 初始化nand flash controller */rn nand_init();rn rn /* 读nand flash */rn ret = nand_read(nand_start, ddr_start, len);rn rn return ret;rnrn[/code]rnrnstart.Srn[code=text]rn.globl _startrn_start:rnrn/* 硬件相关的设置 */rn /* Peri port setup */rn ldr r0, =0x70000000rn orr r0, r0, #0x13rn mcr p15,0,r0,c15,c2,4 @ 256M(0x70000000-0x7fffffff)rn rn/* 关看门狗 */rn/* 往WTCON(0x7E004000)写0 */rn rn ldr r0, =0x7E004000rn mov r1, #0rn str r1, [r0]rn rn /* 设置栈 */rn ldr sp, =8*1024rnrn /* 设置时钟 */rn /*bl clock_init*/rnrn /* 设置DDR */rn bl ddr_initrn rn /* 重定位 */rn/* 把程序的代码段、数据段复制到它的链接地址去 */ rn adr r0, _start /* 获得_start指令当前所在的地址 : 0*/rn ldr r1, =_start /* _start的链接地址 0x51000000 */rn rn ldr r2, =bss_start /* bss段的起始链接地址 */rn rn sub r2, r2, r1rn rn cmp r0,r1rn beq clean_bssrn rn bl copy2ddrrn cmp r0, #0rn bne haltrn rn /* 清BSS */rn/* 把BSS段对应的内存清零 */rnclean_bss:rn ldr r0, =bss_startrn ldr r1, =bss_endrn mov r3, #0rn cmp r0, r1rn beq on_ddrrnclean_loop:rn str r3, [r0], #4rn cmp r0, r1 rn bne clean_loop rnrnon_ddr:rn ldr pc, =mainrnhalt:rn b halt rn[/code]rnrnuart.ldsrn[code=text]SECTIONS rn . = 0x51000000;rn .text : rn start.orn sdram.orn nand.orn * (.text)rn rnrn .rodata : rn * (.rodata)rn rnrn.data : rn * (.data)rn rnrn bss_start = .;rn .bss ALIGN(4) : *(.bss) *(COMMON) rnrn bss_end = .;rnrn[/code] 论坛

没有更多推荐了,返回首页