Commit 9180f051 authored by Bc. Petr Elexa's avatar Bc. Petr Elexa

panel: Add CMake support

parent a03cd57a
cmake_minimum_required(VERSION 3.11)
# Default type is release
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
project(acs-panel VERSION 1.0 LANGUAGES C)
set(CMAKE_EXECUTABLE_SUFFIX ".axf")
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}")
# LPCOpen chip library
add_library(lpc_chip_11cxx STATIC IMPORTED)
target_include_directories(lpc_chip_11cxx INTERFACE
lib/include
)
set_target_properties(lpc_chip_11cxx
PROPERTIES
IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/lib/Debug/liblpc_chip_11cxx.a"
IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/lib/Release/liblpc_chip_11cxx.a"
)
# Firmware
add_executable(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PRIVATE
app
bsp
bsp/board
bsp/can
bsp/weigand
freertos/include
)
target_sources(${PROJECT_NAME} PRIVATE
app/crp.c
app/start.c
app/static_cache.c
app/terminal.c
app/terminal_config.c
bsp/brownout.c
bsp/reader.c
bsp/storage.c
bsp/watchdog.c
bsp/board/board.c
bsp/board/board_sysinit.c
bsp/board/cr_startup_lpc11xx.c
bsp/board/sysinit.c
bsp/can/can_term_driver.c
bsp/weigand/weigand.c
freertos/croutine.c
freertos/event_groups.c
freertos/heap_1.c
freertos/list.c
freertos/port.c
freertos/queue.c
freertos/stream_buffer.c
freertos/tasks.c
freertos/timers.c
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
CORE_M0
__USE_LPCOPEN
CR_INTEGER_PRINTF
__LPC11XX__
__NEWLIB__
)
target_compile_options(${PROJECT_NAME} PRIVATE
-std=c11
-pedantic
-Wall
-Wextra
-Wparentheses
-fno-strict-aliasing
-fno-common
-fmessage-length=0
-fno-builtin
-ffunction-sections
-fdata-sections
-fsingle-precision-constant
-fstack-usage
)
target_link_libraries(${PROJECT_NAME}
lpc_chip_11cxx
)
if(${CMAKE_BUILD_TYPE} STREQUAL Release)
target_compile_definitions(${PROJECT_NAME} PRIVATE
RELEASE
NDEBUG
__CODE_RED
)
target_compile_options(${PROJECT_NAME} PRIVATE
-O3
-g
)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE
DEBUG
)
target_compile_options(${PROJECT_NAME} PRIVATE
-O0
-g3
)
endif()
linker_script_add(${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}_${CMAKE_BUILD_TYPE}.ld")
linker_script_target_dependency(${PROJECT_NAME} "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}_${CMAKE_BUILD_TYPE}.ld")
# Post build steps
firmware_size(${PROJECT_NAME})
generate_object(${PROJECT_NAME} .bin binary)
if(${CMAKE_BUILD_TYPE} STREQUAL Release)
calculate_checksum(${PROJECT_NAME})
endif()
This is Access control system panel source code and project for MCUXpresso IDE.
Main firmware behavior setting are in app/terminal_config.h.
\ No newline at end of file
Main firmware behavior setting can be controlled in app/terminal_config.h.
To build firmware from IDE:
Import enclosed project for MCUXpresso IDE 10.3.1.
To build fimware from command line:
Run build_release_fw.bat.
This requires CMake 3.11+ (https://cmake.org) and NXP version of ARM GCC Toolchain which can be obtained only by installing MCUXpresso IDE.
\ No newline at end of file
@echo off
cmake -G Ninja -DARM_COMPILER_PATH="C:\nxp\MCUXpressoIDE_10.3.1_2233\ide\tools\bin\arm-none-eabi-gcc.exe" -DCMAKE_TOOLCHAIN_FILE=cmake/arm-gcc-toolchain.cmake -DCMAKE_BUILD_TYPE=Release -B Release
cmake --build Release --clean-first --target all
pause
\ No newline at end of file
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from linkscript.ldt by FMCreateLinkLibraries
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 18.11.2019 0:01:44
*/
INCLUDE "acs-panel_Debug_library.ld"
INCLUDE "acs-panel_Debug_memory.ld"
ENTRY(ResetISR)
SECTIONS
{
/* MAIN TEXT SECTION */
.text : ALIGN(4)
{
FILL(0xff)
__vectors_start__ = ABSOLUTE(.) ;
KEEP(*(.isr_vector))
/* Global Section Table */
. = ALIGN(4) ;
__section_table_start = .;
__data_section_table = .;
LONG(LOADADDR(.data));
LONG( ADDR(.data));
LONG( SIZEOF(.data));
__data_section_table_end = .;
__bss_section_table = .;
LONG( ADDR(.bss));
LONG( SIZEOF(.bss));
__bss_section_table_end = .;
__section_table_end = . ;
/* End of Global Section Table */
*(.after_vectors*)
} > MFlash32
.text : ALIGN(4)
{
*(.text*)
*(.rodata .rodata.* .constdata .constdata.*)
. = ALIGN(4);
} > MFlash32
/*
* for exception handling/unwind - some Newlib functions (in common
* with C++ and STDC++) use this.
*/
.ARM.extab : ALIGN(4)
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > MFlash32
__exidx_start = .;
.ARM.exidx : ALIGN(4)
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > MFlash32
__exidx_end = .;
_etext = .;
/* MAIN DATA SECTION */
.uninit_RESERVED : ALIGN(4)
{
KEEP(*(.bss.$RESERVED*))
. = ALIGN(4) ;
_end_uninit_RESERVED = .;
} > RamLoc8
/* Main DATA section (RamLoc8) */
.data : ALIGN(4)
{
FILL(0xff)
_data = . ;
*(vtable)
*(.ramfunc*)
*(.data*)
. = ALIGN(4) ;
_edata = . ;
} > RamLoc8 AT>MFlash32
/* MAIN BSS SECTION */
.bss : ALIGN(4)
{
_bss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4) ;
_ebss = .;
PROVIDE(end = .);
} > RamLoc8
/* DEFAULT NOINIT SECTION */
.noinit (NOLOAD): ALIGN(4)
{
_noinit = .;
*(.noinit*)
. = ALIGN(4) ;
_end_noinit = .;
} > RamLoc8
/* Reserve and place Heap within memory map */
_HeapSize = 0x100;
.heap : ALIGN(4)
{
_pvHeapStart = .;
. += _HeapSize;
. = ALIGN(4);
_pvHeapLimit = .;
} > RamLoc8
_StackSize = 0x200;
/* Reserve space in memory for Stack */
.heap2stackfill :
{
. += _StackSize;
} > RamLoc8
/* Locate actual Stack in memory map */
.stack ORIGIN(RamLoc8) + LENGTH(RamLoc8) - _StackSize - 0: ALIGN(4)
{
_vStackBase = .;
. = ALIGN(4);
_vStackTop = . + _StackSize;
} > RamLoc8
/* ## Create checksum value (used in startup) ## */
PROVIDE(__valid_user_code_checksum = 0 -
(_vStackTop
+ (ResetISR + 1)
+ (( DEFINED(NMI_Handler) ? NMI_Handler : M0_NMI_Handler ) + 1)
+ (( DEFINED(HardFault_Handler) ? HardFault_Handler : M0_HardFault_Handler ) + 1)
)
);
/* Provide basic symbols giving location and size of main text
* block, including initial values of RW data sections. Note that
* these will need extending to give a complete picture with
* complex images (e.g multiple Flash banks).
*/
_image_start = LOADADDR(.text);
_image_end = LOADADDR(.data) + SIZEOF(.data);
_image_size = _image_end - _image_start;
}
\ No newline at end of file
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from library.ldt by FMCreateLinkLibraries
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 18.11.2019 0:01:44
*/
GROUP (
"libgcc.a"
"libc_nano.a"
"libm.a"
"libcr_newlib_nohost.a"
)
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from memory.ldt by FMCreateLinkMemory
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 18.11.2019 0:01:44
*/
MEMORY
{
/* Define each memory region */
MFlash32 (rx) : ORIGIN = 0x0, LENGTH = 0x8000 /* 32K bytes (alias Flash) */
RamLoc8 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8K bytes (alias RAM) */
}
/* Define a symbol for the top of each memory region */
__base_MFlash32 = 0x0 ; /* MFlash32 */
__base_Flash = 0x0 ; /* Flash */
__top_MFlash32 = 0x0 + 0x8000 ; /* 32K bytes */
__top_Flash = 0x0 + 0x8000 ; /* 32K bytes */
__base_RamLoc8 = 0x10000000 ; /* RamLoc8 */
__base_RAM = 0x10000000 ; /* RAM */
__top_RamLoc8 = 0x10000000 + 0x2000 ; /* 8K bytes */
__top_RAM = 0x10000000 + 0x2000 ; /* 8K bytes */
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from linkscript.ldt by FMCreateLinkLibraries
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 17.11.2019 18:39:25
*/
INCLUDE "acs-panel_Release_library.ld"
INCLUDE "acs-panel_Release_memory.ld"
ENTRY(ResetISR)
SECTIONS
{
/* MAIN TEXT SECTION */
.text : ALIGN(4)
{
FILL(0xff)
__vectors_start__ = ABSOLUTE(.) ;
KEEP(*(.isr_vector))
/* Global Section Table */
. = ALIGN(4) ;
__section_table_start = .;
__data_section_table = .;
LONG(LOADADDR(.data));
LONG( ADDR(.data));
LONG( SIZEOF(.data));
__data_section_table_end = .;
__bss_section_table = .;
LONG( ADDR(.bss));
LONG( SIZEOF(.bss));
__bss_section_table_end = .;
__section_table_end = . ;
/* End of Global Section Table */
*(.after_vectors*)
/* Code Read Protection data */
. = 0x000002FC ;
PROVIDE(__CRP_WORD_START__ = .) ;
KEEP(*(.crp))
PROVIDE(__CRP_WORD_END__ = .) ;
ASSERT(!(__CRP_WORD_START__ == __CRP_WORD_END__), "Linker CRP Enabled, but no CRP_WORD provided within application");
/* End of Code Read Protection */
} > MFlash32
.text : ALIGN(4)
{
*(.text*)
*(.rodata .rodata.* .constdata .constdata.*)
. = ALIGN(4);
} > MFlash32
/*
* for exception handling/unwind - some Newlib functions (in common
* with C++ and STDC++) use this.
*/
.ARM.extab : ALIGN(4)
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > MFlash32
__exidx_start = .;
.ARM.exidx : ALIGN(4)
{
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
} > MFlash32
__exidx_end = .;
_etext = .;
/* MAIN DATA SECTION */
.uninit_RESERVED : ALIGN(4)
{
KEEP(*(.bss.$RESERVED*))
. = ALIGN(4) ;
_end_uninit_RESERVED = .;
} > RamLoc8
/* Main DATA section (RamLoc8) */
.data : ALIGN(4)
{
FILL(0xff)
_data = . ;
*(vtable)
*(.ramfunc*)
*(.data*)
. = ALIGN(4) ;
_edata = . ;
} > RamLoc8 AT>MFlash32
/* MAIN BSS SECTION */
.bss : ALIGN(4)
{
_bss = .;
*(.bss*)
*(COMMON)
. = ALIGN(4) ;
_ebss = .;
PROVIDE(end = .);
} > RamLoc8
/* DEFAULT NOINIT SECTION */
.noinit (NOLOAD): ALIGN(4)
{
_noinit = .;
*(.noinit*)
. = ALIGN(4) ;
_end_noinit = .;
} > RamLoc8
/* Reserve and place Heap within memory map */
_HeapSize = 0x100;
.heap : ALIGN(4)
{
_pvHeapStart = .;
. += _HeapSize;
. = ALIGN(4);
_pvHeapLimit = .;
} > RamLoc8
_StackSize = 0x200;
/* Reserve space in memory for Stack */
.heap2stackfill :
{
. += _StackSize;
} > RamLoc8
/* Locate actual Stack in memory map */
.stack ORIGIN(RamLoc8) + LENGTH(RamLoc8) - _StackSize - 0: ALIGN(4)
{
_vStackBase = .;
. = ALIGN(4);
_vStackTop = . + _StackSize;
} > RamLoc8
/* ## Create checksum value (used in startup) ## */
PROVIDE(__valid_user_code_checksum = 0 -
(_vStackTop
+ (ResetISR + 1)
+ (( DEFINED(NMI_Handler) ? NMI_Handler : M0_NMI_Handler ) + 1)
+ (( DEFINED(HardFault_Handler) ? HardFault_Handler : M0_HardFault_Handler ) + 1)
)
);
/* Provide basic symbols giving location and size of main text
* block, including initial values of RW data sections. Note that
* these will need extending to give a complete picture with
* complex images (e.g multiple Flash banks).
*/
_image_start = LOADADDR(.text);
_image_end = LOADADDR(.data) + SIZEOF(.data);
_image_size = _image_end - _image_start;
}
\ No newline at end of file
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from library.ldt by FMCreateLinkLibraries
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 17.11.2019 18:39:25
*/
GROUP (
"libgcc.a"
"libc_nano.a"
"libm.a"
"libcr_newlib_nohost.a"
)
/*
* GENERATED FILE - DO NOT EDIT
* Copyright (c) 2008 - 2013 Code Red Technologies Ltd,
* Copyright 2015, 2018 NXP
* (c) NXP Semiconductors 2013-2019
* Generated linker script file for LPC11C24/301
* Created from memory.ldt by FMCreateLinkMemory
* Using Freemarker v2.3.23
* MCUXpresso IDE v10.3.1 [Build 2233] [2019-02-20] on 17.11.2019 18:39:25
*/
MEMORY
{
/* Define each memory region */
MFlash32 (rx) : ORIGIN = 0x0, LENGTH = 0x8000 /* 32K bytes (alias Flash) */
RamLoc8 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8K bytes (alias RAM) */
}
/* Define a symbol for the top of each memory region */
__base_MFlash32 = 0x0 ; /* MFlash32 */
__base_Flash = 0x0 ; /* Flash */
__top_MFlash32 = 0x0 + 0x8000 ; /* 32K bytes */
__top_Flash = 0x0 + 0x8000 ; /* 32K bytes */
__base_RamLoc8 = 0x10000000 ; /* RamLoc8 */
__base_RAM = 0x10000000 ; /* RAM */
__top_RamLoc8 = 0x10000000 + 0x2000 ; /* 8K bytes */
__top_RAM = 0x10000000 + 0x2000 ; /* 8K bytes */
cmake_minimum_required(VERSION 3.11)
#---------------------
# ARM GCC Toolchain for cross-compiling to LPC11C24_301
#---------------------
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
set(COMPILER_SEARCH_CMD where)
set(NINJA "${CMAKE_CURRENT_LIST_DIR}/utils/ninja.exe")
set(CHECKSUM_BIN "${CMAKE_CURRENT_LIST_DIR}/utils/checksum.exe")
set(EXE ".exe")
else()
message(FATAL_ERROR "Unsupported host system")
endif()
set(CMAKE_MAKE_PROGRAM "${NINJA}" CACHE FILEPATH "")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(TOOLCHAIN_PREFIX arm-none-eabi-)
if(NOT DEFINED ARM_COMPILER_PATH)
get_filename_component(ARM_COMPILER_PATH ${TOOLCHAIN_PREFIX}gcc${EXE} ABSOLUTE)
endif()
get_filename_component(ARM_TOOLCHAIN_DIR "${ARM_COMPILER_PATH}" DIRECTORY)
message(STATUS "Using ARM GCC toolchain:\"${ARM_TOOLCHAIN_DIR}\"")
set(CMAKE_C_COMPILER "${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}gcc${EXE}")
set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}")
set(CMAKE_CXX_COMPILER "${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}g++${EXE}")
set(CMAKE_OBJCOPY "${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}objcopy${EXE}" CACHE INTERNAL "objcopy tool")
set(CMAKE_SIZE_UTIL "${ARM_TOOLCHAIN_DIR}/${TOOLCHAIN_PREFIX}size${EXE}" CACHE INTERNAL "size tool")
set(CMAKE_SYSROOT "${ARM_TOOLCHAIN_DIR}/../arm-none-eabi")
set(CMAKE_FIND_ROOT_PATH "${ARM_TOOLCHAIN_DIR}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_EXE_LINKER_FLAGS_INIT "-nostdlib -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m0 -mthumb")
set(CMAKE_C_FLAGS_INIT "-mcpu=cortex-m0 -mthumb")
#---------------------
# Helper functions
#---------------------
# Add custom command to print firmware size in Berkley format
function(firmware_size target)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_SIZE_UTIL} -B
"${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}"
)
endfunction()
# Add a command to generate firmare in a provided format
function(generate_object target suffix type)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -v -O ${type}
"${CMAKE_CURRENT_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}" "${CMAKE_CURRENT_BINARY_DIR}/${target}${suffix}"
COMMENT "Generating binary..."
)
endfunction()
function(calculate_checksum target)
if(CHECKSUM_BIN)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CHECKSUM_BIN} -p LPC11C24_301 -d "${CMAKE_CURRENT_BINARY_DIR}/${target}.bin"
COMMENT "Calculating checksum..."
)
endif()
endfunction()
# Add custom linker script to the linker flags
function(linker_script_add target path_to_script)
target_link_options(${target} PRIVATE -T "${path_to_script}")
endfunction()
# Update a target LINK_DEPENDS property with a custom linker script.
# That allows to rebuild that target if the linker script gets changed
function(linker_script_target_dependency target path_to_script)
set_target_properties(${target} PROPERTIES LINK_DEPENDS "${path_to_script}")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=\"${target}.map\"")
endfunction()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment