cancel
Showing results for 
Search instead for 
Did you mean: 

SPI interface issues on STM32U575VGT

MJens.2
Associate II

I´m using the SPI1 via the alternative pins PB3-PB5 and I'm experiencing various issues. I have previously used the STM32F722 with somehow same CubeIDE setup and code and that works perfectly.

I have made a simple test application that only sends one byte via. HAL_SPI_Transmit.

When setting a high baud rate (20M) it seems to work ok. This is too high for my design and baud rate is lowered. When monitoring the SPI clk. not all clk. cycles are transmitted. Lowering the baud rate even more results in no clk. cycles being transmitted.

Any idea and thanks in advance...

1 ACCEPTED SOLUTION

Accepted Solutions
MJens.2
Associate II

I think I have a solution. Adding a timeout to the "HAL_SPI_Transmit" did the trick.

  • even though this was not necessary with previous MCU model??

Thanks for any assistance.....

View solution in original post

5 REPLIES 5
gbm
Lead III

So you expect us to guess what you put in your code? Close to impossible, but still.... pin speed settings.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
MJens.2
Associate II

0693W00000Y9bO4QAJ.bmp0693W00000Y9bOOQAZ.bmp 

Thank you for the reply and sorry for the missing details.

My test code is like below:

In main I try to send same data value via SPI1 multiple times

DisplayDriver_Write_Command(0xFD);

DisplayDriver_Write_Command(0xFD);

....

void DisplayDriver_Write_Command(byte command) {

HAL_SPI_Transmit(&hspi1, &command, 1, 0);

while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);

}

1st tx of 0xFD is ok (see picture)

2nd tx of 0xFD is not (see picture)

...

In addition I have copy pasted my Cube generated code for SPI1 and the port configuration

static void MX_SPI1_Init(void)

{

 /* USER CODE BEGIN SPI1_Init 0 */

 /* USER CODE END SPI1_Init 0 */

 SPI_AutonomousModeConfTypeDef HAL_SPI_AutonomousMode_Cfg_Struct = {0};

 /* USER CODE BEGIN SPI1_Init 1 */

 /* USER CODE END SPI1_Init 1 */

 /* 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_HIGH;

 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 = 0x7;

 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;

 hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;

 hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;

 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;

 hspi1.Init.ReadyMasterManagement = SPI_RDY_MASTER_MANAGEMENT_INTERNALLY;

 hspi1.Init.ReadyPolarity = SPI_RDY_POLARITY_HIGH;

 if (HAL_SPI_Init(&hspi1) != HAL_OK)

 {

  Error_Handler();

 }

 HAL_SPI_AutonomousMode_Cfg_Struct.TriggerState = SPI_AUTO_MODE_DISABLE;

 HAL_SPI_AutonomousMode_Cfg_Struct.TriggerSelection = SPI_GRP1_GPDMA_CH0_TCF_TRG;

 HAL_SPI_AutonomousMode_Cfg_Struct.TriggerPolarity = SPI_TRIG_POLARITY_RISING;

 if (HAL_SPIEx_SetConfigAutonomousMode(&hspi1, &HAL_SPI_AutonomousMode_Cfg_Struct) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN SPI1_Init 2 */

 /* USER CODE END SPI1_Init 2 */

}

if(hspi->Instance==SPI1)

 {

 /* USER CODE BEGIN SPI1_MspInit 0 */

 /* USER CODE END SPI1_MspInit 0 */

 /** Initializes the peripherals clock

 */

  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI1;

  PeriphClkInit.Spi1ClockSelection = RCC_SPI1CLKSOURCE_PCLK2;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

  {

   Error_Handler();

  }

  /* Peripheral clock enable */

  __HAL_RCC_SPI1_CLK_ENABLE();

  __HAL_RCC_GPIOB_CLK_ENABLE();

  /**SPI1 GPIO Configuration

  PB3 (JTDO/TRACESWO)   ------> SPI1_SCK

  PB4 (NJTRST)   ------> SPI1_MISO

  PB5   ------> SPI1_MOSI

  */

  GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 /* USER CODE BEGIN SPI1_MspInit 1 */

 /* USER CODE END SPI1_MspInit 1 */

 }

Thanks

MJens.2
Associate II

I think I have a solution. Adding a timeout to the "HAL_SPI_Transmit" did the trick.

  • even though this was not necessary with previous MCU model??

Thanks for any assistance.....

S.Ma
Principal

Not sure about this SPI version, try to use 4 wire mode SPI even if some of the pins are not assigned to a GPIO. I discovered long time ago that in monodirectional mode, some part of the SPI master operation has its SCK generation out of SW control...

Thanks for your answer