cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 usb_audio_device, wrong channel mapping for channel 3 and 4

Dmitriy_777
Associate III

Hi community.

TLV230adc5140 - SAI 4CH(TDM) - STM32 - USB_FS_ 4CHmic - Window(LInux RP5) 

I reuse partly code from memsmic1 project to create 4 microfone audio device. Everything look well for channel 1 and 2 I got some trouble whit CH3 and CH4.  Please help whit    wrong channel mapping for channel 3 and 4. It is mapped on channel  1 and 2  on usb interface. One can see it on attached picture. Here is TLV switched off, SAI(DMA call back) reused for 4 sin generator 1,2,3,4 kHz for every supposed channel. Here you see the picture.

Where i  am wrong?   

 

Capture.JPG

9 REPLIES 9
Dmitriy_777
Associate III

photo_2026-04-06_01-26-42.jpg

here is better quality picture. 

FBL
ST Employee

Hello @Dmitriy_777 

To better understand and reproduce the issue, could you provide a bit more information? Which reference board are you using? Are you using latest version? 

Otherwise, it would be very helpful if you could share a minimal project that reproduces the 4‑channel mapping problem. This would allow us to analyze the configuration and escalate the issue if needed.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

Hi FBL

Thank you for answer.

I've tried to clean up the code as much as possible. I kept the sine wave generator, the audio initialization and callback functions, and a modified usbd_audio_in.c adapted for static buffers. Unfortunately, the STM version with dynamic filling didn't work out

1) Main.c ------ static void fill_usb_sine_1khz_ch4(int16_t *buf) + (ADC5140_Start_Record((uint16_t*)audio_buffer, RECORD_BUF_SIZE) != HAL_OK) + while(1)

2) tlv320adc5140.c --- 

HAL_StatusTypeDef ADC5140_Start_Record, void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai),

void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)

 

3) usbd_audio_if.c --- void Send_Audio_to_USB(int16_t *audioData, uint16_t PCMSamples)

 

4) static uint8_t USBD_AUDIO_Init, static uint8_t USBD_AUDIO_DataIn,uint8_t USBD_AUDIO_Data_Transfer

 

Please build the project, check the 'Listen to this device' box in Windows settings, and run the debug procedure a couple of times. It didn't launch on the first attempt.

 

it look like 4 ch going well. linux  also see card but do not what to record. Screenshot from 2026-04-07 00-21-35.png

 

wire.JPG

 

Hi FBL

 

we got result. please stop guys. i resolve 4 channel task   

 

Tank you so much.4_channel_good.JPG

Hi @Dmitriy_777 

Thank you for your feedback

Can you explain the workaround proposed to solve this issue?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL

Hi FBL.

 

Sure. it was here  + SAI interface settings playing. 

  if(Channels != 2)
    {
      USBD_AUDIO_CfgDesc[35] = 0x0F;                                             /* wChannelConfig 0x0F00  4 channels */
      USBD_AUDIO_CfgDesc[36] = 0x00;
    }
    else
    {
      USBD_AUDIO_CfgDesc[35] = 0x03;                                             /* wChannelConfig 0x0003  Stereo */
      USBD_AUDIO_CfgDesc[36] = 0x00;
    }
 
Question. Could you help whit  new challenge? When i switch  on STM power  whit USB plugged in Windows, everything fine, as soon as take off USB connector and plug again Window see STM  device but no audio data (voice) from STM32. alt_setting changing from 1 to 0. Could you help how to resolve it,? VBUS or CMD_STOP CMD_START?    
FBL
ST Employee

Hello  @Dmitriy_777 

Thank you for your feedback

So the root cause, wChannelConfig was still set for stereo instead of 4 channels. USB Audio middleware and sample code for STM32 generally support stereo (2-channel) configurations by default. User need to configure it manually. Configuration for multi-channel streaming requires both hardware and firmware modifications.

Linux is often more tolerant of USB audio descriptor oddities than Windows.
So if the stream data and packet size are already correct, Linux may still record successfully even when wChannelConfig is not ideal.

About the second issue, it's highly recommended to start new discussion to address this issue. The behavior is likely related to USB disconnect / reconnect handling.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.




Best regards,
FBL