이번에 CUBEMX 를 업데이트하고 나서, USB CDC 를 테스트 해 봤습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** @defgroup usbd_cdc_Exported_Defines * @{ */ #define CDC_IN_EP 0x81 /* EP1 for data IN */ #define CDC_OUT_EP 0x01 /* EP1 for data OUT */ #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ #define CDC_DATA_HS_MAX_PACKET_SIZE 512 /* Endpoint IN & OUT Packet size */ #define CDC_DATA_FS_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ #define CDC_CMD_PACKET_SIZE 8 /* Control Endpoint Packet size */ #define USB_CDC_CONFIG_DESC_SIZ 67 #define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE #define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** @defgroup usbd_cdc_Exported_Defines * @{ */ #define CDC_IN_EP 0x81 /* EP1 for data IN */ #define CDC_OUT_EP 0x01 /* EP1 for data OUT */ #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */ /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */ #define CDC_DATA_HS_MAX_PACKET_SIZE 256 /* Endpoint IN & OUT Packet size */ #define CDC_DATA_FS_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */ #define CDC_CMD_PACKET_SIZE 8 /* Control Endpoint Packet size */ #define USB_CDC_CONFIG_DESC_SIZ 67 #define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE #define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE #define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE #define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE | cs |
1 2 | #include "string.h" #include "usbd_cdc_if.h" | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /* USER CODE BEGIN 0 */ #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif PUTCHAR_PROTOTYPE { while(CDC_Transmit_FS((uint8_t *)&ch, 1) == USBD_BUSY); return ch; } /* USER CODE END 0 */ | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f4xx_hal.h" #include "usb_device.h" /* USER CODE BEGIN Includes */ #include "string.h" #include "usbd_cdc_if.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ I2C_HandleTypeDef hi2c1; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_I2C1_Init(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ #ifdef __GNUC__ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif PUTCHAR_PROTOTYPE { while(CDC_Transmit_FS((uint8_t *)&ch, 1) == USBD_BUSY); return ch; } /* USER CODE END 0 */ int main(void) { /* USER CODE BEGIN 1 */ /* 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_I2C1_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { printf("USB CDC Test ^^\r\n"); HAL_Delay(500); /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } | cs |
'STM32F4' 카테고리의 다른 글
[STM32F4xx] UART1 DMA Receive Test (s/w test) (0) | 2018.09.06 |
---|---|
[STM32F4xx] UART2 DMA Receive Test (s/w test) (0) | 2018.09.06 |
[STM32F4xx] UART DMA Receive Test (H/W 및 CUBEMX 설정) (0) | 2018.09.06 |
[STM32F4xx] I2C DMA 프로그램 (CUBEMX) (1) | 2018.09.06 |
[STM32F4xx] I2C DMA 설정 (CUBEMX) (0) | 2018.09.06 |