/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Programming the CODEC (stw5054a)

Username:     
Password:     
             

Forum

# 1   2009-01-19 17:36:28 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Programming the CODEC (stw5054a)

Hi everybody,
given the fact that the Primer2 has an stw5094a codec on board (already connected to a mic capsule and a headphone connector) .... is there any sample of code using it? Does CircleOS manage the codec? Are these APIs documented somewhere?
Thank you!

Offline

 

# 2   2009-01-19 20:19:09 Programming the CODEC (stw5054a)

samarkh
Member
From: Gloucester UK
Registered: 2009-01-07
Posts: 84

Re: Programming the CODEC (stw5054a)

Hi dzingoni,
I think this is on the 'to-do' list,
http://www.stm32circle.com/projects/circleos.php/forum/

could benefit from your contributions:

"File system" manager for the SD card
Improved audio features (at the moment, the audio chip is used only at its minimal capabilities)

Yours Simon M.

Offline

 

# 3   2009-01-20 07:32:56 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

I followed the link, but most linked items seem to do nothing. Is the source of Circle OS 3.3 available somewhere? Is there an updated documentation of the API?

Offline

 

# 4   2009-01-20 10:42:44 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

There are some functions in the API for the CODEC.
The best is to look at the audio.c file in the CircleOS source files ( http://www.stm32circle.com/projects/project.php?id=49 ).
A short descruption of these functions is available in the same page, on the online documentation of the API.

Offline

 

# 5   2009-01-20 22:52:27 Programming the CODEC (stw5054a)

samarkh
Member
From: Gloucester UK
Registered: 2009-01-07
Posts: 84

Re: Programming the CODEC (stw5054a)

I found this whilst browsing,  don't know if this is any use?
STM32F103xx & external I²S audio codec, & zip file


Yours Simon M.

Offline

 

# 6   2009-01-21 13:54:36 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

At the moment, the audio.c files already contains the main fucntions to play/record... The AN published by ST uses another CODEC.... it is not so usefull for us.

Offline

 

# 7   2009-01-21 15:46:28 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

The previous links are wrong, here's the page where most application notes reside:
http://www.st.com/mcu/familiesdocs-110. … ion%20Note

The problem is that each codec has its own interfacing and set of registers, so we must go with the code developed for the primer 2. The app note about I2S interfacing is interesting anyway, as it explains how to interface a codec to I2S and talks about some specific issues of STM32 (such as potential low accuracy in master clock if the STM has to generate it from the main clock with a prescaler). Worth taking a look ...
Regards. Daniele.

Offline

 

# 8   2009-01-21 17:27:21 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

It's why I recommend to start from audio.c. Its contents should be sufficent for all general actions on the codec, and it is easy to configure the other registers in the same way.
Note that we encountered some issues when driving the I2C bus from audio.c. It's why we moved the write function in the handler of the timer IRQ that is also uses for the SPI.  In such a way, the I2C communication cannot be interrupted by any other task (highest priority).  If you need to update the internal registers, we should add the I2C functions to the API. Let us know.

Offline

 

# 9   2009-01-22 10:22:50 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

Thank you Francis. What I'm going to do is to create systems based on STM32 and audio codecs. This means dealing with I2S and I2c interfacing. Having well defined APIs for dealing with such common tasks (configuring and using I2S and I2C) could be a welcome addon for many people, I think, as the problems are always the same.
Can you tell me if you had experiences regarding simultaneous input and ouput from audio codecs? From the source code in audio.c it looks like the micro can be used either for play or for rec, am I correct?
If so I think that another dma engine should be configured to deal with the other transfer.
Do you think that the overhead could let this happen using the STM32 or am I pushing the thinks too hard? Keep in mind
that I have in mind CD quality audio, so stereo 44100 16 bit x sample ....

Thank you . Daniele.

Offline

 

# 10   2009-01-22 11:01:57 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

There are two channels on the STw5094A
   - one called 'voice' (this chip is made for phones)
   - one called 'data' (to playmusic).
At the moment, we use:
   - the channel 'voice' to record (via I2S2)
   - the channel 'data' to play sounds (via I2S3).

The PCB is made in such a waythat you can use either I2S2 or I2S3 to play.
The modes voice and data are not compatible (you have to select either one or the other). If you wish to be able to record and to play simultaneously, you need to use the VOICE mode (data is only for playing). I believe that we don't have a large choice of 'clock/format/size configuration' in VOICE mode (it has been difficult to set it). But if it works in one direction (recording), it should work on the other (playing).
At the moment, we could easily provide the functions to write the registers in the API, but we don't want to improve the API for the management of the audio modes (too complex).
I suggest to do the following in your application:
    1. Switch off by software (thru the API) the use of the audio device (and buzzer)
    2. with the existing API, you can redirect the SPI irqs to your own handlers (copy first the original handlers from stm32f10x_circle_it.c into your application),
   3. then modify these handlers and configure the chip in your application for your application (using the I2C functions we will add in the API). I guess we will send you a beta version of the 3.4 version of the API.

Note that, if you add some nice improvements for the audio management, we could integrate them in CircleOS...

Offline

 

# 11   2009-01-23 08:11:32 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

Thank you Francis for the clarification and the beta. I'm actually investigating how to use the Primer2 ad an USB codec, so your suggestions are welcome. I'd be happy to contribute something in this field for the API.
I think I'll try to interface a more capable codec (such as the Cirrus 7 Crystal cs4270, I got some for that purpose).
The other part will be the implementation of an USB audio  device class, and the usage of isochronous transfers of data. For this part I'm starting from the official ST USB voice demo, I think that nothing about USB is available inside CircleOS, right?
Regards. Daniele.

Offline

 

# 12   2009-02-02 10:08:34 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

Here's some update about my work on audio (from USB...).
It took a lot of time to understand things, but now I have a USB part working (ported from the ST USB Audio demo) and I'm working on the codec part.
The "USB Audio" interface is working, the device is recognized by the PC as "STM32 Speaker". Now there's the problem of having audio data streamed from the USB to the codec. I took off the original part regarding another codec, and tried to analyze the latest "audio.c" file (for initialization and management of the STw5094a audio codec, and the " stm32f10x_circle_it.c" file where the SPI3_IRQHandler code is located. Understanding is quite simple: we have a buffer for audio data, a pointer to it, an offset initialized to 0, and then playing is achieved by activating the TxE interrupt on SPI3 ...

So it looks like the implementation is based on Interrupts. That's quite a challenging task for the micro, even at 8Khz 8 bit playback we have 8K interrupts per second ... so it will be impossible to manage higher sampling frequencies.
Because my intention is to create an USB Audio device it looks like I'll have to investigate how to use DMA based playback. I really need to lower the overhead of the micro while sending data from the buffer to SPI3.

Is there any reference code dealing with such tasks (DMA initialization and management?).

Offline

 

# 13   2009-02-02 12:32:34 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

IRQ had been managed by software because we had to modify the data that was recorded in a different mode by the 'voice channel'.
DMA2-Channel2 could be used to avoid the interrupt handling if the data is already well formatted.

DMA is already used with the ADC and for scrolling in the list management (memory to memory). The DMA controllers are quite easy to initialize.

Offline

 

# 14   2009-02-02 13:17:46 Programming the CODEC (stw5054a)

dzingoni
Member
Registered: 2008-12-16
Posts: 13

Re: Programming the CODEC (stw5054a)

Can I use DMA2?
I was browsing through the docs and find little about SPI3. In the application notes from ST and in the examples I see only SPI1 and SPI2. Also in the datasheet of the STM32 there's no mention about which DMA can be used for SPI3, maybe that diagrams are referred to the medium density chips where SPI3 is not available.
Which DMA channel can be used for read and write with SPI3?
Thank you. Daniele.

Offline

 

# 15   2009-02-02 15:15:07 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

You MUST use DMA2, channel-2. The channels are preassigned to the peripherals, and only DMA2-Channel2 is connected to SPI3. See the reference manual of the STM32.

Offline

 

# 16   2009-02-02 15:17:30 Programming the CODEC (stw5054a)

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Programming the CODEC (stw5054a)

More info :
           DMA2-Channel2 for SPI3 TX
but
           DMA2-Channel1 for SPI3 RX

Offline

 

Board footer