S3C2440 Nor Flash Driver (Twenty-four)

Publisher:JoyfulSpirit5Latest update time:2020-07-07 Source: eefocusKeywords:S3C2440  Nor Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1.Nor Flash Hardware Introduction:

From the schematic diagram, we can see that NOR FLASH has address lines and data lines. It is similar to our SDRAM interface and can read data directly, but it cannot write data directly to SDRAM and requires commands.


1.1 There are 27 address lines in our 2440 (LADDR0~26). Why 27?


Because 2440 has 7 banks of memory blocks, each bank = 128M = (2^27)B, so there are 27 data lines in total


1.2 Why is the address line A0 of Nor Flash connected to LADDR1 of 2440?


Because Nor Flash has 16 bits of data, each address stores 2B of data, while each address of our 2440 stores 1B of data.


for example:


When 2440 accesses address 0x00, it will read 2B of data at address 0 on Nor Flash, and then the memory controller of 2440 will find the lower 8-bit byte based on 0X00 and return it to the CPU.


When 2440 accesses address 0x01, since the LDRR0 line of 2440 is not connected, it still accesses the 2B data at address 0 of Nor Flash. Then the memory controller finds the high 8-bit byte based on 0x01 and returns it to the CPU.


1.3 The difference between nand and nor:


NOR flash is more expensive than NAND in terms of connection, has a small capacity, and is slow to erase and write data. Its advantages are simple and stable interface, no bit reversal or bad blocks, and is often used to store critical data, while NAND flash is often used to store large-capacity data.


In 2440, the hardware switch is used to set OM0 to Nand boot or Nor boot, as shown in the following figure:

The specific parameters of OM0 are as follows, where the OM1 pin of 2440 is grounded

For nand boot: OM0 is grounded, the first 4KB of nand flash will be automatically loaded into the SRAM buffer built into 2440, and can be directly read and written


For NOR boot: OM0 is connected to the power supply, and the memory accessed by 2440 is NOR flash, which can be read directly, but not written directly.


2. The nor flash command is as follows (reference: MX29LV800BBTC.pdf and MX29LV160DBTI-70G.pdf)

Among them, word is for 16-bit nand and byte is for 8-bit nand.


Since the flash model of our 2440 is MX29LV160DB, the device ID is 0x2249 and the manufacturer ID is C2H.


2.1 For example, when we want to read the ID operation:


NOR manual:


Write AAH to address 555H (send unlock address)


Write 55H to address 2AAH (send unlock address)


Write 90H to address 555H (send command)


Read address 0 to get the manufacturer ID: C2H


Read address 1 to get device ID: 2249


Exit the read ID state: write F0H to any address


(A1 of 2440 is connected to A0 of NOR, so 2440 sends (555H<<1, left shift 1 bit is equivalent to multiplication by 2), and NOR can receive the address 555H)


UBOOT operation:


Write AAH to address AAAH mw.w aaa aa 


Write 55H to address 554H mw.w 554 55 


Write 90H to address AAAH mw.w aaa 90 


Read address 0 to get the manufacturer ID: C2H md.w 0 1 (1: means read once)


Read address 1 to get device ID: 2249 md.w 2 1


Exit the read ID state: write F0H to any address mw.w 0 f0


2.2 There are two specifications for NOR FLASH, jedec and cfi (common flash interface)


each


Just like nand flash, the parameters of nor flash (name, capacity, bit width, etc.) are determined by reading the ID to match the jedec_table[] array in drivers/mtd/chips/jedec_probe.c in the kernel, as shown in the following figure

2.2.1 [0] = MTD_UADDR_0x0555_0x02AA


Indicates that the unlock address is 0x555, 0x2AAAM, where array [0] indicates that it belongs to 8-bit flash


2.2.2 cmdset


Which command to use, generally CmdSet=0xFFF0


2.2.3 .NumEraseRegions= 1


Only 1 different sector area


2.2.4 ERASEINFO(0x10000,64)


There are 64 sectors in total, each sector is 64KB (0x10000)


cfi


Just save these parameters in the specified address in cfi mode, and write 0x98 to the 0x55 address of nor to enter cfi mode (as can be seen from the CFI Query in the above figure)


Some commands in cfi mode are shown in the following figure:

When we are in cfi mode, for example, reading the data at address 0x27 of nor, we can read the capacity of nor.


NOR Manual:


Enter CFI mode: write 98H to 55H


Read data: read 10H to get 0051


Read data: read 11H to get 0052


Read data: read 12H to get 0059


Nor capacity: read 27H to get the capacity


Exit CFI mode: reset


(A1 of 2440 is connected to A0 of NOR, so 2440 sends (555H<<1, left shift 1 bit is equivalent to multiplication by 2), and NOR can receive the address 555H)


UBOOT operation:


Enter CFI mode: write 98H to AAH mw.w aa 98


Read data: read 20H to get 0051 md.w 20 1 (Q)


Read data: read 22H to get 0052 md.w 22 1 (R)


Read data: read 24H to get 0059 md.w 24 1 (Y)


nor capacity: read 4EH to get the capacity md.w 4e 1 (15)


Exit CFI mode: reset mw.w 0 f0


Read 0x15, the decimal value of 0x15 is 21, as shown below, which corresponds to the 21 NOR address lines in our schematic diagram, so the capacity is 2^21=2097152=2MB




2.3 Why is the A20 pin not connected in the above picture?


For 2440, the capacity of A0~A19 is exactly 2MB, which is consistent with the data read in cfi mode, so A20 is not connected.


2.4 Write data operation: (Program)


At address 0x100000 (1M), write 0x1234

The data obtained is still the original data, so it cannot be written like memory


At address 0x30000000 (memory), write 0x1234

The data obtained is 0x1234


NOR Manual:


Write AAH to address 555H


Write 55H to address 2AAH


Write A0H to address 555H


Write PD to address PA


(A1 of 2440 is connected to A0 of NOR, so 2440 sends (555H<<1, left shift 1 bit is equivalent to multiplication by 2), and NOR can receive the address 555H)


UBOOT operation:


Write AAH to address AAAH mw.w aaa aa


Write 55H to address 554H mw.w 554 55


Write A0H to address AAAH mw.w aaa a0


Write 1234h to address 0x100000 mw.w 100000 1234


Read data: read 0x100000 to get 1234 md.w 100000 1



3. Next, let's analyze how to write the NOR flash driver


3.1 Let's recall the previous nand flash driver:


The nand flash driver will be placed in the kernel's mtd device, and the mtd device knows how to operate the nand flash through commands/addresses/data, so our previous nand flash driver only implemented hardware-related operations (constructing mtd_info, nand_chip structures, starting the nand controller, etc.)


Similarly, the NOR flash driver is also placed in the kernel's MTD device. The MTD device also knows how to read, write, and erase NOR, but it does not know the bit width (number of data lines) and base address of NOR flash. Therefore, our NOR flash driver also needs to implement hardware-related operations and provide MTD device calls.


3.2 Refer to the kernel's built-in NOR driver: drivers/mtd/maps/physmap.c


Enter its init function:


It is found that two platform device drivers are registered and enter the physmap_flash structure:


Found 3 undefined variables:


CONFIG_MTD_PHYSMAP_BANKWIDTH: Byte width of the NOR flash


CONFIG_MTD_PHYSMAP_START: physical base address of NOR flash


CONFIG_MTD_PHYSMAP_LEN: nand flash capacity length


These three variables are configured through the linux menuconfig menu. If you fill in the values ​​yourself, you don't need to use the menuconfig menu configuration.


3.3 Next we will configure the kernel and then hang the nor flash driver that comes with this kernel to experiment


3.4 First make menuconfig, configure the above 3 variables, and then set it as a module


 -> Device Drivers                                                   

          -> Memory Technology Device (MTD) support (MTD [=y])             

          -> Mapping drivers for chip access //Enter the mapping driver


CFI Flash device in physical memory map //Nor flash that supports cfi is set as a module

  │ │ (0x0) Physical start address of flash mapping //Set the physical base address  

  │ │ (0X1000000) Physical length of flash mapping //Set the capacity length, which must be greater than or equal to 2MB of NOR (0x1000000=16MB)

  │ │ (2) Bank width in octets //Set the byte width. Since the NOR flash is 16 bits, it is equal to 2 (2 bytes * 8 bits = 16 bits)


3.5 make modules


As shown in the figure below, you can see that physmap.c is compiled into a .ko module


3.6 Then put it in the nfs directory and start the development board


cp drivers/mtd/maps/physmap.ko  /work/nfsroot/first_fs


nfs 30000000 192.168.1.3:/work/nfsroot/uImage_nonand


bootm 30000000


As shown in the figure below, you can see that two mtd0 character devices and one mtd0 block device are created:


4. Next, we will analyze physmap.c and see how to write the NOR flash driver.


The probe function of physmap.c is as follows:


struct physmap_flash_info {

       struct mtd_info *mtd; //Realize the read, write, erase and other operations on the flash

       struct map_info map; //Store hardware related structures

       struct resource             *res;

#ifdef CONFIG_MTD_PARTITIONS

       int                 nr_parts;

       struct mtd_partition      *parts;

#endif

};

 

static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };    //芯片名称

 

... ...

static int physmap_flash_probe(struct platform_device *dev)

{

       const char **probe_type;

       ... ...

       /*1. Allocate structure*/

       info = kzalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);

 

       /*2. Set the map_info structure*/

    info->map.name = dev->dev.bus_id; //norflash name

       info->map.phys = dev->resource->start; //Physical base address

       info->map.size = dev->resource->end - dev->resource->start + 1; //Capacity length

       info->map.bankwidth = physmap_data->width; //Byte width

       info->map.virt = ioremap(info->map.phys, info->map.size); //Virtual address

 

       simple_map_init(&info->map); //Simply initialize other members of map_info

 

       probe_type = rom_probe_types;

       /*3. Set the mtd_info structure*/

       /*Identify the chip by the name pointed to by probe_type. When do_map_probe() function returns NULL, it means it is not found*/

       /*When the corresponding chip mtd_info structure is found, it will be returned to the current info->mtd */

       for (; info->mtd == NULL && *probe_type != NULL; probe_type++)       

       info->mtd = do_map_probe(*probe_type, &info->map); //Identify the chip through do_map_probe ()

[1] [2]
Keywords:S3C2440  Nor Reference address:S3C2440 Nor Flash Driver (Twenty-four)

Previous article:How to use S3C DMA, 2410-2440 DMA introduction
Next article:S3C2440 network card driver introduction and making virtual network card driver (Part 25)

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

S3C2440 bare metal -------LCD_add division
In the s3c2440_lcd_controller.c we mentioned earlier int clkval = (float)HCLK/plcdparams- time_seq.vclk/2-1+0.5; //int clkval = 5; An error occurred during compilation. This is because we have not implemented division. The following method is generally used to solve this problem: Go to uboot to find; Go to t
[Microcontroller]
S3C2440 bare metal -------LCD_add division
Display of BMP images on S3C2440 development board 2
2. BMP picture display test program design 1. Test program structure design (1. Purpose Confirm the understanding of BMP structure and deepen the understanding of RGB color format. Able to display a 160 x 128 size picture on the LCD. (Just the same size as the LCD)   (2) Implementation plan Add a command mptest. In t
[Microcontroller]
Embedded driver writing simple driver Hello_word
Development Environment BootLoader: u-boot-1.1.6 kernel:linux-2.6.30.4 cpu:S3C2440 step 1. Write driver code This should be the simplest driver, which only prints information in the kernel. The code is as follows: #include linux/module.h #include linux/kernel.h MODULE_LICENSE("GPL");                 static in
[Microcontroller]
Embedded driver writing simple driver Hello_word
Nordic SoC enables remote product pricing updates for smart shelf label systems
Nordic SoC enables remote product pricing updates for smart shelf label systems Yunliwuli uses Nordic's nRF52832 and nRF52810 SoCs to connect smart tags and gateways with Bluetooth 5 OSLO, Norway – November 25, 2021 – Nordic Semiconductor announced that Shenzhen Yunliwuli Technology Co., Ltd., a Chinese technology
[Internet of Things]
Nordic SoC enables remote product pricing updates for smart shelf label systems
Design and implementation of firewall supporting IPv6 protocol based on S3C2440 processor
1 Introduction Among many network security facilities, firewall is an important and effective network security device. It filters and shields network communications to prevent unauthorized access into and out of the computer network. A firewall is a security barrier between a trusted network and an untrusted network.
[Microcontroller]
Design and implementation of firewall supporting IPv6 protocol based on S3C2440 processor
12. S3C2440 bare metal—SDRAM
12.1 Introduction to SDRAM 12.1.1 SDRAM definition SDRAM (Synchronous Dynamic Random Access Memory): synchronous dynamic random access memory - memory stick Synchronization means that memory work requires a synchronized clock, and internal command sending and data transmission are based on it; Dynamic means that t
[Microcontroller]
12. S3C2440 bare metal—SDRAM
OnePlus Nord CE 2 released: Dimensity 900 + 65W fast charging + 90Hz display
       More than half a year ago, OnePlus launched the Nord 2 5G. Now the company has launched the new OnePlus Nord CE 2 5G. CE stands for Core Edition. This phone is a streamlined version of Nord 2 5G with a redesigned appearance.   The OnePlus Nord CE 2 retains the Nord 2's 90Hz 6.43-inch AMOLED display and 4,500m
[Mobile phone portable]
s3c2440 learning series 6 (dma continued)
The advantage of DMA is that it does not require CPU intervention when transmitting data, which can greatly improve the CPU's work efficiency. DMA is very important in large-capacity data transmission, such as image data transmission, SD card data transmission, USB data transmission and so on. S3C2410 has four DMA
[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号