TX2440 bare metal program-nor flash

Publisher:翩翩轻舞Latest update time:2019-11-23 Source: eefocusKeywords:TX2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Norflash and nandflash are non-volatile flash memories implemented using different technologies. Their respective characteristics will not be introduced here, but only the operation of norflash by s3c2440 will be explained. The norflash we use is EN29LV160AB. In fact, there is little difference in the reading and writing operations of various types of norflash.


The operations of norflash are mainly read, write, erase and identify. The data width of EN29LV160AB can be 8-bit byte or 16-bit word, which is realized by a pin configuration of EN29LV160AB. Here we select the word.


The read operation of norflash is relatively simple. The system will automatically enter the read mode after power-on, and no additional commands are required to implement the read operation. The following function implements the read operation:


U16 read_en29lv160ab(U32 addr)


{


       return *((volatile U16 *)(addr));


}


Norflash can not only implement hardware reset, but also software reset. The operation of software reset is to write the reset command 0xF0 to any address. The following function implements software reset:


void reset_en29lv160ab(void)


{


       *((volatile U16 *)0x0) = 0xf0;


}


The erase and write operations of norflash are slightly more complicated. They require 4 or 6 cycles to complete. Each cycle requires writing the corresponding command into a command register in norflash. The write operation process is that the first cycle is to write the command 0xAA into the command register with address 0x555, the second cycle is to write the command 0x55 into the command register with address 0x2AA, the third cycle is to write the command 0xA0 into the command register with address 0x555, and the fourth cycle is to actually write the data to be written into the address of norflash. The following function implements the write operation, in which the two input parameters of the function are the data and address to be written. For convenience, we define the command register in advance:


#define flash_base 0x00000000


#define CMD_ADDR0 *((volatile U16 *)(0x555<<1+flash_base))


#define CMD_ADDR1 *((volatile U16 *)(0x2aa<<1+flash_base))


 


U8 en29lv160ab_program(U32 addr, U16 dat)


{


       CMD_ADDR0 = 0xaa;


       CMD_ADDR1 = 0x55;


       CMD_ADDR0 = 0xa0;


       *((volatile U16 *)(addr)) = dat;


 


       return check_toggle();


}


Since we connected norflash to bank 0 of s3c2440, the base address of norflash is 0x00000000 relative to s3c2440. The reason why we shifted the address in norflash to the left (i.e. multiplied by 2) is because we connected ADDR1 of s3c2440 to A0 of norflash. In this function, we also called the check_toggle function, which is used to determine whether the operation is correct. Its prototype is:


U8 check_toggle()


{


       volatile U16 newtoggle,oldtoggle;


       oldtoggle = *((volatile U16 *)0x0);


 


       while(1)


       {    


              newtoggle = *((volatile U16 *)0x0);


             


              if((oldtoggle & 0x40)==(newtoggle & 0x40))


                     break;


             


              if(newtoggle & 0x20) //DQ5


              {


                     oldtoggle = *((volatile U16 *)0x0);


                     newtoggle = *((volatile U16 *)0x0);


                    


                     if((oldtoggle & 0x40)==(newtoggle & 0x40))


                            break;


                     else


                            return 0; //error


              }    


              oldtoggle = newtoggle;


       }


      


       return 1; //Correct


}


Its principle is to read the data on the data bus twice in succession to determine whether the 6th bit value (DQ6) on the data bus is flipped. If it is not flipped, it is correct. Otherwise, the 5th bit (DQ5) must be judged to determine whether the flip is caused by timeout.


The write operation can only change "1" to "0", and only the erase operation can change "0" to "1". Therefore, you must erase before writing. Erasing is divided into block erase and whole chip erase. The process of block erase is that the first cycle is to write the command 0xAA to the command register with address 0x555, the second cycle is to write the command 0x55 to the command register with address 0x2AA, the third cycle is to write the command 0x80 to the command register with address 0x555, the fourth cycle is to write the command 0xAA to the command register with address 0x555, the fifth cycle is to write the command 0x55 to the command register with address 0x2AA, and the sixth cycle is to write the command 0x30 to the first address of the block to be erased. The following function is block erase, where the input parameter is the first address of the block to be erased:


U8 en29lv160ab_sector_erase(U32 section_addr)

 

{

 

       CMD_ADDR0 = 0xaa;

 

       CMD_ADDR1 = 0x55;

 

       CMD_ADDR0 = 0x80;

 

       CMD_ADDR0 = 0xaa;

 

       CMD_ADDR1 = 0x55;

 

       *((volatile U16 *)(section_addr)) = 0x30;

 

       

 

       return check_toggle();

 

}

 

Another common operation for norflash is to read the chip ID. The process of reading the manufacturer ID is that the first cycle is to write the command 0xAA to the command register at address 0x555, the second cycle is to write the command 0x55 to the command register at address 0x2AA, the third cycle is to write the command 0x90 to the command register at address 0x555, and the fourth cycle is to read the content at address 0x100, that is, the manufacturer ID (0x1C). The first three cycles of the process of reading the device ID are the same as reading the manufacturer ID. The fourth cycle is to read the content at address 0x01, that is, the device ID (0x2249). The following function is to read the chip ID:

 

U32 get_en29lv160ab_id(void)

 

{

 

       U32 temp=0;

 

       CMD_ADDR0 = 0xaa;

 

       CMD_ADDR1 = 0x55;

 

       CMD_ADDR0 = 0x90;  

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x100<<1)))<<16;

 

       temp |= *(volatile unsigned short *)(flash_base + (1<<1));

 

       

 

       return temp;

 

}

 

 

 

The following program implements the operations of erasing, writing, and reading an area, and determines whether the written data is the same as the read data:

 

 

 

…… ……

 

