Skip to content

Instantly share code, notes, and snippets.

@rafaneri
Created September 6, 2016 16:25
Show Gist options
  • Save rafaneri/62ac2ab0273bde742b12e458938b9add to your computer and use it in GitHub Desktop.
Save rafaneri/62ac2ab0273bde742b12e458938b9add to your computer and use it in GitHub Desktop.
A shell program to start a gcc4mbed based project - $sudo ln -s /YOUR_PATH/mbed_init /bin/mbed_init
#!/bin/bash
_makefile="makefile"
_main="main.cpp"
_sync_script="script.sh"
_json_config="c_cpp_properties.json"
_vscode=".vscode"
create_makefile() {
echo "PROJECT := $project" >> "$_makefile"
echo "DEVICES := $boards" >> "$_makefile"
echo "NO_FLOAT_SCANF := 1" >> "$_makefile"
echo "NO_FLOAT_PRINTF := 1" >> "$_makefile"
echo "GCC4MBED_DIR := $GCC4MBED_DIR" >> "$_makefile"
echo "USER_LIBS := $ROS_LIB_DIR" >> "$_makefile"
echo "include $GCC4MBED_DIR/build/gcc4mbed.mk" >> "$_makefile"
}
create_json() {
echo "{" >> "$_vscode/$_json_config"
echo " \"configurations\": [" >> "$_vscode/$_json_config"
echo " {" >> "$_vscode/$_json_config"
echo " \"name\": \"Linux\"," >> "$_vscode/$_json_config"
echo " \"includePath\": [" >> "$_vscode/$_json_config"
echo " \"/usr/include\"," >> "$_vscode/$_json_config"
echo " \"$GCC4MBED_DIR/external/mbed/libraries\"," >> "$_vscode/$_json_config"
echo " \"$GCC4MBED_DIR/external/mbed/libraries/mbed/api\"" >> "$_vscode/$_json_config"
echo " ]," >> "$_vscode/$_json_config"
echo " \"browse\": {" >> "$_vscode/$_json_config"
echo " \"limitSymbolsToIncludedHeaders\": true," >> "$_vscode/$_json_config"
echo " \"databaseFilename\": \"\"" >> "$_vscode/$_json_config"
echo " }" >> "$_vscode/$_json_config"
echo " }" >> "$_vscode/$_json_config"
echo " ]" >> "$_vscode/$_json_config"
echo "}" >> "$_vscode/$_json_config"
}
create_main() {
echo "#include \"mbed.h\"" >> "$_main"
echo "int main(int argc, char **argv) {" >> "$_main"
echo " return 0;" >> "$_main"
echo "}" >> "$_main"
}
create_sync_script() {
echo "#!/usr/bin/env sh" >> "$_sync_script"
echo "# Change the BOARD and BOARD_DIRECTORY" >> "$_sync_script"
echo "cp BOARD/$project.bin /media/BOARD_DIRECTORY/ ; sync" >> "$_sync_script"
chmod +x "$_sync_script"
}
create_project() {
if [ ! -d "$project" ]; then
mkdir $project
fi
cd $project
if [ ! -d "$_vscode" ]; then
mkdir "$_vscode"
fi
create_makefile
create_main
create_sync_script
create_json
}
echo "Create a new MBED project for STM boards"
echo "Enter the project name (without space):"
read project
echo "Enter the board names (space separated)"
read boards
create_project
@rafaneri
Copy link
Author

rafaneri commented Sep 6, 2016

Add GCC4MBED_DIR and ROS_LIB_DIR variables for bashrc.
Make as executable:
$ chmod +x /YOUR_PATH/mbed_init

Export a symbolink to mbed_init file:
$ sudo ln -s /YOUR_PATH/mbed_init /bin/mbed_init

Run the script:
$ mbed_init

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment