# This is a CMake example for STM32F429ZI hardware on Nucleof429zi board # using the ARM GCC compiler and STM32F4xx_StdPeriph_Driver library. # # Board Nucleof429zi # MCU STM32F429ZI # CPU Cortex-M4 # Clock 180MHz # RAM 256Kb # Flash 2Mb # # To build this project you need to install: # - ARM GCC compiler # - CMake # # To build this project you need to run: # - cmake -S . -B build # - cmake --build build # # To flash this project you need to run: # - st-flash write build/bacnet-mstp.hex 0x8000000 # # To debug this project you need to run: # - arm-none-eabi-gdb -q build/bacnet-mstp.out # - (gdb) target extended-remote localhost:3333 # - (gdb) monitor reset halt # - (gdb) load # - (gdb) monitor reset halt # - (gdb) monitor reset init # - (gdb) monitor reset run # - (gdb) monitor reset exit # - (gdb) quit # # You can also use VSCode with Cortex-Debug extension # # This example was tested with: # - ARM GCC 10.3.1 # - CMake 3.22.1 # - STM32F4xx_StdPeriph_Driver V1.0.0 # - BACnet Stack V1.3.2 # cmake_minimum_required(VERSION 3.20) # Cross compilers and tools set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_C_COMPILER arm-none-eabi-gcc) set(CMAKE_CXX_COMPILER arm-none-eabi-g++) set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) set(CMAKE_AR arm-none-eabi-ar) set(CMAKE_OBJCOPY arm-none-eabi-objcopy) set(CMAKE_OBJDUMP arm-none-eabi-objdump) set(SIZE arm-none-eabi-size) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) project(bacnet-mstp) enable_language(C ASM) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON) # Specific ARM microcontroller compiler and linker settings add_compile_options(-mcpu=cortex-m4) add_compile_options(-mthumb -mthumb-interwork) add_compile_options(-ffunction-sections -fdata-sections) add_compile_options(-fno-common -fmessage-length=0) add_link_options(-mcpu=cortex-m4) add_link_options(-mthumb -mthumb-interwork) add_link_options(-Wl,-gc-sections,--print-memory-usage) # Enable hardware FPU add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING) # Build types if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") message(STATUS "Maximum optimization for speed") add_compile_options(-Ofast) elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") message(STATUS "Maximum optimization for speed, debug info included") add_compile_options(-Ofast -g) elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") message(STATUS "Maximum optimization for size") add_compile_options(-Os) else () message(STATUS "Minimal optimization, debug info included") add_compile_definitions(DEBUG) add_compile_options(-Og -g3) endif () # eliminate the deprecated function warnings option(BACNET_STACK_DEPRECATED_DISABLE "Disable deprecation compile warnings" ON) if(BACNET_STACK_DEPRECATED_DISABLE) add_definitions(-DBACNET_STACK_DEPRECATED_DISABLE) endif() set(LIBRARY_BACNET_INC "../../src") set(LIBRARY_BACNET_CORE "../../src/bacnet") set(LIBRARY_BACNET_BASIC "../../src/bacnet/basic") set(LIBRARY_STM32_SRC "./STM32F4xx_StdPeriph_Driver/src") set(LIBRARY_STM32_INC "./STM32F4xx_StdPeriph_Driver/inc") set(LIBRARY_CMSIS_INC "./CMSIS") set(LIBRARY_CMSIS_GCC_INC "./CMSIS/gcc_ride7") set(BACNET_PROJECT_SOURCE ${LIBRARY_STM32_SRC}/stm32f4xx_adc.c ${LIBRARY_STM32_SRC}/stm32f4xx_can.c ${LIBRARY_STM32_SRC}/stm32f4xx_crc.c ${LIBRARY_STM32_SRC}/stm32f4xx_dac.c ${LIBRARY_STM32_SRC}/stm32f4xx_dbgmcu.c ${LIBRARY_STM32_SRC}/stm32f4xx_dcmi.c ${LIBRARY_STM32_SRC}/stm32f4xx_dma.c ${LIBRARY_STM32_SRC}/stm32f4xx_exti.c ${LIBRARY_STM32_SRC}/stm32f4xx_flash.c ${LIBRARY_STM32_SRC}/stm32f4xx_fsmc.c ${LIBRARY_STM32_SRC}/stm32f4xx_gpio.c ${LIBRARY_STM32_SRC}/stm32f4xx_i2c.c ${LIBRARY_STM32_SRC}/stm32f4xx_iwdg.c ${LIBRARY_STM32_SRC}/stm32f4xx_misc.c ${LIBRARY_STM32_SRC}/stm32f4xx_pwr.c ${LIBRARY_STM32_SRC}/stm32f4xx_rcc.c ${LIBRARY_STM32_SRC}/stm32f4xx_rng.c ${LIBRARY_STM32_SRC}/stm32f4xx_rtc.c ${LIBRARY_STM32_SRC}/stm32f4xx_sdio.c ${LIBRARY_STM32_SRC}/stm32f4xx_spi.c ${LIBRARY_STM32_SRC}/stm32f4xx_syscfg.c ${LIBRARY_STM32_SRC}/stm32f4xx_tim.c ${LIBRARY_STM32_SRC}/stm32f4xx_usart.c ${LIBRARY_STM32_SRC}/stm32f4xx_wwdg.c ${LIBRARY_STM32_SRC}/syscalls.c ${CMAKE_SOURCE_DIR}/stm32f4xx_conf.h ${CMAKE_SOURCE_DIR}/main.c ${CMAKE_SOURCE_DIR}/stm32f4xx_it.c ${CMAKE_SOURCE_DIR}/stm32f4xx_it.h ${CMAKE_SOURCE_DIR}/system_stm32f4xx.c ${CMAKE_SOURCE_DIR}/system_stm32f4xx.h ${CMAKE_SOURCE_DIR}/bacnet.c ${CMAKE_SOURCE_DIR}/led.c ${CMAKE_SOURCE_DIR}/mstimer-init.c ${CMAKE_SOURCE_DIR}/rs485.c ${CMAKE_SOURCE_DIR}/device.c ${CMAKE_SOURCE_DIR}/netport.c ${LIBRARY_BACNET_BASIC}/service/h_dcc.c ${LIBRARY_BACNET_BASIC}/service/h_apdu.c ${LIBRARY_BACNET_BASIC}/npdu/h_npdu.c ${LIBRARY_BACNET_BASIC}/service/h_rd.c ${LIBRARY_BACNET_BASIC}/service/h_rp.c ${LIBRARY_BACNET_BASIC}/service/h_rpm.c ${LIBRARY_BACNET_BASIC}/service/h_whohas.c ${LIBRARY_BACNET_BASIC}/service/h_whois.c ${LIBRARY_BACNET_BASIC}/service/h_wp.c ${LIBRARY_BACNET_BASIC}/service/h_noserv.c ${LIBRARY_BACNET_BASIC}/service/s_iam.c ${LIBRARY_BACNET_BASIC}/service/s_ihave.c ${LIBRARY_BACNET_BASIC}/tsm/tsm.c ${LIBRARY_BACNET_BASIC}/sys/debug.c ${LIBRARY_BACNET_BASIC}/sys/ringbuf.c ${LIBRARY_BACNET_BASIC}/sys/fifo.c ${LIBRARY_BACNET_BASIC}/sys/mstimer.c ${LIBRARY_BACNET_CORE}/abort.c ${LIBRARY_BACNET_CORE}/bacaddr.c ${LIBRARY_BACNET_CORE}/bacapp.c ${LIBRARY_BACNET_CORE}/bacdcode.c ${LIBRARY_BACNET_CORE}/bacdest.c ${LIBRARY_BACNET_CORE}/bacdevobjpropref.c ${LIBRARY_BACNET_CORE}/bacerror.c ${LIBRARY_BACNET_CORE}/bacint.c ${LIBRARY_BACNET_CORE}/bacreal.c ${LIBRARY_BACNET_CORE}/bacstr.c ${LIBRARY_BACNET_CORE}/datalink/cobs.c ${LIBRARY_BACNET_CORE}/datalink/crc.c ${LIBRARY_BACNET_CORE}/datalink/dlmstp.c ${LIBRARY_BACNET_CORE}/datalink/mstp.c ${LIBRARY_BACNET_CORE}/datalink/mstptext.c ${LIBRARY_BACNET_CORE}/datetime.c ${LIBRARY_BACNET_CORE}/dcc.c ${LIBRARY_BACNET_CORE}/indtext.c ${LIBRARY_BACNET_CORE}/iam.c ${LIBRARY_BACNET_CORE}/ihave.c ${LIBRARY_BACNET_CORE}/hostnport.c ${LIBRARY_BACNET_CORE}/lighting.c ${LIBRARY_BACNET_CORE}/memcopy.c ${LIBRARY_BACNET_CORE}/npdu.c ${LIBRARY_BACNET_CORE}/proplist.c ${LIBRARY_BACNET_CORE}/rd.c ${LIBRARY_BACNET_CORE}/reject.c ${LIBRARY_BACNET_CORE}/rp.c ${LIBRARY_BACNET_CORE}/rpm.c ${LIBRARY_BACNET_CORE}/timestamp.c ${LIBRARY_BACNET_CORE}/weeklyschedule.c ${LIBRARY_BACNET_CORE}/dailyschedule.c ${LIBRARY_BACNET_CORE}/calendar_entry.c ${LIBRARY_BACNET_CORE}/special_event.c ${LIBRARY_BACNET_CORE}/bactimevalue.c ${LIBRARY_BACNET_CORE}/whohas.c ${LIBRARY_BACNET_CORE}/whois.c ${LIBRARY_BACNET_CORE}/wp.c CMSIS/gcc_ride7/startup_stm32f4xx.s CMSIS/stm32f4xx.h ) set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/stm32f4xx.ld) set(EXECUTABLE ${PROJECT_NAME}.elf) add_executable(${EXECUTABLE} ${BACNET_PROJECT_SOURCE}) target_compile_definitions(${EXECUTABLE} PRIVATE -DNDEBUG -DUSE_STDPERIPH_DRIVER -DSTM32F4XX -DBACDL_MSTP -DMAX_APDU=480 -DBIG_ENDIAN=0 -DMAX_TSM_TRANSACTIONS=1 -DBACAPP_MINIMAL ) # inhibit pedantic warnings target_compile_options(${EXECUTABLE} PRIVATE -Wall -Wextra -pedantic -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default # don't warn about conversion, sign, compares, long long and attributes # since they are common in embedded -Wno-sign-conversion -Wno-conversion -Wno-sign-compare -Wno-long-long -Wno-attributes # don't warn about implicit fallthrough since it is common in network protocols -Wno-implicit-fallthrough # the SDK does not meet coding guidelines -Wno-comment -Wno-missing-braces -Wno-unused-variable -Wno-unused-parameter -Wno-char-subscripts ) target_include_directories(${EXECUTABLE} PRIVATE ${CMAKE_SOURCE_DIR} ${LIBRARY_CMSIS_INC} ${LIBRARY_CMSIS_GCC_INC} ${LIBRARY_STM32_INC} ${LIBRARY_BACNET_INC} ) target_link_options(${EXECUTABLE} PRIVATE -T${LINKER_SCRIPT} -specs=nano.specs -lm -lnosys -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections ) # Print executable size add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-size ${EXECUTABLE} ) # Create hex file add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin )