用STM32做一个USB-TTL工具吧

news2024/11/24 23:10:27

某宝1分钱白嫖一个STM32C6T6的板子,然后手里的CH340挂了。那么自己做一个吧。

串口没有使用DMA空闲中断等等机制,有兴趣的加上了call我炒一下。

惯例CUBEMAX配置

1.usb-fs

2.usb-cdc

3.串口开一个中断,使用LL库

贴代码了

usart.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    usart.c
  * @brief   This file provides code for the configuration
  *          of the USART instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "usart.h"

/* USER CODE BEGIN 0 */
#include "usbd_cdc_if.h"
/* USER CODE END 0 */

/* USART1 init function */

void MX_USART1_UART_Init(void)
{

  /* USER CODE BEGIN USART1_Init 0 */

  /* USER CODE END USART1_Init 0 */

  LL_USART_InitTypeDef USART_InitStruct = {0};

  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* Peripheral clock enable */
  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);

  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
  /**USART1 GPIO Configuration
  PA9   ------> USART1_TX
  PA10   ------> USART1_RX
  */
  GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USART1 interrupt Init */
  NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
  NVIC_EnableIRQ(USART1_IRQn);

  /* USER CODE BEGIN USART1_Init 1 */

  /* USER CODE END USART1_Init 1 */
	
  USART_InitStruct.BaudRate = 115200;
  USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
  USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  LL_USART_Init(USART1, &USART_InitStruct);
  LL_USART_ConfigAsyncMode(USART1);
  LL_USART_Enable(USART1);
  /* USER CODE BEGIN USART1_Init 2 */
  
  /* USER CODE END USART1_Init 2 */

}
/* USART2 init function */

void MX_USART2_UART_Init(void)
{

  /* USER CODE BEGIN USART2_Init 0 */

  /* USER CODE END USART2_Init 0 */

  LL_USART_InitTypeDef USART_InitStruct = {0};

  LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

  /* Peripheral clock enable */
  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_USART2);

  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
  /**USART2 GPIO Configuration
  PA2   ------> USART2_TX
  PA3   ------> USART2_RX
  */
  GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
  GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USART2 interrupt Init */
  NVIC_SetPriority(USART2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
  NVIC_EnableIRQ(USART2_IRQn);

  /* USER CODE BEGIN USART2_Init 1 */

  /* USER CODE END USART2_Init 1 */
  USART_InitStruct.BaudRate = 115200;
  USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
  USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
  LL_USART_Init(USART2, &USART_InitStruct);
  LL_USART_ConfigAsyncMode(USART2);
  LL_USART_Enable(USART2);
  /* USER CODE BEGIN USART2_Init 2 */
  LL_USART_EnableIT_RXNE(USART2);
  //LL_USART_EnableIT_IDLE(USART2);
  /* USER CODE END USART2_Init 2 */

}

/* USER CODE BEGIN 1 */
/* USER CODE BEGIN 0 */

#if 1
#pragma import(__use_no_semihosting)
//??????????
struct __FILE
{
    int handle;
};
 
FILE __stdout;
/**
 * @brief ??_sys_exit()??????????
 * @param void
 * @return  void
 */
void _sys_exit(int x)
{
    x = x;
}
 
int fputc(int ch, FILE *f)
{
  while(LL_USART_IsActiveFlag_TXE(USART1) == RESET){}
  LL_USART_TransmitData8(USART1,ch);     
	while(LL_USART_IsActiveFlag_TC(USART1) == RESET){}

    return ch;
}
#endif


uint32_t g_bCharFormat[]={LL_USART_STOPBITS_1,LL_USART_STOPBITS_1_5,LL_USART_STOPBITS_2};
uint32_t g_bParityType[]={LL_USART_PARITY_NONE,LL_USART_PARITY_EVEN,LL_USART_PARITY_ODD,LL_USART_PARITY_NONE,LL_USART_PARITY_NONE};
uint32_t now_dwDTERate=0;
uint8_t now_bCharFormat=0;
uint8_t now_bParityType=0;
uint8_t now_bDataBits=0;
void MX_USART2_UART_GetConfig(uint32_t *dwDTERate,uint8_t *bCharFormat,uint8_t *bParityType,uint8_t *bDataBits)
{
	printf("get dwDTERate=%d,bCharFormat=%d,bParityType=%d,bDataBits=%d\n",now_dwDTERate,now_bCharFormat,now_bParityType,now_bDataBits);
	*dwDTERate=now_dwDTERate;
	*bCharFormat=now_bCharFormat;
	*bParityType=now_bParityType;
	*bDataBits=now_bDataBits;
}
//5, 6, 7, 8 or 16
void MX_USART2_UART_reConfig(uint32_t dwDTERate,uint8_t bCharFormat,uint8_t bParityType,uint8_t bDataBits)
{
	printf("set dwDTERate=%d,bCharFormat=%d,bParityType=%d,bDataBits=%d\n",dwDTERate,bCharFormat,bParityType,bDataBits);
	now_dwDTERate=dwDTERate;
	now_bCharFormat=bCharFormat;
	now_bParityType=bParityType;
	now_bDataBits=bDataBits;
	if(now_dwDTERate==0)return;
	
	LL_USART_Disable(USART2);
  LL_USART_InitTypeDef USART_InitStruct = {0};
  USART_InitStruct.BaudRate = dwDTERate;
  USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
  USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
  USART_InitStruct.Parity = LL_USART_PARITY_NONE;
  USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
  USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
  USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;

  if(bCharFormat < sizeof(g_bCharFormat)/sizeof(uint32_t))
  {
       USART_InitStruct.StopBits = g_bCharFormat[bCharFormat];
  }
    if(bParityType < sizeof(g_bParityType)/sizeof(uint32_t))
  {
       USART_InitStruct.Parity = g_bParityType[bParityType];
  }
  
  LL_USART_Init(USART2, &USART_InitStruct); 
	
	LL_USART_Enable(USART2);
}

__IO uint8_t led_status=LED_OFF;
#define BUF_SIZE 256
uint8_t r_buf[BUF_SIZE];
__IO uint16_t r_len = 0;
/*
uint8_t r_buf1[BUF_SIZE];
__IO uint16_t r_len1 = 0;
uint8_t r_buf2[BUF_SIZE];
__IO uint16_t r_len2 = 0;
*/
void usart2_irq_recv(uint8_t a)
{
   if(r_len<BUF_SIZE)
		 r_buf[r_len++] = a;

  led_status = LED_ON;
}
void uart2_to_usb()
{
  if(r_len>0)
  {
    CDC_Transmit_FS(r_buf,r_len);
		//usart2_send(r_buf,r_len);
    r_len = 0;
  }
}

/* USER CODE END 0 */


void usart2_send(uint8_t *p,uint16_t len)
{
  while(len--)
  {
      while(LL_USART_IsActiveFlag_TXE(USART2) == RESET);
		
       LL_USART_TransmitData8(USART2,*p++);     
  }
	
	while(LL_USART_IsActiveFlag_TC(USART2) == RESET);
	led_status = LED_ON;
}


/* USER CODE END 1 */

main.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "crc.h"
#include "rtc.h"
#include "usart.h"
#include "usb_device.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usart.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */
  uint32_t last_tick = 0;
  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  //MX_CRC_Init();
  //MX_RTC_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USB_DEVICE_Init();
  /* USER CODE BEGIN 2 */
	printf("start\n");
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    if(last_tick>0)
    {
        if(HAL_GetTick()-last_tick>50)
        {
          last_tick=0;
          led_status=LED_OFF;
          LL_GPIO_SetOutputPin(LED_GPIO_Port,LED_Pin);
        }
    }
    else
    {
      if(led_status == LED_ON)
      {
        LL_GPIO_ResetOutputPin(LED_GPIO_Port,LED_Pin);
        last_tick = HAL_GetTick();
      }
    }
		uart2_to_usb();
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */

   
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.LSIState = RCC_LSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USB;
  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

usbd_cdc_if.c

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : usbd_cdc_if.c
  * @version        : v2.0_Cube
  * @brief          : Usb device for Virtual Com Port.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "usbd_cdc_if.h"

/* USER CODE BEGIN INCLUDE */
#include "usart.h"
/* USER CODE END INCLUDE */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  * @brief Usb device library.
  * @{
  */

/** @addtogroup USBD_CDC_IF
  * @{
  */

/** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions
  * @brief Private types.
  * @{
  */

/* USER CODE BEGIN PRIVATE_TYPES */

/* USER CODE END PRIVATE_TYPES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines
  * @brief Private defines.
  * @{
  */

/* USER CODE BEGIN PRIVATE_DEFINES */
/* USER CODE END PRIVATE_DEFINES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros
  * @brief Private macros.
  * @{
  */

/* USER CODE BEGIN PRIVATE_MACRO */

/* USER CODE END PRIVATE_MACRO */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables
  * @brief Private variables.
  * @{
  */
/* Create buffer for reception and transmission           */
/* It's up to user to redefine and/or remove those define */
/** Received data over USB are stored in this buffer      */
uint8_t UserRxBufferFS[APP_RX_DATA_SIZE];

/** Data to send over USB CDC are stored in this buffer   */
uint8_t UserTxBufferFS[APP_TX_DATA_SIZE];

/* USER CODE BEGIN PRIVATE_VARIABLES */

/* USER CODE END PRIVATE_VARIABLES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables
  * @brief Public variables.
  * @{
  */

extern USBD_HandleTypeDef hUsbDeviceFS;

/* USER CODE BEGIN EXPORTED_VARIABLES */

/* USER CODE END EXPORTED_VARIABLES */

/**
  * @}
  */

/** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes
  * @brief Private functions declaration.
  * @{
  */

static int8_t CDC_Init_FS(void);
static int8_t CDC_DeInit_FS(void);
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length);
static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len);

/* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */

/* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */

/**
  * @}
  */

USBD_CDC_ItfTypeDef USBD_Interface_fops_FS =
{
  CDC_Init_FS,
  CDC_DeInit_FS,
  CDC_Control_FS,
  CDC_Receive_FS
};

/* Private functions ---------------------------------------------------------*/
/**
  * @brief  Initializes the CDC media low layer over the FS USB IP
  * @retval USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Init_FS(void)
{
  /* USER CODE BEGIN 3 */
  /* Set Application Buffers */
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
  return (USBD_OK);
  /* USER CODE END 3 */
}

/**
  * @brief  DeInitializes the CDC media low layer
  * @retval USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_DeInit_FS(void)
{
  /* USER CODE BEGIN 4 */
  return (USBD_OK);
  /* USER CODE END 4 */
}

/**
  * @brief  Manage the CDC class requests
  * @param  cmd: Command code
  * @param  pbuf: Buffer containing command data (request parameters)
  * @param  length: Number of data to be sent (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
{
  /* USER CODE BEGIN 5 */
	uint32_t dwDTERate;
	uint8_t bCharFormat;
	uint8_t bParityType;
	uint8_t bDataBits;
	printf("cmd=%02x,length=%d\n",cmd,length);
  switch(cmd)
  {
    case CDC_SEND_ENCAPSULATED_COMMAND:

    break;

    case CDC_GET_ENCAPSULATED_RESPONSE:

    break;

    case CDC_SET_COMM_FEATURE:

    break;

    case CDC_GET_COMM_FEATURE:

    break;

    case CDC_CLEAR_COMM_FEATURE:

    break;

  /*******************************************************************************/
  /* Line Coding Structure                                                       */
  /*-----------------------------------------------------------------------------*/
  /* Offset | Field       | Size | Value  | Description                          */
  /* 0      | dwDTERate   |   4  | Number |Data terminal rate, in bits per second*/
  /* 4      | bCharFormat |   1  | Number | Stop bits                            */
  /*                                        0 - 1 Stop bit                       */
  /*                                        1 - 1.5 Stop bits                    */
  /*                                        2 - 2 Stop bits                      */
  /* 5      | bParityType |  1   | Number | Parity                               */
  /*                                        0 - None                             */
  /*                                        1 - Odd                              */
  /*                                        2 - Even                             */
  /*                                        3 - Mark                             */
  /*                                        4 - Space                            */
  /* 6      | bDataBits  |   1   | Number Data bits (5, 6, 7, 8 or 16).          */
  /*******************************************************************************/
    case CDC_SET_LINE_CODING:
				memcpy(&dwDTERate,pbuf,4);
				bCharFormat=pbuf[5];
			  bParityType=pbuf[6];
			  bDataBits=pbuf[7];
				MX_USART2_UART_reConfig(dwDTERate,bCharFormat,bParityType,bDataBits);
    break;

    case CDC_GET_LINE_CODING:
				MX_USART2_UART_GetConfig(&dwDTERate,&bCharFormat,&bParityType,&bDataBits);
				memcpy(pbuf,&dwDTERate,4);
				pbuf[5] = bCharFormat;
				pbuf[6] = bParityType;
				pbuf[7] = bDataBits;
    break;

    case CDC_SET_CONTROL_LINE_STATE:

    break;

    case CDC_SEND_BREAK:

    break;

  default:
    break;
  }

  return (USBD_OK);
  /* USER CODE END 5 */
}

/**
  * @brief  Data received over USB OUT endpoint are sent over CDC interface
  *         through this function.
  *
  *         @note
  *         This function will issue a NAK packet on any OUT packet received on
  *         USB endpoint until exiting this function. If you exit this function
  *         before transfer is complete on CDC interface (ie. using DMA controller)
  *         it will result in receiving more data while previous ones are still
  *         not sent.
  *
  * @param  Buf: Buffer of data to be received
  * @param  Len: Number of data received (in bytes)
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  usart2_send(Buf,*Len);
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);
  return (USBD_OK);
  /* USER CODE END 6 */
}

/**
  * @brief  CDC_Transmit_FS
  *         Data to send over USB IN endpoint are sent over CDC interface
  *         through this function.
  *         @note
  *
  *
  * @param  Buf: Buffer of data to be sent
  * @param  Len: Number of data to be sent (in bytes)
  * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY
  */
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 7 */
  USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
  if (hcdc->TxState != 0){
    return USBD_BUSY;
  }
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
  result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
	
  /* USER CODE END 7 */
  return result;
}

/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */

/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */

/**
  * @}
  */

/**
  * @}
  */

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2125224.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

电源层 BGA 孔图案对高速信号质量的影响

电源层中的大量间隙孔会对高速信号的行为产生巨大影响。信号完整性对于设计人员来说是一个日益严重的问题&#xff0c;因为新设计需要具有越来越多引脚数的组件&#xff0c;而这些组件必须使用过孔进行连接以访问印刷电路板 (PCB) 的内层。孔和焊盘堆叠的正确设计可以产生高产量…

①MongoDB基本知识①

MongDB属于非关系型数据库一派&#xff0c;没有固定的数据格式存储&#xff0c;是一个具备高性能、高拓展的文档型数据库&#xff0c;数据以BSON(JSON的二进制)的格式存储。 特点: 基于对象模型&#xff0c;关系简单。没有外键的约束&#xff0c;也没有强连接表的关系&#x…

OpengGL教程(三)---使用VAO和VBO方式绘制三角形

本章参考官方教程&#xff1a;learnopengl-cn VertexShader.glsl #version 330 core layout(location 0) in vec3 position; layout(location 1) in vec3 color; uniform mat4 projection; // 投影矩阵 out vec4 ourColor; void main() {gl_Position projection * vec4(p…

信息安全管理工程师

信息安全管理工程师是专门从事信息安全领域的专业人员&#xff0c;主要负责维护计算机系统、网络和数据的安全&#xff0c;以抵御潜在威胁和攻击。 随着信息技术迅猛发展&#xff0c;对此类专业人才的需求持续上升。 如何能够成为一名卓越的信息安全管理工程师呢&#xff1f;…

springboot对数据库进行备份+对一个文件夹内的文件按时间排序,只保留最近的8个文件

首先&#xff0c;对数据库进行备份&#xff0c;用到的命令&#xff1a; mysqldump --opt -h 192.168.1.200 --userroot --passwordxxx --result-fileE://data//20240911141400.sql --default-character-setutf8 xxx&#xff08;数据库名&#xff09; 直接上代码 配置文件部分…

Android 语言国际化三步

1.罗列: 可以多罗列几个 不需要全部实现 res下创建这个文件:locale-config <locale-config xmlns:android"http://schemas.android.com/apk/res/android"><locale android:name"zh" /> <!--中文 --><locale android:name"e…

优化 TCP 以提高网络性能

本页面简要介绍了计算正确设置的方法&#xff0c;以缩短 Google Cloud 和混合场景中 TCP 连接的延迟时间。本页面还可帮助您了解如何缩短 Google Cloud 中流程之间的连接延迟时间。 现代微服务架构主张&#xff0c;开发者应该构建处理单一任务的小型服务。服务应根据系统的可靠…

Open CASCADE学习|通过指定点的曲线

在OpenCASCADE中&#xff0c;如果你想通过一系列指定的点来创建一条曲线&#xff0c;你可以使用Geom2dAPI_Interpolate类来实现二维曲线的插值&#xff0c;或者使用GeomAPI_Interpolate类来实现三维曲线的插值。这些类允许你定义一条B样条曲线&#xff0c;这条曲线将精确地通过…

内网安全:反弹shell

目录 一.Netcat反弹Shell 二.PowerCat反弹Shell PowerCat和nc正向连接 PowerCat和nc反向连接 PowerCat和PowerCat反向连接 三.Bash反弹shell 四.Python 反弹Shell 一.Netcat反弹Shell 在Windows容易被杀 介绍&#xff1a; Netcat简称NC,是一个简单、可靠的网络工具,被…

0V企业级别通配符证书

