2016-07-25 01:32 PM
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
2016-07-26 02:12 AM
Hi berland.guillaume,
I recommend to have a look to the User manual : ''STM32Cube USB host library. You will find examples for the topic in the STM32Cube package relevant for your device from this . As example, of STM32F4 devices, you find examples in ''SB-Host''folder at this path: STM32Cube_FW_F4_V1.12.0\Projects\STM324xG_EVAL\Applications\USB_Host -Hannibal-2016-07-26 04:37 AM
Thank you for your reply.I've watched the examples provided by STM32CubeF4 but there is no example of functions uses.