From be3ecf3e6e1765ed71630084f49d4a263ad6ba5e Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Mon, 26 Apr 2021 17:27:16 +0200 Subject: [PATCH] Initial commit --- .gitmodules | 3 + CMakeLists.txt | 7 ++ README.md | 43 ++++++++++++ blinky.cpp | 38 +++++++++++ build/.gitkeep | 0 eclipse_launch_cfgs/connect_stm32f4.launch | 9 +++ eclipse_launch_cfgs/debug_stm32f4.launch | 63 +++++++++++++++++ eclipse_launch_cfgs/flash_stm32f4.launch | 9 +++ openocd/openocd_debug.cfg | 2 + openocd/openocd_flash.cfg | 8 +++ openocd/stm32f4-load | 78 ++++++++++++++++++++++ rodos | 1 + 12 files changed, 261 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 blinky.cpp create mode 100644 build/.gitkeep create mode 100644 eclipse_launch_cfgs/connect_stm32f4.launch create mode 100644 eclipse_launch_cfgs/debug_stm32f4.launch create mode 100644 eclipse_launch_cfgs/flash_stm32f4.launch create mode 100755 openocd/openocd_debug.cfg create mode 100644 openocd/openocd_flash.cfg create mode 100755 openocd/stm32f4-load create mode 160000 rodos diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2fe62d6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "rodos"] + path = rodos + url = https://gitlab.com/rodos/rodos diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..06d36eb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +project(my-rodos-app) + +cmake_minimum_required(VERSION 3.10) +set(CMAKE_CXX_STANDARD 17) + +add_subdirectory(rodos) +add_rodos_executable(my-rodos-app blinky.cpp) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..72f7057 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Julians Rodos Template + +## Steps to make it work + +### Compiling Rodos +Compiling rodos for discovery / stm32f4: + +```shell script +$ cd build +$ cmake -DCMAKE_TOOLCHAIN_FILE=../rodos/cmake/port/discovery.cmake -DEXECUTABLE=ON .. +``` + +### Openocd installation + +To make it work you need to install openocd on your system (e.g. via package manager). +The installation should create one of these folders: +- _/usr/share/openocd_ +- _/usr/local/share/openocd_ + +There you can find the files referenced in *openocd/openocd_debug.cfg* and *openocd/openocd_flash.cfg*. +Since I did not find *stm32f4x_stlink.cfg* there, I changed it in the config file to *stm32f4x.cfg*. + +### Edit Eclipse launch configs +Eclipse needs to find the folder *eclipse_launch_cfgs*. +For me it worked to create a new launch configuration and go to **Common** and select the folder unter **Shared files**. + +You should also edit all three configurations through the Eclipse run configurations window to update your project name and binary name. + +Sometimes *debug_stm32f4.launch* is not recognized by the big launch configuration window in Eclipse (top left). Just use the small bug icon on the top right of the toolbar instead. + +### Run stm32f4-load +Make *openocd/stm32f4-load* executable and run it once as sudo. This will add some files to */etc/udev/rules.d/* so you wont have to use sudo in the future. + +### Edit CMakeLists.txt +Edit *CMakeLists.txt* to add all your cpp files etc. + +## How to run it +### Flashing +To flash your program just run the external tool configuration *flash_stm32f4* in Eclipse. + +### Debugging +To debug first run the external tool configuration *connect_stm32f4.launch* in Eclipse once. +Then to really start debugging run the debug configuration *debug_stm32f4* in Eclipse. This should compile your code, open debug mode and run it. \ No newline at end of file diff --git a/blinky.cpp b/blinky.cpp new file mode 100644 index 0000000..3136c50 --- /dev/null +++ b/blinky.cpp @@ -0,0 +1,38 @@ +/* + * TestBlinky.cpp + * + */ + + +#include "rodos.h" +#include "hal_gpio.h" + +HAL_GPIO green(GPIO_060); + + +class Test:public Thread + +{ + + + +public: + + void init() + + { + green.init(1,1,1); + + } + + +void run() + +{ + green.setPins(0); +} + +}; + +Test t; + diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/eclipse_launch_cfgs/connect_stm32f4.launch b/eclipse_launch_cfgs/connect_stm32f4.launch new file mode 100644 index 0000000..cff194a --- /dev/null +++ b/eclipse_launch_cfgs/connect_stm32f4.launch @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/eclipse_launch_cfgs/debug_stm32f4.launch b/eclipse_launch_cfgs/debug_stm32f4.launch new file mode 100644 index 0000000..e37b242 --- /dev/null +++ b/eclipse_launch_cfgs/debug_stm32f4.launch @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eclipse_launch_cfgs/flash_stm32f4.launch b/eclipse_launch_cfgs/flash_stm32f4.launch new file mode 100644 index 0000000..a4eea20 --- /dev/null +++ b/eclipse_launch_cfgs/flash_stm32f4.launch @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/openocd/openocd_debug.cfg b/openocd/openocd_debug.cfg new file mode 100755 index 0000000..fbbc982 --- /dev/null +++ b/openocd/openocd_debug.cfg @@ -0,0 +1,2 @@ +source [find interface/stlink-v2.cfg] +source [find target/stm32f4x.cfg] \ No newline at end of file diff --git a/openocd/openocd_flash.cfg b/openocd/openocd_flash.cfg new file mode 100644 index 0000000..affb377 --- /dev/null +++ b/openocd/openocd_flash.cfg @@ -0,0 +1,8 @@ +source [find interface/stlink-v2.cfg] +source [find target/stm32f4x.cfg] + +init +reset halt +flash write_image erase stm32f4.hex 0 ihex +reset run +shutdown \ No newline at end of file diff --git a/openocd/stm32f4-load b/openocd/stm32f4-load new file mode 100755 index 0000000..25a2783 --- /dev/null +++ b/openocd/stm32f4-load @@ -0,0 +1,78 @@ +#! /bin/bash + +#if [ -z $RODOS_ROOT ]; then +# source `dirname $0`/print_no_envs_warning +#fi + +#source ${RODOS_MAKES}/stm32f4-set-vars + +FLASH_TOOL=openocd +FLASH_TOOL_PATH=/usr/bin +OBJCOPY=arm-none-eabi-objcopy +OBJCOPY_PATH= + +ELF_NAME=$1 + +if [ -x ${FLASH_TOOL_PATH}/${FLASH_TOOL} ]; then + echo "${FLASH_TOOL}: installed" + FLASH_TOOL=${FLASH_TOOL_PATH}/${FLASH_TOOL} +else + # look for flash tool in default path + command -v ${FLASH_TOOL} >/dev/null 2>&1 || { echo "${FLASH_TOOL}: NOT installed" >&2; exit 1; } + echo "${FLASH_TOOL}: installed " + FLASH_TOOL="$(command -v ${FLASH_TOOL})" +fi + + +if [ -x $OBJCOPY_PATH/$OBJCOPY ]; then + echo "$OBJCOPY: installed" + OBJCOPY=${OBJCOPY_PATH}/${OBJCOPY} +else + # look for objcopy in default path + command -v ${OBJCOPY} >/dev/null 2>&1 || { echo "${OBJCOPY}: NOT installed" >&2; exit 1; } + echo "${OBJCOPY}: installed" + OBJCOPY="$(command -v ${OBJCOPY})" +fi + + +#if [ -f ./${ARCH}.elf ]; then +# echo "${ARCH}.elf: OK" + rm stm32f4.hex &> /dev/null + $OBJCOPY -O ihex ${ELF_NAME} stm32f4.hex +#else +# echo "${ARCH}.elf: FAIL" +# exit 1; +#fi + + +#if [ -f ./${ELF_NAME}.hex ]; then +# echo "${ARCH}.hex: OK" +#else +# echo "${ARCH}.hex: FAIL" +# exit 1; +#fi + + + +if [ ! -f /etc/udev/rules.d/49-stlinkv1.rules -o ! -f /etc/udev/rules.d/49-stlinkv2.rules ] +then + echo "superuser password needed to access USB-Port" + + # mount rule for stlink1 + echo "SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0483\", ATTRS{idProduct}==\"3744\", MODE:=\"0666\", SYMLINK+=\"stlinkv1_%n\"" > 49-stlinkv1.rules + + # mount rule for stlink2 + echo "SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"0483\", ATTRS{idProduct}==\"3748\", MODE:=\"0666\", SYMLINK+=\"stlinkv2_%n\"" > 49-stlinkv2.rules + + sudo mv 49-stlinkv1.rules /etc/udev/rules.d/ + sudo mv 49-stlinkv2.rules /etc/udev/rules.d/ + + sudo udevadm trigger + sudo udevadm control --reload-rules + + sleep 1s +fi + + +echo "flashing ..." +${FLASH_TOOL} -f $(dirname "$0")/openocd_flash.cfg \ No newline at end of file diff --git a/rodos b/rodos new file mode 160000 index 0000000..2c500a8 --- /dev/null +++ b/rodos @@ -0,0 +1 @@ +Subproject commit 2c500a8d5af14e94c25e861dbcda2b3abde950e5