Mini2440 nand flash bare metal program modified by Wei Dongshan

Publisher:Serendipity99Latest update time:2016-04-13 Source: eefocusKeywords:mini2440  nand  flash Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Description
      Development board: mini2440
      Nand flash: K9F2G08U0B2, 56M
      This program implements the following functions: I referred to the bare metal program in Chapter 8 of Wei Dongshan, but his nand flash model is 64MB K9F12080M, so I modified it according to his program, downloaded it to nand flash, and copied the main.c program from nand flash to sdram for execution.
      Reference books: "Complete Manual of Embedded Application Development"
                "ARM Processor Bare Metal Development Practice---Mechanisms Rather Tactics"
 
Knowledge Points Summary
      Absolute and relative addresses of pages
 
      There is a function void RdNF2SDRAM() in nand.c, and its function is to copy the contents of nand flah to sdram, as follows:
 

The prototype of the page read function of nand flash is void nf_readpage(unsigned int block,unsigned int page,unsigned char *dstaddr), and its function is to read 1 page (for K9F2G, 1 page is equal to 2KB) of the contents from the page page of the block block of nand flash, and store it at the address pointed to by the pointer dstaddr. Some people may say, since nf_readpage can read 1 page of data to the specified address, and the address of sdram is 0x30000000, it can be used directly to copy the code of nand flash to sdram. The answer is of course yes! But there is a premise, the content copied to sdram must be within 2KB, once it exceeds 2KB, you need to borrow the RdNF2SDRAM() function. I believe that this explanation can make you understand the difference and connection between the two functions.
Let's talk about absolute address and relative address. First of all, we know that k9f2g has 2048 blocks, each block has 64 pages, and each page has 2K bytes. What we usually say is the relative address, such as the 2nd block and the 3rd page is a relative address. And the absolute address = block number * 64 + page number, for example, the 2nd block and the 3rd page in front is converted to an absolute address of 131 (131=2*64+3).
The following is an explanation of the RdNF2SDRAM() function:
Line 113: From line 117, we can see that i here refers to the relative address.
Line 114: The starting address in the nand flash. Here, 4096 represents bytes. The memory size of k9f2g is 256Mbyte. The reason why start_addr=4096 here is because we defined the address of the main.c file at 4096 in the nand.lds file. As shown in the figure below:



If AT(4096) is changed to AT(5120), then start_addr here is equal to 5120. Also note that 4096byte is 4KB here. Why is it defined after 4KB of nand flash? Because the hardware circuit will automatically move the first 4KB of the nand flash to the stepping stone for execution. If it is defined after 3KB, the main.c function will be executed directly, and there is no need to copy it.
      Line 115: Defines the location where the read nand flash content is stored. Here, 0x30000000 is the physical address of sdram.
      Line 116: defines how many bytes of nand flash are read in total, here it is defined as 1M, of course a small main.c code is less than 2KB.
      Lines 117-123: this is the key to the function. Because the nf_readpage function reads in pages, 2KB of data is read each time, so the movement of the data pointer is page-aligned, that is, one page is moved each time.
      Line 117: because each page size is 2KB, that is, 2048Byte, here start_addr>>11 bits, which is equivalent to start_addr/2048, so the page corresponding to the given address is obtained.
      Line 119: here i is the absolute address, because each block contains 64 pages, i/64 gets which block the given address is in; id is the page number of the page in the block.
 
      NAND FLASH address cycle:
      
      let's talk about the address cycle. For the mini2440 development board, its nand flash interface circuit is as follows:




      From the interface circuit, we can see that the address line and data line are multiplexed, and the interface line width is 8 bits, so only one byte can be sent at a time. Because the address of nand flash is 28 bits, it takes 5 address cycles to send the address, as shown in Figure 1. After sending the address, the address decoding circuit inside NAND FLASH will automatically combine the received addresses, which does not require our concern, but we need to pay attention to the order of sending, and send the low address first, and then the high address.
      So why are there 29 address lines, not 28 or 30? There must be a reason for this. Generally speaking, the address of nand flash is represented as:
Address Lines [A28:A18] [A17:A12] [A11:A0]
Address indication Block Address Page address Offset address within the page
      For k9f2g, it has 2048 blocks, so it uses 11 address lines for addressing (2^11=2048); each block has 64 pages, so it uses 6 address lines for addressing (2^6=64); each page has 2048 bytes of data and 64 bytes of information, that is, it has 2112 bytes, so it uses 12 address lines for addressing. If you understand this, it is easy to understand the following sending address.
Whether in the nand flash page read function or the write function, you need to send the address to the address register, as shown in the following figure:



