cancel
Showing results for 
Search instead for 
Did you mean: 

Audio Class USB - no data - STM32F4Discovery

nortowianski
Associate II
Posted on December 11, 2015 at 11:09

Hi, I have problem with isochronous transfer between STM32 and PC. I am using USB Audio Class (microphone) to send data to PC. I wrote descriptor and PC discovers my STM32F4 as microphone. Moreover I see in USBlyzer that the transfer between STM and PC is completed successfully, but there is no data received. I assume that my descriptor is ok, so I paste the code contains transfer functions:

static uint8_t USBD_AUDIO_Init (USBD_HandleTypeDef *pdev, 
uint8_t cfgidx)
{
USBD_LL_OpenEP(pdev,
AUDIO_IN_EP,
USBD_EP_TYPE_ISOC,
AUDIO_IN_PACKET);
return USBD_OK;
}
static uint8_t USBD_AUDIO_DeInit (USBD_HandleTypeDef *pdev, 
uint8_t cfgidx)
{
/* Open EP OUT */
USBD_LL_CloseEP(pdev,
AUDIO_IN_EP);
/* DeInit physical Interface components */
if(pdev->pClassData != NULL)
{
((USBD_AUDIO_ItfTypeDef *)pdev->pUserData)->DeInit(0);
USBD_free(pdev->pClassData);
pdev->pClassData = NULL;
}
return USBD_OK;
}
static uint8_t USBD_AUDIO_Setup (USBD_HandleTypeDef *pdev, 
USBD_SetupReqTypedef *req)
{
USBD_AUDIO_HandleTypeDef *haudio;
uint16_t len;
uint8_t *pbuf;
uint8_t ret = USBD_OK;
haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData;
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS : 
switch (req->bRequest)
{
case AUDIO_REQ_GET_CUR:
AUDIO_REQ_GetCurrent(pdev, req);
break;
case AUDIO_REQ_SET_CUR:
AUDIO_REQ_SetCurrent(pdev, req); 
break;
default:
USBD_CtlError (pdev, req);
ret = USBD_FAIL; 
}
break;
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_DESCRIPTOR: 
if( (req->wValue >> 8) == AUDIO_DESCRIPTOR_TYPE)
{
pbuf = USBD_AUDIO_CfgDesc + 18;
len = MIN(USB_AUDIO_DESC_SIZ , req->wLength);
USBD_CtlSendData (pdev, 
pbuf,
len);
}
break;
case USB_REQ_GET_INTERFACE :
USBD_CtlSendData (pdev,
(uint8_t *)&(haudio->alt_setting),
1);
break;
case USB_REQ_SET_INTERFACE :
if ((uint8_t)(req->wValue) <= USBD_MAX_NUM_INTERFACES)
{
haudio->alt_setting = (uint8_t)(req->wValue);
usbd_audio_AltSet = (uint8_t)(req->wValue);
if (usbd_audio_AltSet == 1)
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, 1);
}
else
{
USBD_LL_FlushEP(pdev, AUDIO_IN_EP);
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, 0);
}
}
else
{
/* Call the error management function (command will be nacked */
USBD_CtlError (pdev, req);
}
break; 
default:
USBD_CtlError (pdev, req);
ret = USBD_FAIL; 
}
}
return ret;
}
static uint8_t RecBuf1[32];
static uint8_t USBD_AUDIO_DataIn (USBD_HandleTypeDef *pdev, 
uint8_t epnum)
{
int i;
for(i=0;i<32;i++)
{
RecBuf1[i] = 0xA5;
}
USBD_LL_FlushEP(pdev, AUDIO_IN_EP);
/* Transmit next packet */
USBD_LL_Transmit(pdev,
AUDIO_IN_EP,
RecBuf1,
AUDIO_IN_PACKET);
return USBD_OK;
}

Unfortunately device doesn't call

USBD_AUDIO_DataIn

function. Where do I have to paste the transfer function (

USBD_LL_Transmit

)?

1 REPLY 1
nortowianski
Associate II
Posted on December 11, 2015 at 12:38

I solved the problem. I added dummy transmit to if (usbd_audio_AltSet == 1).