SPI on STM32F4

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
User avatar
martinayotte
Posts: 1234
Joined: Mon Apr 27, 2015 1:45 pm

SPI on STM32F4

Post by martinayotte » Sat May 30, 2015 2:01 am

Wishing to that the work of having EtherCard_STM on my Netduino2Plus, I've decided to start with lower target : the SDCard ...
Unfortunately, I'm stucked at lower level, the SPI ... :(
The low level libmaple spi.c/spi.h of F4 are quite obsolete compare to F1, so simply copy of SPI to F4 doesn't work.
I don't know which direction to go : waiting for F1/F4 merge, or should I investigate of if throwing away low level libmaple spi.c/spi.h of F4 and replacing it with the one from F1 should do the work ?
I don't want to spent time for nothing ... Any hint will be appreciated ...

victor_pv
Posts: 1791
Joined: Mon Apr 27, 2015 12:12 pm

Re: SPI on STM32F4

Post by victor_pv » Sat May 30, 2015 10:24 pm

martinayotte wrote:Wishing to that the work of having EtherCard_STM on my Netduino2Plus, I've decided to start with lower target : the SDCard ...
Unfortunately, I'm stucked at lower level, the SPI ... :(
The low level libmaple spi.c/spi.h of F4 are quite obsolete compare to F1, so simply copy of SPI to F4 doesn't work.
I don't know which direction to go : waiting for F1/F4 merge, or should I investigate of if throwing away low level libmaple spi.c/spi.h of F4 and replacing it with the one from F1 should do the work ?
I don't want to spent time for nothing ... Any hint will be appreciated ...
Martin, there is no one actively working on a merge as far as I know, so I would suggest that you get the F4 and F1 datasheets and have a look at what is different, you may be able to take the one from the F1, but I haven't ever looked at the F4 peripherals to say how close or different they are. Is the F4 code still the Aeroquad one?

User avatar
RogerClark
Posts: 7541
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI on STM32F4

Post by RogerClark » Sun May 31, 2015 12:02 pm

The hardware registers on the F4 are considerably different to the F1

STM have some guides on conversion between the various processors, but I can't remember if there is a F1 to F4.

Merging of F1 and F4 is a long term goal, but there are still issues that need to be resolved on the F1.

I've not looked at the SPI code on the F4, but I'm surprised if it was miles away from the F1 code.
I did some refactoring of the F1 SPI to bring it mostly up to date, and I recall Tim ( on the Arduino forum) making some changes as well, but nothing radical.

I'm pretty sure I just copied the latest AeroQuad code to my repo, but I don't know when the AeroQuad team took their copy of libmaple and whether Leaflabs did much to the SPI in 2012 or 2013
However you can probably look at the dates on the AeroQuad GitHub repo and the Leaflabs libmaple repo and do some detective work.

You could also look at what Avik De did for his SPI in his repo Koduino, but he uses the HAL so the code will be a lot different ( but you could look at the HAL source files )

mubase2

Re: SPI on STM32F4

Post by mubase2 » Sun May 31, 2015 1:07 pm

Hiya. I'm also trying to use the SPI1 on my f4 discovery. I want to communicate with the accelerometer... I'm at my girl's place at the moment where I'm picking up my mini oscilloscope. I'll post two let you know how I get on... :D

User avatar
sheepdoll
Posts: 238
Joined: Fri May 22, 2015 12:58 am
Location: Silicon Valley Vortex
Contact:

Re: SPI on STM32F4

Post by sheepdoll » Sun May 31, 2015 5:23 pm

mubase2 wrote:Hiya. I'm also trying to use the SPI1 on my f4 discovery. I want to communicate with the accelerometer...
Which Discovery do you have? I am finding the F429I is a real challenge to understand all the options are. I gave away my STM32F4DISCOVERY
thinking it was a coretex M0.

