STM32F4Discovery + CS43L22

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
stylon
Posts: 5
Joined: Wed Sep 11, 2013 10:37 am

STM32F4Discovery + CS43L22

Post by stylon »

Hi,

I know this topic has been on the board multiple times and I definitely read all those threads. The one that seems to come closest to my symptoms seems to be viewtopic.php?f=8&t=745, but unfortunately that one doesn't contain any solution.

I'm trying to output audio through the onboard DAC using ChibiOS 2.6.1 (the latest stable), but so far all my attempts fail. I started with the code of 3 different MP3 player projects (from here and on the web) and they all have different initialization code, but it boils down to basically the same initialization sequence. I've the I2C set up correctly and working (reads back DAC register contents and the ID correctly) and my code also sets up a shell via USB-CDC. I added some commands to my shell to do on-board diagnosis without gdb (e.g. read memory / register locations).

I already nailed it all down to the fact that the master clock is missing, so MCLK and SCLK pins stay silent whatever I do. PLL does work, I checked PLLI2SRDY and PLLI2SON and as well routed it to MCO2 and checked it via a scope. I've checked my code multiple times and in addition checked register contents via GDB on my and other examples (including those from ST) and the register contents of the I2CPLL source, SPI3 clock enable and the SPI3 config do all match. However, the only code I ever saw a master clock on my scope was with the one from ST (then also playing audio). All Chibios-based MP3 player examples including my code never manage to enable MCLK. However, I don't see differences in the initialization of the devices anymore (except maybe order of initialization, but I2S is the last stuff I enable and configure).

I'm only asking wether this rings a bell, because I've spent some 10 hours on this already to debug it and I start running out of ideas. Is there something I till miss to setup? Do I need to follow a specific order of initialization? Overall, I was surprised how easy it was to set up USB-CDC with ChibiOS, but this I2S setup of the audio codec drives my nuts.

I can provide source code if needed, there's not too much in it so far.

Best,
STYLON
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4Discovery + CS43L22

Post by Giovanni »

I never tried it, my plan is to add I2S functionality to the SPI driver in the 3.0 branch but I cannot give a timeline for this to happen.

If clocks are generated correctly then I would check the DMA setup and the SPI peripheral initialization in I2S mode.

Giovanni
stylon
Posts: 5
Joined: Wed Sep 11, 2013 10:37 am

Re: STM32F4Discovery + CS43L22

Post by stylon »

Hi,

thanks Giovanni for the quick reply, ChibiOS is a great effort! I have to admit that this is my first STM32F4 project, depite being familiar with ARM and microcontrollers in general and I also know how to use a scope.

An SPI driver may indeed be more elegant, but in my view I should also get it working without. Your comment about DMA and the fact that I did not yet trigger DMA with the MP3 player examples brought up another idea. So, far I though MCK is always there on PC7 regardless of any transfer (so I should see it as long as I gate it correctly to PC7), while SCK may be on PC9 (? sorry, no doc at hand right now) only during transfers. Or is MCK also enabled only during transfers? If yes, then I should indeed do some DMA or write to the DR of SPI3. However, that's exactly what the guy on the other thread tried and he also didn't see MCK. The ST & CS docs don't mention any pitfalls during setup, except that the I2S PLL and CLK gating should be set up pretty early right after reset, but I guess that's what halInit() does based on my mcuconf.h.

Best,
STYLON
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4Discovery + CS43L22

Post by Giovanni »

Correct, all initializations are done in halInit(), including clocks.

Note that there is a DMA helper driver you may use, all driver that use DMA do that.

I also suggest to look at the SPI code because it should be very similar to the code for I2S except probably you have to implement a circular buffer (the ADC driver does this if you need hints).

Giovanni
stylon
Posts: 5
Joined: Wed Sep 11, 2013 10:37 am

Re: STM32F4Discovery + CS43L22

Post by stylon »

Hi again,

indeed SCK *and* MCK are both only there upon transfers. After setting up DMA I saw MCK immediately and it's off as soon as the transfer is finished.

It's nothing related to ChibiOS, I was just misled by the I2S schematics in the ST32F4 documentation (Chapter 27.4, Figure 287) which does not show an additional gate on MCK related to "Communication Control" of that unit, but there must be a link. The STM32F4 documentation seems to be rather poor in this area.

Thanks & best,
STYLON
chelox
Posts: 17
Joined: Tue Jan 22, 2013 8:24 pm

Re: STM32F4Discovery + CS43L22

Post by chelox »

Hello!

I have seen examples of mp3 players for Discovery STM32F4 board, which has a built-DAC (CS43L22).

My question is:

Is it possible to reproduce with any mp3 having a STM32F4 plate without the need to use an external DAC?

Thank you!

Greetings!
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: STM32F4Discovery + CS43L22

Post by Tectu »

Is it possible to reproduce with any mp3 having a STM32F4 plate without the need to use an external DAC?

Yes, that is possible. The internal DAC of the STM32F407 has a bandwidth of something around 200kHz which is fairly enough to play music. In worst case, you can also use a normal GPIO/PWM pin and a low pass filter to generate an analog voltage. However, the CS43L22 already has a D-Class amplifier integrated, including a noise filter, equalizer and so on. That's something you'd be missing. Furthermore, the resolution of the CS43L22 DAC is way higher.


~ Tectu
Post Reply