2025-02-11 02:11 AM
Disclaimer: I don't normally use HAL, but I was trying to learn more about USB hosting so I decided to try out the demonstration application STM32Cube_FW_H7_V1.12.0 STM32H743I-EVAL USB_Host/CDC_Standalone
As I don't have that board, I tried to hook up the LCD output to UART7, but I was surprised to find the baud rate as half what I intended.
The baud rate was set with
huart7.Instance = UART7;
huart7.Init.BaudRate = 115200;
huart7.Init.WordLength = UART_WORDLENGTH_8B;
huart7.Init.StopBits = UART_STOPBITS_1;
huart7.Init.Parity = UART_PARITY_NONE;
huart7.Init.Mode = UART_MODE_TX_RX;
huart7.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart7.Init.OverSampling = UART_OVERSAMPLING_16;
huart7.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart7.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart7.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart7) != HAL_OK)
and my code for
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
includes the lines
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_UART7; PeriphClkInitStruct.Usart234578ClockSelection = RCC_USART234578CLKSOURCE_D2PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
So I'm expecting to use PCLK1, which I intended to be 100 MHz.
In stm32h7xx_hal_uart.c, HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart) duly calls
/** * @brief Returns the PCLK1 frequency * @note Each time PCLK1 changes, this function must be called to update the * right PCLK1 value. Otherwise, any configuration based on this function will be incorrect. * @retval PCLK1 frequency */ uint32_t HAL_RCC_GetPCLK1Freq(void) { #if defined (RCC_D2CFGR_D2PPRE1) /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/ return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->D2CFGR & RCC_D2CFGR_D2PPRE1) >> RCC_D2CFGR_D2PPRE1_Pos]) & 0x1FU)); #else /* Get HCLK source and Compute PCLK1 frequency ---------------------------*/ return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->CDCFGR2 & RCC_CDCFGR2_CDPPRE1) >> RCC_CDCFGR2_CDPPRE1_Pos]) & 0x1FU)); #endif }
But strangely that seems to return 200 MHz. HAL_RCC_GetHCLKFreq also returns 200MHz.
Looking at the Reference Manual, I see RCC->D2CFGR has a three bit field D2PPRE1 which (in my case) has the binary value 100. Which should correspond to division by 2. And why is the mask 0x1FU for 5 bits?
But the lookup table D1CorePrescTable in system_stm32h7xx.c contains 16 elements, suggesting it is intended for four-bit fields like HPRE in RCC->D1CFGR.
Should be a corresponding D2CorePrescTable, with the values [0, 0, 0, 0, 1, 2, 3, 4]?
Am I doing something wrong, or is this likely to be an error in STM32Cube_FW_H7_V1.12.0?
2025-02-11 06:30 AM
Hello @Danish1
I have reported your question internally and will get back to you as soon as possible.
Internal ticket number: 202793 (This is an internal tracking number and is not accessible or usable by customers).