Building wolfSSL library in Visual Studio Code for Raspberry Pi Pico - cmake

I just downloded wolfSSL library but I dont know how to build it using VSCode. What changes do I have to make in cmake file? Or is it something else? Can someone please guide me.
I tried this instructions for using GCC-ARM:
https://github.com/wolfSSL/wolfssl/tree/master/IDE/GCC-ARM
but it still couldnt compile.
# Toolchain location and prefix
#TOOLCHAIN =
TOOLCHAIN ?=C:/VSARM/armcc/10 2021.10/bin/arm-none-eabi-
# Architecture
#ARCHFLAGS ?= -mcpu=cortex-m4 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP
ARCHFLAGS = -mcpu=cortex-m0 -mthumb -mabi=aapcs -DUSE_WOLF_ARM_STARTUP
#ARCHFLAGS = -mcpu=cortex-r5 -mthumb -mabi=aapcs
#ARCHFLAGS = -mcpu=cortex-a53 -mthumb -mabi=aapcs
p.s. I did my VSCode setup based on shawn haymle's guide for rpi pico.

Related

qemu-arm Segmentation Fault

Take a simple file:
int main(void) {
return 0;
}
My CMakeLists.txt file:
cmake_minimum_required(VERSION 3.20)
project(TRA
VERSION 0.0.1
DESCRIPTION "STM32 Traffic Controller"
LANGUAGES C ASM)
set(BSP_DRIVER_FILES
BSP/tra/startup_stm32f429xx.s
BSP/tra/Core/Src/system_stm32f4xx.c
)
set(BSP_COMPILER_FLAGS
-DUSE_HAL_DRIVER
-DSTM32F429xx
-I${CMAKE_SOURCE_DIR}/BSP/tra/Core/Inc
-I${CMAKE_SOURCE_DIR}/BSP/tra/Drivers/STM32F4xx_HAL_Driver/Inc
-I${CMAKE_SOURCE_DIR}/BSP/tra/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
-I${CMAKE_SOURCE_DIR}/BSP/tra/Drivers/CMSIS/Device/ST/STM32F4xx/Include
-I${CMAKE_SOURCE_DIR}/BSP/tra/Drivers/CMSIS/Include
)
add_executable(tra)
target_sources(tra PRIVATE
${BSP_DRIVER_FILES}
code/tra.c
)
set(COMPILER_FLAGS
${BSP_COMPILER_FLAGS}
-O0 -g -ggdb3
-mcpu=cortex-m4 -mthumb -mfloat-abi=soft
-fdata-sections -ffunction-sections
--specs=rdimon.specs
)
target_compile_options(tra PRIVATE
${COMPILER_FLAGS}
)
target_link_options(tra PRIVATE
-mcpu=cortex-m4 -mthumb -mfloat-abi=soft
--specs=rdimon.specs -lm -lc
-Wl,--gc-sections
)
Running qemu-arm build/tra.
I get
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)
My understanding was that this issue was commonly caused by qemu not handling hardware FPU, however I'm specifying software floating point here. Also, I have removed FPU initialization code from my startup.c file.
With gdb:
# Start
qemu-arm -g 1234 build/tra
# Attach
arm-none-eabi-gdb -q --nh -ex 'file build/tra' -ex 'target remote localhost:1234'
I get the segmentation fault at SystemInit(). Running gdb list, it shows the commented out FPU initialization code, so I don't see how that could be the issue.
Therefore, I'm at a loss as to what is going on.
You're building a bare-metal binary for a Cortex-M CPU, and then trying to run it on qemu-arm, which is the emulator for running Cortex-A Linux binaries.
If you're building a bare-metal binary, you need to build it for the exact machine type that you want to run it on, which means you need to target a machine type supported by qemu-system-arm, and you need to tell qemu-system-arm to use that machine type.
As suggested by Peter Maydell require full system emulation. For cortex-M, this was provided by xPack QEMU

Importing (RTEMS ) libraries in CMake

I am trying to import a library in CMake the modern way like shown in this thread:
How do I add a library path in cmake?
The goal is to build a RTEMS test program. I'm building on a Ubuntu 20.04 machine, and I am cross compiling for an ARM target with the arm/stm32h7 BSP.
The libraries are located inside an external lib folder.
I almost got the build process working, however CMake appears to do something which breaks the linking process. I propably did the mistake but I have problems figuring it out.
This is the basic setup of my CMake file, after I set up everything for cross compilation of RTEMS binaries:
...
# Here comes application stuff again
add_executable(${CMAKE_PROJECT_NAME} init.c led.c stm32h7xx_nucleo.c)
set(RTEMS_LIB_NAME "rtems_${RTEMS_ARCH_NAME}_${RTEMS_BSP_NAME}")
add_library(${RTEMS_LIB_NAME} SHARED IMPORTED)
set_target_properties(${RTEMS_LIB_NAME} PROPERTIES
IMPORTED_LOCATION ${RTEMS_BSP_LIB_PATH}
INTERFACE_INCLUDE_DIRECTORIES ${RTEMS_BSP_INC_PATH}
)
#target_link_directories(${RTEMS_LIB_NAME} INTERFACE
# ${RTEMS_BSP_LIB_PATH}
#)
#target_include_directories(${RTEMS_LIB_NAME} INTERFACE
# ${RTEMS_BSP_INC_PATH}
#)
target_link_options(${RTEMS_LIB_NAME} INTERFACE
# -I${RTEMS_BSP_INC_PATH}
# -B${RTEMS_BSP_LIB_PATH}
-Wl,--gc-sections
-Wl,-Bstatic
-Wl,-Bdynamic
-qrtems
)
target_link_libraries(${CMAKE_PROJECT_NAME} ${RTEMS_LIB_NAME})
Building the individual source files appears to work fine.
The raw link command attempted by CMake will be the following:
/home/rmueller/Documents/RTEMS/toolchain/rtems/6/bin/arm-rtems6-gcc
-mthumb -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard
-Wl,--gc-sections -Wl,-Bstatic -Wl,-Bdynamic
-qrtems CMakeFiles/blinky.dir/init.c.o CMakeFiles/blinky.dir/led.c.o CMakeFiles/blinky.dir/stm32h7xx_nucleo.c.o
-o blinky -Wl,-rpath,/home/rmueller/Documents/RTEMS/toolchain/rtems
/6/arm-rtems6/stm32h7 /home/rmueller/Documents/RTEMS/toolchain/rtems/6/arm-rtems6/stm32h7/lib
And I get the error:
./../../../arm-rtems6/bin/ld: cannot open linker script file linkcmds: No such file or directory
This is propably because the libraries are not in the search path somehow.
I then found out that the following command links the binary properly:
/home/rmueller/Documents/RTEMS/toolchain/rtems/6/bin/arm-rtems6-gcc
-mthumb -mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard
-Wl,--gc-sections -Wl,-Bstatic -Wl,-Bdynamic
-qrtems CMakeFiles/blinky.dir/init.c.o CMakeFiles/blinky.dir/led.c.o
CMakeFiles/blinky.dir/stm32h7xx_nucleo.c.o -o blinky
-L/home/rmueller/Documents/RTEMS/toolchain/rtems/6/arm-rtems6/stm32h7/lib
Is the way to import the library wrong? I could just add the -L flag manually to my build target using commands like target_link_options , but I was thinking it would be nice if the search path could just be an interface requirement when linking the RTEMS library.
UPDATE: I think I found one error: I imported the library path as a SHARED library and it propably has to be imported as STATIC.
THe command now looks like this:
/home/rmueller/Documents/RTEMS/toolchain/rtems/6/bin/arm-rtems6-gcc -mthumb
-mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard -Wl,--gc-sections -Wl,-Bstatic -Wl,-Bdynamic -qrtems
CMakeFiles/blinky.dir/init.c.o CMakeFiles/blinky.dir/led.c.o CMakeFiles/blinky.dir/stm32h7xx_nucleo.c.o
-o blinky /home/rmueller/Documents/RTEMS/toolchain/rtems/6/arm-rtems6/stm32h7/lib
UPDATE2:
I solved the problem. There was still a little syntax error, I think the quotes were missing. The command to set the library properties looks like this now :
set_target_properties(${RTEMS_LIB_NAME} PROPERTIES
IMPORTED_LOCATION "${RTEMS_BSP_LIB_PATH}"
INTERFACE_INCLUDE_DIRECTORIES "${RTEMS_BSP_INC_PATH}"
)
And the binary is linked properly :-)
UPDATE3:
And it has stopped working again. This is really weird. The -L flag appears to be missing..
Kind Regards
Robin
Okay, I finally solved the issue. The above option is used to explicitely include libraries. In the RTEMS case, simply adding the library path and using -qrtems is sufficient.
The resulting and working CMakeLists.txt file can be found here: https://github.com/rmspacefish/rtems-demo/blob/master/applications/stm32/blinky/CMakeLists.txt

STM32 Project with CMake

I am trying to create and compile an ARM-based STM32 project using CMake.
CMakeLsts.txt is the following:
cmake_minimum_required(VERSION 3.7)
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
# Enable logging messages
#set(CMAKE_VERBOSE_MAKEFILE ON)
# Project name
set(PROJECT_NAME FixtureTACO)
PROJECT(${PROJECT_NAME} C CXX ASM)
SET(CMAKE_CXX_STANDARD 11)
###################### CHIP CONFIGURATION ##########################
SET(ROOT_PROJ ${CMAKE_CURRENT_SOURCE_DIR})
SET(CPU "cortex-m4")
SET(ARCH_NAME "arm")
SET(ARCH_VER "v7e-m")
SET(FAMILY "stm32f3")
SET(CHIP "STM32F303xC")
SET(ARCH "${ARCH_NAME}${ARCH_VER}")
####################################################################
# MCU Config
set(FPU "-mfpu=fpv4-sp-d16")
set(FLOAT_ABI "-mfloat-abi=hard")
# Toolchain path
set(TOOLCHAIN_PATH "")
set(ARM_LIB "/usr/lib/arm-none-eabi/lib/${ARCH}")
# Specify C, C++ and ASM compilers
SET(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}arm-none-eabi-g++)
set(AS ${TOOLCHAIN_PATH}arm-none-eabi-as)
set(AR ${TOOLCHAIN_PATH}arm-none-eabi-ar)
set(OBJCOPY ${TOOLCHAIN_PATH}arm-none-eabi-objcopy)
set(OBJDUMP ${TOOLCHAIN_PATH}arm-none-eabi-objdump)
set(SIZE ${TOOLCHAIN_PATH}arm-none-eabi-size)
set(GDB ${TOOLCHAIN_PATH}arm-none-eabi-gdb)
set(SIZE ${TOOLCHAIN_PATH}arm-none-eabi-size)
# Definitions passed at compile time (#defines)
add_definitions(-DFAMILY=${FAMILY})
add_definitions(-DCHIP=${CHIP})
add_definitions(-D${CHIP})
add_definitions(-DUSE_FULL_LL_DRIVER)
add_definitions(-USE_HAL_DRIVER)
add_definitions(-DHSE_VALUE=8000000)
add_definitions(-DHSE_STARTUP_TIMEOUT=100)
add_definitions(-DLSE_STARTUP_TIMEOUT=5000)
add_definitions(-DLSE_VALUE=32768)
add_definitions(-DHSI_VALUE=8000000)
add_definitions(-DLSI_VALUE=40000)
add_definitions(-DDD_VALUE=3300)
add_definitions(-DPREFETCH_ENABLE=1)
# Compilation flags
add_compile_options(-mcpu=${CPU})
add_compile_options(-march=${ARCH})
add_compile_options(-mthumb)
add_compile_options(${FPU})
add_compile_options(${FLOAT_ABI})
add_compile_options(-Og)
add_compile_options(-Wall)
add_compile_options(-fdata-sections)
add_compile_options(-ffunction-sections)
# Only for debugging
add_compile_options(-g -gdwarf-2)
# Linker script path
file(GLOB_RECURSE LINKER_SCRIPT ${ROOT_PROJ}/platforms/${FAMILY}/Linker/*.ld)
# Variables initialized first time
SET(CMAKE_CXX_FLAGS_INIT "-std=c++11")
SET(CMAKE_C_FLAGS_INIT "-std=gnu99")
################################## Source code ###############################################################
# Retrieve all sources # "platforms/${FAMILY}/Startup/*.s"
file(GLOB SOURCES "platforms/${FAMILY}/Startup/*.s" "src/*.cpp" "src/*.c" "platforms/${FAMILY}/Hal/src/*.c" "platforms/${FAMILY}/Device/*.c")
#Retrieve all locations of headers
file(GLOB_RECURSE HEADERS "includes/*.h" "src/*.h" "platforms/${FAMILY}*.h")
set (INCLUDE_DIRS "")
foreach (_headerFile ${HEADERS})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND INCLUDE_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES INCLUDE_DIRS)
include_directories(${INCLUDE_DIRS})
link_directories(${ARM_LIB})
################################## Source code END ###########################################################
set(EXE_NAME "${PROJECT_NAME}_${CHIP}")
add_executable(${EXE_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS "-mcpu=${CPU} -mthumb ${FPU} ${FLOAT_ABI} --specs=nano.specs -T${LINKER_SCRIPT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map,--cref -Wl,--gc-sections")
# Libs and external dependencies
target_link_libraries(${EXE_NAME}.elf -lc -lm -lnosys)
# Outputs
set(ELF_FILE ${PROJECT_BINARY_DIR}/${EXE_NAME}.elf)
set(HEX_FILE ${PROJECT_BINARY_DIR}/${EXE_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${EXE_NAME}.bin)
add_custom_command(TARGET "${EXE_NAME}.elf" POST_BUILD
# Build .hex and .bin files
COMMAND ${OBJCOPY} -Obinary ${ELF_FILE} ${BIN_FILE}
COMMAND ${OBJCOPY} -Oihex ${ELF_FILE} ${HEX_FILE}
COMMENT "Building ${PROJECT_NAME}.bin and ${PROJECT_NAME}.hex"
# Copy files to a custom build directory
COMMAND ${CMAKE_COMMAND} -E copy ${ELF_FILE} "${ROOT_PROJ}/builds/${CHIP}/${EXE_NAME}.elf"
COMMAND ${CMAKE_COMMAND} -E copy ${HEX_FILE} "${ROOT_PROJ}/builds/${CHIP}/${EXE_NAME}.hex"
COMMAND ${CMAKE_COMMAND} -E copy ${BIN_FILE} "${ROOT_PROJ}/builds/${CHIP}/${EXE_NAME}.bin"
# Display sizes
COMMAND ${SIZE} --format=berkeley ${EXE_NAME}.elf ${EXE_NAME}.hex
COMMENT "Invoking: Cross ARM GNU Print Size"
)
add_custom_target(UPLOAD
${GDB} -iex "target remote tcp:127.0.0.1:3333"
-iex "monitor program ${EXE_NAME}.elf"
-iex "monitor reset init"
-iex "disconnect" -iex "quit ")
When I try to compile I am getting the following errors:
[ 82%] Building C object CMakeFiles/FixtureTACO_STM32F303xC.elf.dir/platforms/stm32f3/Hal/src/stm32f3xx_ll_utils.c.obj
[ 86%] Building ASM object CMakeFiles/FixtureTACO_STM32F303xC.elf.dir/platforms/stm32f3/Startup/startup_stm32f303xc.s.obj
cc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc: error: unrecognized command line option ‘-mthumb’; did you mean ‘-mtbm’?
cc: error: unrecognized command line option ‘-mfpu=fpv4-sp-d16’
cc: error: unrecognized command line option ‘-mfloat-abi=hard’
The error occurs ONLY when an assembly file (startup.s in this case) is present in source files and when FPU and FLOAR_ABI flags are present. As you can see, error occurs when startup_stm32f303xc.s is compiled.
I suspect that I am adding those flags in the wrong place but I have no clue where to add them in order to get it works.
Later edit: I already have installed arm 7 compiler on my ubuntu system. I can use it without specifying any path as it is already present in environment variables. I can compile without problems ARM code (from Makefiles) for other targets on machine. My problem is with cmake.
In your line set(TOOLCHAIN_PATH "") you must add a path to compiler. First go to get your free GCC ARM ToolChain. Download for your OS. and then just copy to your favorite location. If you using Linux you can use my path configurations:
1.) Copy gcc arm compirel to /opt/ directory:
sudo tar xjfv ~/Downloads/gcc-arm-none-eabi-7-2018-q2-update-linux.tar.bz2 -C /opt/
For more "sexy" path you can do symbolic link:
sudo ln -s /opt/gcc-arm-none-eabi-7-2018-q2-update/ /opt/gcc-arm-none-eabi
After that go to your CMakeLists.txt and rewrite your set command to:
set(TOOLCHAIN_PATH "/opt/gcc-arm-none-eabi/bin")
But there is better solution to build your project for STM32, but with already done stm32-cmake template project, specifically made for STM32 family. It is mush easier done with something working. You will also need two prerequisites STM32CubeMX installed and again GCC ARM ToolChain. If you want to know how to use this template just DM me and I will you give a quick guidance.
OK, I finally managed to figure it out!
I had to replace
set(AS ${TOOLCHAIN_PATH}arm-none-eabi-as)
with
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}arm-none-eabi-gcc)
It is not a mistake, it is gcc compiler. You can also append these flags: -x assembler-with-cpp.
CMake didn't know about my custom ASM compiler so it was using default system ASM compiler unless I force it by writing CMAKE_ASM_COMPILER. Now the project is being build and works fine on microcontroller.
The other answers were ok, but had half of the solution. Only ASM filese were compiled with wrong compiler.
I think you try to compile code for ARM using x86 compiler. It will not work. You need to download the ARM toolchain and use the correct compiler.
-mcpu is depreciated in the x86 branch, but is not in the ARM branch
another options just not exist in the x86 compiler.

OpenKinect: Compile custom code on MAC

Can someone please tell me how to compile custom kinect code on MAC.
I have downloaded and built the OpenKinect as instructed by the guide(and yes glview works fine)
I am following this: http://openkinect.org/wiki/C%2B%2B_GL_Example
But I am not able to produce any output file.
g++ -g -Wall `pkg-config --cflags libfreenect` -lopengl32 -lglut32 `pkg-config --libs libfreenect` -lGL -lGLU -lglut -c main.cpp
Package libfreenect was not found in the pkg-config search path.
Perhaps you should add the directory containing `libfreenect.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libfreenect' found
Package libfreenect was not found in the pkg-config search path.
Perhaps you should add the directory containing `libfreenect.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libfreenect' found
In file included from main.cpp:27:
/usr/local/include/libfreenect.hpp:29:25: error: libfreenect.h: No such file or directory
In file included from main.cpp:27:
/usr/local/include/libfreenect.hpp:46: error: expected `)' before ‘*’ token

Compile C++ code to run on ESXi 3.5

I'm trying to compile a simple c++ program to run inside ESXi 3.5 console window. It seems I'm linking with wrong libraries... Is there a setup described somewhere - which version of G++ and libraries do I have to be using in order to do so?
Here's how I resolved the issue. I did following to compile:
Compiled using gcc under ubuntu
Ran ldd on executable
Copied all libraries that showed up as dependencies to subfolder ESXi-3.5-lib. In my case they were:
ld-linux.so.2
libc.so.6
libgcc_s.so.1
libm.so.6
libstdc++.so.5
Added following switches to gcc:
-nodefaultlibs (to not attempt to link with default libs)
-lc (prevented link error in some crt library)
-fno-stack-protector (prevented another error, some other function was missing)
Following was my final build command:
g++ file1.cpp file2.cpp file3.cpp -o output-biinary-file-name \
ESXi-3.5-lib/ld-linux.so.2 ESXi-3.5-lib/libc.so.6 ESXi-3.5-lib/libgcc_s.so.1\
ESXi-3.5-lib/libm.so.6 ESXi-3.5-lib/libstdc++.so.5 \
-nodefaultlibs -lc -m32 -fno-stack-protector