The F401 is much like the F103 that is popular here. Not sure about the F405 and the F407, but my quick and dirty playing about with the latest STCubeF4 indicates that the hardware profiles are different. Each of these are going to require their own variant and a lot of ifdefs. (Now if only there was an #ifswitch and #ifcase to do all the mappings needed.

I too am interested in SPI on F4 as I use a lot of '165s and '595 shift registers in my designs. For the historical minded SPI was designed to talk directly to these registers through a tristate mux, like the ever popular '138.

User avatar
RogerClark
Posts: 7541
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI on STM32F4

Post by RogerClark » Sun May 31, 2015 10:14 pm

AFIK @mubase has a F407 discovery like I do.

I will take a quick look at the SPI code this morning if I get chance, just to see the scale of the problem ;-)

Edit.

It looks like the AeroQuad guys don't need SPI. I can't see it in their repo at all :-(

There appears to be low level code for SPI within the repo, but I've not had chance to diff it against the f1 code.
One telltail difference is the base address for the SPI register bank. If someone had updated this, then it shows someone has looked to porting to F4 (though doesnt mean they finished porting)

User avatar
RogerClark
Posts: 7541
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI on STM32F4

Post by RogerClark » Sun May 31, 2015 11:14 pm

I just took a look at the programming manual for the F1 and the F4 and I was wrong.

The SPI registers base address appears to be the same on both devices, so this is no guide to whether the files have been ported by AeroQuad


I'm not sure if this is correct either, but my understanding was that the F2 and F4 were similar. If so there is a migration guide from F1 to F2
(Not the AeroQuad guys use the F2 folders, which would suggest that F2 is a close relative to the F4. Personally I'd have renamed the folders ;-) )

I also found this on ST's community forum

https://my.st.com/public/STe2ecommuniti ... tviews=162

http://www.st.com/web/en/resource/techn ... 033267.pdf


So basically, it looks like F2 and F4 are similar enough to assume code for the F2 generally works on the F4.


Also. While I remember.

I thought @mubase had I2S working on his F407, which is strange, as I2S is actually a enhanced version of SPI (and has nothing to do with I2C even though its name sounds very similar)

In which case... Perhaps we are closer to getting SPI working on the F4 that it seems.

and...

One other option. Someone could be cheeky and post an issue on the AeroQuad repo say that you'd like to use SPI with their repo, and see what response you get. As technically we are using their port,albeit a derivative.

User avatar
martinayotte
Posts: 1234
Joined: Mon Apr 27, 2015 1:45 pm

Re: SPI on STM32F4

Post by martinayotte » Mon Jun 01, 2015 2:32 am

Just to let you know about my works : I did replace spi.h/spi.c in F4 with the one from F1 (I diff them and yes, as Roger said, they look simliar).
I've also copied SPI library from F1 to F4, tweak it until it compiled. I'ved then add the SD library from Sparkfun, after some tweaking, I got it also compiled.
But unfortuntely, at runtime, the CPU is hanging during card.init() ... :(
I will have to dig more, but I'm don't have GDB to help me in Netduino2Plus environment, so printfs will still be my friends ... :?

User avatar
RogerClark
Posts: 7541
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: SPI on STM32F4

Post by RogerClark » Mon Jun 01, 2015 3:29 am

Martin,

Can you commit the changes to your repo and send me a pull request

Re: SD Card

This may be a different issue. I know Victor PV has been working with the guy who maintains the SD card lib, and I think there may be a new cross platform version.

Perhaps you can PM Victor, as I'm not sure if he would read this thread as he doesn't have a F4 board

User avatar
mubase
Posts: 30
Joined: Wed Apr 29, 2015 5:10 pm
Contact:

Re: SPI on STM32F4

Post by mubase » Mon Jun 01, 2015 10:34 am

Which Discovery do you have? I am finding the F429I is a real challenge to understand all the options are.
Its an STM32F4 discovery. I got it for its audio and DSP capabilities.. I've got the I2S and codec working with the repo.. I had an STM32f429 with the tft but sold it on ....
I gave away my STM32F4DISCOVERY thinking it was a coretex M0.
Damn!

Post Reply