You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
KED/run.sh

117 lines
2.6 KiB

#!/bin/bash
CSL_TO_USE=$1
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PROJECT_DIR=$SCRIPT_DIR/..
CMAKE_DIR=$SCRIPT_DIR
BUILD_DIR=$SCRIPT_DIR/../ked_build
cd $SCRIPT_DIR
stmLinkInstall()
{
# https://github.com/stlink-org/stlink/blob/develop/doc/compiling.md
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tInstalling STM link"
echo "+--------------------------------------+"
echo -e "\e[32m"
sudo apt install gcc cmake libusb-1.0 libusb-1.0-0-dev
git clone https://github.com/stlink-org/stlink.git
cd stlink
sudo make install
sudo ldconfig
cd ..
sudo rm -r stlink
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tIntalling Finished"
echo "+--------------------------------------+"
echo -e "\e[32m"
}
build()
{
cd $SCRIPT_DIR
if [ -z "$CSL_TO_USE" ];then
echo "Please enter a CSL"
cd csl
echo Curretnly awailable CSL are :
for d in */ ; do #Cheking the directory to print files
if [ "$d" != "csl/" ];then #Exept csl/
echo -e "\t|--> $d" | grep -oP '.*?(?=\/)' #And remove the finel "/"
fi
done
else
cd $CMAKE_DIR
if [ -d "$BUILD_DIR" ];then
rm -r $BUILD_DIR
cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE -DPROJECT_DIR=$PROJECT_DIR
else
cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE -DPROJECT_DIR=$PROJECT_DIR
fi
cd $BUILD_DIR
make -j8
if [ "$CSL_TO_USE" == "raspberry" ];then
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tExecuting $CSL_TO_USE"
echo "+--------------------------------------+"
echo -e "\e[32m"
./$CSL_TO_USE
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tExecution Terminated"
echo "+--------------------------------------+"
echo -e "\e[32m"
fi
if [ "$CSL_TO_USE" == "stm32f042k6t6" ];then
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tFlashing $CSL_TO_USE"
echo "+--------------------------------------+"
echo -e "\e[32m"
sudo st-flash write $CSL_TO_USE.bin 0x08000000
echo -e "\e[36m"
echo "+--------------------------------------+"
echo -e "\tFlashing has Finished"
echo "+--------------------------------------+"
echo -e "\e[32m"
fi
fi
}
autoInit()
{
if [ "$CSL_TO_USE" == "install" ];then
stmLinkInstall
else
cd $PROJECT_DIR
PROJECT_DIR=$(pwd)
if [[ -f "main.c" ]];then
build
else
PROJECT_DIR=$(pwd)
echo "Main.c is not fount"
echo "Creating sample project"
cp -r $SCRIPT_DIR/libraries/examples/autoInit/* .
build
echo "Main Found"
fi
fi
}
autoInit