Page 1 of 2

SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Tue Feb 04, 2014 11:20 am
by Abhishek
Hello,

In order to be able to use SDIO interface and also I2S3 on a F4 Discovery board, I cut the traces going to the CS43L22 from PC10 and PC12 and connected them to PB3 and PB5 respectively, and appropriately remapped the GPIOs.

However I found that I am unable to send data on the I2S3 and simulatenously read another chunk of data from the SD card to enable continuous playback, it fails with a CRC Check Fail error on the sdcRead. After every I2S transfer I have to wait for TX to complete and then receive data from the SD Card before beginning another transmission.

The SDIO_STA register contains the value 1026 = (SDIO_STA_DBCKEND + SDIO_STA_DCRCFAIL bits)

So instead of using this code for double-buffered continuous playback:

Code: Select all

    uint32_t t = 0;

    bufSwitch = 0;

    wf_read(&f1, buf, PLAYBACK_BUFFER_SIZE, &temp);
    bytesToPlay-=temp;

    wf_read(&f1, buf2, PLAYBACK_BUFFER_SIZE, &temp);
    bytesToPlay-=temp;

    codec_audio_send(buf, temp/sizeof(uint16_t));

    while(bytesToPlay)
    {
      dmaWaitCompletion(i2sdma);
      codec_audio_send(bufSwitch ? buf : buf2, temp / sizeof(uint16_t));

      t =  wf_read(&f1, bufSwitch ? buf2 : buf, PLAYBACK_BUFFER_SIZE, &temp);

      bufSwitch = 1 - bufSwitch;

      bytesToPlay-=temp;
    }


I have to use this code which waits till reading completes before I can send another chunk [Which works, I get clear stereo audio, but playback is obviously glitchy]

Code: Select all

    uint32_t t = 0;

    bufSwitch = 0;

    wf_read(&f1, buf, PLAYBACK_BUFFER_SIZE, &temp);
    bytesToPlay-=temp;

    wf_read(&f1, buf2, PLAYBACK_BUFFER_SIZE, &temp);
    bytesToPlay-=temp;

    codec_audio_send(buf, temp/sizeof(uint16_t));

    while(bytesToPlay)
    {
      dmaWaitCompletion(i2sdma);
      t =  wf_read(&f1, bufSwitch ? buf2 : buf, PLAYBACK_BUFFER_SIZE, &temp);
      codec_audio_send(bufSwitch ? buf : buf2, temp / sizeof(uint16_t));


      bufSwitch = 1 - bufSwitch;

      bytesToPlay-=temp;
    }


I am unable to troubleshoot further, but suspect a hardware issue.

I attach the screenshot of the modded F4 board
The left trace cut was PC12 (SDIO_CK) and now connected to PB5 (Alt. I2S3_SD)
The right trace cut was PC10 (SDIO_D2) and now connected to PB3(Alt. I2S3_CK)

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Tue Feb 04, 2014 11:25 am
by Giovanni
Are there DMA conflicts?

Giovanni

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Tue Feb 04, 2014 11:44 am
by Abhishek
I don't think so, SDIO uses STM32_DMA_STREAM_ID(2, 3) while I2S3 TX uses STM32_DMA_STREAM_ID(1, 7).

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Wed Feb 05, 2014 8:11 am
by Abhishek
The issue was of signal integrity.

I observed that the SD Card worked fine and concurrently with I2S3 in 1-bit bus mode (by commenting out bus width change part in sdc.c), but problems arose in 4-bit mode. This meant there was maybe some sort of signal crosstalk between PC10, PC12, PB3 and PB5 near the trace cut (the SDIO bus is operating at 48MHz).

It got fixed by adding a 100 Ohm series resistor between PC12 and SDIO_CK of SD Card. Now I can obtain circular buffer continuous playback.

Maybe someone more experienced than me can help throw light on why it happened. I will try to obtain scope traces.

Regards
Abhishek

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 3:12 pm
by pito
Adding the 100ohm resistor in series limits the "ringing" when the wires are long. How is your sdcard wired? Do you have pullups there? How is your decoupling? Any schematics available?

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 5:25 pm
by Abhishek
My hardware is built wire-wrap. The wires are not quite long from the pinheaders connecting the Discovery board to the microSD connector.
I have 47K pull-ups on all pins except SDIO_CK.

Now I have put 100E resistors in series with SDIO_D2 and SDIO_CK.

The 0.1uF decoupling cap, 10uF capacitor are connected to the power rail via a "via" (4 filled holes in the middle of the SD Card socket) - which I now realise was a bad idea as the via inductance is "killing" the decoupling capacitor. Power to the SD Card is controlled by a PMOS transistor on the bottom layer.

Here is a screenshot. Not quite neat, but it is hopefully working OK now.

What problems could I face in the future? Should I add another 0.1uF decoupling cap near the SD power pins?

Regards
Abhishek

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 6:29 pm
by pito
An sdcard can take 100mA peak. So I would use thicker wires for its power and ground. Also I always use few ceramic multilayer 10u smd capacitors (2-3) for its decoupling, instead of an aluminum or tantalum types. Place the decoupling capacitors close at sdcard's vcc pins (when using transistor for switching the power always place the capacitors at sdcard's side).

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 7:21 pm
by alexblack
Hi.
pito wrote:An sdcard can take 100mA peak.

I had problems with some cards because it has current consumption more than 250 - 300mA in peak at insertion moment!!!

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 7:49 pm
by Giovanni
Probably this is why I have seen inductors in some designs.

Giovanni

Re: SDIO Conflict with I2S on modded F4 Discovery Board

Posted: Sat Feb 08, 2014 7:56 pm
by Abhishek
Indeed. I have a 4.7uH 0805 inductor in series with the MOSFET before the filter capacitors.

The audio sounds very good on headphones but I notice some audible hum in my USB Speakers at maximum volume ,the frequency of which varies inversely with the DMA buffer size. I will try and increase the inductance to see if has any effect on reducing the hum. There is no hum when the board and the speakers are placed on separate power supplies.

Edit: Giovanni was faster :)

Regards