Universal Controller Module for the Internet of Things. FatFs Testing



    In this article, I will demonstrate the testing projects of the FatFs library ported to the K66BLEZ1 module. The open source library FatFs is well known to microcontroller programmers and implements support for the FAT32 file system on SD and MMC cards. An indispensable thing in the development of loggers, programmable logic controllers, recording devices, trackers and so on. But sometimes it can become a bottleneck in real-time systems.


    The introduction to the K66BLEZ1 module was started in this article:
    Universal Controller Module for the Internet of Things. Inhaling life

    The article mentioned the software kit (SDK) for the K66 microcontroller family.
    In particular, in the SDK you can find an example for testing FatFs. The example is very simple and therefore I modified it for greater practicality.

    Organization of debug information output.



    For the original SDK example to work on the K66BLEZ1 board, no changes need to be made to it. But there is one, but! There will be no output to the debugging terminal. Since there is no special connector on the module board for debugging output with RS232 interface.
    Debugging of the module is designed for dense work through the SWD interface and the use of Real Time Terminal (RTT) technology described in this article.. However, this approach may not appeal to owners of debugging adapters incompatible with J-Link. Therefore, I did not fix the debug output code in the application, but redirected it to UART4. Here again, to avoid prototyping, I took advantage of J-Link. This adapter connects the RX and TX signals from the built-in UART <-> Virtual COM port to the SWD connector. I used them. Thus, the first tuning appeared on the module board. It is shown in the diagram below in red.

    (Click to enlarge)


    Ie on the K66BLEZ1 board, we wire the connection of the signals of the debug connector highlighted in red with the necessary signals from the microcontroller.

    (Click to enlarge)


    The diagram below shows the adapter from the J-Link connector to the debugging connector of the K66BLEZ1 board in order to understand where the signals come from the adapter.

    (Click to enlarge)


    Project organization.


    I made two projects in the IAR Embedded Workbench for ARM 7.40.7 environment.
    One completely repeats the example of working with FatFs from the SDK from the manufacturer.
    For greater convenience of copying a project, studying it and refactoring, I extracted from the SDK all the files associated with this project and transferred them to another simpler directory structure with fewer files.

    Then I changed the settings for the debug UART in the board.h file .
    For maximum performance of the board in the sdcard_FatFs.c file, I replaced the BOARD_BootClockRUN function with BOARD_BootClockHSRUN , i.e. CPU frequency set to 180 MHz instead120 MHz.
    The project is here. The

    second project is based on the first, but with significant additions.
    This project allows you to test the speed of opening, creating, writing, reading, closing and deleting files.
    Project is here

    Test description


    We compile the project in the IAR and program it via the JTAG / SWD adapter into the MK66FN2M0VLQ18 microcontroller on the board.
    After the program starts up, a menu of the following type is displayed in the terminal:

    (Click to enlarge) The


    menu offers to launch one of the three tests and the ability to change several test parameters.

    Test number 1 sequentially records the specified number of files with the specified size. The random data received by the rand function is recorded. Each entry is accompanied by a measurement of the opening, recording and closing times of the file.
    Then the files are sequentially read and their contents checked, the time of opening, reading and closing the file is also measured.
    If the Erase flag is set, the files are then deleted and the time it takes to delete the files is measured.
    For 3 groups of operations: file creation, reverse reading and deletion, statistics are summarized.
    This is a window for testing writing, reading, erasing 5 files of 8192 baht.

    (Click to enlarge) The


    number of files and their size can be arbitrarily changed. If the values ​​are too large, the program will display a message about the lack of memory.

    Test number 2 creates, writes, reads, deletes a file of a given size and repeats the specified number of times.
    The name of the file changes every time. Here the number of entries can be very large. The test allows you to test cards to complete wear and at the same time see a picture of the degradation of the speed of writing and reading.

    Test number 3creates a file and writes the specified number (Files Cnt value) to it once the blocks of the specified size. Then the procedure is repeated for another file. This script allows you to test the continuous recording mode typical for audio recording devices with changing volumes.

    results


    On the K66BLEZ1 board, the FatFs library showed very good results.

    For testing, an 8GB microSD card GOOD RAM SDU8GDMGR ( grade 10) was used.

    The average write speed of a file is 32768 bytes in size - 5.1 MB / s. The
    maximum write speed of a file in size by 32768 bytes is 11.8 MB / s

    . c The
    maximum read speed of a file is 32,768 bytes in size - 16.2 MB / s.

    Measurements were made by test number 1 on 100 files.

    It was noted that the multiplicity of the file size of the cluster has a strong influence on the speed of reading and writing.
    Also, with a large number of files, the time of opening a file starts to affect the overall speed, which increases by two orders of magnitude when the number of files changes from one to one hundred.

    The practical value of the tests is that they allow you to find the optimal card formatting parameters, the optimal sizes for the files, as well as optimize the block sizes of the recorded files for maximum performance.
    The same tests will help to see and evaluate sporadic recording delays characteristic of SD and MMC cards in connection with the operation of their internal mechanism for equalizing the wear of memory sectors.

    All materials related to this project are stored here - https://github.com/Indemsys/K66BLEZ1

    Also popular now: