From 9207a6f682538d21019cedbc22cbc11875f90c77 Mon Sep 17 00:00:00 2001 From: Guillaume beuzeboc Date: Tue, 30 Apr 2019 19:41:06 +0200 Subject: [PATCH] feat(stm32): add stm32 support for haricot this feature also involve changes in the haricot usage --- src/haricot/cmake/TopLevelCMake.txt | 5 ++- src/haricot/cmake/stm32/stm32l4xx.cmake | 17 ++++++++ src/haricot/haricot | 54 ++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/haricot/cmake/stm32/stm32l4xx.cmake diff --git a/src/haricot/cmake/TopLevelCMake.txt b/src/haricot/cmake/TopLevelCMake.txt index 9d8bfd3..9bf7945 100644 --- a/src/haricot/cmake/TopLevelCMake.txt +++ b/src/haricot/cmake/TopLevelCMake.txt @@ -6,7 +6,10 @@ execute_process(COMMAND bash -c ${cmd} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} RESULT_VARIABLE result OUTPUT_VARIABLE ORIGIN) - +# By default build shared lib +if(NOT DEFINED BUILD_SHARED_LIBS) + set(BUILD_SHARED_LIBS ON) # by default shared is on and will be set to OFF if we do arm stuff +endif() include(${ORIGIN}/customMacro.cmake) include(${ORIGIN}/python.cmake) set(ROOT_DIR "${CMAKE_SOURCE_DIR}") diff --git a/src/haricot/cmake/stm32/stm32l4xx.cmake b/src/haricot/cmake/stm32/stm32l4xx.cmake new file mode 100644 index 0000000..6aad6f1 --- /dev/null +++ b/src/haricot/cmake/stm32/stm32l4xx.cmake @@ -0,0 +1,17 @@ +if (NOT DEFINED ENV{CUBE}) + message(FATAL_ERROR "CUBE environment variable was not defined!") +endif() + +set(CUBE_HOME "$ENV{CUBE}" CACHE INTERNAL "Copied from environment variable") + +SET (CUBE_ROOT "${CUBE_HOME}/Repository/STM32Cube_FW_L4_V1.14.0") + +SET (LINKER_SCRIPT "${CUBE_ROOT}/Projects/NUCLEO-L476RG/Templates/SW4STM32/STM32L476RG_NUCLEO/STM32L476RGTx_FLASH.ld") + +SET (CMAKE_SYSTEM_NAME Generic) +SET (CMAKE_SYSTEM_PROCESSOR arm) + + +SET(CMAKE_CXX_FLAGS "-mcpu=cortex-m4 -std=c++11 -fno-rtti -fno-exceptions -Wall -fdata-sections -ffunction-sections -MD -Wall" CACHE INTERNAL "cxx compiler flags") + +SET (CMAKE_EXE_LINKER_FLAGS "-T ${LINKER_SCRIPT} -specs=nosys.specs -Wl,--gc-sections" CACHE INTERNAL "exe link flags") diff --git a/src/haricot/haricot b/src/haricot/haricot index b63a71e..6355d30 100755 --- a/src/haricot/haricot +++ b/src/haricot/haricot @@ -1,6 +1,58 @@ +#!/bin/bash set -e DIR=$(dirname ${0}) +SL_PATH=$( dirname $(realpath ${0}) ) + +USAGE="$(basename "$0"): Haricot build system + +where: + clean -- clean build & install directory + -s|--stm32 toolchain -- Cross-compile using the provided toolchain ex: stm32l4 + -h|--help -- print this" + +function clean_directories { + echo "Deleting install directory and build directory content" + rm -Rf ${DIR}/install + rm -Rf ${DIR}/build/* + echo "Cleaned" +} + +function stm32_compiler { + CMAKE_COMPILER_ARGS="-DBUILD_SHARED_LIBS:BOOL=OFF -DCMAKE_CXX_COMPILER=arm-none-eabi-g++" + CMAKE_COMPILER_ARGS="${CMAKE_COMPILER_ARGS} -DCMAKE_C_COMPILER=arm-none-eabi-gcc " +} + +function stm32_toolchain { + CMAKE_TOOLCHAIN_ARGS="-DCMAKE_TOOLCHAIN_FILE=${SL_PATH}/cmake/stm32/${STM32_TO_USE}.cmake" +} + +USE_STM32=false +CMAKE_COMPILER_ARGS="" +CMAKE_TOOLCHAIN_ARGS="" +STM32_TO_USE="" +while [[ $# -gt 0 ]] +do + case "$1" in + -s|--stm32) + USE_STM32=true + STM32_TO_USE=$2 + stm32_compiler + stm32_toolchain + shift + shift + ;; + clean) + clean_directories + exit 1 + ;; + -h|--help) + echo "$USAGE" + exit 1 + ;; + esac +done + cd ${DIR}/build -cmake -GNinja .. +cmake ${CMAKE_COMPILER_ARGS} ${CMAKE_TOOLCHAIN_ARGS} -GNinja .. ninja cd -