C

Qt Quick Ultralite fileloading Example

cmake_minimum_required (VERSION 3.21.1)

project(fileloading VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::Core)
    find_package(Qul)
endif()

qul_add_target(fileloading QML_PROJECT mcu_fileloading.qmlproject os/${QUL_OS_LOWERCASE}/main.cpp)

if (QUL_PLATFORM STREQUAL "qt" OR (CMAKE_CROSSCOMPILING AND QUL_OS STREQUAL "linux"))
    target_sources(fileloading PRIVATE posix/board_config.cpp)
    target_sources(fileloading PRIVATE posix/posixfilesystem.cpp)
    target_compile_features(fileloading PRIVATE cxx_std_17)

    target_include_directories(fileloading PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

    # On Linux / desktop the files by default need to be available next
    # to the built binary on the filesystem
    add_custom_command(
            TARGET fileloading POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_directory
                    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/fileloading.dir/resources/logos
                    $<TARGET_FILE_DIR:${PROJECT_NAME}>/logos)
elseif(CMAKE_CROSSCOMPILING)
    if(QUL_PLATFORM MATCHES "^stm32f469i" OR QUL_PLATFORM MATCHES "^stm32f769i")
        target_sources(fileloading PRIVATE
            3rdparty/FatFs/src/diskio.c
            3rdparty/FatFs/src/ff.c
            3rdparty/FatFs/src/ff_gen_drv.c
            3rdparty/FatFs/src/option/unicode.c
            3rdparty/FatFs/src/sd_diskio.c
            stm/board_config.cpp)

        if (QUL_PLATFORM MATCHES "^stm32f469i")
            target_sources(fileloading PRIVATE
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_sdmmc.c
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_sd.c
                ${QUL_BOARD_SDK_DIR}/Drivers/BSP/STM32469I-Discovery/stm32469i_discovery_sd.c)

        else()
            target_sources(fileloading PRIVATE
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_sdmmc.c
                ${QUL_BOARD_SDK_DIR}/Drivers/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sd.c
                ${QUL_BOARD_SDK_DIR}/Drivers/BSP/STM32F769I-Discovery/stm32f769i_discovery_sd.c)
        endif()

        if(NOT IAR)
            # Required for SDK code to build
            target_compile_options(fileloading PRIVATE
                -Wno-unused-parameter
            )
        endif()

        target_include_directories(fileloading PRIVATE 3rdparty/FatFs/src)
        target_compile_definitions(fileloading PRIVATE FF_FS_READONLY)

        target_link_libraries(fileloading PRIVATE Qul::PlatformBSPConfig)
    elseif(QUL_PLATFORM MATCHES "^mimxrt")
        set(NXP_BOARD_CORE_DIR "")
        if (QUL_PLATFORM MATCHES "^mimxrt1050")
            set(NXP_BOARD_DRIVER_DIR MIMXRT1052)
        elseif (QUL_PLATFORM MATCHES "^mimxrt1060")
            set(NXP_BOARD_DRIVER_DIR MIMXRT1062)
        elseif (QUL_PLATFORM MATCHES "^mimxrt1064")
            set(NXP_BOARD_DRIVER_DIR MIMXRT1064)
        elseif (QUL_PLATFORM MATCHES "^mimxrt1170")
            set(NXP_BOARD_DRIVER_DIR MIMXRT1176)
            set(NXP_BOARD_CORE_DIR cm7)
        else()
            message(FATAL_ERROR "Unsupported NXP board")
        endif()

        if (QUL_OS MATCHES "FreeRTOS")
            if (QUL_PLATFORM MATCHES "^mimxrt10")
                # mimxrt1050-evk and mimxrt1064-evk
                qul_override_freertos_heap_size(fileloading "472 * 1024")
            endif()
        endif()

        target_sources(fileloading PRIVATE
            3rdparty/FatFs/src/diskio.c
            3rdparty/FatFs/src/ff.c
            3rdparty/FatFs/src/ff_gen_drv.c
            3rdparty/FatFs/src/option/unicode.c
            3rdparty/NXP/${NXP_BOARD_DRIVER_DIR}/sdmmc_config.c
            # We have to use a modified version of fsl_adapter_gpio.c to comment out the
            # GPIO1_Combined_0_15_IRQHandler() handler, which otherwise conflicts with the one in platform_irq.c
            3rdparty/NXP/fsl_adapter_igpio.c
            ${QUL_BOARD_SDK_DIR}/devices/${NXP_BOARD_DRIVER_DIR}/drivers/fsl_usdhc.c
            ${QUL_BOARD_SDK_DIR}/devices/${NXP_BOARD_DRIVER_DIR}/drivers/${NXP_BOARD_CORE_DIR}/fsl_cache.c
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/common/fsl_sdmmc_common.c
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/host/usdhc/non_blocking/fsl_sdmmc_host.c
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/osa/fsl_sdmmc_osa.c
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/sd/fsl_sd.c
            nxp/board_config.cpp)

        if (QUL_OS STREQUAL "FreeRTOS")
            target_sources(fileloading PRIVATE ${QUL_BOARD_SDK_DIR}/components/osa/fsl_os_abstraction_free_rtos.c)
        else()
            target_sources(fileloading PRIVATE ${QUL_BOARD_SDK_DIR}/components/osa/fsl_os_abstraction_bm.c)
        endif()

        if(NOT IAR)
            # Required for SDK code to build
            target_compile_options(fileloading PRIVATE
                -Wno-unused-parameter
                -Wno-unused-variable
                )
        endif()

        target_include_directories(fileloading PRIVATE
            3rdparty/FatFs/src
            3rdparty/NXP/${NXP_BOARD_DRIVER_DIR}
            ${QUL_BOARD_SDK_DIR}/components/gpio
            ${QUL_BOARD_SDK_DIR}/components/lists
            ${QUL_BOARD_SDK_DIR}/components/osa
            ${QUL_BOARD_SDK_DIR}/devices/${NXP_BOARD_DRIVER_DIR}/drivers/${NXP_BOARD_CORE_DIR}
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/common
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/host/usdhc/
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/osa
            ${QUL_BOARD_SDK_DIR}/middleware/sdmmc/sd)

        target_compile_definitions(fileloading PRIVATE FF_FS_READONLY SD_ENABLED)

        target_link_libraries(fileloading PRIVATE Qul::PlatformBSPConfig)
    else()
        message(FATAL_ERROR "Unsupported platform")
    endif()
endif()

app_target_setup_os(fileloading)