cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4Discovery Cube-based USB Speaker application not working

maggie
Associate III
Posted on September 08, 2014 at 08:46

I downloaded STM32CubeF4 package here, and I can't find a USB Speaker (or USB Audio Standalone) application at:

STM32Cube_FW_F4_V1.3.0\Projects\STM32F4-Discovery

So what I did was use:

STM32Cube_FW_F4_V1.3.0\Projects\STM324xG_EVAL\Applications\USB_Device\AUDIO_Standalone

... as reference, since it's meant to be tailored among STM32F407x/STM32F417x devices and it is configured to use the same CS43L22 DAC which the STM32F4Discovery uses. Basically, I want STM32F4Discovery to act as a USB Speaker when it's connected to a Host PC, by having this audio flow:

[PC] --USB Device IN--> [STM32F407x] --I2S OUT--> [CS43L22 DAC] --DAC--> earphones (via CN4)

I just did the following changes: Step 1. At General Options' Target Device in Project Options, replace:

- ST STM32F407IG
+ ST STM32F407VG

Step 2. Applied this change in main.c

- RCC_OscInit.PLL.PLLM = 25;
+ RCC_OscInit.PLL.PLLM = 8;
RCC_OscInit.PLL.PLLN = 336;
- RCC_OscInit.PLL.PLLP = 2;
+ RCC_OscInit.PLL.PLLP = RCC_PLLP_DIV2;

Step 3. At Drivers/BSP in Project Explorer, replace:

- ''STM324xG_EVAL'' drivers (stm324xg_eval.c, stm324xg_eval_audio.c)
+ ''STM32F4-Discovery'' drivers (stm32f4_discovery.c, stm32f4_discovery_audio.c)

Step 4. At C/C++ Compiler's Preprocessor in Project Options, replace:

- define of USE_STM324xG_EVAL and include directory $PROJ_DIR$\..\..\..\..\..\..\Drivers\BSP\STM324xG_EVAL
+ define of USE_STM32F4_DISCO and include directory $PROJ_DIR$\..\..\..\..\..\..\Drivers\BSP\STM32F4-Discovery

Step 5. Changed all LED references from LED 1-4 to LED 3-6 instead. Note: I retained usage of the following, since these should be the same regardless of whether STM32F4Discovery or STM324xG_EVAL board is used:
  • At Project Explorer: Application/EWARM/startup_stm32f407xx.s
  • At Project Explorer: Drivers/CMSIS/system_stm32f4xx.c
  • At Project Explorer: Application/User/usbd_conf.c (usage of PA9, PA10, PA11 and PA12 as USB pins)
