cancel
Showing results for 
Search instead for 
Did you mean: 

HSLV example code?

BDoon.1
Associate III

I am using a U585QI and have some external flash memory connected to an OCTOSPI. We are having some intermittent failures with it, and since we're powering the processor with 1.8v I want to try enabling HSLV for the Data/Clock lines. I found HAL_GPIO_EnableHighSPeedLowVoltage, but I'm not sure when to call it...

1) Is this a common use case for the high-speed-low-voltage functionality?

2) Is there any example code for this? Particularly the option bits aspect?

1 ACCEPTED SOLUTION

Accepted Solutions
Mohamed Aymen HZAMI
ST Employee

Hello,

This is an example of OCTOSPI with HSLV configuration

/**
* @brief OSPI MSP Initialization
* This function configures the hardware resources used in this example
* @param hospi: OSPI handle pointer
* @retval None
*/
void HAL_OSPI_MspInit(OSPI_HandleTypeDef* hospi)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(hospi->Instance==OCTOSPI1)
  {
  /* USER CODE BEGIN OCTOSPI1_MspInit 0 */
    HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_CS_GPIO_PORT, OCTOSPI_CS_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_DQS0_GPIO_PORT, OCTOSPI_DQS0_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_DQS1_GPIO_PORT, OCTOSPI_DQS1_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_CLK_GPIO_PORT,  OCTOSPI_CLK_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_NCLK_GPIO_PORT, OCTOSPI_NCLK_PIN);
                                     
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D0_GPIO_PORT, OCTOSPI_D0_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D1_GPIO_PORT, OCTOSPI_D1_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D2_GPIO_PORT, OCTOSPI_D2_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D3_GPIO_PORT, OCTOSPI_D3_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D4_GPIO_PORT, OCTOSPI_D4_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D5_GPIO_PORT, OCTOSPI_D5_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D6_GPIO_PORT, OCTOSPI_D6_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D7_GPIO_PORT, OCTOSPI_D7_PIN);
                                     
  /* USER CODE END OCTOSPI1_MspInit 0 */
 
  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_OSPI;
    PeriphClkInit.OspiClockSelection = RCC_OSPICLKSOURCE_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Peripheral clock enable */
    __HAL_RCC_OSPIM_CLK_ENABLE();
    __HAL_RCC_OSPI1_CLK_ENABLE();
 
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**OCTOSPI1 GPIO Configuration
    PC0     ------> OCTOSPIM_P1_IO7
    PC1     ------> OCTOSPIM_P1_IO4
    PC2     ------> OCTOSPIM_P1_IO5
    PA7     ------> OCTOSPIM_P1_IO2
    PC3     ------> OCTOSPIM_P1_IO6
    PB0     ------> OCTOSPIM_P1_IO1
    PB2     ------> OCTOSPIM_P1_DQS
    PA2     ------> OCTOSPIM_P1_NCS
    PA3     ------> OCTOSPIM_P1_CLK
    PA6     ------> OCTOSPIM_P1_IO3
    PB1     ------> OCTOSPIM_P1_IO0
    */
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF3_OCTOSPI1;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /* USER CODE BEGIN OCTOSPI1_MspInit 1 */
 
  /* USER CODE END OCTOSPI1_MspInit 1 */
  }
 
}

The High speed low voltage (HSLV) is a feature, when enabled it allow the GPIOs to reach higher frequencies. The only constraint is that Vdd must not exceed 2.5v (Vdd < 2.5v)

Mohamed Aymen

View solution in original post

5 REPLIES 5
Mohamed Aymen HZAMI
ST Employee

Hello @Community member​ and welcome to the community,

You need to enable HSLV of OCTOSPI pins before initializing its pins.

Mohamed Aymen

BDoon.1
Associate III

@Mohamed Aymen HZAMI​ Does that mean calling HAL_GPIO_EnableHighSPeedLowVoltage before HAL_OSPI_Init? And does it mean I need to do it to run OSPI from a 1.8v VDD reliably?

Mohamed Aymen HZAMI
ST Employee

Hello,

This is an example of OCTOSPI with HSLV configuration

/**
* @brief OSPI MSP Initialization
* This function configures the hardware resources used in this example
* @param hospi: OSPI handle pointer
* @retval None
*/
void HAL_OSPI_MspInit(OSPI_HandleTypeDef* hospi)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  if(hospi->Instance==OCTOSPI1)
  {
  /* USER CODE BEGIN OCTOSPI1_MspInit 0 */
    HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_CS_GPIO_PORT, OCTOSPI_CS_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_DQS0_GPIO_PORT, OCTOSPI_DQS0_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_DQS1_GPIO_PORT, OCTOSPI_DQS1_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_CLK_GPIO_PORT,  OCTOSPI_CLK_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_NCLK_GPIO_PORT, OCTOSPI_NCLK_PIN);
                                     
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D0_GPIO_PORT, OCTOSPI_D0_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D1_GPIO_PORT, OCTOSPI_D1_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D2_GPIO_PORT, OCTOSPI_D2_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D3_GPIO_PORT, OCTOSPI_D3_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D4_GPIO_PORT, OCTOSPI_D4_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D5_GPIO_PORT, OCTOSPI_D5_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D6_GPIO_PORT, OCTOSPI_D6_PIN);
  HAL_GPIO_EnableHighSPeedLowVoltage(OCTOSPI_D7_GPIO_PORT, OCTOSPI_D7_PIN);
                                     
  /* USER CODE END OCTOSPI1_MspInit 0 */
 
  /** Initializes the peripherals clock
  */
    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_OSPI;
    PeriphClkInit.OspiClockSelection = RCC_OSPICLKSOURCE_SYSCLK;
    if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
    {
      Error_Handler();
    }
 
    /* Peripheral clock enable */
    __HAL_RCC_OSPIM_CLK_ENABLE();
    __HAL_RCC_OSPI1_CLK_ENABLE();
 
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**OCTOSPI1 GPIO Configuration
    PC0     ------> OCTOSPIM_P1_IO7
    PC1     ------> OCTOSPIM_P1_IO4
    PC2     ------> OCTOSPIM_P1_IO5
    PA7     ------> OCTOSPIM_P1_IO2
    PC3     ------> OCTOSPIM_P1_IO6
    PB0     ------> OCTOSPIM_P1_IO1
    PB2     ------> OCTOSPIM_P1_DQS
    PA2     ------> OCTOSPIM_P1_NCS
    PA3     ------> OCTOSPIM_P1_CLK
    PA6     ------> OCTOSPIM_P1_IO3
    PB1     ------> OCTOSPIM_P1_IO0
    */
    GPIO_InitStruct.Pin = GPIO_PIN_0;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF3_OCTOSPI1;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
    GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_2|GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF10_OCTOSPI1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /* USER CODE BEGIN OCTOSPI1_MspInit 1 */
 
  /* USER CODE END OCTOSPI1_MspInit 1 */
  }
 
}

The High speed low voltage (HSLV) is a feature, when enabled it allow the GPIOs to reach higher frequencies. The only constraint is that Vdd must not exceed 2.5v (Vdd < 2.5v)

Mohamed Aymen

BDoon.1
Associate III

Awesome, thank you! Can you confirm that this is something I should be doing to get reliable OSPI communication when powered at 1.8v?

Mohamed Aymen HZAMI
ST Employee

Hello @Community member​,

If you are targeting higher frequencies at Vdd < 2.5V, yes it is recommended to Enable the HSLV.

Mohamed Aymen