Skip to content

Commit

Permalink
Merge pull request #44 from tridge/pr-vscode-support-rebase
Browse files Browse the repository at this point in the history
support building with vscode - version 2
  • Loading branch information
AlkaMotors authored Jul 25, 2024
2 parents ed44082 + cefc68f commit b502e36
Show file tree
Hide file tree
Showing 30 changed files with 415 additions and 514 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/CI_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI Build Linux

on: [push, pull_request]

jobs:
build:
runs-on: 'ubuntu-latest'

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Build CI
run: |
make arm_sdk_install
make -j8
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: AM32-binaries
path: |
obj/*.hex
retention-days: 7
25 changes: 25 additions & 0 deletions .github/workflows/CI_build_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI Build Windows

on: [push, pull_request]

jobs:
build:
runs-on: 'windows-latest'

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Build CI
run: |
make arm_sdk_install
tools/windows/make/bin/make
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: AM32-binaries
path: |
obj/*.hex
retention-days: 7
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ Keil_Projects/*.uvguix.*
Keil_Projects/Objects
Keil_Projects/RTE/*
Keil_Projects/Listings
*.bin
*.elf
*.d
*.hex
*.log
*~
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// STLink configuration
{
"name": "AM32 STLink",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/obj/debug.elf",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4,
},
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": [
"${workspaceFolder}/obj/openocd.cfg",
],
"showDevDebugOutput": "none",

"serverpath": "${workspaceFolder}${/}tools${/}${config:OS}${/}openocd${/}bin${/}openocd",
"armToolchainPath": "${workspaceRoot}/tools/${config:OS}/xpack-arm-none-eabi-gcc-10.3.1-2.3/bin",
},

// JLink configuration
{
"type": "cortex-debug",
"request": "launch",
"name": "AM32 JLink",
"cwd": "${workspaceRoot}",
"device" : "-AT32F421K8U7",
"gdbPath": "${workspaceRoot}/tools/${config:OS}/xpack-arm-none-eabi-gcc-10.3.1-2.3/bin/arm-none-eabi-gdb",
"executable": "${workspaceRoot}/obj/debug.elf",
"showDevDebugOutput": "raw",
"servertype" : "jlink",
"swoConfig": {
"enabled": false,
},
"serialNumber": "",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
}
}
]
}
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"OS": "windows",
"makefile.makePath": "tools/windows/make/bin/make.exe",

//"OS": "linux",
//"makefile.makePath": "/usr/bin/make",

"makefile.configurations": [
{
"name": "MakeSingle",
"makeArgs": [
"-j1"
]
},
{
"name": "MakeParallel-8",
"makeArgs": [
"-j8"
]
},
{
"name": "MakeParallel-MAX",
"makeArgs": [
"-j"
]
}
}
22 changes: 13 additions & 9 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
#endif
/****************************************Generic********************************************/

#ifdef AT32F421_PB4_054
#ifdef AT32PB4_054_F421
#define FIRMWARE_NAME "AT32PB4_054 "
#define FILE_NAME "AT32PB4_054_F421"
#define DEAD_TIME 80
Expand All @@ -336,7 +336,7 @@
#define USE_SERIAL_TELEMETRY
#endif

#ifdef AT32F421_PB4_405
#ifdef AT32PB4_405_F421
#define FIRMWARE_NAME "AT32PB4_405 "
#define FILE_NAME "AT32PB4_405_F421"
#define DEAD_TIME 80
Expand All @@ -345,7 +345,7 @@
#define USE_SERIAL_TELEMETRY
#endif

#ifdef AT32F421_PB4_540
#ifdef AT32PB4_540_F421
#define FIRMWARE_NAME "AT32PB4_540 "
#define FILE_NAME "AT32PB4_540_F421"
#define DEAD_TIME 80
Expand Down Expand Up @@ -406,7 +406,7 @@
#define ADC_CHANNEL_TEMP ADC_CHANNEL_6
#endif

#ifdef FLYROTOR_150A_F421
#ifdef FLYROTOR_F421
#define FIRMWARE_NAME "FLYROTOR_150"
#define FILE_NAME "FLYROTOR_F421"
#define DEAD_TIME 100
Expand Down Expand Up @@ -513,12 +513,13 @@
#define FILE_NAME "AT32DEV_F415"
#define DEAD_TIME 100
#define HARDWARE_GROUP_AT_D
#define HARDWARE_GROUP_AT_045
#define USE_SERIAL_TELEMETRY
#endif

#ifdef DAKEFPV_35A_F415
#define FIRMWARE_NAME "DakeFPV 35A "
#define FILE_NAME "DAKEFPV_35A_F415"
#define FILE_NAME "DAKEFPV_35A_F415" // DISABLE_BUILD
#define DEAD_TIME 20
#define HARDWARE_GROUP_AT_D
#define USE_SERIAL_TELEMETRY
Expand All @@ -535,7 +536,7 @@

#ifdef SPEEDYBEE_F421
#define FIRMWARE_NAME "SpeedyBee F4"
#define FILE_NAME "SpeedyBee_F421"
#define FILE_NAME "SPEEDYBEE_F421"
#define DEAD_TIME 100
#define HARDWARE_GROUP_AT_C
#define HARDWARE_GROUP_AT_540
Expand Down Expand Up @@ -867,7 +868,7 @@
#endif

#ifdef ARIA_RAMP_F051
#define FILE_NAME "FLYCOLOR_F051"
#define FILE_NAME "ARIA_RAMP_F051"
#define FIRMWARE_NAME "Aria Slow "
#define DEAD_TIME 45
#define HARDWARE_GROUP_F0_A
Expand Down Expand Up @@ -1134,7 +1135,7 @@
#endif

#ifdef IFLIGHT_12S_SINGLE_N_G071
#define FILE_NAME "IFLIGHT_12S_G071"
#define FILE_NAME "IFLIGHT_12S_SINGLE_N_G071"
#define FIRMWARE_NAME "12s G071N "
#define DEAD_TIME 100
#define MILLIVOLT_PER_AMP 67
Expand Down Expand Up @@ -1390,7 +1391,10 @@
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_7
#endif


#ifndef FIRMWARE_NAME
/* if you get this then you have forgotten to add the section for your target above */
#error "Missing defines for target"
#endif

/********************************** defaults if not set
* ***************************/
Expand Down
5 changes: 5 additions & 0 deletions Inc/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
update this file for new releases
*/
#define VERSION_MAJOR 2
#define VERSION_MINOR 16
143 changes: 143 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

QUIET = @

# tools
CC = $(ARM_SDK_PREFIX)gcc
OBJCOPY = $(ARM_SDK_PREFIX)objcopy
ECHO = echo

# common variables
IDENTIFIER := AM32

# Folders
HAL_FOLDER := Mcu
MAIN_SRC_DIR := Src
MAIN_INC_DIR := Inc

SRC_DIRS_COMMON := $(MAIN_SRC_DIR)

# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

# include the rules for OS independence
include $(ROOT)/make/tools.mk

# Include processor specific makefiles
include f051makefile.mk
include g071makefile.mk
include f031makefile.mk
include f421makefile.mk
include e230makefile.mk
include f415makefile.mk
include gd32makefile.mk

# Default MCU type to F051
MCU_TYPE ?= F051

# additional libs
LIBS := -lnosys

# extract version from Inc/version.h
VERSION_MAJOR := $(shell $(FGREP) "define VERSION_MAJOR" $(MAIN_INC_DIR)/version.h | $(CUT) -d" " -f3 )
VERSION_MINOR := $(shell $(FGREP) "define VERSION_MINOR" $(MAIN_INC_DIR)/version.h | $(CUT) -d" " -f3 )

FIRMWARE_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR)

# Compiler options
CFLAGS_COMMON := -DUSE_MAKE -fsingle-precision-constant -fomit-frame-pointer -ffast-math
CFLAGS_COMMON += -I$(MAIN_INC_DIR) -g -O3 -Wall -ffunction-sections
CFLAGS_COMMON += -D$(TARGET)

# Linker options
LDFLAGS_COMMON := -specs=nano.specs $(LIBS) -Wl,--gc-sections -Wl,--print-memory-usage

