cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7xx SPI. Tutorial, documentation or example code needed.

JBend.6
Associate III

I need to write firmware for STM32H7xx to interact with an SPI flash memory chip. (STM32 master, 8-bit, full-duplex polling, no CRC and application controlled #CS.) I am using STM32CubeIDE 1.14.0 and used the device configuration tool to produce my SPI1 configuration code using LL library calls.

I encountered problems with code based upon HAL library hanging whilst reading to verify a write. So I wish to use either the Low-Level or register based programming. I have written firmware for SPI peripherals before but this STM32H7xx is a whole new level.

Yes, I have read, re-read and read again the RM0468 Reference Manual. The poor English quality and lack of clear procedures do not help. It's like trying to learn a foreign language using a dictionary. I am struggling to find any good material for this family of chips. I have spent days on this and getting nowhere.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

@JBend.6 Again, my hopes here are with AI. It can interpret the documentation personally for every user, search a lot of documents, erratas, forums, source code. It's not right there yet but getting close.

View solution in original post

12 REPLIES 12

https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/NUCLEO-H743ZI/Examples/SPI

etc..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

> I have spent days on this and getting nowhere.

Using LL leads to frustration as you need to know not only what the registers do but also what the LL library is doing.

Use registers only.

SPI initialization and sending should be maybe 10 lines of code. What do you have?

The reference manual lists explicitly the steps you need to take. Where are you getting stuck?

 

TDK_1-1701802954114.png

 

Edit: was referencing the wrong manual initially. F7 manual is a little better, but H7 still seems reasonable.

 

If you feel a post has answered your question, please click "Accept as Solution".
FBL
ST Employee

Hello @JBend.6 

Could you please share your configuration and HW setup to understand better the issue?

Are you using Nucleo H723?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


I'm out of offce with limited access to my emails.
Happy New Year!

Thank you but the code there is of minimal help. LL examples are DMA or IT.

JBend.6
Associate III

The Reference Manual example you provide here is quite readable. The SPI section for the STM32H723/733 device appears to be a clumsy translation from technical writing in another language. I understand the configuration. I do not understand what the action sequences are for any of the major functions. Eg: do we release CS# after every instruction?

JBend.6
Associate III

I cannot share my LL or register based code since I have not been able to get started with it. Here instead is my HAL based code with setup code produced by STM32CubeMX. The function I am having trouble with is nvrPutArray(). My logic analyser output suggests that everything is working fine, except only zeros (0x00) are read back after the write.

 

 

> I do not understand what the action sequences are for any of the major functions. Eg: do we release CS# after every instruction?

It is your choice. Use CS how you want. It can be controlled by hardware or by you control it manually using it as a GPIO output. Generally, GPIO output is preferred but the STM32H7 also has proper hardware support for controlling CS.

 

> The SPI section for the STM32H723/733 device appears to be a clumsy translation from technical writing in another language.

Are we looking at the same thing? Here's a screenshot from the current RM available online. I don't see much difference between this and what I posted in the last thread.

TDK_0-1701965934256.png

 

 

I have no interest in writing or debugging LL code, but if you want to use direct register access I can help (by reviewing code, not writing it for you).

 

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

@JBend.6 What bitrate you set up for the SPI? With flying wires on the Nucleo we could not achieve anything above 5 MHz. On the real printed board with proper placement, our SPI device is good at ~ 30 Mhz, Try lower bit rate or improve connections.

 

I have this working now thank you to everyone who provided help.

The issue was not bitrate as the SPI device adjacent to the MCU on the PCB. Foremost it was the bewildering array of options on the STM32H7xx SPI interface. Mostly it was shocking documentation for the SPI Flash device which confused the reader.

In my career it strikes me that as these embedded devices become more complicated, the available documentation becomes worse.