diff --git a/konan/platforms/zephyr/stm32f4_disco b/konan/platforms/zephyr/stm32f4_disco index 45e30ddb1cd..10b3a4fdfe9 100644 --- a/konan/platforms/zephyr/stm32f4_disco +++ b/konan/platforms/zephyr/stm32f4_disco @@ -34,3 +34,9 @@ dependencies.osx-zephyr_stm32f4_disco = \ gcc-arm-none-eabi-7-2017-q4-major-mac \ clang-llvm-5.0.0-darwin-macos \ target-sysroot-2-wasm + +targetToolchain.mingw-zephyr_stm32f4_disco = gcc-arm-none-eabi-7-2017-q4-major-win32/arm-none-eabi +dependencies.mingw-zephyr_stm32f4_disco = \ + msys2-mingw-w64-x86_64-gcc-7.2.0-clang-llvm-5.0.0-windows-x86-64 \ + gcc-arm-none-eabi-7-2017-q4-major-win32 \ + target-sysroot-2-wasm diff --git a/samples/zephyr/CMakeLists.txt b/samples/zephyr/CMakeLists.txt index 2d178c91749..eafd56496ea 100644 --- a/samples/zephyr/CMakeLists.txt +++ b/samples/zephyr/CMakeLists.txt @@ -15,5 +15,7 @@ set_source_files_properties(program.o PROPERTIES EXTERNAL_OBJECT true GENERATED add_custom_command( OUTPUT program.o - COMMAND cp kotlin/program.o program.o + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/kotlin/program.o + ${CMAKE_BINARY_DIR}/program.o ) diff --git a/samples/zephyr/build.bat b/samples/zephyr/build.bat new file mode 100644 index 00000000000..bc47682a4b8 --- /dev/null +++ b/samples/zephyr/build.bat @@ -0,0 +1,55 @@ +@echo off +setlocal + +set BOARD=stm32f4_disco +set ZEPHYR_BASE=%userprofile%\zephyr +set TOOLCHAIN=gcc-arm-none-eabi-7-2017-q4-major-win32 + +set DIR=%~dp0 +set KONAN_USER_DIR=%userprofile%/.konan +set KONAN_DEPS=%KONAN_USER_DIR%/dependencies +set GCC_ARM=%KONAN_DEPS%/%TOOLCHAIN% +set ZEPHYR_TOOLCHAIN_VARIANT=gccarmemb +set GCCARMEMB_TOOLCHAIN_PATH=%GCC_ARM% + +if defined KONAN_HOME ( + set "PATH=%KONAN_HOME%\bin;%PATH%" +) else ( + set "PATH=%DIR%..\..\dist\bin;%DIR%..\..\bin;%PATH%" +) + +if not exist build\ (mkdir build) +cd build + +if not exist CMakeCache.txt (cmake -GNinja -DBOARD=%BOARD% .. || exit /b) + +:: We need generated headers to be consumed by `cinterop`, +:: so we preconfigure the project with `make zephyr`. +ninja zephyr + +call %DIR%\c_interop\platforms\%BOARD%.bat + +del program.o + +mkdir %DIR%\build\kotlin + +call konanc %DIR%/src/main.kt ^ + -target zephyr_%BOARD% ^ + -r %DIR%/c_interop/platforms/build ^ + -l %BOARD% ^ + -opt -g -o %DIR%/build/kotlin/program || exit /b + +ninja || exit /b + +:: ninja flash +:: +:: For our STM32 boards the OpenOCD unable to flash the binary, +:: so we go with the following alternative utility: + +echo. +echo Now run 'ninja flash' to flash the .bin to the card. +echo. +echo Or, if that doesn't work, like, for example if you have an stm32f4-disco, +echo run the following command: +echo st-flash --reset write build/zephyr/zephyr.bin 0x08000000 +echo. diff --git a/samples/zephyr/c_interop/platforms/stm32f4_disco.bat b/samples/zephyr/c_interop/platforms/stm32f4_disco.bat new file mode 100644 index 00000000000..34766bbbdd1 --- /dev/null +++ b/samples/zephyr/c_interop/platforms/stm32f4_disco.bat @@ -0,0 +1,46 @@ +:: Copyright 2010-2017 JetBrains s.r.o. +:: +:: Licensed under the Apache License, Version 2.0 (the "License"); +:: you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. + +:: This is board specific. + +if "%BOARD%" == "" ( + echo This script is to be included by build.bat + exit /b +) + +:: TODO: we need a robust automated way to ask Zephyr for +:: all these $ZEPHYR_BASE based paths and the proper defines. +:: TODO: The D flag in `-copt -Dxxx` sequence is interpreted to be a jvm property, +:: so we workaround the using -Xclang. + +call cinterop -def %DIR%/c_interop/platforms/%BOARD%.def ^ + -pkg platform.zephyr.%BOARD% ^ + -copt "-Xclang -DSTM32F407xx" ^ + -copt -I%ZEPHYR_BASE%/kernel/include ^ + -copt -I%ZEPHYR_BASE%/arch/arm/include ^ + -copt -I%ZEPHYR_BASE%/arch/arm/soc/st_stm32/stm32f4 ^ + -copt -I%ZEPHYR_BASE%/arch/arm/soc/st_stm32/stm32f4/include ^ + -copt -I%ZEPHYR_BASE%/arch/arm/soc/st_stm32/include ^ + -copt -I%ZEPHYR_BASE%/boards/arm/%BOARD% ^ + -copt -I%ZEPHYR_BASE%/include ^ + -copt -I%ZEPHYR_BASE%/include/drivers ^ + -copt -I%ZEPHYR_BASE%/ext/hal/cmsis/Include ^ + -copt -I%ZEPHYR_BASE%/ext/hal/st/stm32cube/stm32f4xx/soc ^ + -copt -I%ZEPHYR_BASE%/ext/hal/st/stm32cube/stm32f4xx/drivers/include ^ + -copt -I%ZEPHYR_BASE%/ext/hal/st/stm32cube/stm32f4xx/drivers/include/Legacy ^ + -copt -I%ZEPHYR_BASE%/drivers ^ + -copt -I%DIR%/build/zephyr/include/generated ^ + -copt -I%DIR%/build/zephyr/include/generated/syscalls ^ + -o %DIR%/c_interop/platforms/build/%BOARD% ^ + -target zephyr_%BOARD% || exit /b diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt index eba31ef992d..a89ef651e63 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanTarget.kt @@ -164,7 +164,7 @@ open class HostManager(protected val distribution: Distribution = Distribution() KonanTarget.MINGW -> listOf( KonanTarget.MINGW, KonanTarget.WASM32 - ) + ) + zephyrSubtargets KonanTarget.MACBOOK -> listOf( KonanTarget.MACBOOK, KonanTarget.IPHONE,