However, after flashing, I don't hear any sound when I connected my earphones at STM32F4Discovery's CN4. Board was detected as ''STM32 AUDIO Streaming in FS Mode'', and all the Sound window detects music as being played via Windows Media Player (host PC's in Windows 7). The Control Panel --> Hardware and Sound --> Sound --> Speakers (right click, click ''Test'' works). The audio bar at the right part of ''Speakers'' also reacts to the sound being played (goes up and down). # With this, I assume the USB connection is fine - and problem seems to be on either the DAC or I2S. I don't see any special instructions to enable AUDIO OUT at STM32F4Discovery's CN4. I also rechecked schematics and verified that CN4's resistors, as well as AUDIO_DAC_OUT are properly mounted I also tried manually connecting the earphones at CN4's connections just to see if it's the connector's problem, to no avail. Any help will be so much appreciated. Thank you. #stm32cubef4-stm32f4discovery-usb
16 REPLIES 16
Posted on September 08, 2014 at 11:03

Hi maggie.roxas,

Thank you for the details, that can give us enough insight into what specifically you are doing, and how.

Please be patient as we try to reporoduce your issue.

Regards.

maggie
Associate III
Posted on September 08, 2014 at 11:44

Thank you very much for looking into this.

I uploaded the modified ''AUDIO_Standalone''

https://app.box.com/s/p77a5kyzoti57v050sqo

.

# Please extract at STM32Cube_FW_F4_V1.3.0\Projects\STM324xG_EVAL\Applications\USB_Device.

Also attached screenshot of the USB streaming in host PC.

Will wait for your feedback, then!

________________

Attachments :

screenshot090814.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0RV&d=%2Fa%2F0X0000000bcm%2FMBd4RNfBYHR8gwQFmY_hrCNoW6IgbnGPpCjX4N9THT0&asPdf=false
Posted on September 09, 2014 at 18:57

Himaggie.roxas,

After investigating your code, and making the appropriate tests on the STM32F4-Discovery board, we suggest the following modifications: stm32f4xx_it.c

- extern I2S_HandleTypeDef haudio_i2s;
+ extern I2S_HandleTypeDef hAudioOutI2s;

- void AUDIO_I2Sx_DMAx_IRQHandler(void)
+ void I2S3_IRQHandler(void)

- HAL_DMA_IRQHandler(haudio_i2s.hdmatx);
+ HAL_DMA_IRQHandler(hAudioOutI2s.hdmatx);

stm32f4xx_it.h

- void AUDIO_I2Sx_DMAx_IRQHandler(void);
+ void I2S3_IRQHandler(void);

Your projectnever come to fruition because of the confusion between the Audio OUT configuration of the EVAL/DISCO boards. It's better to add a breakpoint in theBSP_AUDIO_OUT_Play() API call to ensure that the audio stream playing is starting... You may have some audio quality limitations. We are working to give you the best configuration.Keep us informed about your finding. Regards.
maggie
Associate III
Posted on September 10, 2014 at 05:34

> After investigating your code, and making the appropriate tests on the STM32F4-Discovery board, we suggest the following modifications:

 

I did the stm32f4xx_it.c and stm32f4xx_it.h patches you suggested, and finally, after that, I can hear sounds (coming from the host PC) being played in the STM32F4Discovery. :)

The quality is not that good though (please see below).

In any case, thank you so much for checking on this issue!

> Your project never come to fruition because of the confusion between the Audio OUT configuration of the EVAL/DISCO boards.

You're right.

> You may have some audio quality limitations. We are working to give you the best configuration. Keep us informed about your finding.

 

Indeed.

The music coming out from the disco is a bit slower and low frequency/tone than the one being actually played on the host PC (either via Media Player or through test tone in Sound's speaker configurations).

Is it the same on your side?

maggie
Associate III
Posted on September 10, 2014 at 10:54

As advised to me, I managed to improve the sound quality by applying further modifications @stm32f4xx_hal_conf.h:

- #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */

Sound quality before above modifications: non-continuous (audible stops), slow timing, low frequency Sound quality after above modifications:continuous (non-audible stops), right timing, low frequency So only the problem on low frequency remains (ie, woman's voice sounds like a man's). Any ideas?
Posted on September 10, 2014 at 14:13

I confirm that you've to make the following changes, because the external oscillator value changes from EVAL to DISCO board:

- #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
+ #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */

I'm trying to check the root cause of the limitation you've got.Please be patient as we work to fix it. Regards.
maggie
Associate III
Posted on September 10, 2014 at 14:55

> I confirm that you've to make the following changes, because the external oscillator value changes from EVAL to DISCO board:

Yes, indeed.

> I'm trying to check the root cause of the limitation you've got. Please be patient as we work to fix it.

Sure! Thank you.

Posted on September 10, 2014 at 16:00

Hi,

We have detected a limitation within the BSP_AUDIO_OUT_Init() API, under the Audio driver for the STM32F4-Discovery board (stm32f4_discovery_audio.c) file.

We’ll pass it along to our development team. In the meantime, you can run your project with the attached modified file.

Thanks for your participation and keep an eye out for the next update!

Regards.

________________

Attachments :

stm32f4_discovery_audio.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0Tl&d=%2Fa%2F0X0000000bcl%2FdJcECX_zZc.mgKBUOoNwub0xRVMgjE65OtiJr1034S4&asPdf=false
maggie
Associate III
Posted on September 11, 2014 at 04:09

I confirm that I used the modified stm32f4_discovery_audio.c file you attached and verified that sound quality coming from host PC is now OK at STM32F4Discovery board.

Thank you for assisting me on this issue! :)