Skip to main content
ABasi.2
Senior
Solved

problem with STM32H563zi USBX audio class

Hi

i’m triyng to use USBX audio class on nucleo-h563zi.

 

i have succed to make PC to recognise the board like a controller audio but windows have problem to start the device (error code 10), problem 0xA status:  0xC0440027

i’m stuck at this fase unfortunately

 

also i think there are some missing files in the middleware directory, in the example provided by ST UX_Device_Audio2.0_Playback 

(not sure is related to the error to start device)

there is this code: 

VOID USBD_AUDIO_PlaybackStreamChange(UX_DEVICE_CLASS_AUDIO_STREAM *audio_play_stream,
ULONG alternate_setting)
{
/* USER CODE BEGIN USBD_AUDIO_PlaybackStreamChange */

/* Do nothing if alternate setting is 0 (stream closed). */
if (alternate_setting == 0)
{
return;
}

BufferCtl.state = PLAY_BUFFER_OFFSET_UNKNOWN;

/* Start reception (stream opened). */
ux_device_class_audio_reception_start(audio_play_stream);

/* USER CODE END USBD_AUDIO_PlaybackStreamChange */

return;
}

the function ux_device_class_audio_reception_start(audio_play_stream);

is located in ux_device_class_audio_reception_start.c

that i’m not able to find in the files generated by cube MX for my project

 

any idea?

 

best reguards!

ABasi.2
ABasi.2Best answer
Senior

hello ​@FBL 

i have found the bug that caused the hardfault, 

UX_SLAVE_REQUEST_DATA_MAX_LENGTH was set to 64 byte, but for my descriptor should be >= of 192 byte,

i made it 512 byte and now the issue is resolved, i can receive Audio packet without problem.

 

there is one more think but its more difficult to replicate, it happened that when i switched on windows from my board to normal headphone the output of sound it went to hard fault, but it happended only two times, i’m trying to replicate to investigate the problem.

 

where i can find the ux_device_class_audio_reception_start.c file of release 6.4.0 like the other files?

the copied file ( i remember to you that cube MX don’t create this file anda i have to copy from the example) is of a previous relese.

 

now i’m developing the circular buffer ecc to send the audio packet to the audio chip.

 

i attach to this post the new project that now can receive the Audio packet without hard fault

 

thank you!

 

best reguards

8 replies

ST Technical Moderator

Hi ​@ABasi.2 

I’m not sure if we delivered examples for USBX audio on H5, can you point me directly to the example you are using. Otherwise share minimal project to reproduce the issue you are seeing. 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
ABasi.2
ABasi.2Author
Senior

Hi ​@FBL 

thank you for your response

 

the example that i’m using to understand the USB Audio is Ux_Device_Audio2.0_Playback , written for nucleo-H743

the first issue is that to use the function ux_device_class_audio_reception_start(audio_play_stream) the file ux_device_class_audio_reception_start.c is missing, cube MX don’t generate it, i have to copy that file from the example.

but the real issue is:

now i’m able to make my board (NUCLEO-H563ZI) enumerate like a Audio device on windows, but as soon i try to send some audio to it ( i open youtube and select from windows the device to use to reproduce the sound) the board goes in HardFault.

almost always the list of function called before the hardfault are:

_tx_ts_restore()

_tx_ipsr_get()

_tx_thread_system_return_inline()

_tx_thread_system_suspend()

 

i attach my entire project, my goal for now is to be able to receive the audio packet (using a printf to ensure a correctly receive), after this step i will pass the audio pachet to a audio chip.

thank you in advance

best reguards

 

 

ST Technical Moderator

Hi ​@ABasi.2 

Thank you for reporting the issue regarding code generation. I will let my colleague ​@Mahmoud Ben Romdhane  manage it.

Regarding ThreadX functions you listed are scheduler and thread suspension routines nd seeing them before a HF does not by itself identify the cause. The fault may occur while a thread is being suspended or resumed ...

Don’t call printf directly from an interrupt or a time critical USB callback. Copy the received bytes and length into a buffer or queue, then print them from a separate ThreadX thread. 

To start, USBD_AUDIO_ControlProcess() receives audio_instance, but currently calls USBX with the global audio pointer

status = ux_device_class_audio20_control_process(audio_instance, transfer, &group);

 

 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
ABasi.2
ABasi.2Author
Senior

hi ​@FBL 

 

it seems to me there is some memory issue or something like that

 

actually we didn’t arrive to call printf, it crash before.

 

it seems to crash when the firse packet arrive, but i don’t understand why.

 

what modification are you suggesting about status = ux_device_class_audio20_control_process(audio_instance, transfer, &group); ?

did you already check my files?

 

thank you in advance 

 

best reguards

 

 

ST Technical Moderator

 Hi ​@ABasi.2 

First, I found that ux_device_class_audio20_control_process was pointing to audio pointer instead of audio_instance

Second, capture the faulting PC, LR, SP, CFSR, HFSR, and the debugger call stack. Those are needed to distinguish a bad pointer or stack problem from a USB transfer configuration issue.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
ABasi.2
ABasi.2AuthorBest answer
Senior

hello ​@FBL 

i have found the bug that caused the hardfault, 

UX_SLAVE_REQUEST_DATA_MAX_LENGTH was set to 64 byte, but for my descriptor should be >= of 192 byte,

i made it 512 byte and now the issue is resolved, i can receive Audio packet without problem.

 

there is one more think but its more difficult to replicate, it happened that when i switched on windows from my board to normal headphone the output of sound it went to hard fault, but it happended only two times, i’m trying to replicate to investigate the problem.

 

where i can find the ux_device_class_audio_reception_start.c file of release 6.4.0 like the other files?

the copied file ( i remember to you that cube MX don’t create this file anda i have to copy from the example) is of a previous relese.

 

now i’m developing the circular buffer ecc to send the audio packet to the audio chip.

 

i attach to this post the new project that now can receive the Audio packet without hard fault

 

thank you!

 

best reguards

ABasi.2
ABasi.2Author
Senior

Hello ​@FBL !

 

the code have some evolution but i have another problem and a question about the Ux_Device_Audio2.0_Playback example.

the problem is that at the first debug after a PC power UP it goes hard fault, after that each new debug session is ok

 

thinking the problem is in the enumeration  i find this strange thing in this function in the example:

 

VOID USBD_AUDIO_Activate(VOID *audio_instance)
{
/* USER CODE BEGIN USBD_AUDIO_Activate */

/* Save the Audio instance. */
audio = (UX_DEVICE_CLASS_AUDIO *)audio_instance;

/* Get the streams instances. */
ux_device_class_audio_stream_get(audio, 0, &stream_read);

/* USER CODE END USBD_AUDIO_Activate */

return;
}

/**
* @brief USBD_AUDIO_Deactivate
* This function is called when extraction of a Audio device.
* @param audio_instance: Pointer to the audio class instance.
* @retval none
*/
VOID USBD_AUDIO_Deactivate(VOID *audio_instance)
{
/* USER CODE BEGIN USBD_AUDIO_Deactivate */

/* Reset the Audio instance. */
audio = UX_NULL;

/* Reset the Audio streams. */
stream_read = UX_NULL;

/* USER CODE END USBD_AUDIO_Deactivate */

return;
}

/**
* @brief USBD_AUDIO_ControlProcess
* This function is invoked to manage the UAC class requests.
* @param audio_instance: Pointer to Audio class stream instance.
* @param transfer: Pointer to the transfer request.
* @retval status
*/
UINT USBD_AUDIO_ControlProcess(UX_DEVICE_CLASS_AUDIO *audio_instance,
UX_SLAVE_TRANSFER *transfer)
{
UINT status = UX_SUCCESS;

/* USER CODE BEGIN USBD_AUDIO_ControlProcess */
static uint8_t vol;

UX_DEVICE_CLASS_AUDIO20_CONTROL_GROUP group;

group.ux_device_class_audio20_control_group_controls_nb = 1;
group.ux_device_class_audio20_control_group_controls = audio_control;


status = ux_device_class_audio20_control_process(audio, transfer, &group);
if (status == UX_SUCCESS)
{

switch(audio_control[0].ux_device_class_audio20_control_changed)
{
case UX_DEVICE_CLASS_AUDIO20_CONTROL_MUTE_CHANGED:

BSP_AUDIO_OUT_Mute(0);

break;

case UX_DEVICE_CLASS_AUDIO20_CONTROL_VOLUME_CHANGED:

vol = audio_control[0].ux_device_class_audio20_control_volume[0];

BSP_AUDIO_OUT_SetVolume(0, vol);

break;
default:
break;
}
}
/* USER CODE END USBD_AUDIO_ControlProcess */

return status;
}

whats the purpouse of the  variables audio and stream_read ? in the USBD_AUDIO_Activate function we can use directly audio_instance and stream_reader is never used in any file after the ux_device_class_audio_stream_get(audio, 0, &stream_read); .. in the function USBD_AUDIO_ControlProcess we lso can use audio_instance insead of audio… i didn’t understand.

 

and of coarse i didn’t understand whythere is a hard fault only in the first debug session after a PC restart

 

i attach my code 

 

thank you in advance

ST Technical Moderator

Hi ​@ABasi.2 

To better align with the ST Community guidelines, we recommend addressing issues one at a time in separate posts rather than providing direct support for an entire project.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL