You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
4.0 KiB

cmake_minimum_required(VERSION 3.22)
#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#
# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
# Define the build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Set the project name
set(CMAKE_PROJECT_NAME PMU)
# Include toolchain file
include("cmake/gcc-arm-none-eabi.cmake")
# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Core project settings
project(${CMAKE_PROJECT_NAME})
message("Build type: " ${CMAKE_BUILD_TYPE})
# Enable CMake support for ASM and C languages
enable_language(C ASM)
set(define_syms
# USE_FULL_LL_DRIVER
USE_FULL_ASSERT=0U
PY32F030x8
USE_HAL_DRIVER
$<$<CONFIG:Debug>:DEBUG>
)
add_library(hal_lib INTERFACE)
target_include_directories(hal_lib INTERFACE
${CMAKE_SOURCE_DIR}/Core/Inc
${CMAKE_SOURCE_DIR}/Drivers/BSP
${CMAKE_SOURCE_DIR}/Drivers/CMSIS/Device/PY32F0xx/Include
${CMAKE_SOURCE_DIR}/Drivers/CMSIS/Include
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Inc
${CMAKE_SOURCE_DIR}/FreeRTOS/include
${CMAKE_SOURCE_DIR}/FreeRTOS/portable/GCC/ARM_CM0
${CMAKE_SOURCE_DIR}/User
)
target_compile_definitions(hal_lib INTERFACE ${define_syms})
set(application_src
${CMAKE_SOURCE_DIR}/User/main.c
${CMAKE_SOURCE_DIR}/User/py32f0xx_hal_msp.c
${CMAKE_SOURCE_DIR}/User/py32f0xx_it.c
${CMAKE_SOURCE_DIR}/User/py32f0xx_it.c
${CMAKE_SOURCE_DIR}/User/FreeRTOSConfig.h
${CMAKE_SOURCE_DIR}/User/system_py32f0xx.c
${CMAKE_SOURCE_DIR}/FreeRTOS/croutine.c
${CMAKE_SOURCE_DIR}/FreeRTOS/event_groups.c
${CMAKE_SOURCE_DIR}/FreeRTOS/list.c
${CMAKE_SOURCE_DIR}/FreeRTOS/queue.c
${CMAKE_SOURCE_DIR}/FreeRTOS/tasks.c
${CMAKE_SOURCE_DIR}/FreeRTOS/timers.c
${CMAKE_SOURCE_DIR}/FreeRTOS/portable/MemMang/heap_4.c
${CMAKE_SOURCE_DIR}/FreeRTOS/portable/GCC/ARM_CM0/port.c
${CMAKE_SOURCE_DIR}/startup_py32f030xx.s
)
# TODO: HAL和LL 2选1即可
set(drivers_src
${CMAKE_SOURCE_DIR}/Drivers/BSP/rgb.c
${CMAKE_SOURCE_DIR}/Drivers/BSP/usart.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_gpio.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_cortex.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_dma.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_exti.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_pwr.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_rcc_ex.c
${CMAKE_SOURCE_DIR}/Drivers/PY32F0xx_HAL_Driver/Src/py32f0xx_hal_uart.c
)
add_executable(${CMAKE_PROJECT_NAME}
${application_src}
${drivers_src}
)
# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME}
hal_lib
)
# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})
# Add the map file to the list of files to be removed with 'clean' target
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)
if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
message(ERROR "Generated code requires C11 or higher")
endif()
# 添加生成BIN和HEX文件的规则
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
COMMENT "生成BIN文件")
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.hex
COMMENT "生成HEX文件")