[nRF51822] 6, based on the nRF51822 platform Flash Read and write research

Source: Internet
Author: User

Preface

This paper focuses on the data access characteristics of flash, the memory partition of Flash, a simple memory management method of accessing images, and a small experiment to measure the time of flash writing before deletion, the time of reading after deletion, and the time of writing after reading. The goal is to better understand the characteristics of the flash itself (especially the limitations), so as to facilitate the design of efficient memory management drive.

This paper : Storage Management and indexing method of flash Memory _ Zhao Pei _ huazhong kejida doctoral dissertation _2011

E-mail:[email protected]

first, the characteristics of flash

  Flash has several great features of the wonderful:

Flash memory has a variety of features not used for disk, such as: (1) Flash memory has an asymmetric read and write operation time, that is, the flash memory write time is much larger than the read time, erase time is much more than write time. (2) The Flash exists to overwrite the data in the same flash storage location before the erasure operation is required, that is, has the Erase-before-write feature. It is clear that the strategy of updating flash memory with the traditional "in-place-update" method (erase the entire flash memory before each update of the Flash memory page) is not feasible. In general, the Flash storage System updates the data in the flash memory in a "out-place-updata" manner, that is, the new version of the data is written to other idle pages, and then the original data page is recorded as a failed page (Dead page or dirty page). The Flash page containing the latest version becomes the live page. When empty pages in flash memory are insufficient, the erase operation reclaims space is performed. If the flash block to be reclaimed contains valid data, you need to copy the valid data to the other idle pages of the Flash memory before performing the erase operation, which becomes garbage Collection. (3) Each Flash block has a limited number of erase times (typically 10K or 100K times), if a block exceeds the maximum erase count, then this block is a "bad block" (worn-out block or ill block). Bad blocks have poor reliability and will frequently read and write errors that cannot be used to store data. (4) In order to prolong the life of flash memory, the flash storage system needs to use the wear-leveling mechanism to make all flash blocks have the same or similar erasure times as possible.

  These features allow traditional disk-based data management to be applied directly to the flash memory system with poor performance, and do not give full play to the excellent features of the flash memory (SSD and mechanical hdd).

Second, gd25q128b (16M) Introduction

Http://www.xinyahong.com/upLoad/product/month_1411/20141118164301603.pdf

2.1, GD25Q128B Storage Division

The chip is used on the NRF51822EK_TM Development Board

2.2. gd25q128b Operation Speed

2.3, gd25q128b page write operation and function

    • Like in the driver code:void Spiflash_write_data (char *pbuffer, uint8_t block_num, uint8_t page_num, uint32_t writebytesnum)
need three address: block_num,page_num,addrin this function, set the addr to 0.pcmd[0] = block_num;pcmd[1] = page_num;pcmd[2] = 0;
    • void Spiflash_write_sector_data (char *pbuffer, uint8_t block_num, uint8_t sector_num, uint32_t WriteBytesNum)
Which data in which block is written in which sectorfirst calculate how many page (1page=256bytes) will be occupiedwrite_page_num = writebytesnum/256;if ((writebytesnum%)! = 0) Write_page_num + = 1;
    • uint8_t spiflash_write_morepage (uint8_t *pbuffer, uint32_t writeaddr, uint32_t writebytesnum)

Write by page, write multiple pages, incoming is the address and the amount of data to be written, the internal write is a fraction, and then the page full page full page of writing

Third, flash access to the image of the specific case (a relatively simple memory management)

A picture 128x160 the 40960bytes=160x256 (page), and the 1block is the 64kb=2^16=2^8x256≈256 page (and 2^7 is less than 160, so 1block 64K is used to store an image). So:

1Spiflash_erase_block (0);2Spiflash_erase_block (1);3Spiflash_erase_block (2);4Nrf_delay_ms ( -);5Spiflash_write_morepage (Gimage_a,0,40960);6Spiflash_write_morepage (Gimage_b,1<< -,40960);7Spiflash_write_morepage (Gimage_c,2*(1<< -),40960);8 //disppic (pic_eval);9DISPPICFROMSD (0);TenDISPPICFROMSD (1); OneDISPPICFROMSD (2);
Note: here is a little bit of spiflash_write_morepage is the first to write a fraction, and then full page to write, read is called in the Disppicfromsd Spiflash_read_data ( Buffer, Picnum, address_s, n);void Spiflash_read_data (uint8_t *pbuffer, uint8_t block_num, uint8_t page_num, uint32_t readbytesnum)Iv. Measurement of Flash read-write and purge speed (preparation for more complex and efficient storage management)

Since the picture described in section III is about 1block in size, and the entire store is used to store all of the same specifications, plus these images only need to be saved once, and then simply read the pictures (not involving multiple deletions, random indexes, etc.), therefore, the storage utilization method in the third section can meet the requirements.

But for a kind of bracelet with gyroscope acquisition data, storage and synchronization: 17byte per frame of the sensor data acquisition,(1) first to meet the acquisition of data at the time of high-speed storage, (2) second to meet the synchronization of the full synchronization of data, (3) Also to meet the flash full after the new data can be overwritten with the old data.

This 3-point requirement can be implemented in the following ways:

For the above implementation, you need to test the effect of access:

4.1, Write_before_erasesector and Read_before_erasesector delay time difference calculation:

Experiment core code: 48 lines above test sector erase after the shortest time to write operation no problem; 48 lines The following is the shortest test sector erase after the read operation no problem:

Test result: Erase sector after write at least 100ms delay (recommended 120ms), write after read and erase sector after read do not need delay.

4.2, Write_before_eraseblock and Read_before_eraseblock delay time difference calculation:

With 4.1 understanding.

Test Result: Erase block after at least 350ms delay, in order to write effectively! (The latter part is the result of commenting out the 50th line of code)

Ps:erase full at least 40s, tested 6 times without errors, experiment with 4.1, 4.2.

PS: If you feel good, point a praise, let more people benefit ~

@link: Http://pan.baidu.com/s/1pK13HUV (private)
@beautifulzzzz 2016-03-19 continue~
E-mail:[email protected]

[nRF51822] 6, based on the nRF51822 platform Flash Read and write research

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.