Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting for CH32V203 #33

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion Inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ extern char dshot_extended_telemetry;
extern char EDT_ARM_ENABLE;
extern char EDT_ARMED;
extern uint16_t send_extended_dshot;

#ifdef MCU_CH32V203
extern volatile char input_ready;
#endif
// typedef struct PID{
// float error;
// float Kp;
Expand Down
79 changes: 79 additions & 0 deletions Inc/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@

/*****************************************************AT32F415 targets
* ************************************************/
#ifdef AIRBOT_V20x
#define USE_MAKE
//#define USE_PA2_AS_COMP
#define FIRMWARE_NAME "AIRBOT_V203 "
#define FILE_NAME "AIRBOT_PA0_V203"
#define DEAD_TIME 75
#define HARDWARE_GROUP_CH_A
#define USE_SERIAL_TELEMETRY
#endif


/*****************************************************CH32V203 targets
* ************************************************/


#ifdef PB450_F051
#define FILE_NAME "PB450_F051"
Expand Down Expand Up @@ -2218,6 +2232,38 @@
#define PHASE_C_COMP 0x400000D1 // pa5
#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 @@ -2249,6 +2295,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 @@ -2396,6 +2443,38 @@
#define COM_TIMER_IRQ TMR1_TRG_HALL_TMR11_IRQn
#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)0x08007C00
#define INTERVAL_TIMER TIM4
#define TEN_KHZ_TIMER SysTick
#define UTILITY_TIMER NULL //for delay unimportant
#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.
Loading