Skip to content

Commit

Permalink
(#33) Linux Support and System Info Debug
Browse files Browse the repository at this point in the history
Linux support
  • Loading branch information
jia-xie authored Apr 6, 2024
2 parents 8d8b098 + 2f05b17 commit d3635e9
Show file tree
Hide file tree
Showing 29 changed files with 106 additions and 25 deletions.
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
}
]
}
18 changes: 15 additions & 3 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 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 @@ -208,8 +208,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 @@ -234,7 +234,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 @@ -273,8 +273,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 @@ -299,8 +301,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 @@ -311,4 +313,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 ***
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ git submodule update --init
### 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`.
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
27 changes: 25 additions & 2 deletions src/app/src/debug_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,37 @@ extern Remote_t g_remote;
extern Launch_Target_t g_launch_target;
extern uint64_t t;
extern Daemon_Instance_t *g_daemon_instances[3];
extern Daemon_Instance_t *g_remote_daemon;
#define PRINT_RUNTIME_STATS
#ifdef PRINT_RUNTIME_STATS
char g_debug_buffer[1024*2] = {0};
#endif

const char* top_border = "\r\n\r\n\r\n/***** System Info *****/\r\n";
const char* bottom_border = "/***** End of Info *****/\r\n";

#define DEBUG_ENABLED

void Debug_Task_Loop(void)
{
#ifdef DEBUG_ENABLED
static uint32_t counter = 0;
DEBUG_PRINTF(&huart6, "time=%.1f,a=%d,b=%d,c=%f,d=%d\r\n", (float) counter / 1000.0f * DEBUG_PERIOD,
2, 12, g_imu.deg.roll, counter);
#ifdef PRINT_RUNTIME_STATS
if (counter % 100 == 0) // Print every 100 cycles
{
vTaskGetRunTimeStats(g_debug_buffer);
DEBUG_PRINTF(&huart6, "%s", top_border);
DEBUG_PRINTF(&huart6, "%s", g_debug_buffer);
DEBUG_PRINTF(&huart6, "%s", bottom_border);
}
#endif

DEBUG_PRINTF(&huart6, ">time:%.1f\n>yaw:%f\n>pitch:%f\n>roll:%f\n", (float) counter / 1000.0f * DEBUG_PERIOD,
g_imu.deg.yaw, g_imu.deg.pitch, g_imu.deg.roll);
DEBUG_PRINTF(&huart6, ">remote_daemon:%d\n", g_remote_daemon->counter);
counter++;
if (counter > 0xFFFFFFFF) {
counter = 0;
}
#endif
}
1 change: 0 additions & 1 deletion src/bsp/Inc/bsp_can.h → src/bsp/inc/bsp_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "FreeRTOS.h"
#include "can.h"
#include "freertos.h"
#include "queue.h"
#include "cmsis_os.h"
#include <stdint.h>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "BMI088driver.h"
#include "BMI088reg.h"
#include "BMI088Middleware.h"
#include "bmi088driver.h"
#include "bmi088reg.h"
#include "bmi088middleware.h"


float BMI088_ACCEL_SEN = BMI088_ACCEL_3G_SEN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "BMI088Middleware.h"
#include "bmi088middleware.h"
#include "main.h"
#include "cmsis_os.h"
#include "bsp_delay.h"
Expand Down
2 changes: 2 additions & 0 deletions src/devices/src/imu_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ void IMU_Task_Temp() {
switch (start_complete)
{
case 1:
{
uint16_t temp_pwm = (uint16_t) PID(&g_imu_temp_pid, 40 - g_imu.bmi088_raw.temp);
__HAL_TIM_SetCompare(&htim10, TIM_CHANNEL_1, temp_pwm);
break;
}
case 0:
__HAL_TIM_SetCompare(&htim10, TIM_CHANNEL_1, 4999);
break;
Expand Down

0 comments on commit d3635e9

Please sign in to comment.