cancel
Showing results for 
Search instead for 
Did you mean: 

Having a hardtime to get SPI1 working on STM32H753ZI

CLeo.1
Senior II

Hi everyone,

Hope all is well. I am trying to setup a basic SPI demo for the STM32H753ZI using the nucleo H753ZI just seeing if I can output my test word onto the MOSI line.

The conditions in my SPI demo is as follows:

  • MCU clocked at 400MHz
  • SPI is set as Full Duplex Master
  • SPI Clocked at 400MHz/256 = 1.5625MHz approx
  • PA4 = SS, PA5 = CLK, PA6 = MISO, PA7 = MOSI
  • Theres no slave on the otherend just hooked up to the Salae logic Analyzer

The issues I am seeing is that My SPI demo and STs theres no data on the MOSI line additional to that the CLK is behaving super weird in my SPI demo. You can see boths STs and My SPI demo down below from the logic anayalzer

void initSPI() {
 
	LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOA);
	LL_AHB4_GRP1_EnableClock(LL_AHB4_GRP1_PERIPH_GPIOB);
 
	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI2);
 
	LL_GPIO_InitTypeDef LL_GPIO;
	LL_SPI_InitTypeDef LL_SPI1;
	LL_SPI_InitTypeDef LL_SPI2;
 
	LL_GPIO_StructInit(&LL_GPIO);
	LL_SPI_StructInit(&LL_SPI1);
	LL_SPI_StructInit(&LL_SPI2);
 
	// Setting up SPI 1 GPIO
	LL_GPIO.Alternate = LL_GPIO_AF_5;
	LL_GPIO.Mode = LL_GPIO_MODE_ALTERNATE;
	LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	LL_GPIO.Pin = LL_GPIO_PIN_5 | LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
	LL_GPIO.Pull = LL_GPIO_PULL_NO;
	LL_GPIO.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
	LL_GPIO_Init(GPIOA, &LL_GPIO);
 
	// Setting up SPI 1 GPIO
	LL_GPIO.Alternate = 0x00;
	LL_GPIO.Mode = LL_GPIO_MODE_OUTPUT;
	LL_GPIO.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	LL_GPIO.Pin = LL_GPIO_PIN_4;
	LL_GPIO.Pull = LL_GPIO_PULL_UP;
	LL_GPIO.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
	LL_GPIO_Init(GPIOA, &LL_GPIO);
 
	// Setting up SP1 1 Peri
	LL_SPI1.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV256;
	LL_SPI1.BitOrder = LL_SPI_MSB_FIRST;
	LL_SPI1.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
	LL_SPI1.CRCPoly = 0x00;
	LL_SPI1.ClockPhase = LL_SPI_PHASE_2EDGE;
	LL_SPI1.ClockPolarity = LL_SPI_POLARITY_LOW;
	LL_SPI1.DataWidth = LL_SPI_DATAWIDTH_8BIT;
	LL_SPI1.Mode = LL_SPI_MODE_MASTER;
	LL_SPI1.NSS = LL_SPI_NSS_SOFT;
	LL_SPI1.TransferDirection = LL_SPI_FULL_DUPLEX;
	LL_SPI_Init(SPI1, &LL_SPI1);
 
	LL_SPI_EnableGPIOControl(SPI1);
 
}
int main(void)
{
 
	char word = 'H';
 
	HAL_Init();
	SystemClock_Config();
 
	initSPI();
	LL_SPI_SetTransferSize(SPI1, 1);
	GPIOA->BSRR |= (1 << 4); //Sets the SS line HIGH
 
	LL_SPI_Enable(SPI1);
	LL_SPI_StartMasterTransfer(SPI1);
	GPIOA->BSRR |= (1 << 20); //Sets the SS line LOW
 
	while(LL_SPI_IsActiveFlag_TXP(SPI1) == 0){};
	SPI1->TXDR = (uint8_t)word;
	while(LL_SPI_IsActiveFlag_EOT(SPI1) == 0){};
 
	GPIOA->BSRR |= (1 << 4); //Sets the SS line HIGH
	LL_SPI_Disable(SPI1);
 
  while (1)
  {
 
  }
 
}

My SPI Demo

0693W00000Y99iuQAB.pngSTs SPI Demo

0693W00000Y99ltQAB.png 

Any help would be appericiated, super stumped as to why its not behaving as it should.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Community member​, I got it working it was due to the Nucleo reserving PIN PA7 for ethernet. Just swapped onto SPI2 and now I am seeing data on the MOSI line.

View solution in original post

5 REPLIES 5
MM..1
Chief III

Took your advice, added in any difference and still the samething, nothing output on the MOSI line and SCLK still acting funky.

Chris1
Senior III

SPI1->TXDR is 32 bits,

*((volatile uint8_t *)&SPI1->TXDR) = byte_0; // 8-bit transaction on the data bus

as said by Tesla DeLorean:

https://community.st.com/s/question/0D53W00000kuqp9SAA/h7-migration-send-spi-without-using-hal

Chris1
Senior III

Isn't there a LL function for this?

like:

__STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)

{

 *((__IO uint8_t *)&SPIx->DR) = TxData;

}

Hi @Community member​, I got it working it was due to the Nucleo reserving PIN PA7 for ethernet. Just swapped onto SPI2 and now I am seeing data on the MOSI line.