Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ extern GPIO_TypeDef* current_GPIO_PORT;
#ifndef MCU_F031
extern COMP_TypeDef* active_COMP;
#endif
#ifdef MCU_F031
extern char input_ready;
#endif
#endif
#ifdef GIGADEVICES
extern uint32_t current_GPIO_PORT;
Expand All @@ -53,7 +50,9 @@ extern char dshot_extended_telemetry;
extern char EDT_ARM_ENABLE;
extern char EDT_ARMED;
extern uint16_t send_extended_dshot;

#ifdef NEED_INPUT_READY
extern volatile char input_ready;
#endif
// typedef struct PID{
// float error;
// float Kp;
Expand Down
69 changes: 69 additions & 0 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -2299,6 +2299,16 @@
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_7
#endif

/*****************************************************CH32V203 targets
* ************************************************/
#ifdef AIRBOT_V203
//#define USE_PA2_AS_COMP
#define FIRMWARE_NAME "AIRBOT_V203"
#define FILE_NAME "AIRBOT_V203"
#define DEAD_TIME 75
#define HARDWARE_GROUP_CH_A
#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"
Expand Down Expand Up @@ -3916,6 +3926,36 @@
#define CURRENT_ADC_CHANNEL LL_ADC_CHANNEL_8
#define VOLTAGE_ADC_CHANNEL LL_ADC_CHANNEL_11

#endif

#ifdef HARDWARE_GROUP_CH_A

#define MCU_CH32V203
#define USE_TIMER_15_CHANNEL_1

#define INPUT_PIN GPIO_Pin_0
#define INPUT_PIN_PORT GPIOA
#define IC_TIMER_CHANNEL (1-1)
#define IC_TIMER_REGISTER TIM2
#define INPUT_DMA_CHANNEL DMA1_Channel5
#define IC_DMA_IRQ_NAME DMA1_Channel5_IRQn

#define PHASE_A_GPIO_LOW GPIO_Pin_1
#define PHASE_A_GPIO_PORT_LOW GPIOB
#define PHASE_A_GPIO_HIGH GPIO_Pin_10
#define PHASE_A_GPIO_PORT_HIGH GPIOA

#define PHASE_B_GPIO_LOW GPIO_Pin_0
#define PHASE_B_GPIO_PORT_LOW GPIOB
#define PHASE_B_GPIO_HIGH GPIO_Pin_9
#define PHASE_B_GPIO_PORT_HIGH GPIOA

#define PHASE_C_GPIO_LOW GPIO_Pin_7
#define PHASE_C_GPIO_PORT_LOW GPIOA
#define PHASE_C_GPIO_HIGH GPIO_Pin_8
#define PHASE_C_GPIO_PORT_HIGH GPIOA


#endif

