Skip to content

Commit

Permalink
feat(stm32): add stm32 support for haricot
Browse files Browse the repository at this point in the history
this feature also involve changes in the haricot usage
  • Loading branch information
Guillaumebeuzeboc committed May 6, 2019
1 parent a2e7294 commit 9207a6f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/haricot/cmake/TopLevelCMake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
17 changes: 17 additions & 0 deletions src/haricot/cmake/stm32/stm32l4xx.cmake
Original file line number Diff line number Diff line change
@@ -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")
54 changes: 53 additions & 1 deletion src/haricot/haricot
Original file line number Diff line number Diff line change
@@ -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 -

0 comments on commit 9207a6f

Please sign in to comment.