OV企业级别通配符证书&#xff0c;支持顶级域名下面的所有二级子域名&#xff0c;不限制二级子域名个数&#xff0c;证书显示单位实名名称。 加密算法支持2048bits&#xff1b;签名算法支持SHA256withRSA。 可提供各种服务器的证书文件安装格式。 加密支持协议&#xff1a;T…

微信如何转发群消息给其他群或其他好友?

使用微加机器人将群消息转发到其他群或好友 工具选择&#xff1a; 近期想做一个从某个微信群将消息自动转发到另一个微信群的效果&#xff08;一些课程群和线报群只有付费才能进&#xff09; 试了市面上很多免费的转发软件&#xff0c;发现免费还是很难有好东西&#xff0c;…

Nature Communications 可远程操控食欲的口服软体机器人

肥胖对人群的的影响是深远的&#xff0c;它不仅关系到个人的健康&#xff0c;还与全球公共卫生挑战密切相关。据世界卫生组织的数据&#xff0c;全球每8人中就有1人患有肥胖症。肥胖增加了患2型糖尿病、心血管疾病、某些癌症等多种健康问题的风险&#xff0c;并对社会经济产生重…

公开课 | 金九银十,测试开发面试秘籍大公开!

随着金九银十的求职旺季悄然来临&#xff0c;你是否已经摩拳擦掌&#xff0c;准备在职场上大展拳脚了呢&#xff1f;但面对激烈的竞争和复杂的面试环节&#xff0c;你是否也曾感到过迷茫和不安&#xff1f;别担心&#xff0c;我们懂你&#xff01; 本周四&#xff0c;我们特别…

Oracle与AWS和解! Oracle市场破历史新高 4350亿美金

数据库去o风风火火&#xff0c;然而似乎对甲骨文来讲并没有丝毫影响。很多人曾经都在嘲笑Oracle在云上发力的太晚太晚&#xff0c;错过了公有云的历史发展机遇。 今天看到群里有人分享一个消息说甲骨文老板想通了&#xff0c;跟三大云厂商合作了&#xff0c;看来是真的。 我们…

通过XMLHttpRequest和window.open在浏览器中打开文件流pdf以及下载pdf

1、浏览器预览pdf&#xff1a; 首先通过接口获取文件流数据 下发是源码 var xhr new XMLHttpRequest(); xhr.open("GET", http://www.baidut.com/downloadFile); xhr.responseType "blob"; xhr.onload function(){ if(this.status 200){ var blob…

全视通医院智慧后勤全场景管理+一体化解决方案,让医院管理提质增效

在 “十四五” 时期&#xff0c;公立智慧医院建设正如火如荼地进行着。2021年&#xff0c;国家卫生健康委医政医管局发布《医院智慧管理分级评估标准体系&#xff08;试行&#xff09;》&#xff0c;从政策层面给出了推进面向医务人员的“智慧医疗”、面向患者的“智慧服务”、…

Cadenza 项目:机器学习如何改善听力受损人士的音乐聆听体验

音乐&#xff0c;作为全人类共享的文化瑰宝&#xff0c;具有强大的凝聚力&#xff0c;它不仅塑造了我们的社会风貌&#xff0c;更为我们的身心健康带来诸多益处。然而&#xff0c;听力损失却无情地削弱了这份美妙的体验。据世界卫生组织预测&#xff0c;到2050年&#xff0c;全…

大模型技术场景与商业应用(2024):赋能千行百业产业链升级

大模型技术场景与商业应用&#xff08;2024&#xff09;&#xff1a;赋能千行百业产业链升级 引言 随着人工智能技术的飞速发展&#xff0c;大模型&#xff08;Large Language Models, LLMs&#xff09;已成为推动各行业数字化转型的关键驱动力。从2023年的ChatGPT大模型爆火至…

低代码平台与统一待办:提升工作效率的新趋势

什么是低代码平台&#xff1f; 低代码平台是一种允许用户通过图形化界面和简单的拖放操作创建应用程序的开发工具。它极大地简化了应用程序的开发过程&#xff0c;使得非技术背景的用户也能够参与到应用开发中来。低代码平台通常包括预建的组件、模板和集成功能&#xff0c;大…

【论文阅读】视觉分割新SOTA: Segment Anything(SAM)

导言 随着基于对比文本—图像对的预训练&#xff08;CLIP&#xff09;方法或者模型、聊天生成预训练转换器&#xff08;ChatGPT&#xff09;、生成预训练转换器-4&#xff08;GPT-4&#xff09;等基础大模型的出现&#xff0c;通用人工智能&#xff08; AGI&#xff09;的研究…