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

Working with F prime with Ardunio #38

Open
coreymitterer opened this issue Dec 10, 2024 · 1 comment
Open

Working with F prime with Ardunio #38

coreymitterer opened this issue Dec 10, 2024 · 1 comment

Comments

@coreymitterer
Copy link

I am working with an Arduino Portenta with an M4 and M7 chip inside of it and was wondering if it was possible to use F prime with it all ive seen on the readme and online seem to give me no clear answer on how to do it.

@ethancheez
Copy link
Collaborator

You would need to add a new toolchain for the board. Add a file like portentaH7.cmake inside of fprime-arduino/cmake/toolchain/ with its contents that look like this:

####
# portentaH7.cmake:
#
# Toolchain file setup for building F prime for the Portenta H7 hardware platform. This must, by definition, include the
# Arduino framework in order to ensure that basic functions of the Portenta H7 hardware platform are available. This
# toolchain will build the core Portenta H7 Arduino libraries, and include the headers as part of the target include headers.
####
set(CMAKE_CXX_STANDARD 14)
add_compile_options(-std=c++14)

set(CMAKE_SYSTEM_NAME "Generic")
set(CMAKE_SYSTEM_PROCESSOR "arm")
set(CMAKE_CROSSCOMPILING 1)
set(FPRIME_PLATFORM "ArduinoFw")
set(FPRIME_USE_BAREMETAL_SCHEDULER ON)
set(ARDUINO_BUILD_PROPERTIES)

# Prevent test program compiling
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)

set(ARDUINO_FQBN "arduino:mbed_portenta:envie_m7")
add_compile_options(-D_BOARD_PORTENTA_H7)
# Run the base arduino setup which should detect settings!
include("${CMAKE_CURRENT_LIST_DIR}/support/arduino-support.cmake")

There needs to be a few things that need to be modified with the drivers and other stuff to support this board, but this would get you started.

P.S. I ran into an interesting error with the arduino-cli-cmake-wrapper miner.py file when trying to generate for this board. If you get the same error, I changed this as a temporary (and possibly wrong) fix:

def identify_line(
    stage: Stage,
    stages: Dict[Stage, List[str]],
    match: Callable[[str], bool],
    single: bool = True,
) -> str:
    """Identify a line based on the given stage and criteria.

    Args:
    - stage: The current stage to identify lines for.
    - stages: A dictionary mapping stages to lists of lines.
    - match: A function that checks if a line matches a certain condition.
    - single: If True (default), raises an exception if multiple matching lines are found.

    Returns:
    - The identified line (str).

    Raises:
    - MissingStageException: If no lines are found for the given stage.
    - MultipleInvocationException: If multiple matching lines are found when 'single' is True.
    """
    stage_lines = stages.get(stage, [])
    matching_lines = [line for line in stage_lines if match(line)]
    if not matching_lines:
        return stage_lines[0]
        # raise MissingStageException(stage)
    if single and len(matching_lines) > 1:
        print('\n'.join(matching_lines))
        raise MultipleInvocationException
    return matching_lines[0]

And then I managed to get to a 100% build, but ended with this error:

[ 98%] Built target LedBlinker_Top
[ 98%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime/Os/Generic/DefaultPriorityQueue.cpp.obj
[ 99%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/Main.cpp.obj
[ 99%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime/Os/Stub/DefaultFile.cpp.obj
[ 99%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-baremetal/fprime-baremetal/Os/Baremetal/DefaultCpu.cpp.obj
[ 99%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-baremetal/fprime-baremetal/Os/Baremetal/DefaultMemory.cpp.obj
[100%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-arduino/Arduino/Os/DefaultConsole.cpp.obj
[100%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-baremetal/fprime-baremetal/Os/Baremetal/DefaultTask.cpp.obj
[100%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-baremetal/fprime-baremetal/Os/Baremetal/DefaultMutex.cpp.obj
[100%] Building CXX object LedBlinker/CMakeFiles/LedBlinker.dir/__/fprime-arduino/Arduino/Os/DefaultRawTime.cpp.obj
[100%] Linking CXX executable ../bin/portentaH7/LedBlinker.elf
/home/ethancheez/.arduino15/packages/arduino/hardware/mbed_portenta/4.2.1/variants/PORTENTA_H7_M7/libs/libmbed.a(mbed_boot_gcc_arm.o): In function `__wrap_main':
mbed_boot_gcc_arm.c:(.text.__wrap_main+0x0): undefined reference to `main'
collect2: error: ld returned 1 exit status
gmake[2]: *** [LedBlinker/CMakeFiles/LedBlinker.dir/build.make:340: bin/portentaH7/LedBlinker.elf] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:7462: LedBlinker/CMakeFiles/LedBlinker.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2
[ERROR] CMake erred with return code 2

I currently don't have much time to test right now, but hopefully these pointers can get you started in debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants