2 ******************************************************************************
3 * @file usbd_cdc_if_template.c
4 * @author MCD Application Team
7 * @brief Generic media access Layer.
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
23 #pragma data_alignment = 4
24 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
26 /* Includes ------------------------------------------------------------------*/
27 #include "usbd_cdc_if_template.h"
28 #include "stm32_eval.h"
30 /* Private typedef -----------------------------------------------------------*/
31 /* Private define ------------------------------------------------------------*/
32 /* Private macro -------------------------------------------------------------*/
33 /* Private variables ---------------------------------------------------------*/
34 /* These are external variables imported from CDC core to be used for IN
35 transfer management. */
36 extern uint8_t APP_Rx_Buffer []; /* Write CDC received data in this buffer.
37 These data will be sent over USB IN endpoint
38 in the CDC core functions. */
39 extern uint32_t APP_Rx_ptr_in; /* Increment this pointer or roll it back to
40 start address when writing received data
41 in the buffer APP_Rx_Buffer. */
43 /* Private function prototypes -----------------------------------------------*/
44 static uint16_t TEMPLATE_Init (void);
45 static uint16_t TEMPLATE_DeInit (void);
46 static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
47 static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len);
48 static uint16_t TEMPLATE_DataRx (uint8_t* Buf, uint32_t Len);
50 CDC_IF_Prop_TypeDef TEMPLATE_fops =
59 /* Private functions ---------------------------------------------------------*/
62 * @brief TEMPLATE_Init
63 * Initializes the CDC media low layer
65 * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
67 static uint16_t TEMPLATE_Init(void)
70 Add your initialization code here
76 * @brief TEMPLATE_DeInit
77 * DeInitializes the CDC media low layer
79 * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
81 static uint16_t TEMPLATE_DeInit(void)
84 Add your deinitialization code here
91 * @brief TEMPLATE_Ctrl
92 * Manage the CDC class requests
93 * @param Cmd: Command code
94 * @param Buf: Buffer containing command data (request parameters)
95 * @param Len: Number of data to be sent (in bytes)
96 * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
98 static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
102 case SEND_ENCAPSULATED_COMMAND:
103 /* Add your code here */
106 case GET_ENCAPSULATED_RESPONSE:
107 /* Add your code here */
110 case SET_COMM_FEATURE:
111 /* Add your code here */
114 case GET_COMM_FEATURE:
115 /* Add your code here */
118 case CLEAR_COMM_FEATURE:
119 /* Add your code here */
122 case SET_LINE_CODING:
123 /* Add your code here */
126 case GET_LINE_CODING:
127 /* Add your code here */
130 case SET_CONTROL_LINE_STATE:
131 /* Add your code here */
135 /* Add your code here */
146 * @brief TEMPLATE_DataTx
147 * CDC received data to be send over USB IN endpoint are managed in
149 * @param Buf: Buffer of data to be sent
150 * @param Len: Number of data to be sent (in bytes)
151 * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
153 static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len)
156 /* Get the data to be sent */
157 for (i = 0; i < Len; i++)
159 /* APP_Rx_Buffer[APP_Rx_ptr_in] = XXX_ReceiveData(XXX); */
162 /* Increment the in pointer */
165 /* To avoid buffer overflow */
166 if(APP_Rx_ptr_in == APP_RX_DATA_SIZE)
175 * @brief TEMPLATE_DataRx
176 * Data received over USB OUT endpoint are sent over CDC interface
177 * through this function.
180 * This function will block any OUT packet reception on USB endpoint
181 * untill exiting this function. If you exit this function before transfer
182 * is complete on CDC interface (ie. using DMA controller) it will result
183 * in receiving more data while previous ones are still not sent.
185 * @param Buf: Buffer of data to be received
186 * @param Len: Number of data received (in bytes)
187 * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
189 static uint16_t TEMPLATE_DataRx (uint8_t* Buf, uint32_t Len)
193 /* Send the received buffer */
194 for (i = 0; i < Len; i++)
196 /* XXXX_SendData(XXXX, *(Buf + i) ); */
202 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/