Skip to content

Commit 08f9ed6

Browse files
authored
Merge pull request #2336 from hathach/fix-h7-otg_fs-wfi
Fix h7 running on fullspeed phy has issue with WFI
2 parents 460a8b5 + 01f22a9 commit 08f9ed6

File tree

12 files changed

+368
-828
lines changed

12 files changed

+368
-828
lines changed

hw/bsp/stm32h7/boards/daisyseed/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
//--------------------------------------------------------------------+
5656
// RCC Clock
5757
//--------------------------------------------------------------------+
58-
static inline void board_stm32h7_clock_init(void)
58+
static inline void SystemClock_Config(void)
5959
{
6060
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
6161
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };

hw/bsp/stm32h7/boards/stm32h723nucleo/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
//--------------------------------------------------------------------+
6363
// RCC Clock
6464
//--------------------------------------------------------------------+
65-
static inline void board_stm32h7_clock_init(void)
65+
static inline void SystemClock_Config(void)
6666
{
6767
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
6868
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };

hw/bsp/stm32h7/boards/stm32h743eval/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
//--------------------------------------------------------------------+
6262
// RCC Clock
6363
//--------------------------------------------------------------------+
64-
static inline void board_stm32h7_clock_init(void) {
64+
static inline void SystemClock_Config(void) {
6565
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
6666
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
6767
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };

hw/bsp/stm32h7/boards/stm32h743nucleo/board.h

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,60 +53,73 @@
5353
//--------------------------------------------------------------------+
5454
// RCC Clock
5555
//--------------------------------------------------------------------+
56-
static inline void board_stm32h7_clock_init(void)
57-
{
58-
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
59-
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
56+
static inline void SystemClock_Config(void) {
57+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
58+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
59+
60+
/** Supply configuration update enable
61+
*/
62+
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
6063

61-
/* The PWR block is always enabled on the H7 series- there is no clock
62-
enable. For now, use the default VOS3 scale mode (lowest) and limit clock
63-
frequencies to avoid potential current draw problems from bus
64-
power when using the max clock speeds throughout the chip. */
64+
/** Configure the main internal regulator output voltage
65+
*/
66+
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
6567

66-
/* Enable HSE Oscillator and activate PLL1 with HSE as source */
68+
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
69+
70+
/** Initializes the RCC Oscillators according to the specified parameters
71+
* in the RCC_OscInitTypeDef structure.
72+
*/
6773
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
68-
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
69-
RCC_OscInitStruct.HSIState = RCC_HSI_OFF;
70-
RCC_OscInitStruct.CSIState = RCC_CSI_OFF;
74+
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
7175
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
7276
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
73-
RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000;
74-
RCC_OscInitStruct.PLL.PLLN = 336;
77+
RCC_OscInitStruct.PLL.PLLM = 1;
78+
RCC_OscInitStruct.PLL.PLLN = 100;
7579
RCC_OscInitStruct.PLL.PLLP = 2;
76-
RCC_OscInitStruct.PLL.PLLQ = 7;
77-
RCC_OscInitStruct.PLL.PLLR = 2; /* Unused */
78-
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_0;
79-
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM;
80+
RCC_OscInitStruct.PLL.PLLQ = 4;
81+
RCC_OscInitStruct.PLL.PLLR = 2;
82+
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
83+
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
8084
RCC_OscInitStruct.PLL.PLLFRACN = 0;
81-
HAL_RCC_OscConfig(&RCC_OscInitStruct);
82-
83-
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | \
84-
RCC_CLOCKTYPE_D1PCLK1 | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | \
85-
RCC_CLOCKTYPE_D3PCLK1);
85+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
86+
{
87+
Error_Handler();
88+
}
89+
90+
/** Initializes the CPU, AHB and APB buses clocks
91+
*/
92+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
93+
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
94+
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
8695
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
8796
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
88-
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
89-
90-
/* Unlike on the STM32F4 family, it appears the maximum APB frequencies are
91-
device-dependent- 120 MHz for this board according to Figure 2 of
92-
the datasheet. Dividing by half will be safe for now. */
97+
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
9398
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
9499
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
95100
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
96101
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
97102

98-
/* 4 wait states required for 168MHz and VOS3. */
99-
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
100-
101-
/* Like on F4, on H7, USB's actual peripheral clock and bus clock are
102-
separate. However, the main system PLL (PLL1) doesn't have a direct
103-
connection to the USB peripheral clock to generate 48 MHz, so we do this
104-
dance. This will connect PLL1's Q output to the USB peripheral clock. */
105-
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = { 0 };
106-
107-
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
108-
RCC_PeriphCLKInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL;
109-
HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct);
103+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
104+
{
105+
Error_Handler();
106+
}
107+
108+
// Initialize USB clock
109+
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = { 0 };
110+
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USB;
111+
PeriphClkInitStruct.PLL3.PLL3M = 1;
112+
PeriphClkInitStruct.PLL3.PLL3N = 24;
113+
PeriphClkInitStruct.PLL3.PLL3P = 2;
114+
PeriphClkInitStruct.PLL3.PLL3Q = 4;
115+
PeriphClkInitStruct.PLL3.PLL3R = 2;
116+
PeriphClkInitStruct.PLL3.PLL3RGE = RCC_PLL3VCIRANGE_3;
117+
PeriphClkInitStruct.PLL3.PLL3FRACN = 0;
118+
PeriphClkInitStruct.UsbClockSelection = RCC_USBCLKSOURCE_PLL3;
119+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
120+
{
121+
Error_Handler();
122+
}
110123
}
111124

112125
static inline void board_stm32h7_post_init(void)

0 commit comments

Comments
 (0)