U16 buffer[1024];

 

char cmd;

 

…… ……

 

 

 

void test_en29lv160ab(void)

 

{

 

       U32 temp;

 

       U8 sta;

 

       int i;

 

       

 

       for(i=0;i<1024;i++)

 

       buffer[i]=2*i+1;

 

           

 

       //Read ID

 

temp = get_en29lv160ab_id();

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)((temp&0xff000000)>>24);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)((temp&0x00ff0000)>>16);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)((temp&0x0000ff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)((temp&0x000000ff));

 

   

 

reset_en29lv160ab(); //Must reset here

 

     

 

delay(100);

 

     

 

       // Erase block 33

 

       sta=en29lv160ab_sector_erase(0xf0000);

 

if(sta == 0)

 

       {

 

              while(!(rUTRSTAT0 & 0x2)) ;

 

              rUTXH0=0xaf; //Erase error

 

       }

 

       else

 

       {

 

              for(i=0;i<1024;i++)

 

              {

 

                     sta = en29lv160ab_program(0xf0000+(i<<1),buffer[i]); //write

 

                     if(sta == 0) //Write error

 

                     {

 

                            while(!(rUTRSTAT0 & 0x2));

 

                            rUTXH0=0xbf;      

 

                            break;

 

                     }

 

                     delay(200);

 

              }

 

              

 

              if(sta == 1)

 

              {

 

                     for(i=0;i<1024;i++)

 

                     {

 

                            if(read_en29lv160ab(0xf0000+(i<<1))!=buffer[i]) //Read error

 

                            {

 

                                   while(!(rUTRSTAT0 & 0x2)) ;

 

                                   rUTXH0=0xcf; 

 

                                   sta = 3;

 

                                   break;

 

                            }

 

                     }

 

                     if(sta !=3) //All operations are correct

 

                     {

 

                            while(!(rUTRSTAT0 & 0x2)) ;

 

                            rUTXH0=0x66;      

 

                     }

 

              }

 

       }

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=0x88; //End

 

}

 

 

 

//Simple test CFI

 

void test_en29lv160ab_CFI(void)

 

{

 

       U16 temp;

 

       

 

       *((volatile U16 *)(0x55<<1+flash_base))=0x98; //CFI command

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x10<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x11<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x12<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x13<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x14<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x15<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

 

       while(!(rUTRSTAT0 & 0x2)) ;

 

       rUTXH0=(U8)(temp&0x00ff);

 

       

 

       temp = (*(volatile unsigned short *)(flash_base+ (0x16<<1)));

 

       //while(!(rUTRSTAT0 & 0x2)) ;

 

       //rUTXH0=(U8)((temp&0xff00)>>8);

[1] [2]
Keywords:TX2440 Reference address:TX2440 bare metal program-nor flash

Previous article:Simple configuration of linux-arm development environment
Next article:TX2440 bare metal program-touch screen

Recommended ReadingLatest update time:2024-11-15 16:53

PC SSDs see first increase in a year due to NAND Flash controller shortage
Due to a shortage of component controllers, supply of solid-state drives (SSDs) for PCs is tight and prices have risen for the first time in a year. According to Nikkei News, wholesale prices of SSDs for PCs have risen for the first time in a year, with benchmark product prices rising 5-10% from the previous quarter i
[Mobile phone portable]
Friendly Arm Mini2440 Nand Flash driver analysis under embedded Linux
1. The meaning of Nand Flash driver source code file        In the Linux kernel, the MTD source code is placed in the /driver/mtd directory, which contains six subdirectories: chips, devices, maps, nand, onenand and ubi. Only the codes in the nand and onenand directories are related to the Nand driver. The codes in th
[Microcontroller]
Issues related to flash erase and write and RAM initialization in bootloader
I am working on the online upgrade bootloader program for Freescale 16-bit microcontrollers. There are two questions that I am not very clear about. I would like to ask the experts in the forum. 1. In the bootloader program, the flash space where the application is stored is erased and a new application is written to
[Microcontroller]
stm8 program occupies flash and ram plug-in
STVD compiler, when compiling, does not show how much RAM and ROM are used? For this problem, there are two ways: one is to look at the .map file and the other is to add a patch. The specific operation is as follows. You can download the corresponding file in My Resources. Link: https://pan.baidu.com/s/1BpPNJ5W08M6l
[Microcontroller]
s3c2440 bare metal-NorFlash1-principle
1. Flash types and characteristics: Flash is generally divided into NAND flash and NOR flash, and their respective characteristics are as follows: - Nor NAND XIP (Execute in Place) yes no Performance(Erase) Very slow (5s, chunks are too big)
[Microcontroller]
Some key points for operating STM32 flash
When it comes to STM32's flash, our first reaction is that it is used to install programs. In fact, the STM32's on-chip FLASH is not only used to install programs, but also to install chip configuration, chip ID, bootloader, etc. Of course, FLASH can also be used to store data. FLASH classification        According to
[Microcontroller]
【STM8S】 FLASH and EEPROM read and write operations
The following are FLASH operations: #include "flash.h" #include "stm8s_flash.h"     void Flash_Write_bytes(uint32_t Address , uint8_t * DataBuff,uint16_t length) {   uint16_t Count=0;   for( Count=0 ; Count length ; Count++ )   {     FLASH_ProgramByte_User(Address+Count,DataBuff );   } }       void FLASH_ProgramBy
[Microcontroller]
Flash storage technology under uClinux platform
1 Flash Types and Technical Features Flash is mainly divided into two categories: NOR and NAND. The following is a more detailed comparison of the two. 1.1 Performance Comparison Flash memory is a non-volatile memory that can erase and reprogram blocks of memory cells. Any Flash device must be erased before a wr
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号