/************************************ MCU COMMON PERIPHERALS
Expand Down Expand Up @@ -3950,6 +3990,7 @@
#endif

#ifdef MCU_F031
#define NEED_INPUT_READY
#define STMICRO
#define CPU_FREQUENCY_MHZ 48
#define EEPROM_START_ADD (uint32_t)0x08007C00
Expand Down Expand Up @@ -4141,6 +4182,34 @@
#endif


#ifdef MCU_CH32V203
#define WCH
#define NEED_INPUT_READY
#define ERASED_FLASH_BYTE 0x39
#define CPU_FREQUENCY_MHZ 48 //PWM freq is 48MHz, CPU freq is 96MHz
#define EEPROM_START_ADD (uint32_t)0x0800f800
#define INTERVAL_TIMER TIM4
#define TEN_KHZ_TIMER SysTick
#define UTILITY_TIMER TIM4
#define COM_TIMER TIM3 //for
#define TIM1_AUTORELOAD 2000
#define APPLICATION_ADDRESS 0x08001000

#define TARGET_MIN_BEMF_COUNTS 6
#define USE_ADC
// #define DSHOT_PRE 95
#define DSHOT_PRIORITY_THRESHOLD 50
#define COM_TIMER_IRQ TIM3_IRQn

#ifndef USE_PA2_AS_COMP
#define COMPARATOR_IRQ EXTI3_IRQn
#define COMPARATOR_IRQ_2 EXTI4_IRQn
#else
#define COMPARATOR_IRQ EXTI2_IRQn
#endif

#endif

#ifndef LOOP_FREQUENCY_HZ
#define LOOP_FREQUENCY_HZ 20000
#endif
Expand Down
151 changes: 151 additions & 0 deletions MRS_Projects/ch32v203f8u6/Am32V203/.cproject

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions MRS_Projects/ch32v203f8u6/Am32V203/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<projectDescription>
<name>Am32V203</name>
<comment/>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments/>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments/>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<filteredResources>
<filter>
<id>1595986042669</id>
<name/>
<type>22</type>
<matcher>
<id>org.eclipse.ui.ide.multiFilter</id>
<arguments>1.0-name-matches-false-false-*.wvproj</arguments>
</matcher>
</filter>
</filteredResources>
<linkedResources>
<link>
<name>v203</name>
<type>2</type>
<location>PARENT-3-PROJECT_LOC/Mcu/v203</location>
</link>
<link>
<name>Src</name>
<type>2</type>
<location>PARENT-3-PROJECT_LOC/Src</location>
</link>
<link>
<name>Inc</name>
<type>2</type>
<location>PARENT-3-PROJECT_LOC/Inc</location>
</link>
</linkedResources>
</projectDescription>
14 changes: 14 additions & 0 deletions MRS_Projects/ch32v203f8u6/Am32V203/.settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="ilg.gnumcueclipse.managedbuild.cross.riscv.config.elf.release.1008047074" name="obj">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-755220019984086581" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
</extension>
</configuration>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//v203/Drivers/Peripheral/inc/ch32v20x.h=UTF-8
17 changes: 17 additions & 0 deletions MRS_Projects/ch32v203f8u6/Am32V203/.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Mcu Type=CH32V20x
Address=0x08000000
Target Path=obj/Am32V203.hex
Erase All=true
Program=true
Verify=true
Reset=true

Vendor=WCH
Link=WCH-Link
Toolchain=RISC-V
Series=CH32V203
RTOS=NoneOS
MCU=CH32V203F8U6
Description=Website: http://www.wch.cn/products/CH32V203.html?\nROM(byte): 64K, SRAM(byte): 20K, CHIP PINS: 20, GPIO PORTS: 17.\nWCH CH32V2 series of mainstream MCUs covers the needs of a large variety of applications in the industrial,medical and consumer markets. High performance with first-class peripherals and low-power,low-voltage operation is paired with a high level of integration at accessible prices with a simple architecture and easy-to-use tools.

PeripheralVersion=2.1
61 changes: 61 additions & 0 deletions MRS_Projects/ch32v203f8u6/Am32V203/Am32V203.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" ?>
<launchConfiguration type="com.mounriver.debug.gdbjtag.openocd.launchConfigurationType">
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doContinue" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doDebugInRam" value="false" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doFirstReset" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doGdbServerAllocateConsole" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doGdbServerAllocateTelnetConsole" value="false" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doSecondReset" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doStartGdbCLient" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.doStartGdbServer" value="true" />
<booleanAttribute key="com.mounriver.debug.gdbjtag.openocd.enableSemihosting" value="false" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.firstResetType" value="init" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbClientOtherCommands" value="set mem inaccessible-by-default off&#xD;&#xA;set architecture riscv:rv32&#xD;&#xA;set remotetimeout unlimited" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbClientOtherOptions" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerConnectionAddress" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerExecutable" value="${eclipse_home}toolchain/OpenOCD/bin/${openocd_executable}" />
<intAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerGdbPortNumber" value="3333" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerLog" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerOther" value="-f &quot;${eclipse_home}toolchain/OpenOCD/bin/wch-riscv.cfg&quot;" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerTclPortNumber" value="6666" />
<intAttribute key="com.mounriver.debug.gdbjtag.openocd.gdbServerTelnetPortNumber" value="4444" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.otherInitCommands" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.otherRunCommands" value="" />
<stringAttribute key="com.mounriver.debug.gdbjtag.openocd.secondResetType" value="halt" />
<stringAttribute key="com.mounriver.debug.gdbjtag.svdPath" value="${eclipse_home}template/wizard/WCH/RISC-V/CH32V203/NoneOS/CH32V203xx.svd" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageFileName" value="" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.imageOffset" value="" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="GNU MCU OpenOCD" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value="" />
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="3333" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="false" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setResume" value="false" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setStopAt" value="true" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.stopAt" value="handle_reset" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsFileName" value="" />
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.symbolsOffset" value="" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForImage" value="false" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useFileForSymbols" value="false" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForImage" value="true" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true" />
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true" />
<stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="${eclipse_home}toolchain/RISC-V Embedded GCC/bin/riscv-none-embed-gdb.exe" />
<booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="false" />
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2" />
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value="" />
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="obj\Am32V203.elf" />
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="Am32V203" />
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true" />
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="" />
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/Am32V203" />
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4" />
</listAttribute>
<stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#xD;&#xA;&lt;memoryBlockExpressionList context=&quot;Context string&quot;/&gt;&#xD;&#xA;" />
<stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory" />
</launchConfiguration>
Binary file added MRS_Projects/ch32v203f8u6/Am32V203/Am32V203.wvproj
Binary file not shown.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
include $(ROOT)/make/tools.mk

# supported MCU types
MCU_TYPES := E230 F031 F051 F415 F421 G071 L431 G431
MCU_TYPES := E230 F031 F051 F415 F421 G071 L431 G431 V203
MCU_TYPE := NONE

# Function to include makefile for each MCU type
Expand Down Expand Up @@ -86,13 +86,17 @@ $(2)_BASENAME = $(BIN_DIR)/$(IDENTIFIER)_$(2)_$(FIRMWARE_VERSION)

$(2) : $$($(2)_BASENAME).bin

# get MCU specific compiler, objcopy and link script or use the ARM SDK one
$(eval xCC := $(if $($(MCU)_CC), $($(MCU)_CC), $(CC)))
$(eval xOBJCOPY := $(if $($(MCU)_OBJCOPY), $($(MCU)_OBJCOPY), $(OBJCOPY)))

# Generate bin and hex files from elf
$$($(2)_BASENAME).bin: $$($(2)_BASENAME).elf
echo building BIN $$@
@$(ECHO) Generating $$(notdir $$@)
$(QUIET)$(OBJCOPY) -O binary $$(<) $$@
$(QUIET)$(xOBJCOPY) -O binary $$(<) $$@
$(QUIET)python3 Src/DroneCAN/set_app_signature.py $$@ $$(<)
$(QUIET)$(OBJCOPY) $$(<) -O ihex $$(@:.bin=.hex)
$(QUIET)$(xOBJCOPY) $$(<) -O ihex $$(@:.bin=.hex)
$(QUIET)$(CP) -f $$(<) $(OBJ)$(DSEP)debug.elf > $(NUL)

# check for CAN support
Expand All @@ -108,7 +112,7 @@ LDFLAGS_$(2) = $(LDFLAGS_COMMON) $(LDFLAGS_$(1)) -T$(xLDSCRIPT)
$$($(2)_BASENAME).elf: $(SRC_COMMON) $$(SRC_$(1)) $(xSRC)
@$(ECHO) Compiling $$(notdir $$@)
$(QUIET)$(MKDIR) -p $(OBJ)
$(QUIET)$(CC) $$(CFLAGS_$(2)) $$(LDFLAGS_$(2)) -MMD -MP -MF $$(@:.elf=.d) -o $$(@) $(SRC_COMMON) $$(SRC_$(1)) $(xSRC)
$(QUIET)$(xCC) $$(CFLAGS_$(2)) $$(LDFLAGS_$(2)) -MMD -MP -MF $$(@:.elf=.d) -o $$(@) $(SRC_COMMON) $$(SRC_$(1)) $(xSRC)
# 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
$(QUIET)$(CP) -f $$(SVD_$(1)) $(OBJ)/debug.svd
Expand Down
1 change: 0 additions & 1 deletion Mcu/f031/Src/stm32f0xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ extern char servoPwm;

// extern uint32_t gcr[];
// extern uint8_t gcr_size;
char input_ready = 0;
int update_interupt = 0;
uint8_t update_count = 0;
uint16_t interrupt_time = 0;
Expand Down
Loading