2025-05-20 6:47 AM
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.
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:
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" ?
____
Solved! Go to Solution.
2025-05-20 8:58 AM
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.
2025-05-20 8:58 AM
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.
2025-05-20 11:32 AM
I don't think ST's been entirely consistent with these types of things.
Some times using enumerations, some time literal constants.
See also PLL settings, FLASH wait states, SDIO/SDMMC, etc.
Personally I'd prefer the value in the field is the value into the register, with as little manipulation as possible. But I don't want to have to refactor a bunch of code, with all the regression that might cause.
If the number space changes entirely, #defines
2025-05-21 1:23 AM
Updating the description would make this clearer.
I guess it's something to keep in mind when using the OCTOSPI.