cancel
Showing results for 
Search instead for 
Did you mean: 

USB Host CDC

guigui
Associate II
Posted on July 25, 2016 at 22:32

Hi,

I want to use the USB Host CDC. For this I use the HAL library and the middleware layer Here is my code:


#include ''uart_USB.h''

#include ''usb_host.h''

#include ''usbh_core.h''

#include ''usbh_cdc.h''


USBH_HandleTypeDef hUsbHostFS;


static
USBH_StatusTypeDef USB_SetLineCoding(USB_CommunicationParam_t param);


static
void
USB_Process(USBH_HandleTypeDef *phost, uint8_t id);


USBH_StatusTypeDef USB_Init(USB_CommunicationParam_t param)

{

USBH_StatusTypeDef returnCode = USBH_OK;

if
((returnCode = USBH_Init(&hUsbHostFS, USB_Process, HOST_FS)) != USBH_OK){

return
returnCode;

}

if
((returnCode = USBH_RegisterClass(&hUsbHostFS, USBH_CDC_CLASS)) != USBH_OK){

return
returnCode;

}

if
((returnCode = USBH_Start(&hUsbHostFS)) != USBH_OK){

return
returnCode;

}

if
((returnCode = USB_SetLineCoding(param)) != USBH_OK){

return
returnCode;

}

return
returnCode;

}


static
void
USB_Process(USBH_HandleTypeDef *phost, uint8_t id)

{

switch
(id){

case
HOST_USER_SELECT_CONFIGURATION:

break
;


case
HOST_USER_DISCONNECTION:

break
;


case
HOST_USER_CLASS_ACTIVE:

break
;


case
HOST_USER_CONNECTION:

break
;


default
:

break
;

}

}


static
USBH_StatusTypeDef USB_SetLineCoding(USB_CommunicationParam_t param){

CDC_LineCodingTypeDef lineCoding;

lineCoding.b.dwDTERate = param.baudrate;

lineCoding.b.bCharFormat = param.stopBits;

lineCoding.b.bParityType = param.parity;

lineCoding.b.bDataBits = param.dataBits;

return
USBH_CDC_SetLineCoding(&hUsbHostFS, &lineCoding);

}

#ifndef UART_USB

#define UART_USB


#include ''stdint.h''


typedef 
enum
{

STOP_BIT_1 = 0, 
/*!< 1 Stop bit */

STOP_BIT_1_HALF = 1, 
/*!< 1.5 Stop bits */

STOP_BIT_2 = 2 
/*!< 2 Stop bits */

}USB_StopBits_e;


typedef 
enum
{

NONE = 0,

ODD = 1,

EVEN = 2,

MARK = 3,

SPACE = 4

}USB_Parity_e;


typedef 
enum
{

DATABITS_5 = 5,

DATABITS_6 = 6,

DATABITS_7 = 7,

DATABITS_8 = 8,

DATABITS_16 = 16

}USB_DataBits_e;


typedef 
struct
{

uint32_t baudrate;

USB_StopBits_e stopBits;

USB_Parity_e parity;

USB_DataBits_e dataBits;

}USB_CommunicationParam_t;


#endif /* UART_USB */

I'm looking for the right way to use functions : - USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length); - USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length); - uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost); - USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost); - void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost); - void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost); - void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost); If you have a code sample that would be perfect. Thanks #cdc #host #usb #stm32f407
2 REPLIES 2
Walid FTITI_O
Senior II
guigui
Associate II
Posted on July 26, 2016 at 13:37

Thank you for your reply.I've watched the examples provided by STM32CubeF4 but there is no example of functions uses.