Skip to content

Commit

Permalink
Merge branch 'main' into unitree
Browse files Browse the repository at this point in the history
  • Loading branch information
jia-xie committed Apr 8, 2024
2 parents 789a8f5 + 35f2643 commit 9da822a
Show file tree
Hide file tree
Showing 36 changed files with 406 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
27 changes: 23 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "cmsis-dap-debug (Windows)",
"name": "dap (Win)",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}\\build\\control-base.elf",
"request": "launch",
Expand All @@ -21,7 +21,7 @@
"preLaunchTask": "build (Windows)" // build before debug
},
{
"name": "stlink-debug (Windows)",
"name": "stlink (Win)",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}\\build\\control-base.elf",
"request": "launch",
Expand All @@ -40,7 +40,7 @@
"preLaunchTask": "build (Windows)" // build before debug
},
{
"name": "cmsis-dap-debug (Darwin)",
"name": "dap",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/control-base.elf",
"request": "launch",
Expand All @@ -56,7 +56,26 @@
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build (Darwin)" // build before debug
"preLaunchTask": "build" // build before debug
},
{
"name": "stlink",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}\\build\\control-base.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "STM32F407.svd",
"servertype": "openocd", //GDB server
"configFiles": [
"${workspaceRoot}/config/openocd_stlink.cfg" // config
],
//"runToEntryPoint": "main", // stop at main
//"rtos": "FreeRTOS",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build" // build before debug
}
]
}
22 changes: 17 additions & 5 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"version": "2.0.0",
"tasks": [
/* For Unix-Like (Linux and MacOS) */
{
"label": "build (Darwin)",
"label": "build",
"type": "shell",
"command": "make -j24 V=1",
"args": [],
Expand All @@ -24,14 +25,25 @@
}
},
{
"label": "flash (Darwin)",
"label": "flash",
"type": "shell",
"command": "mingw32-make -j24 V=1; mingw32-make download",
"command": "make -j24 V=1; make download",
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "rebuild",
"type": "shell",
"command": "git submodule update; make clean_unix; make -j24 V=1",
"group": {
"kind": "build",
"isDefault": false
},
"problemMatcher": [],
},
/* For Windows */
{
"label": "build (Windows)",
"type": "shell",
Expand All @@ -45,12 +57,12 @@
{
"label": "rebuild (Windows)",
"type": "shell",
"command": "mingw32-make clean; mingw32-make -j24 V=1",
"command": "git submodule update; mingw32-make clean; mingw32-make -j24 V=1",
"group": {
"kind": "build",
"isDefault": false
},
"problemMatcher": []
"problemMatcher": [],
},
{
"label": "clean (Windows)",
Expand Down
13 changes: 1 addition & 12 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,7 @@

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2024 Purdue Robomaster

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
23 changes: 14 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ src/bsp/src/bsp_spi.c \
src/bsp/src/bsp_serial.c \
src/bsp/src/bsp_crc.c \
src/bsp/src/bsp_uart.c \
src/devices/src/BMI088driver.c \
src/devices/src/BMI088Middleware.c \
src/devices/src/bmi088driver.c \
src/devices/src/bmi088middleware.c \
src/devices/src/buzzer.c \
src/devices/src/dji_motor.c \
src/devices/src/dm_motor.c \
Expand Down Expand Up @@ -209,8 +209,8 @@ C_INCLUDES = \
-Ilib/CMSIS-DSP/PrivateInclude \
-Isrc/algo/inc \
-Isrc/devices/inc \
-Isrc/bsp/Inc \
-Isrc/app/Inc
-Isrc/bsp/inc \
-Isrc/app/inc

# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -fdata-sections -ffunction-sections
Expand All @@ -235,7 +235,7 @@ LDSCRIPT = $(BOARD_BASE)/$(LINK_SCRIPT_PREFIX)_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -flto -Wl,--no-warn-rwx-segments -Wl,--print-memory-usage -u _printf_float
LDFLAGS = $(MCU) -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -flto -Wl,--print-memory-usage -u _printf_float

# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin
Expand Down Expand Up @@ -274,8 +274,10 @@ $(BUILD_DIR):
# clean up
#######################################
clean:
rd $(BUILD_DIR) /s/q

rm -rf $(BUILD_DIR) /s/q

clean_unix:
rm -rf $(BUILD_DIR)
#######################################
# dependencies
#######################################
Expand All @@ -300,8 +302,8 @@ download_powershell:


# Unix-Like (Linux, MacOS)
ECHO_WARNING=@echo -e "\033[33m[Warning]\033[0m"
ECHO_SUCCESS=@echo -e "\033[32m[Success]\033[0m"
ECHO_WARNING=echo "\033[33m[Warning]\033[0m"
ECHO_SUCCESS=echo "\033[32m[Success]\033[0m"

download:
@echo "Attempting to use CMSIS-DAP..."
Expand All @@ -312,4 +314,7 @@ download:
($(ECHO_SUCCESS) "Successfully programmed the device using STLink.") || \
($(ECHO_WARNING) "Failed to connect using both CMSIS-DAP and STLink. Please check your connections and try again."))

test_download:
openocd -d4 -f config/openocd_cmsis_dap.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).bin 0x08000000 verify reset" -c "reset run" -c shutdown

