Norflash型号为sst39vf32

#ifndef __NORFLASH_H_

#define __NORFLASH_H_

#include "common.h"

#include "delay.h"

#include "debugserial.h"

#define NOR_FLASH_BASE      0x80000000

#define NOR_FLASH_SIZE      0x00100000

#define GET_ADDR(addr)  (volatile uint16_t *)(NOR_FLASH_BASE | (addr<<1))

#define SECTOR_SIZE     0x800   /* Must be 2048 words for 39VF160 */

#define BLOCK_SIZE      0x8000  /* Must be 32K words for 39VF160  */

#define SST_ID          0xBF    /* SST Manufacturer's ID code   */

#define SST_39VF160     0x235D  /* SST 39VF160 device code      */

#define PROGRAM_TIMEOUT 0x00008000

//norflash 初始化必须在sram初始化之前

void norflash_init(void);

void norflash_erase(void);

u32 norflash_check_id(void);

u32 norflash_write_word(u32 add, u16 data);

u32 norflash_toggle_bit_check(u32 addr,u16 data);

#endif

#include "norflash.h"

static void norflash_io_init(void)

{

//a0-a22

/* init EMC_A1 */

LPC_IOCON->P4_1 = 0x21;

/* init EMC_A2 */

LPC_IOCON->P4_2 = 0x21;

/* init EMC_A3 */

LPC_IOCON->P4_3 = 0x21;

/* init EMC_A4 */

LPC_IOCON->P4_4 = 0x21;

/* init EMC_A5 */

LPC_IOCON->P4_5 = 0x21;

/* init EMC_A6 */

LPC_IOCON->P4_6 = 0x21;

/* init EMC_A7 */

LPC_IOCON->P4_7 = 0x21;

/* init EMC_A8 */

LPC_IOCON->P4_8 = 0x21;

/* init EMC_A9 */

LPC_IOCON->P4_9 = 0x21;

/* init EMC_A10 */

LPC_IOCON->P4_10 = 0x21;

/* init EMC_A11 */

LPC_IOCON->P4_11 = 0x21;

/* init EMC_A12 */

LPC_IOCON->P4_12 = 0x21;

/* init EMC_A13 */

LPC_IOCON->P4_13 = 0x21;

/* init EMC_A14 */

LPC_IOCON->P4_14 = 0x21;

/* init EMC_A15 */

LPC_IOCON->P4_15 = 0x21;

/* init EMC_A16 */

LPC_IOCON->P4_16 = 0x21;

/* init EMC_A17 */

LPC_IOCON->P4_17 = 0x21;

/* init EMC_A18 */

LPC_IOCON->P4_18 = 0x21;

/* init EMC_A19 */

LPC_IOCON->P4_19 = 0x21;

/* init EMC_A20 */

LPC_IOCON->P4_20 = 0x21;

/* init EMC_A21 */

LPC_IOCON->P4_21 = 0x21;

/* init EMC_A22 */

LPC_IOCON->P4_22 = 0x21;

//d0-d15

/* init EMC_D0 */

LPC_IOCON->P3_0 = 0x21;

/* init EMC_D1 */

LPC_IOCON->P3_1 = 0x21;

/* init EMC_D2 */

LPC_IOCON->P3_2 = 0x21;

/* init EMC_D3 */

LPC_IOCON->P3_3 = 0x21;

/* init EMC_D4 */

LPC_IOCON->P3_4 = 0x21;

/* init EMC_D5 */

LPC_IOCON->P3_5 = 0x21;

/* init EMC_D6 */

LPC_IOCON->P3_6 = 0x21;

/* init EMC_D7 */

LPC_IOCON->P3_7 = 0x21;

/* init EMC_D8 */

LPC_IOCON->P3_8 = 0x21;

/* init EMC_D9 */

LPC_IOCON->P3_9 = 0x21;

/* init EMC_D10 */

LPC_IOCON->P3_10 = 0x21;

/* init EMC_D11 */

LPC_IOCON->P3_11 = 0x21;

/* init EMC_D12 */

LPC_IOCON->P3_12 = 0x21;

/* init EMC_D13 */

LPC_IOCON->P3_13 = 0x21;

/* init EMC_D14 */

LPC_IOCON->P3_14 = 0x21;

/* init EMC_D15 */

LPC_IOCON->P3_15 = 0x21;

/* init EMC_WE */

LPC_IOCON->P4_25 = 0x21;

/* init EMC_oe */

LPC_IOCON->P4_24 = 0x21;

/* init EMC_cs0 */

LPC_IOCON->P4_30 = 0x21;

}

void norflash_init(void)

