Running the 'perf_xfile' example on the STM32F746IGT6, using a NAND chip on the QSPI bus.

This page describes the steps required to build and run the perf_xfile example on an STM32F746IGT6 evaluation board equipped with an SD card.

The perf_xfile example demonstrates how to use external storage (e.g., an SD card, NAND flash, etc.) with eXtremeDB/rt.

The STM32F746IGT6-based board has the following specifications:

As shown, the board’s resources are relatively constrained, making it representative of a mid-range target in the embedded systems landscape.

Note: Development for STM32 microcontrollers is typically performed using STM32CubeIDE.

Building the Project

To build and run the perf_xfile example, follow these steps:

  1. Create a new empty project in STM32CubeIDE for the STM32F746IGTx target.

  2. Use STM32CubeMX to generate a default configuration for this target.

  3. In the configuration:

    • Enable UART (required to view example output via serial console).
    • Set the system clock (SYSCLK) to 200 MHz.

  4. Enable the SPI peripheral (or peripherals, if needed) and ensure the APB2 peripheral clock is set to 100 MHz. In the QSPI bus settings, specify the following parameters:

    • QuadSPI mode: Bank1 with Quad SPI Lined
    • Clock Prescaler: 2
    • Fifo Threshold: 1
    • Sample Shifting: Sample Shifting Half Cycle
    • Flash Size: 8
    • Chip Select High Time: 8 Cycles
    • Clock Mode: Low
    • FlashID: Flash ID 1
    • Dual Flash: Disabled
  5. In the project’s linker script (.ld file), configure the heap and stack sizes as follows. Database memory will be allocated dynamically via malloc():

        _Min_Heap_Size = 0x40000; /* 256 KB heap */
        _Min_Stack_Size = 0x1000; /* 4 KB stack */
    
  6. After saving the configuration and generating the startup code, verify that the basic project builds and runs correctly on the target hardware.

  7. In the eXtremeDB/rt package, generate the database schema code for the perf_xfile example:

        cd eXtremeDB_rt/samples/perf_xfile
        ../../host/bin/mcocomp -x32 schema.mco
    
  8. Add the following files from the eXtremeDB/rt package to your project source tree. This includes the eXtremeDB/rt core, the MURSIW transaction manager, persistent storage support, and MX35LFxGE4AD flash driver:

        ./include/mcoewslite.h
        ./include/mcoflashsim.h
        ./include/mco.h
        ./include/mco.hpp
        ./include/mconet.h
        ./include/mcoquad.h
        ./include/mcorestrt.h
        ./include/mcosmint.h
        ./include/mcosmp.h
        ./include/mcospec.h
        ./include/mcossl.h
        ./include/mcostatrt.h
        ./include/mcotargt.h
        ./include/mcotime.h
        ./include/mcotrace.h
        ./include/mcouda.h
        ./include/mcovers.h
        ./include/mcowrap.h
        ./samples/perf_xflash/main.c
        ./samples/perf_xflash/perf.c
        ./samples/perf_xflahh/perf.h
        ./samples/perf_xflash/schema.mco
        ./target/crypt/mcocryptstub.c
        ./target/mcolib/mcoabst.c
        ./target/mcolib/mcoabst.h
        ./target/mcolib/mcoamp.c
        ./target/mcolib/mcoamp.h
        ./target/mcolib/mcoautoid.c
        ./target/mcolib/mcoautoid.h
        ./target/mcolib/mcobmap.h
        ./target/mcolib/mcobse.h
        ./target/mcolib/mcobtree.c
        ./target/mcolib/mcocfg.h
        ./target/mcolib/mcocmpkt.c
        ./target/mcolib/mcocobj.c
        ./target/mcolib/mcocobj.h
        ./target/mcolib/mcoconn.c
        ./target/mcolib/mcoconn.h
        ./target/mcolib/mcoconst.h
        ./target/mcolib/mcocont.c
        ./target/mcolib/mcocryptmem.c
        ./target/mcolib/mcocryptmem.h
        ./target/mcolib/mcocsr.c
        ./target/mcolib/mcocsr.h
        ./target/mcolib/mcodb.c
        ./target/mcolib/mcodb.h
        ./target/mcolib/mcodict.c
        ./target/mcolib/mcodict.h
        ./target/mcolib/mcodiskbtree.h
        ./target/mcolib/mcodisk.h
        ./target/mcolib/mcodup.c
        ./target/mcolib/mcoerr.h
        ./target/mcolib/mcoevasy.c
        ./target/mcolib/mcoevasy.h
        ./target/mcolib/mcoevsyn.c
        ./target/mcolib/mcoevsyn.h
        ./target/mcolib/mcohash.c
        ./target/mcolib/mcoindex.c
        ./target/mcolib/mcoindex.h
        ./target/mcolib/mcomd.c
        ./target/mcolib/mcomembtree.c
        ./target/mcolib/mcomembtree.h
        ./target/mcolib/mcomem.h
        ./target/mcolib/mcoobj.c
        ./target/mcolib/mcoobj.h
        ./target/mcolib/mcoorder.c
        ./target/mcolib/mcopage.c
        ./target/mcolib/mcopmbuf.c
        ./target/mcolib/mcopmbuf.h
        ./target/mcolib/mcoproto.h
        ./target/mcolib/mcorec.c
        ./target/mcolib/mcortmt.c
        ./target/mcolib/mcortree_core.c
        ./target/mcolib/mcortreeu.c
        ./target/mcolib/mcortreeu.h
        ./target/mcolib/mcortst.c
        ./target/mcolib/mcoseri.h
        ./target/mcolib/mcoshm0.c
        ./target/mcolib/mcoshm.h
        ./target/mcolib/mcoshmu.c
        ./target/mcolib/mcostat.c
        ./target/mcolib/mcostatimpl.h
        ./target/mcolib/mcosys.h
        ./target/mcolib/mcothash.c
        ./target/mcolib/mcotmgr.h
        ./target/mcolib/mcotrans.c
        ./target/mcolib/mcotrans.h
        ./target/mcolib/mcowarr.c
        ./target/mcolib/mcowev.c
        ./target/mcolib/mcowfnd.c
        ./target/mcolib/mcowimp.c
        ./target/mcolib/mcowimp.h
        ./target/mcolib/mcowobj.c
        ./target/mcolib/mcowoid.c
        ./target/mcolib/mcowrap.c
        ./target/mcolib/mcowvec.c
        ./target/mcomd/mcomconv.c
        ./target/mcoseri/mcobse.c
        ./target/mcoseri/mcoseri.c
        ./target/mcoseri/mcosericmn.c
        ./target/mcotrace/mcoasynctrace.c
        ./target/mcotrace/mcostrerror.c
        ./target/mcotrace/mcotrace.c
        ./target/mcotrace/mcotracehandlers.c
        ./target/mcovtdsk/mcodiskbtree.c
        ./target/mcovtdsk/mcodisk.c
        ./target/mcovtdsk/mcovtdsk.c
        ./target/mcovtdsk/mcoxflash/mcoxflash.c
        ./target/misc/mcobmap.c
        ./target/misc/mcocompress.c
        ./target/misc/mcoerr.c
        ./target/misc/mcoheap.c
        ./target/misc/mcosort.c
        ./target/misc/mcosort.d
        ./target/misc/mcostrrt.c
        ./target/sal/atomic/mcosalatomic.c
        ./target/sal/flash/mx35lfxge4ad/MX35LFxGE4AD.c
        ./target/sal/flash/mx35lfxge4ad/MX35LFxGE4AD.h
        ./target/sal/flash/mx35lfxge4ad/MX35LFxGE4AD_STM32.c
        ./target/sal/latches/mcosallatches.c
        ./target/sal/mem/mcosysmem.c
        ./target/sal/smp/mcofreertos.c
        ./target/sal/smp/mconoos.c
        ./target/sal/smp/mcopool.c
        ./target/sal/sync/mcosnone.c
        ./target/sal/timer/mcosaltimer.c
        ./target/tmgr/mcotque.c
        ./target/tmgr/mcotuctrl.h
        ./target/tmgr/mursiw.c
    
  9. Add the following include paths to your project settings:

        ../eXtremeDB_rt/include
        ../eXtremeDB_rt/target/mcolib
        ../eXtremeDB_rt/target/tmgr
        ../eXtremeDB_rt/samples/common
    
  10. Add the following preprocessor definitions to your project settings:

        _ARM32
        STM32F746xx
        USE_HAL_DRIVER
        STM32F746IGTx
        STM32
        STM32F7
        MCO_TRACE_ENABLED=1
        MCO_TRACE_CONSOLE_SUPPORTED=1
        MCO_CONFIG_OVERRIDE_TRACE_FILE_ROTATION
    
  11. Modify the example code in samples/perf_xfile/main.c so that the database resides inside the MX35LFxGE4AD flash chip. During database initialization, the application must provide three devices:

    • A RAM segment for database metadata,
    • A RAM segment for the persistent device cache,
    • A persistent device bus handle targeting the NAND chip.
    The database initialization code may look like this:

        extern QSPI_HandleTypeDef hqspi; /* QSPI bus handle, defined in HAL */
        ...
        /* flash chip specs */
        #define P_RAMFLASH_PAGE_SIZE         (4096)
        #define P_RAMFLASH_PAGES_PER_BLOCK   (64)
        #define P_RAMFLASH_NUM_BLOCKS        (2048)
    
        #define P_RAMFLASH_SIZE              (P_RAMFLASH_PAGE_SIZE * P_RAMFLASH_PAGES_PER_BLOCK * P_RAMFLASH_NUM_BLOCKS)
    
        #define P_DB_CACHE_SZ        (220 * 1024)
        #define P_DB_MEM_PAGE_SZ     (128)
        #define P_DB_MODE_MASK       (0)
        #define P_DB_SIZE            (48*1024)
        #define P_DB_DISK_PAGE_SZ    P_RAMFLASH_PAGE_SIZE
        #define P_DB_DISK_MAX_SIZE   P_RAMFLASH_SIZE / 2
    
        #define P_DB_FLASH_GC_RATIO     4
        /* Flash cache params */
        #define P_DB_META_CACHE_LINES  64
        #define P_DB_META_CACHE_WAYS    4
    
        mco_device_t    devices[3] = {0};
        mco_db_params_t db_params = {0};
        void * media_context = &hqspi;
    
        devs[0].assignment = MCO_MEMORY_ASSIGN_DATABASE;
        devs[0].size       = P_DB_SIZE;
        devs[0].type       = MCO_MEMORY_CONV;
        devs[0].dev.conv.ptr = (char*)malloc(devs[0].size);
        devs[0].dev.conv.flags = 0;
    
        devs[1].assignment = MCO_MEMORY_ASSIGN_CACHE;
        devs[1].size       = P_DB_CACHE_SZ;
        devs[1].type       = MCO_MEMORY_CONV;
        devs[1].dev.conv.ptr = (char*)malloc(devs[1].size);
        devs[1].dev.conv.flags = 0;
    
        devs[2].assignment = MCO_MEMORY_ASSIGN_PERSISTENT;
        devs[2].type       = MCO_MEMORY_FLASH;
        devs[2].dev.flash.flags = MCO_FILE_OPEN_WITH_MEDIA_CTX | MCO_FILE_OPEN_TRUNCATE;
        devs[2].dev.flash.id    = 0;
        devs[2].dev.flash.media_context      = media_context;
        devs[2].dev.flash.media_context_size = sizeof(media_context);
    
        mco_db_params_init ( &db_params );
        db_params.mode_mask                 = P_DB_MODE_MASK;
        db_params.mem_page_size             = P_DB_MEM_PAGE_SZ;
        db_params.disk_page_size            = P_RAMFLASH_PAGE_SIZE;
        db_params.disk_max_database_size    = P_DB_DISK_MAX_SIZE;
        db_params.db_max_connections        = 1;
    
        db_params.meta_cache_lines          = P_DB_META_CACHE_LINES;
        db_params.meta_cache_ways           = P_DB_META_CACHE_WAYS;
        db_params.flash_gc_ratio            = P_DB_FLASH_GC_RATIO;
    
        MCO_RET rc = mco_db_open_dev(db_name, perf_get_dictionary(), devs, 3, &db_params );
    
  12. Modify the auto-generated main.c (from STM32CubeMX) to call the example entry point: sample_main().

  13. Build the project and flash it onto the STM32F746IGT6 board.

Expected Output

After successful compilation and deployment, the perf_xfile example will execute on the target device. The output will appear on the UART console as follows:

    Insert               : .................... 1000 objects: 32 milliseconds,(32 microsecs/object)
    Random search        : .................... 1000 searches: 0 milliseconds (0 microsecs/search)
    Sequential search    : .................... 1000 searches: 1 milliseconds (1 microsecs/search)
    Random update        : .................... 1000 objects: 26 milliseconds (26 microsecs/object)
    Sequential update    : .................... 1000 objects: 3 milliseconds (3 microsecs/object)
    Random delete        : .................... 1000 objects: 33 milliseconds (33 microsecs/object)