Making a 2 channel USB soundcard

My starting point is the Audio Standalone application example for the STM3240G_Eval board.
It is a 2 channel USB soundcard with stereo 16bit, 48KHz parameters.

First I had to port the application to my STM32F4 Discovery board.

– I changed the processor type from STM32F407IG to t STM32F407VG in the project, and changed the 25MHz clock to 8MHz.
– I changed the USE_STM324xG_Eval to USE_STM32F4_DISCO in the Define section
– I changed the BSP packages in the project and also changed the include path from the original board to mine.
– I don’t need the STMPE811 touch controller so I removed this from the component files
– I used LED3-6 instead of the original board LED1-4
– I configured ST-Link as the debugger, and added the correct STM32F4xx Flash 1MB partition to the Flash Download settings.
– The Discovery board BSP uses SPI so I added the SPI HAL driver to the project and uncommented it in stm32f4xx_hal_conf.h
– In the same file I modified the original 25MHz clock to 8 MHz in #define HSE_VALUE
– I generated a new SystemClock_Config function with STM32Cube MX, for 168MHz and proper PLL settings and replaced the original.
– Discovery is using I2S3 port instead of I2S2 sothe interrupt functions had to be renamed, and also some data structures have different names as you can see.
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);

– For now I’m not using SRAM, FSMC, UART HAL drivers so I removed them from the project.

After this modifications, my USB soundcard started to work, but there were problems with the playback speed. I read the CS43L22 I2S DAC  datasheet about the configuration, and played with STM32Cube MX I2S clock config part. There was something wrong with the I2S Init in the stm32f4_doscovery_audio.c file. I googled a bit and I found the corrected file in the ST Forum, uploaded by an ST engineer, which correct the Init function’s clock configuraton.
– I changed the mentioned file to the new one, and the audio started to work properly.

Now I have the working Audio Streaming on my Discovery board. High Five!

Advertisements

4 thoughts on “Making a 2 channel USB soundcard

  1. Tamas B. says:

    Hello gorcsgergely,
    Nice post! I’m trying to do the same, but I can’t make it to the end. I’m having trouble with adding stm32f4xx_hal_conf.h

    Could you be so kind, and send me your version of this project ?
    It will help me a lot.

    Thank You
    Tamas

    Like

    • Hi!

      Unfortunatelly, i don’t have this simple 2 sound card as a project. I heavily upgraded it to 4 channels and MIDI and hid with sensors and stuff you follow the project. I don’t have any saved project from that early phase, sorry.
      But anyway, I wrote every modification I did. Line by line. What is it that does not work?

      Like

      • Tamas B. says:

        actually i think the stm32f4xx_hal is doing the problem, becouse the original project uses different libs, and a lot of functions will be by that doubled.
        when you added USE_STM32F4_DISCO, did you deleted the USE_STM324xG_Eval ?
        Also in step:
        – I changed the BSP packages in the project and also changed the include path from the original board to mine.
        you mean changing paths in “properties->c/c++->include paths” ? anything else ? functions in project ? maybe different naming ? these from hal, has hal in their name, while the originals not.

        Please can you write in more detail that step (BSP packages)?

        Like

      • The prcedure is very simple. You have to delete the BSP for the eval board, and delete the include pathes as well. And after that you need to add the new BSP package and set up the new path. Actually the disco BSP is just a different folder in the same subdolder as the EVAL. So modifying thhe include path is easy.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s