{

LPC_SC->SCS |= (1<<0);//emc地址不移位

//打开emc时钟与端口时钟

LPC_SC->PCONP |= (1<<15)|(1<<11);//打开时钟

LPC_SC->EMCDLYCTL = 0x00001010;//延时时间初始化

LPC_EMC->Control  = 0x00000001;//emc使能

LPC_EMC->Config  = 0x00000000;//emc配置清零,小端模式

norflash_io_init();

DelayMs(100);

LPC_EMC->StaticConfig0 &= ~(3<<0);  //

LPC_EMC->StaticConfig0 |= (1<<0);   //设置总线宽度16位

LPC_EMC->StaticConfig0 |= (1<<7);   //设置读写有效电平,读为低电平

LPC_EMC->StaticWaitWen0 &= ~(7<<0);

LPC_EMC->StaticWaitWen0 |= (2<<0);//设置片选到写使能的延时时间

LPC_EMC->StaticWaitOen0 &= ~(7<<0);

LPC_EMC->StaticWaitOen0 |= (2<<0);//设置片选到输出使能的延时

LPC_EMC->StaticWaitWr0 &= ~(0x1f<<0);

LPC_EMC->StaticWaitWr0 |= (0x1f<<0);//设置片选到写入的延时

LPC_EMC->StaticWaitPage0 &= ~(0x1f<<0);

LPC_EMC->StaticWaitPage0 |= (0x1f<<0);//设置读模式顺序存取延时

LPC_EMC->StaticWaitRd0 &= ~(0x1f<<0);

LPC_EMC->StaticWaitRd0 |= (0x1f<<0);//设置片选到读取的延时

LPC_EMC->StaticWaitTurn0 &= ~(0x1f<<0);

LPC_EMC->StaticWaitTurn0 |= (0x1f<<0);//设置总线周转周期

DelayMs(100);

}

void norflash_erase(void)

{

volatile uint16_t *ip;

ip  = GET_ADDR(0x5555);

*ip = 0x00AA;

ip  = GET_ADDR(0x2AAA);

*ip = 0x0055;

ip  = GET_ADDR(0x5555);

*ip = 0x0080;

ip  = GET_ADDR(0x5555);

*ip = 0x00AA;

ip  = GET_ADDR(0x2AAA);

*ip = 0x0055;

ip  = GET_ADDR(0x5555);

*ip = 0x0010;

DelayMs(10);                /* Use timer 1 */

return;

}

//检查nand id

u32 norflash_check_id(void)

{

volatile uint16_t *ip;

uint16_t SST_id1, SST_id2;

/*  Issue the Software Product ID code to 39VF160   */

ip  = GET_ADDR(0x5555);

*ip = 0x00AA;

ip  = GET_ADDR(0x2AAA);

*ip = 0x0055;

ip  = GET_ADDR(0x5555);

*ip = 0x0090;

DelayMs(10);

/* Read the product ID from 39VF160 */

ip  = GET_ADDR(0x0000);

SST_id1 = *ip & 0x00FF;

ip  = GET_ADDR(0x0001);

SST_id2 = *ip;

/* Issue the Soffware Product ID Exit code thus returning the 39VF160 */

/* to the read operating mode */

ip  = GET_ADDR(0x5555);

*ip = 0x00AA;

ip  = GET_ADDR(0x2AAA);

*ip = 0x0055;

ip  = GET_ADDR(0x5555);

*ip = 0x00F0;

DelayMs(10);

/* Check ID */

if ((SST_id1 == SST_ID) && (SST_id2 ==SST_39VF160))

{

return( 0 );

}

else

{

printf("SST_id1 = %x \r\n",SST_id1);

printf("SST_id2 = %x \r\n",SST_id2);

return( 1 );

}

}

//写入数据,只能16位写入

u32 norflash_write_word(u32 add, u16 data)

{

volatile uint16_t *ip;

ip  = GET_ADDR(0x5555);

*ip = 0x00AA;

ip  = GET_ADDR(0x2aaa);

*ip = 0x0055;

ip  = GET_ADDR(0x5555);

*ip = 0x00A0;

ip = GET_ADDR(add);       /* Program 16-bit word */

*ip = data;

return ( norflash_toggle_bit_check( add, data ) );

}

//数据写入检查

u32 norflash_toggle_bit_check(u32 addr,u16 data)

{

volatile u16 *ip;

u16 temp1, temp2;

u32 TimeOut = PROGRAM_TIMEOUT;

while( TimeOut > 0 )

{

ip = GET_ADDR(addr);

temp1 = *ip;

ip = GET_ADDR(addr);

temp2 = *ip;

if ( (temp1 == temp2) && (temp1 == data) )

{

return( 0 );

}

TimeOut--;

}

printf("temp1 = %x \r\n",temp1);

printf("temp2 = %x \r\n",temp2);

return ( 1 );

}

LPC1788的EMC驱动norflash的更多相关文章

  1. lPC1788的GPIO驱动

    #include "led.h" void led_init(void) { //p1.14 p0.16 p1.13 p4.27 LPC_SC->PCONP |= (1< ...

  2. 单片机STM32在开发中常用库函数详解

    1.GPIO初始化函数 用法: voidGPIO_Configuration(void) { GPIO_InitTypeDefGPIO_InitStructure;//GPIO状态恢复默认参数 GPI ...

  3. stm32中的串口通信你了解多少

    在基础实验成功的基础上,对串口的调试方法进行实践.硬件代码顺利完成之后,对日后调试需要用到的printf重定义进行调试,固定在自己的库函数中. b) 初始化函数定义: void USART_Confi ...

  4. 嵌入式物联网之SPI接口原理与配置

    本实验采用W25Q64芯片 W25Q64是华邦公司推出的大容量SPI FLASH产品,其容量为64Mb.该25Q系列的器件在灵活性和性能方面远远超过普通的串行闪存器件.W25Q64将8M字节的容量分为 ...

  5. stm32学习笔记之串口通信

    在基础实验成功的基础上,对串口的调试方法进行实践.硬件代码顺利完成之后,对日后调试需要用到的printf重定义进行调试,固定在自己的库函数中. b) 初始化函数定义: void USART_Confi ...

  6. STM32的串口通信

    本篇文章主要讲解一个在开发过程中经常使用到的一个外设---串口. 串口是绝大多数 MCU 中不可或缺的一个外设,同时也是我们开发中经常使用的一种调试手段,所以在STM32的学习中,串口的配置使用也是必 ...

  7. USART波特率 vs SPI速率--学习笔记

    本篇文章将与大家探讨USART波特率 vs SPI速率.这里提出一个问题,为什么USART的波特率是内核时钟的1/8或者1/16,而SPI最快的频率可以是内核时钟的1/2. 请大家带着这个问题来阅读本 ...

  8. LPC1788 nand驱动

    Lpc 1788自带有emc接口用于驱动nandflash,norflash,sdram设备,对于nandflash驱动因为配置简单,时序也简单 首先,针对nandflash而言应当在系统中有三个地址 ...

  9. lPC1788驱动SDRAM

    Sdram型号为hy57v256 #ifndef __SRAM_H_ #define __SRAM_H_ #include "common.h" #include "de ...

随机推荐

  1. oracle 基础使用以及sql语句基础

        oracle的安装与卸载 要记住数据库口令,适用于sys.system.sysman/dbsnmp等账户,而scott帐号密码默认为tiger, 以oracle  10g来说,scott账户默 ...

  2. java 读取URL中的资源

    Example13_1.java import java.net.*; import java.io.*; import java.util.*; public class Example13_1 { ...

  3. 优化之zencart第一时间修改原始内容

    Zen Cart 基本修改指南 Zen Cart,全球顶级B2C商城网站!要想自行搭建一个基本的Zen Cart的网站,这篇文章是绝对不能错过的.目前我已经做了两个B2C网站,但是还是离不开这篇文章的 ...

  4. 第13章 Swing程序设计----常用面板

    面板也是一个Swing容器,它可以作为容器容纳其他组件,但它也必须被添加到其他容器中. Swing常用的面板包括JPanel面板和JScrollPanel面板. 1.JPanel面板 import j ...

  5. 【转】js/jquery中刷新iframe方法(兼容主流)

    一.js实现刷新两种方式: 1.//方法1 2.document.getElementById('FrameID').contentWindow.location.reload(true); 3.// ...

  6. 【转】PHP里的basename函数不支持中文名的解决

    今天用到basename 函数获取文件名称时,发现如果是中文的文件名返回只有后缀的空文件名(如:.pdf)    string basename ( string path [, string suf ...

  7. DP CF 319 div1B

    http://codeforces.com/contest/319/problem/B 题目大意: 有删除操作,每次都删除数组右边比自己小的.且紧挨着自己的数字.问最小需要删除几次. 思路: 我们定义 ...

  8. Android AudioPolicyService和AudioPolicyManager

    AudioPolicyService是Android音频系统的两大服务之一,另一个服务是AudioFlinger,这两大服务都在系统启动时有 MediaSever加载,加载的代码位于:framewor ...

  9. 【转】Grub Rescue修复方法

    症状: 开机显示: GRUB loading error:unknow filesystem grub rescue> 原因:已经发现下面几种操作会导致这种问题:1,想删除debian,于是直接 ...

  10. 介绍Angular的注入服务

    其实angular的注入服务是挺复杂的,目前看源码也只看懂了一半,为了不误导大家,我也不讲敢讲太复杂,怕自己都理解错了. 首先我们要知道angular的三种注入方式: 第一种:inference va ...