This repository contains the shared control code between Purdue Robomasters robots.
git clone https://github.com/RoboMaster-Club/Control_Base_Template.git
cd Control_Base_Template
git submodule update --init
Download VSCode from here
Windows
- Download MSYS2 from here
- The default installation path is
C:\msys64
, runC:\msys64\msys2.exe
. - Install OpenOCD, arm-none-eabi-gcc, and gdb-multiarch by running these commands in MSYS2 terminal.
pacman -S mingw-w64-x86_64-make
pacman -S mingw-w64-x86_64-openocd
pacman -S mingw-w64-x86_64-arm-none-eabi-gcc
pacman -S mingw-w64-x86_64-gdb-multiarch
MacOS - Apple Silicon
- Install Arm embedded toolchain and OpenOCD and arm-none-eabi-gdb using homebrew.
brew install gcc-arm-embedded
brew install openocd
Make sure to add necessary tools to VSCode settings.json Alternatively, you can add them to PATH variable to allow them to be accessed globally.
-
Add the tool path for OpenOCD and make tools.
-
Install the VSCode extension Cortex-Debug to enable ARM microcontroller debugging.
-
Add GDB path by opening your VSCode settings.json in VSCode and add the following to the end of the file.
- Windows:
"cortex-debug.gdbPath": "c:/msys64/mingw64/bin/gdb-multiarch.exe"
. - MacOS:
"cortex-debug.gdbPath": "/opt/homebrew/bin/arm-none-eabi-gdb"
.
- Windows:
Open the Command Palatte in VSCode: [Ctrl+Shift+P]. Then, select Tasks: Run Build Tasks and pick the appropriate build task.
- Windows: build (Windows).
- MacOS: build (Darwin).
You can use the shortcut [Ctrl+Shift+B] if you set it as the default build task.
Navigate to [Run and Debug] in VSCode or press [Ctrl+Shift+D]. Select the appropriate launch configuration
- Windows: cmsis-dap-debug (Windows)
- MacOS: cmsis-dap-debug (Darwin)
Click on the green play button or press [F5] to start debugging.
Solution: Go to device manager and uninstall the usb device (probably having some error message in the list). Unplug and plug in the debugger again.
Failed to launch OpenOCD GDB Server:...
or
mingw32-make: The term 'mingw32-make' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Solution1:
Add openocd.exe to system environmental variable. If you followed the installation instruction in this README file, then OpenOCD should be install at default location C:\msys64\mingw64\bin\openocd.exe
, for windows user. Add C:\msys64\mingw64\bin
to system executable path.
Solution2:
If you don't want to mess with the system path, you could also add local openocd path in .vscode/launch.json
. Add attribute serverpath
by adding "serverpath": "C:\\msys64\\mingw64\\bin\\openocd.exe"
in configuration.
Note restarting vscode might be needed for new environment variable to take effect.
"C_Cpp.default.compilerPath": "C:/msys64/mingw64/bin/arm-none-eabi-gcc.exe"
adding this would link the standard library header files, such as stdint.h
, stdlib.h
, math.h
.
All names must use snake_case.
Variable names are all lowercase.
float example_float = 1.5f;
Macros should be all UPPERCASE.
#define EXAMPLE_MACRO 3.14f
Function names should capitalize the first letter of each word.
float Example_Function() {}
Wrapper functions should capitalize the first word.
float MOTOR_Example_Function() {}
Struct names should capitalize the first letter of each word and end in _t.
struct Example_Struct_t {}
When using struct pointers, don't put a space between the arrow.
struct Example_Struct_t {
int example_struct_member;
} example_struct;
// access member
example_struct->example_struct_member;
Enum names should capitalized the first letter of each word and end in _e.
enum Example_Enum_e {};
In general, indent code blocks for functions and if statments as such, but for switches put cases in the same line.
void Example_Func()
{
if (some_condition)
{
switch(some_num)
{
case 0:
break;
default:
break;
}
}
}
For multiline macros, indent as such:
#define YOUR_MACRO \
{ \
FIRST_LINE = 0, \
SECOND_LINE = 1, \
THIRD_LINE = 2, \
}