cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with STM32H7 and SPI on trasmission

frnt
Senior

Hello,

I'm just started using a nucleo-h742x. I have configured the SPI and the Fatfs library using the default settings, the SPI speed was configured at speed below 1Mbit/s. The sys clock is below 100MHz.

I always get disk_not_ready error when trying to mount the drive (error code 3).

The problem is that I don't see any signal on the MOSI line when a transaction should appear. I have also tried a simple HAL_spi_transmit(), but I have the same problem. I see the clock appearing but no signal on MOSI.

Someone has some suggestions? On other STM32 M4/M3/M0 I have no problem using the same code.

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Missing structure members in the example are binary zeros (as normally C static variables and structures are initialized by zeros).

You can find in the SPI include files which symbolic constants correspond to value 0.

Note that in the 1st fragment :

 

 

SpiHandle.Init.NSSPMode          = SPI_NSS_PULSE_DISABLE;
SpiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;

 

 

In the 2nd fragment (generated)

 

 

hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;

 

 

 

 

View solution in original post

9 REPLIES 9
Pavel A.
Evangelist III

SPI controller of STMH7 differs from F4, F0 and so on. You can't use *exactly* same code on H7.

Find and study SPI examples in CubeH7 software package, read the RM. Make a simple test or two.

AScha.3
Chief III

H742 has sdio - for sd-card the reasonable interface.

why you dont use it ??

If you feel a post has answered your question, please click "Accept as Solution".
Piranha
Chief II

In addition I will just remind that all of ST's cache maintenance code is broken:

https://community.st.com/t5/stm32-mcus-products/maintaining-cpu-data-cache-coherence-for-dma-buffers/m-p/95746

I have looked at the firmware package of H7 but I don’t see a project that can be imported into cubeide with ioc. Any suggestions?

I don’t use the sdio because I have SD card module with spi connectivity and I was testing it.

Pavel A.
Evangelist III

@frnt The H7 examples have been created before the time point when ST begun including .ioc files with the project. So unfortunately no ready .ioc's there. Suggestions: 1. Try to use the examples as is, without CubeMX or "device configuration tool"; 2. Have somebody produce the .ioc for you.

@Pavel A. ,

I see. I have looked at the SPI example (SPI_FullDuplex_ComPolling), here the initialization of the SPI:

 

  /* Set the SPI parameters */
  SpiHandle.Instance               = SPIx;
  SpiHandle.Init.Mode = SPI_MODE_MASTER;
  SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
  SpiHandle.Init.Direction         = SPI_DIRECTION_2LINES;
  SpiHandle.Init.CLKPhase          = SPI_PHASE_1EDGE;
  SpiHandle.Init.CLKPolarity       = SPI_POLARITY_LOW;
  SpiHandle.Init.DataSize          = SPI_DATASIZE_8BIT;
  SpiHandle.Init.FirstBit          = SPI_FIRSTBIT_MSB;
  SpiHandle.Init.TIMode            = SPI_TIMODE_DISABLE;
  SpiHandle.Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLE;
  SpiHandle.Init.CRCPolynomial     = 7;
  SpiHandle.Init.CRCLength         = SPI_CRC_LENGTH_8BIT;
  SpiHandle.Init.NSS               = SPI_NSS_SOFT;
  SpiHandle.Init.NSSPMode          = SPI_NSS_PULSE_DISABLE;
  SpiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;  /* Recommended setting to avoid glitches */ 

 

 Here is the initialization generated from ioc file:

 

 /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 0x0;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;

 

As you can see, the initialization from .ioc has more parameters than the example.

Pavel A.
Evangelist III

Missing structure members in the example are binary zeros (as normally C static variables and structures are initialized by zeros).

You can find in the SPI include files which symbolic constants correspond to value 0.

Note that in the 1st fragment :

 

 

SpiHandle.Init.NSSPMode          = SPI_NSS_PULSE_DISABLE;
SpiHandle.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_ENABLE;

 

 

In the 2nd fragment (generated)

 

 

hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;

 

 

 

 

Thanks, the problem has been solved!