This commit is contained in:
muzkr committed 2025-11-10 05:23:05 +08:00
1 parent 1e44113fde
commit f3fbb8d32b
8 files changed
+108 -77

No files matched your search

+10 -10
View File
@@ -898,6 +898,14 @@ void APP_Update(void)
}
#endif
#ifdef ENABLE_USB
if (UART_IsCommandAvailable(UART_PORT_VCP)) {
// SCHEDULER_Disable();
UART_HandleCommand(UART_PORT_VCP);
// SCHEDULER_Enable();
}
#endif
#ifdef ENABLE_FEAT_F4HWN
if (gCurrentFunction == FUNCTION_TRANSMIT && (gTxTimeoutReachedAlert || SerialConfigInProgress()))
{
@@ -1365,17 +1373,9 @@ void APP_TimeSlice10ms(void)
#ifdef ENABLE_UART
if (UART_IsCommandAvailable(UART_PORT_UART)) {
SCHEDULER_Disable();
// SCHEDULER_Disable();
UART_HandleCommand(UART_PORT_UART);
SCHEDULER_Enable();
}
#endif
#ifdef ENABLE_USB
if (UART_IsCommandAvailable(UART_PORT_VCP)) {
SCHEDULER_Disable();
UART_HandleCommand(UART_PORT_VCP);
SCHEDULER_Enable();
// SCHEDULER_Enable();
}
#endif
+63 -29
View File
@@ -57,6 +57,9 @@
#define DMA_CHANNEL LL_DMA_CHANNEL_2
#endif
// !! Make sure this is correct!
#define MAX_REPLY_SIZE 144
typedef struct {
uint16_t ID;
uint16_t Size;
@@ -187,8 +190,65 @@ typedef union
// static bool bIsEncrypted = true;
#define bIsEncrypted true
#ifdef ENABLE_USB
static void SendReply_VCP(void *pReply, uint16_t Size)
{
static uint8_t VCP_ReplyBuf[MAX_REPLY_SIZE + sizeof(Header_t) + sizeof(Footer_t)];
// !!
if (Size > MAX_REPLY_SIZE)
{
return;
}
memcpy(VCP_ReplyBuf + sizeof(Header_t), pReply, Size);
Header_t *pHeader = (Header_t *)VCP_ReplyBuf;
Footer_t *pFooter = (Footer_t *)(VCP_ReplyBuf + sizeof(Header_t) + Size);
pReply = VCP_ReplyBuf + sizeof(Header_t);
if (bIsEncrypted)
{
uint8_t *pBytes = (uint8_t *)pReply;
unsigned int i;
for (i = 0; i < Size; i++)
pBytes[i] ^= Obfuscation[i % 16];
}
pHeader->ID = 0xCDAB;
pHeader->Size = Size;
// VCP_Send((uint8_t *)&Header, sizeof(Header));
// VCP_Send(pReply, Size);
if (bIsEncrypted)
{
pFooter->Padding[0] = Obfuscation[(Size + 0) % 16] ^ 0xFF;
pFooter->Padding[1] = Obfuscation[(Size + 1) % 16] ^ 0xFF;
}
else
{
pFooter->Padding[0] = 0xFF;
pFooter->Padding[1] = 0xFF;
}
pFooter->ID = 0xBADC;
// VCP_Send((uint8_t *)&Footer, sizeof(Footer));
VCP_SendAsync(VCP_ReplyBuf, sizeof(Header_t) + Size + sizeof(Footer_t));
}
#endif // ENABLE_USB
static void SendReply(uint32_t Port, void *pReply, uint16_t Size)
{
#if defined(ENABLE_USB)
if (Port == UART_PORT_VCP)
{
SendReply_VCP(pReply, Size);
return;
}
#endif
Header_t Header;
Footer_t Footer;
@@ -203,21 +263,8 @@ static void SendReply(uint32_t Port, void *pReply, uint16_t Size)
Header.ID = 0xCDAB;
Header.Size = Size;
if(0) {}
#if defined(ENABLE_UART)
else if (Port == UART_PORT_UART)
{
UART_Send(&Header, sizeof(Header));
UART_Send(pReply, Size);
}
#endif
#if defined(ENABLE_USB)
else if (Port == UART_PORT_VCP)
{
VCP_Send((uint8_t *)&Header, sizeof(Header));
VCP_Send(pReply, Size);
}
#endif
UART_Send(&Header, sizeof(Header));
UART_Send(pReply, Size);
if (bIsEncrypted)
{
@@ -231,20 +278,7 @@ static void SendReply(uint32_t Port, void *pReply, uint16_t Size)
}
Footer.ID = 0xBADC;
if(0) {}
#if defined(ENABLE_UART)
else if (Port == UART_PORT_UART)
{
UART_Send(&Footer, sizeof(Footer));
}
#endif
#if defined(ENABLE_USB)
else if (Port == UART_PORT_VCP)
{
VCP_Send((uint8_t *)&Footer, sizeof(Footer));
}
#endif
UART_Send(&Footer, sizeof(Footer));
}
static void SendVersion(uint32_t Port)
+2
View File
@@ -25,6 +25,8 @@ void SYSTICK_Init(void)
{
SysTick_Config(480000);
gTickMultiplier = 48;
NVIC_SetPriority(SysTick_IRQn, 0);
}
void SYSTICK_DelayUs(uint32_t Delay)
+4 -3
View File
@@ -18,12 +18,12 @@
#include "usb_config.h"
#include "py32f071_ll_bus.h"
uint8_t VCP_RxBuf[256];
uint32_t VCP_RxBufPointer = 0;
uint8_t VCP_RxBuf[VCP_RX_BUF_SIZE];
volatile uint32_t VCP_RxBufPointer = 0;
void VCP_Init()
{
// LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG);
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_SYSCFG);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA); // PA12:11
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USBD);
@@ -34,5 +34,6 @@ void VCP_Init()
};
cdc_acm_init(rx_buf);
NVIC_SetPriority(USBD_IRQn, 3);
NVIC_EnableIRQ(USBD_IRQn);
}
+9 -2
View File
@@ -21,8 +21,10 @@
#include <string.h>
#include "usb_config.h"
extern uint8_t VCP_RxBuf[256];
extern uint32_t VCP_RxBufPointer;
#define VCP_RX_BUF_SIZE 256
extern uint8_t VCP_RxBuf[VCP_RX_BUF_SIZE];
extern volatile uint32_t VCP_RxBufPointer;
void VCP_Init();
@@ -39,4 +41,9 @@ static inline void VCP_SendStr(const char *Str)
}
}
static inline void VCP_SendAsync(const uint8_t *Buf, uint32_t Size)
{
cdc_acm_data_send_with_dtr_async(Buf, Size);
}
#endif // _DRIVER_VCP_H
+3 -3
View File
@@ -89,12 +89,12 @@
typedef struct
{
uint8_t *buf;
uint32_t size;
uint32_t *write_pointer;
const uint32_t size;
volatile uint32_t *write_pointer;
} cdc_acm_rx_buf_t;
void cdc_acm_init(cdc_acm_rx_buf_t rx_buf);
void cdc_acm_data_send_with_dtr(const uint8_t *buf, uint32_t size);
void cdc_acm_data_send_with_dtr_async(const uint8_t *buf, uint32_t size);
#endif
+16 -30
View File
@@ -87,7 +87,7 @@ static const uint8_t cdc_descriptor[] = {
};
USB_MEM_ALIGNX uint8_t read_buffer[128];
USB_MEM_ALIGNX uint8_t write_buffer[4];
// USB_MEM_ALIGNX uint8_t write_buffer[4];
static cdc_acm_rx_buf_t client_rx_buf = {0};
@@ -161,7 +161,8 @@ struct usbd_interface intf1;
void cdc_acm_init(cdc_acm_rx_buf_t rx_buf)
{
client_rx_buf = rx_buf;
// client_rx_buf = rx_buf;
memcpy(&client_rx_buf, &rx_buf, sizeof(cdc_acm_rx_buf_t));
*client_rx_buf.write_pointer = 0;
usbd_desc_register(cdc_descriptor);
@@ -185,34 +186,19 @@ void usbd_cdc_acm_set_dtr(uint8_t intf, bool dtr)
void cdc_acm_data_send_with_dtr(const uint8_t *buf, uint32_t size)
{
if (dtr_enable)
if (dtr_enable && 0 != size)
{
if (0 != size)
{
uint32_t size1 = ((uint32_t)buf) % 4;
if (0 != size1)
{
if (size < size1)
{
size1 = size;
}
memcpy(write_buffer, buf, size1);
buf += size1;
size -= size1;
ep_tx_busy_flag = true;
usbd_ep_start_write(CDC_IN_EP, write_buffer, size1);
while (ep_tx_busy_flag)
;
}
}
if (0 != size)
{
ep_tx_busy_flag = true;
usbd_ep_start_write(CDC_IN_EP, buf, size);
while (ep_tx_busy_flag)
;
}
ep_tx_busy_flag = true;
usbd_ep_start_write(CDC_IN_EP, buf, size);
while (ep_tx_busy_flag)
;
}
}
void cdc_acm_data_send_with_dtr_async(const uint8_t *buf, uint32_t size)
{
if (0 != size)
{
usbd_ep_start_write(CDC_IN_EP, buf, size);
}
}
+1
View File
@@ -11,6 +11,7 @@
"CMAKE_BUILD_TYPE": "Release",
"ENABLE_FMRADIO": false,
"ENABLE_UART": true,
"ENABLE_USB": true,
"ENABLE_AIRCOPY": false,
"ENABLE_NOAA": false,
"ENABLE_VOICE": false,