cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U535: SPI2 Stops Working When TRNG Enabled in CubeIDE

Badrinathan
Associate III

Hi @all  @stforum @stforum2  @stforum.tormod9  @stforum23 @jkn_stforum 

I’m using STM32U535CBTx MCU, using STM32Cube IDE.

Peripherals in use:

  • I2C1

  • UART4

  • LPUART1

  • SPI2

  • GPIO PB8, PB9, PB10 for LEDs

Issue:

 

  • SPI2 works fine when TRNG is disabled.

  • After enabling TRNG, SPI2 stops working.

I’ve attached both .ioc files (with TRNG enabled and disabled). Could someone please review them and suggest a solution?

Could anyone please:

  1. Review my .ioc files

  2. Explain why this happens and how to fix this issue?

  3. Suggest how to use TRNG and SPI2 together

I have attached two .ioc files for reference:

  1. sensor nodewith TRNG.ioc – this version has the TRNG peripheral enabled.

  2. sensor node without TRNG.ioc – this version does not use TRNG and SPI2 works correctly.

Please review and help identify why SPI2 stops working when TRNG is enabled.”

Thanks in advance!

8 REPLIES 8
Ghofrane GSOURI
ST Employee

Hello @Badrinathan 

I'm currently checking this behavior. I will get back to you asap.

THX

Ghofrane

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.

Badrinathan
Associate III

Hi @Ghofrane GSOURI 

Thanks, Ghofrane. I’ll wait for your update.

Thank you

Badrinathan J

Hello @Badrinathan 

I compared the two provided IOC files and identified the key differences in the clock configuration:

Without RNG:

The PLL is enabled and used as the system clock (SYSCLK).
MSI is selected as the PLL source.
SYSCLK is derived from the PLL, resulting in a higher system frequency.
Voltage scaling is set to SCALE1, providing the highest performance.
With RNG:

HSI48 (the 48 MHz internal oscillator, required for TRNG) is enabled.
The PLL is disabled (PLLState = RCC_PLL_NONE).
SYSCLK is sourced directly from MSI, not the PLL, leading to a much lower system frequency.
Voltage scaling is set to SCALE3, which is the lowest performance setting.
Recommendation:
To ensure both RNG and SPI2 function correctly, enable HSI48 for the RNG peripheral while maintaining your original PLL-based system clock and high-performance voltage scaling. This configuration will allow both peripherals to operate at their required speeds.

Please try this adjustment, and let me know the results.

PS: I used the latest version of CubeMX6.16.0 , you can download it from the following LINK

THX

Ghofrane

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.

Badrinathan
Associate III

Hello @Ghofrane GSOURI 

Thank you for your prompt response.

I would like to clarify that I am not using CubeMX .
I am configuring everything directly in STM32CubeIDE (latest version) using the .ioc file inside the Cube IDE. I am not manually changing the voltage scaling, but as soon as I enable the RNG, CubeIDE may be automatically switches the Voltage Scaling from SCALE1 to SCALE3

Could you please explain step-by-step how to correctly keep:

  • PLL enabled

  • SYSCLK sourced from PLL

  • Voltage Scaling = SCALE1

  • HSI48 enabled only for RNG

specifically inside STM32CubeIDE?

In this Cube IDE,  I am not sure where to set the voltage scaling back to SCALE1 or how to prevent CubeIDE from changing it automatically.

A detailed sequence of steps (menu paths, tabs, and settings) would really help me solve this using STM32 CubeIDE.

Thank you,
Badrinathan

Hello @Badrinathan 

Here are the steps I followed: I used CubeMX 6.16.0  standalone  and loaded your IOC file (sensor node without TRNG.ioc). I kept your original configuration, then activated the RNG and ensured that HSI48 is selected as the input for the RNG multiplexer. Afterward, I generated the code and chose STM32CubeIDE as the toolchain.

GhofraneGSOURI_1-1763386039256.png

 

GhofraneGSOURI_0-1763385953158.png

I will review this in STM32CubeIDE and get back to you.

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.

Hello @Badrinathan 

Inside STM32CubeIDE, import the attached IOC  

GhofraneGSOURI_2-1763387012151.png

Then generate code 

GhofraneGSOURI_3-1763387071880.png

 

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.

Badrinathan
Associate III

