Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the stm32 platform #2185

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1ef67b0
Added Stm32 platform
lhstrh Nov 7, 2023
56ed5f6
initial STM32 support works but very hard-coded
naichenzhao Nov 11, 2023
9728279
we dont need STM_main anymore
naichenzhao Nov 19, 2023
e87f1b2
should be able to copy most of generated libraaries
naichenzhao Nov 19, 2023
522db67
updated to move code out of core cmake
naichenzhao Nov 22, 2023
127d62a
fixed print
naichenzhao Dec 7, 2023
6423ee1
maybe this works?
naichenzhao Dec 18, 2023
2de5aa4
removed sdk
naichenzhao Feb 2, 2024
972470c
bump reactor
naichenzhao Jul 15, 2024
58a444c
Merge branch 'master' of github.com:lf-lang/lingua-franca into stm32_2
naichenzhao Aug 31, 2024
b9f4770
small test commit
naichenzhao Aug 31, 2024
368ffe3
updating pointers:
naichenzhao Aug 31, 2024
8876b6b
bump reactor
naichenzhao Aug 31, 2024
0be631e
slight update to code
naichenzhao Aug 31, 2024
38b2313
bump reactor again
naichenzhao Aug 31, 2024
e89b9e7
formatting
naichenzhao Sep 5, 2024
35c7437
bimp and format
naichenzhao Sep 7, 2024
4ea0ab3
bump reactor-c again
naichenzhao Sep 24, 2024
5c3939d
bump reactor
naichenzhao Oct 5, 2024
1192af1
bump reactor again
naichenzhao Oct 5, 2024
60d9eac
bump reactor and clean
naichenzhao Oct 5, 2024
9f0dd8e
Add cmake-init-include target property
erlingrj Nov 5, 2024
b8b75e2
Move STM32F4 cmake out of lfc and require the user to provide it inst…
erlingrj Nov 5, 2024
a34676f
Merge remote-tracking branch 'origin/master' into stm32_2
erlingrj Nov 5, 2024
05b449c
Merge with master and bump reactor-c
erlingrj Nov 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.lflang.FileConfig;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.FilesProperty;
import org.lflang.target.property.ProtobufsProperty;
import org.lflang.util.FileUtil;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void doClean() throws IOException {
* the generated .lf file for the federate.
*/
public void relativizePaths(FederateTargetConfig targetConfig) {
List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE)
List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, CmakeInitIncludeProperty.INSTANCE)
.forEach(
p -> {
if (targetConfig.isSet(p)) {
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.lflang.target.property.AuthProperty;
import org.lflang.target.property.BuildTypeProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.CompilerProperty;
import org.lflang.target.property.PlatformProperty;
Expand Down Expand Up @@ -142,6 +143,11 @@ CodeBuilder generateCMakeCode(

cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")");

// Add the cmake-init-include files
for (String includeFile : targetConfig.getOrDefault(CmakeInitIncludeProperty.INSTANCE)) {
cMakeCode.pr("include(\"" + Path.of(includeFile).getFileName() + "\")");
}

// Setup the project header for different platforms
switch (platformOptions.platform()) {
case ZEPHYR:
Expand Down Expand Up @@ -261,6 +267,11 @@ CodeBuilder generateCMakeCode(
cMakeCode.pr("endif()");

cMakeCode.pr("# Require C11");
switch (platformOptions.platform()) {
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
case STM32F4:
cMakeCode.pr("enable_language(C CXX ASM)");
break;
}
cMakeCode.pr("set(CMAKE_C_STANDARD 11)");
cMakeCode.pr("set(CMAKE_C_STANDARD_REQUIRED ON)");
cMakeCode.newLine();
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
// into the cmake file (and fileConfig.srcPath is the wrong directory anyway).
if (!fileConfig.srcPath.toString().contains("fed-gen")) {
// Do not convert to Unix path
arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'");
arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'");
arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'");
arguments.add("-DLF_SOURCE_DIRECTORY=" + srcPath);
arguments.add("-DLF_PACKAGE_DIRECTORY=" + rootPath);
arguments.add("-DLF_SOURCE_GEN_DIRECTORY=" + srcGenPath);
}
arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath()));

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.lflang.target.TargetConfig;
import org.lflang.target.property.BuildCommandsProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.DockerProperty;
import org.lflang.target.property.FedSetupProperty;
Expand Down Expand Up @@ -788,6 +789,15 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {
true);
}

if (targetConfig.isSet(CmakeInitIncludeProperty.INSTANCE)) {
FileUtil.copyFilesOrDirectories(
targetConfig.get(CmakeInitIncludeProperty.INSTANCE),
destination,
fileConfig,
messageReporter,
true);
}

try {
var file = targetConfig.get(FedSetupProperty.INSTANCE);
if (file != null) {
Expand Down Expand Up @@ -926,6 +936,11 @@ protected void copyTargetFiles() throws IOException {
FileUtil.copyFileFromClassPath(
"/lib/platform/zephyr/Kconfig", fileConfig.getSrcGenPath(), true);
}
case STM32F4 -> {
// Copy over STM32 library (Currently hard-coded)
FileUtil.copyFileFromClassPath(
"/lib/platform/stm32/arm-none-eabi-gcc.cmake", fileConfig.getSrcGenPath(), true);
}
case RP2040 -> {
// For the pico src-gen, copy over vscode configurations for debugging
Path vscodePath = fileConfig.getSrcGenPath().resolve(".vscode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ private String generateMainFunction() {
case RP2040 -> {
return String.join("\n", "int main(void) {", " return lf_reactor_c_main(0, NULL);", "}");
}

case STM32F4 -> {
return String.join("\n", "int main(void) {", " return lf_reactor_c_main(0, NULL);", "}");
}
default -> {
return String.join(
"\n",
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/lflang/target/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.lflang.target.property.ClockSyncModeProperty;
import org.lflang.target.property.ClockSyncOptionsProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.CompilerProperty;
import org.lflang.target.property.CoordinationOptionsProperty;
Expand Down Expand Up @@ -589,6 +590,7 @@ public void initialize(TargetConfig config) {
ClockSyncModeProperty.INSTANCE,
ClockSyncOptionsProperty.INSTANCE,
CmakeIncludeProperty.INSTANCE,
CmakeInitIncludeProperty.INSTANCE,
CompileDefinitionsProperty.INSTANCE,
CompilerProperty.INSTANCE,
CoordinationOptionsProperty.INSTANCE,
Expand All @@ -608,6 +610,7 @@ public void initialize(TargetConfig config) {
case CPP ->
config.register(
BuildTypeProperty.INSTANCE,
CmakeInitIncludeProperty.INSTANCE,
CmakeIncludeProperty.INSTANCE,
CompilerProperty.INSTANCE,
DockerProperty.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.lflang.target.property;

import java.util.List;

import org.lflang.MessageReporter;
import org.lflang.ast.ASTUtils;
import org.lflang.lf.Element;

/**
* Directive to specify cmake initialize files to be included at the very beginning of the
* generated CMakeLists.txt. Here the user can override things like the toolchain file
*/

public final class CmakeInitIncludeProperty extends FileListProperty {

/** Singleton target property instance. */
public static final CmakeInitIncludeProperty INSTANCE = new CmakeInitIncludeProperty();

private CmakeInitIncludeProperty() {
super();
}

@Override
protected List<String> fromAst(Element node, MessageReporter reporter) {
return ASTUtils.elementToListOfStrings(node);
}

@Override
protected List<String> fromString(String string, MessageReporter reporter) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Element toAstElement(List<String> value) {
return ASTUtils.toElement(value);
}

@Override
public String name() {
return "cmake-init-include";
}

@Override
public boolean loadFromFederate() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum Platform {
LINUX("Linux"),
MAC("Darwin"),
ZEPHYR("Zephyr"),
STM32F4("STM32F4"),
FLEXPRET("FlexPRET"),
PATMOS("Patmos"),
WINDOWS("Windows");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.lflang.generator.PrependOperator
import org.lflang.joinWithLn
import org.lflang.target.property.BuildTypeProperty
import org.lflang.target.property.CmakeIncludeProperty
import org.lflang.target.property.CmakeInitIncludeProperty
import org.lflang.target.property.Ros2DependenciesProperty
import org.lflang.target.property.RuntimeVersionProperty
import org.lflang.toUnixString
Expand Down Expand Up @@ -52,7 +53,7 @@ class CppRos2PackageGenerator(generator: CppGenerator, private val nodeName: Str

fun generatePackageCmake(sources: List<Path>): String {
// Resolve path to the cmake include files if any was provided
val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() }
val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() }

return with(PrependOperator) {
with(CppGenerator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import org.lflang.FileConfig
import org.lflang.target.TargetConfig
import org.lflang.generator.PrependOperator
import org.lflang.joinWithLn
import org.lflang.target.property.BuildTypeProperty
import org.lflang.target.property.CmakeIncludeProperty
import org.lflang.target.property.ExternalRuntimePathProperty
import org.lflang.target.property.RuntimeVersionProperty
import org.lflang.target.property.*
import org.lflang.toUnixString
import java.nio.file.Path

Expand Down Expand Up @@ -140,7 +137,7 @@ class CppStandaloneCmakeGenerator(private val targetConfig: TargetConfig, privat

fun generateCmake(sources: List<Path>): String {
// Resolve path to the cmake include files if any was provided
val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() }
val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() }

val reactorCppTarget = when {
targetConfig.isSet(ExternalRuntimePathProperty.INSTANCE) -> "reactor-cpp"
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/resources/lib/platform/stm32/arm-none-eabi-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

# Some default GCC settings
set(TOOLCHAIN_PREFIX arm-none-eabi-)
set(FLAGS
erlingrj marked this conversation as resolved.
Show resolved Hide resolved
"-fdata-sections -ffunction-sections \
--specs=nano.specs -Wl,--gc-sections")
set(CPP_FLAGS
"-fno-rtti -fno-exceptions \
-fno-threadsafe-statics")

set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc ${FLAGS})
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++ ${FLAGS} ${CPP_FLAGS})
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)

set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
2 changes: 1 addition & 1 deletion test/C/src/FileReader.lf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ reactor Source {

reaction(startup) -> out {=
char* file_path =
LF_SOURCE_DIRECTORY
"LF_SOURCE_DIRECTORY"
LF_FILE_SEPARATOR "lib"
LF_FILE_SEPARATOR "FileReader.txt";

Expand Down
Loading