QCC300x notes (5)-read and write operations of external Flash

Hello everyone, this is the fifth article in this series~ article~

<<[Series Blog Index] Fast Track>

1. QCC300X external Flash read and write
        QCC300x uses external Flash film. The advantage of using external flash is that the cost comes down. Everyone knows that CSR films have always been very expensive, and such films can only have low cost requirements. Project priority. When using external Flash, we generally use 32M by default (because the official configuration is this parameter, which will make it easier to use), but we often can’t use such a large space in the process of use. Now we use it. Get up and learn about the application of external Flash.

        1.1. Partitioning the external flash
            To use the external Flash, the external Flash must be partitioned first. The partition file is explained when upgrading in the previous section, that is, the XXX.ptn file.
          It should be noted that external Flash can be used for two purposes, one is a read-only file system, and the other is a raw serial data partition (Raw Serial). The read-only file system is for code and voice files. User files are stored in Flash, but this needs to be packaged and written in the form of files, which cannot be modified in the code, but can only be read.
        The unprocessed continuous data partition is pure Flash data, which can be written and read in the program.

        When using the file system, we need to mount the partition, and when using the Raw Serial partition, we don't need to mount the partition.

        We want to implement a data write and read in Flash, so Flash adds a Raw Serial partition under the original partition:

        0, 8K, PS, (none) # For PS Store
        1, 32K, RO, i1107e_patch_bundle.xuv # Logical #0 : For DSP & firmware patches #0,1
        2, 32K, RO, (erase) # Logical #0 : For DSP & firmware patches #0,2
        3, 612K, RO, (erase) # Logical #1 Audio prompts #1,1
        4, 612K, RO, (erase) # Logical #1 Audio prompts #1,2
        5, 300K, RO, i1107e.xuv # Logical #2 Main application image and other files. #2,1
        6, 300K, RO, (erase) # Logical #2 Main application image and other files. #2,2
        7, 8K, RO, system_i1107e.xuv # Logical #3 PSFS  #3,1
        8, 8K, RO, (erase) # Logical #3 PSFS #3,2
        9, 8K, RS, (erase) 
        10, 8K, RS, (erase) 
        11, *, RS, (erase)
        That is to add partitions 9 and 10, the size is 8K, the partition type is RS (Raw Serial), and (erase) is erased every time it is downloaded.

        I need to explain that this partition file involves the download process of the download software Xide.exe. Try to fill in the newly added partition every time you download and erase, otherwise it will affect the download.
        I have debugged and used (none) before, which will cause the card to be downloaded for a long time. Pause, causing the download time to be too long.

        1.2. Flash write data
        Flash can read and write after dividing the area, Flash reading and writing is also an introduction to the flow, writing needs to get a Sink, reading needs to get a Source, it should be noted that Flash has no data When the data cannot be read, the Flash that directly reads the unwritten data will be empty.

        1.2.1. Get the Sink of Flash to
        get the Sink. ADK provides two functions to get the Sink of Flash. They are
        Sink StreamPartitionOverwriteSink(partition_filesystem_devices device,
        uint16 partition) 
        Sink StreamPartitionResumeSink(partition_filesystem_devices device,
        uint16 partition,uint16 first_word); 

        It can be found in the code files of Partition and Stream.

        The first function rewrites the Flash, and the acquired Sink will overwrite the previously written data after being written.

        The second function is to write to Flash again. The third parameter is the starting address that needs to be written. If data already exists in the sink, you can use the
        uint32 PartitionSinkPosition(Sink sink) function to get the size of the existing Flash data

        partition_filesystem_devices: is to select the type of partition file, we need to select Flash
        Partition: this parameter is the partition number of our partition, which is the 9 or 10 partition number added in the XXX.ptn file.

        1.2.2. Set Flash write configuration
        Flash needs to set its write configuration when writing, and the configuration requires the following function settings:
        bool PartitionSetMessageDigest(Sink sink, partition_message_digest_type md_ty, uint16 *data, uint16 len) 
        This function can set Flash configuration,
        sink: at The sink that IS Writing to at The Partition
        md_type: at The of the type of the Message Digest:
            PARTITION_MESSAGE_DIGEST_APP_SIGNATURE: Signed with at The the Application DFU Key (See note)
            PARTITION_MESSAGE_DIGEST_CRC: Filesystem CRC
            PARTITION_MESSAGE_DIGEST_SKIP: the Do not the perform Verification
        the Data: pointer to at The the Message Digest
        len : length of message digest. 2 for CRC verification, 66 for signature verification 

        1.2.3.
        This step is not necessary to get the status of the Flash . We are operating the Flash. If you need to check the status, you can use:
        bool PartitionGetInfo(partition_filesystem_devices device, uint16 partition,partition_info_key key, uint32 *value) 

        参数说明:
        device: The device to query. Set to PARTITION_SERIAL_FLASH to query the serial flash device.
        partition: The number of the partition to query.
        key: The type of information requested:
            PARTITION_INFO_IS_MOUNTED: Whether a partition is mounted or not (1 = mounted, 0 = unmounted).
            PARTITION_INFO_SIZE: The size of the partition in words.
            PARTITION_INFO_TYPE: The type of the partition (0 = unused, 1 = filesystem, 2 = PS Store).
        value: The pointer to return the query result to 

        1.2.4. Writing Flash Data
        Writing data is the last step, but without the previous foreshadowing, it cannot be written successfully. The partition Sink we get is the data entry we write.

        After we get the sink, we can't write blindly. You can use SinkSlack (Sink sink) to check the maximum amount of data that the sink can write. I got 48 during the test, which means that Flash can only write 48 at a time. If we need to write a large number of characters, we can write data in batches.

        Data writing: The
        first step: Use SinkMap (Sink sink) to obtain a pointer; SinkClaim (Sink sink, uint16 extra) declares the size of the write, in order to check whether it can be written, if it returns 0xFFFF, it means that it cannot be written.

        Step 2: Use memcpy() to transport the data to be written to the address pointed to by the SinkMap() pointer,

        The third step: Use SinkFlush (Sink sink uint6 amount) to realize the real writing of Flash.

        Step 4: Use SinkClose (Sink sink) to close the sink.
        Note that:
        1. After the sink writes data, if you need to read it, you must first use the fourth step to close the sink before you can read it, but after you close the sink with SinkClose() , You cannot write to the Flash again, you need to use the restart write function to restart the write to the Flash.
        2. If you need to write to the Flash in batches for multiple times, do not close the sink with SinkClose(). After the complete writing is completed, close the sink again. After closing, writing to the Flash again becomes invalid and needs to be overwritten again.

        3. When the sink writes again, it needs to get the sink again, and the obtained sink offset needs to be obtained by the PartitionSinkGetPosition function.

        If there is no error in the above steps, congratulations, your Flash data has been successfully written.

        1.2.5. The
        sample code in the appendix of the Flash writing program is just a preliminary demonstration:

        Flash writing:        

Please contact the moderator for the complete code                '

Guess you like

Origin blog.csdn.net/zhanghuaishu0/article/details/81021162