Why is this the case? Since the page read and write functions are performed in units of pages, each time you have to start at the 0th byte of the page, that is, the offset address within the page is 0, so the lower 12 bits of the address line can be set to 0, such as lines 93 and 94.
Line 95, at this time it is in the third address cycle, so you need to send the A12-A19 bits of blockpage (blockpage is the absolute address of the page at this time), so just AND the blockpage with 0xff. It is important to note that the absolute address of the page is represented by A28-A12, and has nothing to do with A11-A0.
Line 96, at this time it is in the third address cycle, so it is necessary to send the A20-A27 bits of blockpage (at this time blockpage is the absolute address of the page), so it is sufficient to shift the blockpage right by 8
bits and AND it with 0xff. Line 97, at this time it is in the third address cycle, so it is necessary to send the A28 bit of blockpage (at this time blockpage is the absolute address of the page). As can be seen from Figure 1, although 8 bits are sent at this time, only the 0th bit is valid, and the other bits are invalid. Therefore, shift the blockpage right by 16 bits, and then AND it with 0x1, and only keep the 0th bit.
 
      nand.lds code explanation:
      
      If the code is less than 4096 bytes, they will be automatically copied into "Steppingstone" after the development board is started; the purpose of this example is to store part of the code after the NAND Flash address 4096, and read and execute them through the NAND Flash controller when the program is started. nand.lds is used to achieve this purpose. The linking script nand.lds divides the code into two parts. The code of nand.lds is as follows:



      The second line indicates that the running address of the three files head.o, init.o, and nand.o is 0, and their offset addresses in the generated image file are also 0 (stored from 0). The
      third line indicates that the running address of main.o is 0x30000000, and its offset address in the generated image file is 4096.
      The size of the bin file generated at this time is 4.10KB.
      If AT(4096) in the third line is removed and the other file programs remain unchanged, the size of the bin file generated by make is 1.7KB. By comparing them in this way, we can see that AT really works.
 
 
 
The clock of mini2440 development board
 
   is Fin=12MHz,    FCLK=400MHz,    HCLK=100MHz,     PCLK=50MHz,
      so FCLK: HCLK: PCLK=1:4:8, CLKDIV_VAL=5,
      MDIV=127,   PDIV=2  ,  SDIV=1.
Compile and generate bin file, download and run.
 
      This experiment contains 6 files, namely Makefile, head.S, init.c, main.c, nand.c, nand.lds, and all the source code files will be posted at the end.
      Copy the 6 files to the Linux system of the virtual machine, then compile and generate nand.bin file by make, download it to the board through supervivi's v command and DNW, then start the board from nand flash, and you can see that all 4 LED lights are on.
 
 
Code source file

Baidu Wenku pdf address: http://wenku.baidu.com/view/85e30572168884868662d603 .html?st=1
PDF file download address: http://download.csdn.net/detail/mybelief321/5234586
Source code download address: http://download.csdn.net/detail/mybelief321/ 5234602


Keywords:mini2440  nand  flash Reference address:Mini2440 nand flash bare metal program modified by Wei Dongshan

Previous article:Bare metal code of mini2440 interrupt modified by Wei Dongshan
Next article:ARM assembly instruction MCR/MRC learning

Recommended ReadingLatest update time:2024-11-23 11:24

mini2440 uboot transplant
1. Add new configuration options for the development board in the top-level makefile (the red part is the code that needs to be added, the same below)   smdk2410_config:unconfig @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0   mini2440_config:unconfig @$(MKCONFIG) $(@:_config=) arm arm920t mini2440 NULL
[Microcontroller]
Install u-boot on mini2440
There are many articles on the Internet about how to port u-boot to 2440. I am just a novice and have never been involved in porting, so here I will just talk about my experience in installing u-boot on mini2440. I hope everyone can give me more advice. 1. Supervivi is already installed by default in the NOR flash o
[Microcontroller]
How to connect mini2440 with secureCRT serial port
Step 1: Double-click to open secureCRT, the following window will pop up, click ① new session ② select protocol as serial ③ click next Step 2: Select the corresponding serial port number, baud rate 115200, and data flow control. Click Next. Step 3: Name the session: mini2440 and click Finish.
[Microcontroller]
How to connect mini2440 with secureCRT serial port
ATmega64 Flash Program Memory
In-system programmable Flash program memory ATmega64 has 64K bytes of online programming Flash for storing program instruction codes. Because all AVR instructions are 16 or 32 bits, the Flash is organized into 32K x 16 bits. The security of user programs should be considered separately based on the two areas of Flash
[Microcontroller]
ATmega64 Flash Program Memory
Analysis: SK Hynix plans to acquire Intel's NAND production capacity, and its market share will jump to second place
SK Hynix announced today (20) that it will acquire Intel's NAND memory and storage business, as well as the Fab68 plant in Dalian that specializes in manufacturing 3D NAND Flash, for US$9 billion. SK Hynix will apply for licenses from government agencies in China, the United States, South Korea and other countries in
[Mobile phone portable]
Analysis: SK Hynix plans to acquire Intel's NAND production capacity, and its market share will jump to second place
430 Flash Operation
General impression: The flash of 430 seems a bit like the flash of ARM, except that the flash of ARM is much larger than that of 430, and the flash of 430 is different from that of E2PROOM, which needs to be noted   The basic features of MSP430flash: 1. Has a built-in programming voltage generator 2: Can address bits,
[Microcontroller]
430 Flash Operation
mini2440-i2c driver analysis
In the i2c driver framework of s3c2440, there are two parts, one is i2c-adapter initialization, the other is i2c-driver initialization. For the eeprom that comes with s3c2440, read the code to see what is worth learning and reference. There are several i2c-adapters on s3c2440, each corresponding to an i2c bus. Multi
[Microcontroller]
mini2440-i2c driver analysis
Design and implementation of large capacity NAND FLASH in ARM embedded system
1 Introduction With the increasing application of embedded systems in mobile devices such as digital cameras, digital video cameras, mobile phones, and mp3 music players, FLASH memory has gradually replaced other semiconductor storage components and become the main data and program carrier in embedded systems.
[Microcontroller]
Design and implementation of large capacity NAND FLASH in ARM embedded system
Latest Microcontroller Articles
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号