cancel
Showing results for 
Search instead for 
Did you mean: 

SPI3 not working on stm32u585 but other SPI peripherals work ok (SPI1 and SPI2). No CLK output.

JKahn.1
Associate III

As described.
I am using the B-U585I-IOT02A Discovery development kit. Just testing basic SPI operation and trying to use all three SPI lines.

Using basic setup with STM Cube ID I can send data using HAL_SPITransmit over SPI1 and SPI2. Trying to do the same on SPI3 returns an error. I also do not see any signals when probing SCK and MOSI on SPI3 when using an oscilloscope.

Am I missing something here? Or is there maybe a deeper issue?

 

Test code (SPI3 call returns an error, due to lack of EOT flag resulting in a timeout:

 

Setup code (seems to be the same for each SPI instance...) generated by STMCube:

 

 

 

/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
*  hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  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_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_SPI1_CLK_ENABLE();

    __HAL_RCC_GPIOE_CLK_ENABLE();
    /**SPI1 GPIO Configuration
    PE14     ------> SPI1_MISO
    PE13     ------> SPI1_SCK
    PE15     ------> SPI1_MOSI
    */
    GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_13|GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
    HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI1_MspInit 1 */

  /* USER CODE END SPI1_MspInit 1 */
  }
  else if(hspi->Instance==SPI2)
  {
  /* USER CODE BEGIN SPI2_MspInit 0 */

  /* USER CODE END SPI2_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI2;
    PeriphClkInit.Spi2ClockSelection = RCC_SPI2CLKSOURCE_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_SPI2_CLK_ENABLE();

    __HAL_RCC_GPIOD_CLK_ENABLE();
    /**SPI2 GPIO Configuration
    PD4     ------> SPI2_MOSI
    PD3     ------> SPI2_MISO
    PD1     ------> SPI2_SCK
    */
    GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI2_MspInit 1 */

  /* USER CODE END SPI2_MspInit 1 */
  }
  else if(hspi->Instance==SPI3)
  {
  /* USER CODE BEGIN SPI3_MspInit 0 */

  /* USER CODE END SPI3_MspInit 0 */

  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_SPI3;
    PeriphClkInit.Spi3ClockSelection = RCC_SPI3CLKSOURCE_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }

    /* Peripheral clock enable */
    __HAL_RCC_SPI3_CLK_ENABLE();

    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOD_CLK_ENABLE();
    /**SPI3 GPIO Configuration
    PG9     ------> SPI3_SCK
    PD6     ------> SPI3_MOSI
    PG10     ------> SPI3_MISO
    */
    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
    HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI3;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI3_MspInit 1 */

  /* USER CODE END SPI3_MspInit 1 */
  }

}
/* USER CODE BEGIN 2 */
  uint8_t tx_data1[] = {1, 1, 1, 1};
  HAL_StatusTypeDef status1 = HAL_ERROR;
  uint8_t tx_data2[] = {2, 2, 2, 2};
  HAL_StatusTypeDef status2 = HAL_ERROR;
  uint8_t tx_data3[] = {3, 3, 3, 3};
  HAL_StatusTypeDef status3 = HAL_ERROR;
  (void)status1;
  (void)status2;
  (void)status3;
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  status1 = HAL_SPI_Transmit(&hspi1, tx_data1, sizeof(tx_data1), 10); // Returns ok
	  status2 = HAL_SPI_Transmit(&hspi2, tx_data2, sizeof(tx_data2), 10); // Returns ok
	  status3 = HAL_SPI_Transmit(&hspi3, tx_data3, sizeof(tx_data3), 10); //Returns error!
	  __NOP();

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
JKahn.1
Associate III

I solved the issue.

SPI clock pin was PG9, which is in the VDDIO2 power domain. I enabled VDDIO2 power with the HAL_PWREx_EnableVddIO2() function and this solved the problem.

It was not really related to SPI. Even trying to use PG9 as a regular GPIO without enabling VDDIO2 did not work.

View solution in original post

1 REPLY 1
JKahn.1
Associate III

I solved the issue.

SPI clock pin was PG9, which is in the VDDIO2 power domain. I enabled VDDIO2 power with the HAL_PWREx_EnableVddIO2() function and this solved the problem.

It was not really related to SPI. Even trying to use PG9 as a regular GPIO without enabling VDDIO2 did not work.