# *** EOF ***
176 changes: 166 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,175 @@
![Build Project](https://github.com/RoboMaster-Club/control-base/actions/workflows/build.yml/badge.svg)
# Purdue Robomasters Control Base Template
This repository contains the shared control code between Purdue Robomasters robots.

# About The Library
This is a shareable hardware library for robomaster embedded system. It contains board support packages, device-drivers, and algorithms for control systems.

## Setup Guide
Clone repo, initialize submodule (STM32-CubeMX project)
``` shell
# Repository Initialization Guide
``` bash
git clone https://github.com/RoboMaster-Club/control-base.git
cd control-base
git submodule update --init
```
# Usage
## Motor Initialization

an example usage
## VSCode MAKEFILE environment setup guide
### Install tools
Download VSCode from [here](https://code.visualstudio.com/download)

**Linux**
- Install tools
```bash
sudo apt update
sudo apt upgrade
sudo apt install openocd
sudo apt install gcc-arm-none-eabi gdb-arm-none-eabi
```
- Check tool path with `which`
```
which arm-none-eabi-gcc
which arm-none-eabi-gdb //will be used when debug, so remember this path
which openocd
```
- Install extensions
- Install Cortex Debug vscode extension
- Edit the extension setting .json file
```json
"cortex-debug.gdbPath": "/usr/bin/gdb-multiarch" // this is the output from last step
```

**Windows**
- Download MSYS2 from [here](https://www.msys2.org/)
- The default installation path is `C:\msys64`, run `C:\msys64\msys2.exe`.
- Install OpenOCD, arm-none-eabi-gcc, and gdb-multiarch by running these commands in MSYS2 terminal.
```powershell
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
```
- Modify Environmental Variables
Add `C:\msys64\mingw64\bin` to `PATH`

> Refer to [Common Issues](#common-issues) section for local pointer to openocd and GNU toolchain
**MacOS - Apple Silicon**
- Install Arm embedded toolchain and OpenOCD and arm-none-eabi-gdb using [homebrew](https://docs.brew.sh/Installation).
```zsh
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.

### Set up VSCode
- Add the tool path for OpenOCD and make tools.

- Install the VSCode extension [Cortex-Debug](https://marketplace.visualstudio.com/items?itemName=marus25.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"```.

## How to use
### Building the Project
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.


### Debugging the Project
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.

## Common Issues
### 1. Windows fails to initializing cmsis-dap debugger.
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.

### 2. Tools (OpenOCD, make tools) not found
```
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.


> restarting terminal is liekly needed for new environment variable to take effect.
## Tips
### VSCode IntelliSense Configuration
```
"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`.

# Development Conventions
**All names must use snake_case.**

Variable names are all lowercase.
```c
float example_float = 1.5f;
```

Macros should be all UPPERCASE, and enclosed by ()
```c
#define EXAMPLE_MACRO (3.14f)
```
Function names should capitalize the first letter of each word.
```c
float Example_Function() {}
```

typedef names should capitalize the first letter of each word and end in _t.
```c
typedef struct _Example_Struct_s Example_Typedef_t {}
```

Enum names should capitalized the first letter of each word and end in _e.
```c
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.
```c
void Example_Func()
{
if (some_condition)
{
switch(some_num)
{
case 0:
break;
default:
break;
}
}
}
```

For multiline macros, indent as such:
```c
#define YOUR_MACRO \
{ \
FIRST_LINE = 0, \
SECOND_LINE = 1, \
THIRD_LINE = 2, \
}
```
# an example usage
```C
Motor_Config_t yaw_motor_config = {
// Comm Config
Expand Down
2 changes: 1 addition & 1 deletion lib/typec-board-base
2 changes: 1 addition & 1 deletion src/app/inc/debug_task.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef DEBUG_TASK_H
#define DEBUG_TASK_H

#define DEBUG_PERIOD (1)
#define DEBUG_PERIOD (10)

void Debug_Task_Init(void);
void Debug_Task_Loop(void);
Expand Down
Loading

0 comments on commit 9da822a

Please sign in to comment.