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!
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?
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.
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.
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.
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.
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 ....
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...
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.
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?).
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.
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.
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.