mirror of
https://github.com/XIVN1987/DAPLink.git
synced 2026-09-26 22:16:11 +00:00
解决外部供电时,先接收到串口数据、后插入电脑导致无法接收的问题
This commit is contained in:
@@ -53,15 +53,16 @@ void USBHS_RCC_Init(void)
|
|||||||
{
|
{
|
||||||
RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
|
RCC_USBCLK48MConfig(RCC_USBCLK48MCLKSource_USBPHY);
|
||||||
|
|
||||||
RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE); // USBHS PLL 时钟源:HSE
|
RCC_USBHSPLLCLKConfig(RCC_HSBHSPLLCLKSource_HSE); // USBHS PLL 时钟源:HSE
|
||||||
RCC_USBHSConfig(RCC_USBPLL_Div2); // USBHS PLL 时钟源进入 PLL 前 2 分频
|
RCC_USBHSConfig(RCC_USBPLL_Div2); // USBHS PLL 时钟源进入 PLL 前 2 分频
|
||||||
RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M); // USBHS PLL 时钟源分频后频率为 4MHz(外接晶振为 8MHz)
|
RCC_USBHSPLLCKREFCLKConfig(RCC_USBHSPLLCKREFCLK_4M); // USBHS PLL 时钟源分频后频率为 4MHz(外接晶振为 8MHz)
|
||||||
RCC_USBHSPHYPLLALIVEcmd(ENABLE);
|
RCC_USBHSPHYPLLALIVEcmd(ENABLE);
|
||||||
|
|
||||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_USBHS, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern volatile VCOM Vcom;
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* @fn USBHS_Device_Endp_Init
|
* @fn USBHS_Device_Endp_Init
|
||||||
*
|
*
|
||||||
@@ -75,7 +76,7 @@ void USBHS_Device_Endp_Init(void)
|
|||||||
USBHS_UEP2_T_EN |
|
USBHS_UEP2_T_EN |
|
||||||
USBHS_UEP3_T_EN | USBHS_UEP3_R_EN;
|
USBHS_UEP3_T_EN | USBHS_UEP3_R_EN;
|
||||||
|
|
||||||
USBHSD->UEP0_MAX_LEN = USB_MAX_EP0_SZ; // 端点 n 接收数据的最大包长度
|
USBHSD->UEP0_MAX_LEN = USB_MAX_EP0_SZ; // 端点 n 接收数据的最大包长度
|
||||||
USBHSD->UEP1_MAX_LEN = HID_INT_OUT_SZ_HS;
|
USBHSD->UEP1_MAX_LEN = HID_INT_OUT_SZ_HS;
|
||||||
USBHSD->UEP3_MAX_LEN = CDC_BULK_OUT_SZ_HS;
|
USBHSD->UEP3_MAX_LEN = CDC_BULK_OUT_SZ_HS;
|
||||||
|
|
||||||
@@ -101,6 +102,8 @@ void USBHS_Device_Endp_Init(void)
|
|||||||
USBHSD->UEP3_TX_LEN = 0;
|
USBHSD->UEP3_TX_LEN = 0;
|
||||||
USBHSD->UEP3_TX_CTRL = USBHS_UEP_T_RES_NAK;
|
USBHSD->UEP3_TX_CTRL = USBHS_UEP_T_RES_NAK;
|
||||||
USBHSD->UEP3_RX_CTRL = USBHS_UEP_R_RES_ACK;
|
USBHSD->UEP3_RX_CTRL = USBHS_UEP_R_RES_ACK;
|
||||||
|
|
||||||
|
Vcom.in_ready = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include "vcom_serial.h"
|
#include "vcom_serial.h"
|
||||||
|
|
||||||
|
|
||||||
volatile VCOM Vcom = {.in_ready = 1};
|
volatile VCOM Vcom;
|
||||||
|
|
||||||
VCOM_LINE_CODING LineCfg = {115200, 0, 0, 8}; // Baud rate, stop bits, parity bits, data bits
|
VCOM_LINE_CODING LineCfg = {115200, 0, 0, 8}; // Baud rate, stop bits, parity bits, data bits
|
||||||
|
|
||||||
@@ -133,9 +133,9 @@ void USART2_IRQHandler(void)
|
|||||||
|
|
||||||
void VCOM_TransferData(void)
|
void VCOM_TransferData(void)
|
||||||
{
|
{
|
||||||
if(Vcom.in_ready) // 可以向主机发送数据
|
if(Vcom.in_ready) // 可以向主机发送数据
|
||||||
{
|
{
|
||||||
if(Vcom.rx_bytes) // 有新的数据可以发送
|
if(Vcom.rx_bytes) // 有新的数据可以发送
|
||||||
{
|
{
|
||||||
Vcom.in_bytes = Vcom.rx_bytes;
|
Vcom.in_bytes = Vcom.rx_bytes;
|
||||||
if(Vcom.in_bytes > CDC_BULK_IN_SZ_HS)
|
if(Vcom.in_bytes > CDC_BULK_IN_SZ_HS)
|
||||||
@@ -172,7 +172,7 @@ void VCOM_TransferData(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 从主机接收到数据,且 tx_buff 能够装下它们 */
|
/* 从主机接收到数据,且 tx_buff 能够装下它们 */
|
||||||
if(Vcom.out_ready && (Vcom.out_bytes <= TX_BUFF_SIZE - Vcom.tx_bytes))
|
if(Vcom.out_ready && (Vcom.out_bytes <= TX_BUFF_SIZE - Vcom.tx_bytes))
|
||||||
{
|
{
|
||||||
for(int i = 0; i < Vcom.out_bytes; i++)
|
for(int i = 0; i < Vcom.out_bytes; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user