# Search source files
SRC_COMMON := $(foreach dir,$(SRC_DIRS_COMMON),$(wildcard $(dir)/*.[cs]))

TARGET_FNAME = $(IDENTIFIER)_$(TARGET)_$(FIRMWARE_VERSION)
TARGET_BASENAME = $(BIN_DIR)/$(TARGET_FNAME)

# configure some directories that are relative to wherever ROOT_DIR is located
OBJ := obj
BIN_DIR := $(ROOT)/$(OBJ)

TOOLS_DIR ?= $(ROOT)/tools
DL_DIR := $(ROOT)/downloads

.PHONY : clean all binary f051 g071 f031 e230 f421 f415
ALL_TARGETS := $(TARGETS_F051) $(TARGETS_G071) $(TARGETS_F031) $(TARGETS_E230) $(TARGETS_F421) $(TARGETS_F415)
all : $(ALL_TARGETS)
f051 : $(TARGETS_F051)
g071 : $(TARGETS_G071)
f031 : $(TARGETS_F031)
e230 : $(TARGETS_E230)
f421 : $(TARGETS_F421)
f415 : $(TARGETS_F415)

clean :
@echo Removing $(OBJ) directory
@$(RM) -rf $(OBJ)

# lowercase version of MCU_TYPE
MCU_LOWER = $(call lc,$(MCU_TYPE))

binary : $(TARGET_BASENAME).bin
# we copy debug.elf to give us a constant debug target for vscode
# this means the debug button will always debug the last target built
@$(CP) -f $(OBJ)$(DSEP)$(TARGET_FNAME).elf $(OBJ)$(DSEP)debug.elf > $(NUL)
# also copy the openocd.cfg from the MCU directory to obj/openocd.cfg for auto config of Cortex-Debug
# in vscode
@$(CP) -f Mcu$(DSEP)$(MCU_LOWER)$(DSEP)openocd.cfg $(OBJ)$(DSEP)openocd.cfg > $(NUL)
@$(ECHO) done $(TARGET)

$(TARGETS_F051) :
@$(MAKE) -s MCU_TYPE=F051 TARGET=$@ binary

$(TARGETS_G071) :
@$(MAKE) -s MCU_TYPE=G071 TARGET=$@ binary

$(TARGETS_F031) :
@$(MAKE) -s MCU_TYPE=F031 TARGET=$@ binary

$(TARGETS_E230) :
@$(MAKE) -s MCU_TYPE=E230 TARGET=$@ binary

$(TARGETS_F421) :
@$(MAKE) -s MCU_TYPE=F421 TARGET=$@ binary

$(TARGETS_F415) :
@$(MAKE) -s MCU_TYPE=F415 TARGET=$@ binary

# Compile target
$(TARGET_BASENAME).elf: CFLAGS := $(MCU_$(MCU_TYPE)) $(CFLAGS_$(MCU_TYPE)) $(CFLAGS_COMMON)
$(TARGET_BASENAME).elf: LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_$(MCU_TYPE)) -T$(LDSCRIPT_$(MCU_TYPE))
$(TARGET_BASENAME).elf: $(SRC_COMMON) $(SRC_$(MCU_TYPE))
@$(ECHO) Compiling $(notdir $@)
$(QUIRT)$(MKDIR) -p $(OBJ)
$(QUIET)$(CC) $(CFLAGS) $(LDFLAGS) -MMD -MP -MF $(@:.elf=.d) -o $(@) $(SRC_COMMON) $(SRC_$(MCU_TYPE))

# Generate bin and hex files
$(TARGET_BASENAME).bin: $(TARGET_BASENAME).elf
@$(ECHO) Generating $(notdir $@)
$(QUIET)$(OBJCOPY) -O binary $(<) $@
$(QUIET)$(OBJCOPY) $(<) -O ihex $(@:.bin=.hex)

# mkdirs
$(DL_DIR):
$(QUIET)$(MKDIR) -p $@

$(TOOLS_DIR):
$(QUIET)$(MKDIR) -p $@

# include the targets for installing tools
include $(ROOT)/make/tools_install.mk

targets:
$(QUIET)echo Targets for each MCU. To build a target use 'make TARGETNAME'
$(QUIET)echo F051 Targets: $(TARGETS_F051)
$(QUIET)echo G071 Targets: $(TARGETS_G071)
$(QUIET)echo F031 Targets: $(TARGETS_F031)
$(QUIET)echo E230 Targets: $(TARGETS_E230)
$(QUIET)echo F421 Targets: $(TARGETS_F421)
$(QUIET)echo F415 Targets: $(TARGETS_F415)
$(QUIET)echo GD32 Targets: $(TARGETS_GD32)
7 changes: 7 additions & 0 deletions Mcu/e230/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# config for openocd for GD32E230 MCUs
source [find interface/stlink.cfg]
source [find target/gd32e23x.cfg]

# use -gdb-max-connections to allow for live watch in vscode
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -gdb-max-connections 4
init
7 changes: 7 additions & 0 deletions Mcu/f031/openocd.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# config for openocd for STM32F031 MCUs
source [find interface/stlink.cfg]
source [find target/stm32f0x.cfg]

# use -gdb-max-connections to allow for live watch in vscode
$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -gdb-max-connections 4
init
Loading

0 comments on commit b502e36

Please sign in to comment.