cancel
Showing results for 
Search instead for 
Did you mean: 

OCTOSPI prescaler value use in HAL seems odd

DanPy
Associate

Hello everyone,

I have a question regarding the configuration of the OCTOSPI, especially the prescaler value.

I am using the UI to configure the XSPI's prescaler and setting it to 3.

DanPy_0-1747747617849.png

The generated code is as follows. You can see that the prescaler value is set to 3.

XSPI_HandleTypeDef hospi1;
/* OCTOSPI1 init function */
void MX_OCTOSPI1_Init(void)
{
  /* USER CODE BEGIN OCTOSPI1_Init 0 */
  /* USER CODE END OCTOSPI1_Init 0 */
  /* USER CODE BEGIN OCTOSPI1_Init 1 */
  /* USER CODE END OCTOSPI1_Init 1 */
  hospi1.Instance = OCTOSPI1;
  hospi1.Init.FifoThresholdByte = 1;
  hospi1.Init.MemoryMode = HAL_XSPI_SINGLE_MEM;
  hospi1.Init.MemoryType = HAL_XSPI_MEMTYPE_MACRONIX;
  hospi1.Init.MemorySize = HAL_XSPI_SIZE_128MB;
  hospi1.Init.ChipSelectHighTimeCycle = 1;
  hospi1.Init.FreeRunningClock = HAL_XSPI_FREERUNCLK_DISABLE;
  hospi1.Init.ClockMode = HAL_XSPI_CLOCK_MODE_0;
  hospi1.Init.WrapSize = HAL_XSPI_WRAP_NOT_SUPPORTED;
  hospi1.Init.ClockPrescaler = 3; /*HERE value set at 3*/
  hospi1.Init.SampleShifting = HAL_XSPI_SAMPLE_SHIFT_NONE;
  hospi1.Init.DelayHoldQuarterCycle = HAL_XSPI_DHQC_DISABLE;
  hospi1.Init.ChipSelectBoundary = HAL_XSPI_BONDARYOF_NONE;
  hospi1.Init.DelayBlockBypass = HAL_XSPI_DELAY_BLOCK_BYPASS;
  hospi1.Init.Refresh = 0;
  if (HAL_XSPI_Init(&hospi1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN OCTOSPI1_Init 2 */
  /* USER CODE END OCTOSPI1_Init 2 */
}

In the function "HAL_XSPI_Init" you have this part:

/* Configure clock prescaler */
        MODIFY_REG(hxspi->Instance->DCR2, XSPI_DCR2_PRESCALER,
                   ((hxspi->Init.ClockPrescaler) << XSPI_DCR2_PRESCALER_Pos));

The register is directly set with the value of "ClockPrescaler".

However, in the user manual it's written:

DanPy_1-1747747956713.png

Meaning, that if the value "ClockPrescaler" is "3" the prescaler is actually 4.

Shouldn't the register be set with the value "ClockPrescaler - 1" instead of "ClockPrescaler" ?

____

  • STM32H533RE
  • STM32CubeIDE1.18.0
  • STM32Cube_FW_H5_V1.5.0
  • User Manual RM0481 Rev 3
1 REPLY 1
TDK
Super User

It says the valid range is 0 to 255. Subtracting one from it doesn't make sense here.

The Pulse value and Reload values for timers have the same drawback. The description could be updated to be more clear.

It's going to be confusing one way or another since the field itself is named PRESCALER with the description "Clock Prescaler" in the Reference Manual yet the clock scaling factor is (PRESCALER + 1). Just something you need to learn and adapt.

If you feel a post has answered your question, please click "Accept as Solution".