Hi @Ghofrane GSOURI 

After enabling the TRNG and selecting HSI48 as its clock source, CubeIDE automatically changes the SPI2 clock source from PCLK1 to SYSCLK, which causes SPI2 to fail.

Even when I manually switch the SPI2 clock source back to PCLK1, the issue persists and SPI2 still does not work.

parameters' also changing automatically.

Please find attached the clock configuration on snippet and the IOC file with the TRNG enabled.

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct = {0};

RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 

/** Configure the main internal regulator output voltage

*/

if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

{

Error_Handler();

}

 

/** Initializes the CPU, AHB and APB buses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48|RCC_OSCILLATORTYPE_LSI

|RCC_OSCILLATORTYPE_MSI;

RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

RCC_OscInitStruct.LSIState = RCC_LSI_ON;

RCC_OscInitStruct.MSIState = RCC_MSI_ON;

RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;

RCC_OscInitStruct.LSIDiv = RCC_LSI_DIV1;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;

RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;

RCC_OscInitStruct.PLL.PLLM = 3;

RCC_OscInitStruct.PLL.PLLN = 10;

RCC_OscInitStruct.PLL.PLLP = 2;

RCC_OscInitStruct.PLL.PLLQ = 2;

RCC_OscInitStruct.PLL.PLLR = 1;

RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;

RCC_OscInitStruct.PLL.PLLFRACN = 0;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

Error_Handler();

}

 

/** Initializes the CPU, AHB and APB buses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2

|RCC_CLOCKTYPE_PCLK3;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;

 

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)

{

Error_Handler();

}

}

 

static void MX_SPI2_Init(void)
{

/* USER CODE BEGIN SPI2_Init 0 */

/* USER CODE END SPI2_Init 0 */

SPI_AutonomousModeConfTypeDef HAL_SPI_AutonomousMode_Cfg_Struct = {0};

/* USER CODE BEGIN SPI2_Init 1 */

/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_4BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 0x7;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
hspi2.Init.ReadyMasterManagement = SPI_RDY_MASTER_MANAGEMENT_INTERNALLY;
hspi2.Init.ReadyPolarity = SPI_RDY_POLARITY_HIGH;
if (HAL_SPI_Init(&hspi2) != 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(&hspi2, &HAL_SPI_AutonomousMode_Cfg_Struct) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */

/* USER CODE END SPI2_Init 2 */

}

Please review and help identify why SPI2 stops working when TRNG is enabled.”

Thanks in advance!

Thank you
Badrinathan 


Badrinathan_1-1763443692584.png



Badrinathan_0-1763442834455.png

Badrinathan
Associate III

Hello @Ghofrane GSOURI  @stforum  @stforum2  @stforum23 

Subject: SPI2 failing when GPIO/TRNG enabled in .ioc (STM32U535)

I am working with STM32U535CBTx and STM32CubeIDE and I am facing a blocking issue where SPI2 stops working after modifying the .ioc file enabling GPIO Pin and TRNG

This issue is reproducible in two cases:

1. SPI2 stops working when I add GPIO pins in CubeMX (.ioc)

SPI2 works correctly only when my LED GPIO pins (PB8 / PB9 / PB10) are configured manually in the USER CODE section in main.c file.

But if I configure the exact same pins in cubeide (.ioc):

SPI2 is failing

Removing the GPIO from the .ioc and configuring them manually → SPI2 works again

2. SPI2 also stops working when TRNG is enabled in Cube IDE , IOC 

Even without touching GPIO pins:

  • Enabling TRNG → SPI2 fails
  • Disabling TRNG → SPI2 works normally

SPI2 Pinout

I am using the default SPI2 pins on STM32U5:

  • PB13 → SPI2_SCK
  • PB14 → SPI2_MISO
  • PB15 → SPI2_MOSI
  • CS Pin: PC13

Attached Files

  • I have attached two .ioc files:
  • The configuration where SPI2 fails
  • The configuration where SPI2 works.

Could anyone please:

  • Review my .ioc files
  • Explain why this happens and how to fix this issue?
  • Suggest how to use TRNG, SPI2 and GPIO together.

I am currently blocked by this and need a solution as soon as possible. Please suggest me the correct approach to fix this issue.

Thank you
Badrinathan