diff --git a/CH32V305/.cproject b/CH32V305/.cproject
index 15edf7d..7dd1779 100644
--- a/CH32V305/.cproject
+++ b/CH32V305/.cproject
@@ -20,7 +20,7 @@
-
+
@@ -45,11 +45,11 @@
-
-
-
+
+
+
-
+
@@ -75,13 +75,16 @@
+
@@ -114,7 +117,7 @@
-
+
diff --git a/CH32V305/.project b/CH32V305/.project
index 54ad0f9..9e7b031 100644
--- a/CH32V305/.project
+++ b/CH32V305/.project
@@ -1,41 +1,44 @@
- DAPLink
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
-
- 1595986042669
-
- 22
-
- org.eclipse.ui.ide.multiFilter
- 1.0-name-matches-false-false-*.wvproj
-
-
-
-
-
- core
- 2
- PARENT-1-PROJECT_LOC/core
-
-
+ DAPLink
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
+
+ core
+ 2
+ PARENT-1-PROJECT_LOC/core
+
+
+
+
+ 1685539991138
+
+ 22
+
+ org.eclipse.ui.ide.multiFilter
+ 1.0-name-matches-false-false-*.wvproj
+
+
+
diff --git a/CH32V305/.template b/CH32V305/.template
index f6b89b7..1faa1f6 100644
--- a/CH32V305/.template
+++ b/CH32V305/.template
@@ -1,18 +1,17 @@
+Target Path=obj\DAPLink.hex
Address=0x08000000
-Erase All=true
+Erase All=false
Program=true
Verify=true
Reset=true
-
Toolchain=RISC-V
-Series=CH32V307
-Description=ROM(byte): 256K, SRAM(byte): 64K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 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=1.4
-Target Path=obj/DAPLink.hex
-
+Series=CH32V305
+RTOS=NoneOS
+Description=Website: http://www.wch.cn/products/CH32V307.html?\nROM(byte): 128K, SRAM(byte): 32K, CHIP PINS: 64, GPIO PORTS: 51.\nWCH CH32V3 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.0
+CLKSpeed=0
Vendor=WCH
-MCU=CH32V307RCT6
+MCU=CH32V305FBP6
Mcu Type=CH32V30x
-Link=WCH-Link
+Link=WCH-Link
\ No newline at end of file
diff --git a/CH32V305/DAPLink.launch b/CH32V305/DAPLink.launch
new file mode 100644
index 0000000..be4b2e6
--- /dev/null
+++ b/CH32V305/DAPLink.launch
@@ -0,0 +1,62 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CH32V305/DAPLink.wvproj b/CH32V305/DAPLink.wvproj
index 2cd99d9..84e0723 100644
--- a/CH32V305/DAPLink.wvproj
+++ b/CH32V305/DAPLink.wvproj
@@ -1,2 +1,2 @@
-iCZ ?"ǁrF<.ſ?/XOĿChQN$*EBk!2t+buhnUb]xll|
-+"MaDX}&ntyTfVOD(BA$ 1M{}J3XFFa&z lDu8u9{FLASH AT>FLASH
.vector :
{
*(.vector);
. = ALIGN(64);
} >FLASH AT>FLASH
.text :
{
. = ALIGN(4);
*(.text)
*(.text.*)
*(.rodata)
*(.rodata*)
*(.gnu.linkonce.t.*)
. = ALIGN(4);
} >FLASH AT>FLASH
.fini :
{
KEEP(*(SORT_NONE(.fini)))
. = ALIGN(4);
} >FLASH AT>FLASH
PROVIDE( _etext = . );
PROVIDE( _eitcm = . );
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH AT>FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH AT>FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH AT>FLASH
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
} >FLASH AT>FLASH
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >FLASH AT>FLASH
.dalign :
{
. = ALIGN(4);
PROVIDE(_data_vma = .);
} >RAM AT>FLASH
.dlalign :
{
. = ALIGN(4);
PROVIDE(_data_lma = .);
} >FLASH AT>FLASH
.data :
{
*(.gnu.linkonce.r.*)
*(.data .data.*)
*(.gnu.linkonce.d.*)
. = ALIGN(8);
PROVIDE( __global_pointer$ = . + 0x800 );
*(.sdata .sdata.*)
*(.sdata2.*)
*(.gnu.linkonce.s.*)
. = ALIGN(8);
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
. = ALIGN(4);
PROVIDE( _edata = .);
} >RAM AT>FLASH
.bss :
{
. = ALIGN(4);
PROVIDE( _sbss = .);
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss*)
*(.gnu.linkonce.b.*)
*(COMMON*)
. = ALIGN(4);
PROVIDE( _ebss = .);
} >RAM AT>FLASH
PROVIDE( _end = _ebss);
PROVIDE( end = . );
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
PROVIDE( _heap_end = . );
. = ALIGN(4);
PROVIDE(_susrstack = . );
. = . + __stack_size;
PROVIDE( _eusrstack = .);
} >RAM
}
\ No newline at end of file
+ENTRY( _start )
__stack_size = 4096;
PROVIDE( _stack_size = __stack_size );
MEMORY
{
/* CH32V30x_D8C - CH32V305RB-CH32V305FB
CH32V30x_D8 - CH32V303CB-CH32V303RB
*/
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 128K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
/* CH32V30x_D8C - CH32V307VC-CH32V307WC-CH32V307RC
CH32V30x_D8 - CH32V303VC-CH32V303RC
FLASH + RAM supports the following configuration
FLASH-192K + RAM-128K
FLASH-224K + RAM-96K
FLASH-256K + RAM-64K
FLASH-288K + RAM-32K
*/
/*
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 288K
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K
*/
}
SECTIONS
{
.init :
{
_sinit = .;
. = ALIGN(4);
KEEP(*(SORT_NONE(.init)))
. = ALIGN(4);
_einit = .;
} >FLASH AT>FLASH
.vector :
{
*(.vector);
. = ALIGN(64);
} >FLASH AT>FLASH
.text :
{
. = ALIGN(4);
*(.text)
*(.text.*)
*(.rodata)
*(.rodata*)
*(.gnu.linkonce.t.*)
. = ALIGN(4);
} >FLASH AT>FLASH
.fini :
{
KEEP(*(SORT_NONE(.fini)))
. = ALIGN(4);
} >FLASH AT>FLASH
PROVIDE( _etext = . );
PROVIDE( _eitcm = . );
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >FLASH AT>FLASH
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >FLASH AT>FLASH
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >FLASH AT>FLASH
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
} >FLASH AT>FLASH
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >FLASH AT>FLASH
.dalign :
{
. = ALIGN(4);
PROVIDE(_data_vma = .);
} >RAM AT>FLASH
.dlalign :
{
. = ALIGN(4);
PROVIDE(_data_lma = .);
} >FLASH AT>FLASH
.data :
{
*(.gnu.linkonce.r.*)
*(.data .data.*)
*(.gnu.linkonce.d.*)
. = ALIGN(8);
PROVIDE( __global_pointer$ = . + 0x800 );
*(.sdata .sdata.*)
*(.sdata2.*)
*(.gnu.linkonce.s.*)
. = ALIGN(8);
*(.srodata.cst16)
*(.srodata.cst8)
*(.srodata.cst4)
*(.srodata.cst2)
*(.srodata .srodata.*)
. = ALIGN(4);
PROVIDE( _edata = .);
} >RAM AT>FLASH
.bss :
{
. = ALIGN(4);
PROVIDE( _sbss = .);
*(.sbss*)
*(.gnu.linkonce.sb.*)
*(.bss*)
*(.gnu.linkonce.b.*)
*(COMMON*)
. = ALIGN(4);
PROVIDE( _ebss = .);
} >RAM AT>FLASH
PROVIDE( _end = _ebss);
PROVIDE( end = . );
.stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size :
{
PROVIDE( _heap_end = . );
. = ALIGN(4);
PROVIDE(_susrstack = . );
. = . + __stack_size;
PROVIDE( _eusrstack = .);
} >RAM
}
\ No newline at end of file
diff --git a/CH32V305/src/vcom_serial.c b/CH32V305/src/vcom_serial.c
index 7a1a531..68e0348 100644
--- a/CH32V305/src/vcom_serial.c
+++ b/CH32V305/src/vcom_serial.c
@@ -11,12 +11,10 @@ volatile VCOM Vcom;
VCOM_LINE_CODING LineCfg = {115200, 0, 0, 8}; // Baud rate, stop bits, parity bits, data bits
-volatile uint32_t RX_Timeout = (1000.0 / 115200) * (512 * 10) * 1.5;
-
-#define BUF_SZ 1024
-uint8_t TXBuffer[BUF_SZ] __attribute__((aligned(4)));
-uint8_t RXBuffer[BUF_SZ] __attribute__((aligned(4)));
+#define RXDMA_SZ (CDC_BULK_IN_SZ_HS * 2)
+uint8_t RXBuffer[RXDMA_SZ] __attribute__((aligned(4)));
+uint8_t TXBuffer[CDC_BULK_OUT_SZ_HS] __attribute__((aligned(4)));
void VCOM_Init(void)
@@ -29,10 +27,9 @@ void VCOM_Init(void)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_DMA1, ENABLE);
-
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure); // PB10 => USART3_TX
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
@@ -48,14 +45,23 @@ void VCOM_Init(void)
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_BufferSize = 0;
- DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel2, ENABLE);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
+ DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&USART3->DATAR;
+ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)RXBuffer;
+ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
+ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
+ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
+ DMA_InitStructure.DMA_BufferSize = RXDMA_SZ;
+ DMA_InitStructure.DMA_Priority = DMA_Priority_High;
+ DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
+ DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel3, ENABLE);
@@ -110,72 +116,40 @@ void VCOM_LineCoding(VCOM_LINE_CODING * LineCfgx)
__disable_irq();
USART_Init(USART3, &USART_InitStructure);
-
- RX_Timeout = (1000.0 / USART_InitStructure.USART_BaudRate) * (512 * 10) * 1.5;
__enable_irq();
}
extern volatile uint32_t SysTick_ms;
+
void VCOM_TransferData(void)
{
- uint8_t *rxdata = RXBuffer;
+ static uint32_t last_ms = 0;
+ static uint32_t last_pos = 0;
if(Vcom.in_ready) // 可以向主机发送数据
{
- if((DMA1->INTFR & (DMA1_FLAG_HT3 | DMA1_FLAG_TC3)) || (SysTick_ms > RX_Timeout))
+ uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel3);
+ if((pos - last_pos >= CDC_BULK_IN_SZ_HS) || ((pos != last_pos) && (SysTick_ms != last_ms)))
{
- if(DMA1->INTFR & DMA1_FLAG_HT3)
- {
- rxdata = &RXBuffer[0];
-
- Vcom.in_bytes = BUF_SZ/2;
-
- DMA1->INTFCR = DMA1_FLAG_HT3;
- }
- else if(DMA1->INTFR & DMA1_FLAG_TC3)
- {
- rxdata = &RXBuffer[BUF_SZ/2];
-
- Vcom.in_bytes = BUF_SZ/2;
-
- DMA1->INTFCR = DMA1_FLAG_TC3;
-
- SysTick_ms = 0;
- }
- else
- {
- SysTick_ms = 0;
-
- uint32_t n_xfer = BUF_SZ - DMA_GetCurrDataCounter(DMA1_Channel3);
- if(n_xfer == 0)
- {
- goto xfer_out;
- }
- if(n_xfer < BUF_SZ/2)
- {
- rxdata = &RXBuffer[0];
-
- Vcom.in_bytes = n_xfer;
- }
- else
- {
- rxdata = &RXBuffer[BUF_SZ/2];
-
- Vcom.in_bytes = n_xfer - BUF_SZ/2;
- }
-
- DMA_Cmd(DMA1_Channel3, DISABLE);
- DMA_SetCurrDataCounter(DMA1_Channel3, BUF_SZ);
- DMA_Cmd(DMA1_Channel3, ENABLE);
- }
+ if(pos < last_pos)
+ pos = RXDMA_SZ;
+
+ if(pos - last_pos > CDC_BULK_IN_SZ_HS)
+ pos = last_pos + CDC_BULK_IN_SZ_HS;
+
+ Vcom.in_bytes = pos - last_pos;
Vcom.in_ready = 0;
- USBHSD->UEP3_TX_DMA = (uint32_t)rxdata;
+ USBHSD->UEP3_TX_DMA = (uint32_t)&RXBuffer[last_pos];
USBHSD->UEP3_TX_LEN = Vcom.in_bytes;
USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_ACK;
+
+ last_pos = pos % RXDMA_SZ;
+
+ last_ms = SysTick_ms;
}
else
{