cancel
Showing results for 
Search instead for 
Did you mean: 

Slow SPI data transfer B-L475E-IOT01A kit

Dmitriy Belimov
Associate II
Posted on April 18, 2018 at 06:43

Hi

After looong work with Microchip's PICs we are moving our desing on the fly to STM32L4 series MCU because it has hardware SDIO core. After some tests I see 55Mbps on STM32L476-EVAL with microSD Class 10 and 32KB buffer. It's great. But I need transfer fast data over SPI too. With SPI I see wery sloooow transfer.

My Software:

  • MXCube 4.25,
  • TrueStudio 9.0

My clock settings

0690X0000060AdIQAU.png

My SPI settings

0690X0000060AdRQAU.png

My Hardware:

  • B-L475E-IOT01A kit
  • Salea Logic Analyzer
  • RF module

Just for test transfer over SPI I used LL functions with monopoly MCU using. No any other tasks.

void _SPI_WriteBlock(const uint8_t* pData, const uint16_t pDataSize)

{

    uint16_t i;

    uint8_t * lc_ptr;

    lc_ptr = (uint8_t*)pData;

    for (i = 0; i < pDataSize; i++)

    {

        while(!LL_SPI_IsActiveFlag_TXE(RF_SPI));

        LL_SPI_TransmitData8 (RF_SPI, *lc_ptr++);

    }

    while(LL_SPI_IsActiveFlag_BSY(RF_SPI));

}

For write 1024 bytes buffer of data

_SPI_CS(true);

_SPI_WriteBlock(_test_buf, 1024);

_SPI_CS(false);

All looks good and working. But what I see over Logic Analyzer? It's terrible:

0690X0000060AdNQAU.png

For write 1024 bytes need spend 50ms, data rate is 20KB too slow.

Let's looking what happens:

0690X0000060AdWQAU.png

Period of byte writing is huge, around 51us

0690X0000060AdbQAE.png

But for write single byte SPI spended only 2us. Other 49us we waste.

I don't understand why and what happens? Write function waiting only TXE flag. The TXE flag will be set when data moved from DR register to internal shifter. Main core works on 80MHz, one tick is around 12ns. Let's we spend 10 ticks for move data to shifter and set TXE flag it's 120ns but not 48us.

What happens and how to I can fix it.

Thank you!

5 REPLIES 5
Dmitriy Belimov
Associate II
Posted on April 18, 2018 at 13:42

Hi,

I found what's wrong. Bad idea use timer with 1MHz interrupt frequency.

Thank you!

AvaTar
Lead
Posted on April 18, 2018 at 14:02

Why is the question now assumed to be answered ... ?

I would check what the LL code does, i.e. what flags it actually checks.

At least the Cube code is notorious for it's generous use of busy-wait loops.

I did no project with either (Cube or LL lib) of them, for that and other reasons.

Posted on April 18, 2018 at 14:32

Prescaler seems high.

Initial communications can be at 400 KHz but once card is up you could presumably clock at 25 or 50 MHz, but SPI is going to be relatively slow compared to 4-bit SDR/DDR modes.

>>I see 55Mbps

What does this mean?

You have an SDIO/SDMMC clock of 55 MHz? At 4-bit that would be 220 Mbps (27.5 MBps)

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on April 18, 2018 at 14:45

No, SPI for transfer data over RF module not for SD card.

I use example SD card project for STM32L476-EVAL for write data to a microSD card. I can write 100MB file by 15 seconds. SD data transfer around 55Mbps. SDIO clock was 24MHz.
Posted on April 18, 2018 at 14:46

My post premoderated. I already found what happens and mark as solved.