Hi!
A kind of a rant, this time. I have fortunately caught this one just in time! I was ready to send a quite complex 4 layer PCB with STM32F429ZIT to be manufactured, looked in a CS4244 datasheet for the last time and... NO SH!T ... it can't do TDM is master mode. :palm
http://www.hardwaresecrets.com/datasheets/CS4244.pdfWhy aren't they saying that explicitly, that not all serial port modes do support master? Cirrus, why?!
(To skip the rant, continue reading below the horizontal line.)Now you may be asking why is that a trouble? Well it is, because STM32 audio peripheral (SAI) can not produce a correct MCLK/BCLK (12.288MHz or multiples) by itself (being a TDM master), it needs to be supplied by external clock to do so.
You may be asking, why don't I just supply those 24.576MHz to the STM32 and be done with it? Well.. that is a good question:
The facking AUDIO_CLK_IN pin, is not available as free IO to be used. You may now ask why? Because there is the only free I2C peripheral I need. Why don't I remap the I2C3 to another pin? I f**ng can't, because the only free I2C3 is only available on a single set of two pins.
Who would have thought, that one would like to use LCD, SDRAM and some audio in master mode with I2C to manage the codec and LCD touch panel?
Sometimes I really wonder, how do those ST designers make those alternate function mappings. Because they are one hell of a pain to use and mostly useless for many applications?
I do not say, that I want a full routing matrix capability, just they could put a bit of thought to it! Typical pain in the ass examples of those afio muxing failery, where ALWAYS one freaking pin is ruining everything.
1) I want a simple CAN-USB bridge. I have a nice small 32pin package STM32F042K, but I can't do it, because the CAN has only a single pin available, instead of having both RX and TX!
2) I want a more complicated CAN-USB bridge, having 2 CAN buses and a high speed USB for fast data access to a buffer storage. Good luck finding a MCU for this. (you will end up with something way too much fucking large!) You cant, because USB ULPI always blocks out all possible pinouts of the second CAN peripheral. (you will need an extremely overkill large STM32 MCU with THREE CANs, just to be still able to use only two of them).
3) Now suppose a larger MCU. We want a graphical GUI (LCD + SDRAM), with ETH connectivity. Nice 144pin package could do it, but hell NO, because a single freaking LCD pin is a blocking the only available RMII interface. (you will likely end up having the largest of all, the LQFP208 to do so).
4) Same as above, but let's add an SD card with fast access to files - 4bit SDIO. In most cases you only end up with just 1-lane SDIO, because one freaking pin is more than likely needed for: the only free I2S, the only free I2C, the only existing I2S_CKIN, etc.
5) Hurray! Some STM32s support QuadSPI. Good, you say, until you want to add fast accessible storage for a smaller package. Who would have thought, someone would like to have a 64pin package with QuadSPI? Sorry.. you can do just DualSPI, other pins not available on the package.
6) So you want to add audio to your application with GUI? (LCD+SDRAM). You need also I2C? and standard audio sample rates? hahaha! Forget it. Just another stupid pin is preventing you to do so. Using LCD+SDRAM is an instant loss of two I2C peripherals on a 144pin package, and the only one left is blocking other important functions.
7) So you want to fix point 6) with a larger 176pin package? Meh.. try it. Your I2S_CKIN will get blocked by SDIO, if you want 4bit wide bus. (Who wouldn't want a 32bit SDRAM and 4bit SDIO on such large package?). Just again only a single stupid pin ruining everything.
... I could write many more of these examples of the STM32 afio mapping failing basic peripheral combinations, just by one single pin (or two)!
But back to my original problem...
As I have kind of stated in the beginning, I have a board with STM32F429ZI (144pin) and CS4244 audio codec. Unfortunately, the CS4244 does not support TDM master mode, which is a major pain in the ass, as the STM32 can not provide correct MCLK/BITCLK in master mode, without being supplied with the audio-specific clock of 12.288MHz or it's multiples.
To be able to supply such clock, one needs the I2S_CKIN pin (PC9). However the PC9 pin is blocked by the only available I2C (I2C3), that for some stupid reason can not be remapped. (I2C1 and I2C2 are automatically blocked by the combination of LTDC + SDRAM ... how rude!)
So I have thought - hey! I could set both the codec and the STM32 to be TDM slaves and supply the BCLK from external circuitry - which is more then simple, because I would need to just copy MCLK to BCLK, or divide the MCLK by 2, then send to BCLK (because the damn SAI peripheral does not support frames longer than 256fs - which is just PURE EVIL STUPID).
The above however can not be done. SAI can not generate the FS (frame sync) when in slave mode. I would need to generate both BCLK and FS using external circuitry.
Generating the FS signal is not unfortunately easy, using just pure logic. (I'd need at minimum an 8bit counter and other logic gates).
Do you have any interesting suggestion how to solve this? Have you ever been in a similar situation with STM32?
What I came up with so far are these:
A) ditch the HW I2C peripheral, use the I2S_CKIN. Ouch!!! Having to maintain a touch screen controller using software I2C. Evil! (Like if the HW I2C peripheral wouldn't be evil enough by itself!)
B) use a small CPLD (greenpak enyone?) to fix the damn *** ... ouch!! There is not much space left on the PCB, even for a small CPLD.
C) This one came to mind just while writing this rant! I could probably find a couple pins left with a timer on them to produce the FS signal, synchronously to the BCLK!
D) any other ideas anyone?
Thanks for thoughts and comments. Feel free to add a rant on STM32 afio mapping.
Y.