Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define RX_BUFF_SIZE
Private variables
xPos
yLinePos
CDC_RX_Buffer
Private function prototypes
CDC_Handle_Receive_Menu()
USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *)
DumpReceivedData()
Files
loading...
CodeScopeSTM32 Libraries and SamplesCDC_StandaloneSrc/cdc_receive.c
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/CDC_Standalone/Src/cdc_receive.c * @author MCD Application Team * @brief CDC Receive state machine ****************************************************************************** * @attention * * Copyright (c) 2017 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. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" Includes /* Private define ------------------------------------------------------------*/ #define RX_BUFF_SIZE 0x400 /* Max Received data 1KB */ Private define /* Private typedef -----------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ uint16_t xPos, yLinePos; uint8_t CDC_RX_Buffer[RX_BUFF_SIZE]; Private variables /* Private function prototypes -----------------------------------------------*/ static void DumpReceivedData(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Handles CDC Receive Menu. * @param None * @retval None *//* ... */ void CDC_Handle_Receive_Menu(void) { switch(CdcDemo.Receive_state) { case CDC_RECEIVE_IDLE: /* Start Reception */ LCD_LOG_ClearTextZone(); CdcDemo.Receive_state = CDC_RECEIVE_WAIT; USBH_CDC_Stop(&hUSBHost); LCD_DbgLog("Receiving data ...\n"); xPos = 0; yLinePos = 5; memset(CDC_RX_Buffer, 0, RX_BUFF_SIZE); USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE); BSP_LCD_ClearStringLine(19); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start sending data "); break; case CDC_RECEIVE_IDLE: case CDC_RECEIVE_WAIT: if((BSP_PB_GetState(BUTTON_WAKEUP) == SET) && (Appli_state != APPLICATION_DISCONNECT)) { CdcDemo.state = CDC_DEMO_WAIT; CdcDemo.Receive_state = CDC_RECEIVE_IDLE; }if ((BSP_PB_GetState(BUTTON_WAKEUP) == SET) && (Appli_state != APPLICATION_DISCONNECT)) { ... } break; case CDC_RECEIVE_WAIT: default: break;default }switch (CdcDemo.Receive_state) { ... } }{ ... } /** * @brief CDC data receive callback. * @param phost: Host handle * @retval None *//* ... */ void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost) { DumpReceivedData(); USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE); }{ ... } /** * @brief Displays received data * @param data: Keyboard data to be displayed * @retval None *//* ... */ static void DumpReceivedData(void) { uint16_t size; uint8_t *ptr = CDC_RX_Buffer; size = USBH_CDC_GetLastReceivedDataSize(&hUSBHost); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); while(size--) { if((*ptr != '\n') && (*ptr != '\r')) { if(*ptr == '\t') { BSP_LCD_DisplayChar(xPos, LINE(yLinePos), ' '); }if (*ptr == '\t') { ... } else { BSP_LCD_DisplayChar(xPos, LINE(yLinePos), *ptr); }else { ... } xPos += 10; }if ((*ptr != '\n') && (*ptr != '\r')) { ... } else if(*ptr == '\n') { yLinePos++; xPos = 0; }else if (*ptr == '\n') { ... } ptr++; if(xPos > (BSP_LCD_GetXSize() - 7)) { xPos = 0; yLinePos++; }if (xPos > (BSP_LCD_GetXSize() - 7)) { ... } if(yLinePos > 13) { xPos = 0; yLinePos = 5; }if (yLinePos > 13) { ... } }while (size--) { ... } }{ ... }