SPI on F4

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Mon May 08, 2017 6:22 pm

OK, back to F4, I can confirm the results, successful with the first F4 bin from Pito:

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2397.93,19155,207,212
2399.08,16532,207,212
2412.97,15940,207,211

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2446.03,1590,208,208
2447.22,972,208,208
2447.22,972,208,208

Done
Pito, please share your local core + SdFat lib, I definitely need it!

EDIT
In average each third read test is corrupted, giving the same error code 0x28 0x1:

Code: Select all

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2447.22,1532,208,208
error: read failed
SD errorCode: 0X28,0X1
Type any character to start
The next test may run again correctly though.

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Mon May 08, 2017 10:15 pm

It seems that I used wrongly the SdFatEx functionality til now - sorry Pito for misleading information from my side :oops:
I realized that it is not enough to set in SdFatConfig.h,

Code: Select all

#define ENABLE_EXTENDED_TRANSFER_CLASS 1
but the sketch must use

Code: Select all

SdFatEX sd(1);
This info has been discussed here earlier, should have paid attention.

With this settings I get these results (SPI1 @ 21MHz, no DMA):

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2465.33,18159,201,206
2472.64,17247,201,206

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
1748.14,1529,291,292
1748.14,1092,291,292
The much slower reading speed compared to the writing speed can be explained by the fact that by writing the software can write the next byte to be sent during the current byte is being transmitted. The clock is (mostly) continuous.
By reading the code must wait till the last bit of a byte is clocked in, must store the data and only afterwards can transfer the next byte, so that clock gaps occur.

And here the results for the version with SPI1 @ 42MHz, no DMA:

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
4237.02,16585,115,120
4247.82,18663,115,119

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2553.46,1411,199,200
2554.77,1032,199,200

EDIT
Just for the record, this is the result with optimized block read routine (SdFatEX, SPI1 @ 42MHz, no DMA):

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
4247.82,11877,115,119
4180.33,23571,115,121

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
3927.48,1369,129,129
3930.57,968,129,129
The SdFatEX class makes the magic :mrgreen:

Bench for blue pill can be checked here.

Next step is to debug the SPI + DMA, to check why the card FAT system is not recognized when using DMA.
Last edited by stevestrong on Wed May 10, 2017 11:07 pm, edited 2 times in total.

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Wed May 10, 2017 5:15 pm

Hot news :!:

Bench for Black F4 @ 168MHz, SPI1 @ 21MHZ, with DMA, SdFatEX, Sandisk Ultra 16GB, CL10 (red/grey):

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2438.87,13975,204,208
2446.03,14013,204,208

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
2499.84,1448,203,204
2501.09,909,203,204
*** SPI1 @ 42MHz ***

Code: Select all

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
4574.27,14191,105,110
4642.23,13894,105,109

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
4798.16,1615,105,106
4807.38,971,105,106
:mrgreen: :mrgreen: :mrgreen: :mrgreen:

Ten consecutive tests show similar results, ~4.6 MBps for write, ~4.8 MBbps for read. Card is still readable.

I attach the BIN file for those who want to test it. Connect the SD card module to the SPI1 pins PA4/5/6/7, output on USB serial.
Attachments
STM32F4_SD_bench.ino.bin.zip
(25.6 KiB) Downloaded 4 times

User avatar
Pito
Posts: 1497
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: SPI on F4

Post by Pito » Fri May 12, 2017 5:44 pm

FYI - Blue F103ZET, Sandisk Ultra 16GB red/gray, SPI @44MHz (88MHz fcpu clock), the latest SPI from victor, SdFatEX, short wires <10cm.

Code: Select all

File size 5 MB
Buffer size 512 bytes
Starting write test, please wait.

write speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
4393.39,7474,112,114
4328.73,10052,112,116
4378.00,7742,112,115

Starting read test, please wait.

read speed and latency
speed,max,min,avg
KB/Sec,usec,usec,usec
3887.78,975,129,130
3887.78,836,129,130
3890.80,835,129,130
The clocks higher than 44MHz show error "SD errorCode: 0X31,0X7F".. This Sandisk does not work at 42MHz SPI and 20cm long wires with F407 (error 0X54,0XFF).
Last edited by Pito on Fri May 12, 2017 6:12 pm, edited 1 time in total.
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Fri May 12, 2017 6:10 pm

Which "latest SPI from Victor" do you mean? The generic version?

Your F1 results look very close to be proportional to my ones, which were done at 36MHz:
44MHz/36MHz = 1.222
WR speed: (my result) 3.7 * 1.22 = 4.5, your result is ~4.4
RD speeed: (my result) 3.38 * 1.22 = 4.1, your result is ~3.9

Similar proportionality is achieved for F4 @ 42MHz WR speed: ~4.6.
I find it interesting that the F4 RD result is not proportional anymore, ~4.8 being ~20% higher than F1 performs using the same card, although the SPI code for F4 is very similar to F1 code.
I only can think that the difference is made by the CPU clock.
Last edited by stevestrong on Sat May 13, 2017 12:23 pm, edited 1 time in total.

User avatar
Pito
Posts: 1497
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: SPI on F4

Post by Pito » Fri May 12, 2017 6:13 pm

Victor's STM32Generic one. Still thinking why the reads with F1 are so slow..
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Fri May 12, 2017 6:20 pm

The RD speed is higher than the WR speed also @ 21MHz for F4 (which, btw, looks logical for me)...
So it seems to be a general difference/issue somewhere.

User avatar
Pito
Posts: 1497
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: SPI on F4

Post by Pito » Fri May 12, 2017 6:35 pm

Interestingly I cannot get the Samsung Evo working at F407 42MHz with the latest SPI generic from Victor. In the past it worked with his generic core at 42MHz, as I did a lot of testing. Now the both Samsung and Sandisk throws errors at 42MHz.. :?
Pukao Hats Cleaning Services Ltd.

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Fri May 12, 2017 6:53 pm

You could eventually try the BIN file I attached in one of the previous posts (SPI1: PA4..7, USB serial).

stevestrong
Posts: 1502
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: SPI on F4

Post by stevestrong » Sat May 13, 2017 12:19 pm

Pito wrote:Still thinking why the reads with F1 are so slow..
I experimented a lot with the SPI software for F1 to try to increase the RD speed, but I couldn't make it faster.
The F4 achieves 20% more speed.
So I finally think that it must be an F1 chip internal hardware issue, either the DMA controller itself or any of the data bus bridges.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest