Skip to content

Commit 8b8e0b7

Browse files
committed
fix wrong received message length for L5,G0,G4 serieses
enable MSIPLL auto calibration for L5,U5 serieses adjusted PLL1Q clock for H5, H7 series to enable CAN FD a data rate of 5 MBit/s
1 parent eebd68d commit 8b8e0b7

File tree

11 files changed

+124
-35
lines changed

11 files changed

+124
-35
lines changed

targets/TARGET_STM/TARGET_STM32H5/clock_cfg/system_clock.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ else // Divisible by 5MHz
125125
RCC_OscInitStruct.PLL.PLLP = 2;
126126
// Most of the SPI busses are clocked off of PLL1Q, and the max usable frequency for SPI is about
127127
// ~50MHz. Plus, SPI has only limited, power-of-2 prescaler options so a high input clock really hurts
128-
// its clock resolution. So, give it a much lower input clock.
129-
RCC_OscInitStruct.PLL.PLLQ = 10; // output freq = 50MHz
128+
// its clock resolution. So, give it a lower input clock.
129+
// Note PLL1Q is also used by the CAN FD, 100MHz is needed to support a data rate of 5Mbit/s.
130+
RCC_OscInitStruct.PLL.PLLQ = 5; // output freq = 100MHz
130131
RCC_OscInitStruct.PLL.PLLR = 2;
131132
RCC_OscInitStruct.PLL.PLLFRACN = 0;
132133
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;
@@ -194,8 +195,8 @@ uint8_t SetSysClock_PLL_HSI(void)
194195
RCC_OscInitStruct.PLL.PLLP = 2;
195196
// Most of the SPI busses are clocked off of PLL1Q, and the max usable frequency for SPI is about
196197
// ~50MHz. Plus, SPI has only limited, power-of-2 prescaler options so a high input clock really hurts
197-
// its clock resolution. So, give it a much lower input clock.
198-
RCC_OscInitStruct.PLL.PLLQ = 10; // output freq = 50MHz
198+
// its clock resolution. So, give it a lower input clock.
199+
RCC_OscInitStruct.PLL.PLLQ = 5; // output freq = 100MHz
199200
RCC_OscInitStruct.PLL.PLLR = 2;
200201
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1_VCIRANGE_3;
201202
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1_VCORANGE_WIDE;

targets/TARGET_STM/TARGET_STM32H7/clock_cfg/TARGET_STM32H7_280MHZ/system_clock.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
* It is used for all STM32H7 family microcontrollers with a top speed of 280MHz.
2828
* The input clock from the external oscillator may be any frequency evenly divisible by
2929
* 5MHz or 2MHz, and must be between 4MHz and 50MHz.
30-
*
30+
*
3131
* Note that 280MHz is the "overdrive" mode and is basically an overclock. It is only supported
3232
* under certain conditions (LDO in use) and cannot be used over the full temperature range.
3333
* For industrial applications it is recommended to disable overdrive. Overdrive can be enabled/
3434
* disabled via the "target.enable-overdrive-mode" option in mbed_app.json.
35-
*
35+
*
3636
**/
3737

3838
#include "stm32h7xx.h"
@@ -160,9 +160,9 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
160160
RCC_OscInitStruct.PLL.PLLP = 2; // PLLCLK = SYSCLK = 280/225 MHz
161161

162162
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
163-
RCC_OscInitStruct.PLL.PLLQ = 56; // PLL1Q used for FDCAN = 10 MHz
163+
RCC_OscInitStruct.PLL.PLLQ = 7; // PLL1Q used for FDCAN = 80 MHz
164164
#else
165-
RCC_OscInitStruct.PLL.PLLQ = 45; // PLL1Q used for FDCAN = 10 MHz
165+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 90 MHz
166166
#endif
167167

168168
RCC_OscInitStruct.PLL.PLLR = 2;
@@ -234,11 +234,11 @@ uint8_t SetSysClock_PLL_HSI(void)
234234
RCC_OscInitStruct.PLL.PLLP = 2; // PLLCLK = SYSCLK = 280/225 MHz
235235

236236
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
237-
RCC_OscInitStruct.PLL.PLLQ = 56; // PLL1Q used for FDCAN = 10 MHz
237+
RCC_OscInitStruct.PLL.PLLQ = 7; // PLL1Q used for FDCAN = 80 MHz
238238
#else
239-
RCC_OscInitStruct.PLL.PLLQ = 45; // PLL1Q used for FDCAN = 10 MHz
239+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 90 MHz
240240
#endif
241-
241+
242242
RCC_OscInitStruct.PLL.PLLR = 2;
243243
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; // PLL1 VCO clock is between 128 and 560 MHz
244244
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1; // PLL1 input clock is between 2 and 4 MHz

targets/TARGET_STM/TARGET_STM32H7/clock_cfg/TARGET_STM32H7_480MHZ/system_clock.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
* It is used for all STM32H7 family microcontrollers with a top speed of 480MHz.
3333
* The input clock from the external oscillator may be any frequency evenly divisible by
3434
* 5MHz or 2MHz, and must be between 4MHz and 50MHz.
35-
*
35+
*
3636
* Note that 480MHz is the "overdrive" mode and is basically an overclock. It is only supported
3737
* under certain conditions (LDO in use) and cannot be used over the full temperature range.
3838
* For industrial applications it is recommended to disable overdrive. Overdrive can be enabled/
3939
* disabled via the "target.enable-overdrive-mode" option in mbed_app.json.
40-
*
40+
*
4141
**/
4242

4343
#include "stm32h7xx.h"
@@ -171,9 +171,9 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
171171
RCC_OscInitStruct.PLL.PLLP = 2; // PLLCLK = SYSCLK = 480/400 MHz
172172

173173
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
174-
RCC_OscInitStruct.PLL.PLLQ = 96; // PLL1Q used for FDCAN = 10 MHz
174+
RCC_OscInitStruct.PLL.PLLQ = 12; // PLL1Q used for FDCAN = 80 MHz
175175
#else
176-
RCC_OscInitStruct.PLL.PLLQ = 80; // PLL1Q used for FDCAN = 10 MHz
176+
RCC_OscInitStruct.PLL.PLLQ = 10; // PLL1Q used for FDCAN = 80 MHz
177177
#endif
178178

179179
RCC_OscInitStruct.PLL.PLLR = 2;
@@ -251,11 +251,11 @@ uint8_t SetSysClock_PLL_HSI(void)
251251
#endif
252252

253253
RCC_OscInitStruct.PLL.PLLP = 2; // 480/400 MHz
254-
254+
255255
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
256-
RCC_OscInitStruct.PLL.PLLQ = 96; // PLL1Q used for FDCAN = 10 MHz
256+
RCC_OscInitStruct.PLL.PLLQ = 12; // PLL1Q used for FDCAN = 80 MHz
257257
#else
258-
RCC_OscInitStruct.PLL.PLLQ = 80; // PLL1Q used for FDCAN = 10 MHz
258+
RCC_OscInitStruct.PLL.PLLQ = 10; // PLL1Q used for FDCAN = 80 MHz
259259
#endif
260260

261261
RCC_OscInitStruct.PLL.PLLR = 2;
@@ -278,7 +278,7 @@ uint8_t SetSysClock_PLL_HSI(void)
278278
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY) != HAL_OK) {
279279
return 0; // FAIL
280280
}
281-
281+
282282
return 1; // OK
283283
}
284284
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */

targets/TARGET_STM/TARGET_STM32H7/clock_cfg/TARGET_STM32H7_550MHZ/system_clock.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
* It is used for all STM32H7 family microcontrollers with a top speed of 550MHz.
3333
* The input clock from the external oscillator may be any frequency evenly divisible by
3434
* 5MHz or 2MHz, and must be between 4MHz and 50MHz.
35-
*
35+
*
3636
* Note that 550MHz is the "overdrive" mode and is basically an overclock. It is only supported
3737
* under certain conditions (LDO in use) and cannot be used over the full temperature range.
3838
* For industrial applications it is recommended to disable overdrive. Overdrive can be enabled/
3939
* disabled via the "target.enable-overdrive-mode" option in mbed_app.json.
40-
*
40+
*
4141
**/
4242

4343
#include "stm32h7xx.h"
@@ -167,10 +167,10 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
167167

168168
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
169169
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; // PLL1 VCO clock is between 192 and 836 MHz
170-
RCC_OscInitStruct.PLL.PLLQ = 55; // PLL1Q used for FDCAN = 10 MHz
170+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 110 MHz
171171
#else
172172
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM; // PLL1 VCO clock is between 150 and 420 MHz
173-
RCC_OscInitStruct.PLL.PLLQ = 40; // PLL1Q used for FDCAN = 10 MHz
173+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 80 MHz
174174
#endif
175175

176176
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
@@ -244,15 +244,15 @@ uint8_t SetSysClock_PLL_HSI(void)
244244

245245
#if MBED_CONF_TARGET_ENABLE_OVERDRIVE_MODE
246246
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; // PLL1 VCO clock is between 192 and 836 MHz
247-
RCC_OscInitStruct.PLL.PLLQ = 55; // PLL1Q used for FDCAN = 10 MHz
247+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 110 MHz
248248
#else
249249
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOMEDIUM; // PLL1 VCO clock is between 150 and 420 MHz
250-
RCC_OscInitStruct.PLL.PLLQ = 40; // PLL1Q used for FDCAN = 10 MHz
250+
RCC_OscInitStruct.PLL.PLLQ = 5; // PLL1Q used for FDCAN = 80 MHz
251251
#endif
252252

253253
RCC_OscInitStruct.PLL.PLLR = 2; // 275 MHz
254254
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_1; // PLL1 input clock is between 2 and 4 MHz
255-
255+
256256
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
257257
return 0; // FAIL
258258
}

targets/TARGET_STM/TARGET_STM32L5/system_clock.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ uint8_t SetSysClock_PLL_MSI(void)
121121
{
122122
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
123123
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
124-
124+
125125
/* Configure LSE Drive Capability */
126126
__HAL_RCC_PWR_CLK_ENABLE();
127127
__HAL_RCC_SYSCFG_CLK_ENABLE();
@@ -192,6 +192,9 @@ uint8_t SetSysClock_PLL_MSI(void)
192192
}
193193
#endif
194194

195+
/* Enable MSI Auto calibration */
196+
HAL_RCCEx_EnableMSIPLLMode();
197+
195198
return 1; // OK
196199
}
197200
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U545xE/system_clock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
218218
*/
219219
HAL_RCCEx_EnableMSIPLLModeSelection(RCC_MSIKPLL_MODE_SEL);
220220
HAL_RCCEx_EnableMSIPLLMode();
221+
HAL_RCCEx_EnableMSIPLLFastStartup();
221222

222223
return 1; // OK
223224
}

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xG/system_clock.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ MBED_WEAK void SetSysClock(void)
9898

9999
// Output clock on MCO pin(PA8) for debugging purpose
100100
#if DEBUG_MCO == 1
101-
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_SYSCLK, RCC_MCO_NODIV); // 160 MHz
101+
HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_SYSCLK, RCC_MCO_NODIV); // 160 MHz
102102
#endif
103103

104104
// Output clock on LSCO pin(PA2) for debugging purpose
@@ -121,7 +121,7 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
121121
#if DEVICE_USBDEVICE
122122
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit = {0};
123123
#endif /* DEVICE_USBDEVICE */
124-
124+
125125
/* GPIO Ports Clock Enable */
126126
__HAL_RCC_GPIOH_CLK_ENABLE();
127127
__HAL_RCC_GPIOB_CLK_ENABLE();
@@ -176,7 +176,7 @@ MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
176176
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; // 160 MHz
177177
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 160 MHz
178178
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1; // 160 MHz
179-
179+
180180
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
181181
return 0; // FAIL
182182
}
@@ -274,6 +274,12 @@ MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
274274
return 0; // FAIL
275275
}
276276

277+
/** Enable MSI Auto calibration
278+
*/
279+
HAL_RCCEx_EnableMSIPLLModeSelection(RCC_MSIKPLL_MODE_SEL);
280+
HAL_RCCEx_EnableMSIPLLMode();
281+
HAL_RCCEx_EnableMSIPLLFastStartup();
282+
277283
return 1; // OK
278284
}
279285
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xI/system_clock.c

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,73 @@ MBED_WEAK void SetSysClock(void)
9898
/******************************************************************************/
9999
MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
100100
{
101-
return 0;
101+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
102+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
103+
104+
#if DEVICE_USBDEVICE
105+
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit = {0};
106+
#endif /* DEVICE_USBDEVICE */
107+
108+
/* GPIO Ports Clock Enable */
109+
__HAL_RCC_GPIOH_CLK_ENABLE();
110+
__HAL_RCC_GPIOB_CLK_ENABLE();
111+
__HAL_RCC_PWR_CLK_ENABLE();
112+
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) {
113+
return 0; // FAIL
114+
}
115+
116+
// Enable HSE oscillator and activate PLL with HSE as source
117+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI48;
118+
if (bypass == 0) {
119+
RCC_OscInitStruct.HSEState = RCC_HSE_ON; // External xtal on OSC_IN/OSC_OUT
120+
} else {
121+
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // External clock on OSC_IN
122+
}
123+
#if DEVICE_USBDEVICE
124+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
125+
#else
126+
RCC_OscInitStruct.HSI48State = RCC_HSI48_OFF;
127+
#endif /* DEVICE_USBDEVICE */
128+
#if HSE_VALUE==10000000UL
129+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
130+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
131+
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
132+
RCC_OscInitStruct.PLL.PLLM = 1; // VCO input clock = 10 MHz (10 MHz / 1)
133+
#else
134+
#error Unsupported external clock value, check HSE_VALUE define
135+
#endif
136+
RCC_OscInitStruct.PLL.PLLN = 16; // VCO output clock = 160 MHz (10 MHz * 16)
137+
RCC_OscInitStruct.PLL.PLLP = 2;
138+
RCC_OscInitStruct.PLL.PLLQ = 2;
139+
RCC_OscInitStruct.PLL.PLLR = 1; // PLL clock = 160 MHz
140+
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
141+
RCC_OscInitStruct.PLL.PLLFRACN = 0;
142+
143+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
144+
return 0; // FAIL
145+
}
146+
147+
#if DEVICE_USBDEVICE
148+
RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
149+
PeriphClkIniRCC_PeriphClkInittStruct.UsbClockSelection = RCC_USBCLKSOURCE_HSI48; /* 48 MHz */
150+
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) {
151+
return 0; // FAIL
152+
}
153+
#endif /* DEVICE_USBDEVICE */
154+
155+
// Select PLL clock as system clock source and configure the HCLK, PCLK1 and PCLK2 clock dividers
156+
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3);
157+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 160 MHz
158+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 160 MHz
159+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; // 160 MHz
160+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 160 MHz
161+
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1; // 160 MHz
162+
163+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
164+
return 0; // FAIL
165+
}
166+
return 1; // OK
167+
102168
}
103169
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */
104170

@@ -167,6 +233,11 @@ MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
167233
return 0; // FAIL
168234
}
169235

236+
/** Enable MSI Auto calibration
237+
*/
238+
HAL_RCCEx_EnableMSIPLLModeSelection(RCC_MSIKPLL_MODE_SEL);
239+
HAL_RCCEx_EnableMSIPLLMode();
240+
HAL_RCCEx_EnableMSIPLLFastStartup();
170241

171242
return 1; // OK
172243
}

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U585xI/system_clock.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
167167
return 0; // FAIL
168168
}
169169

170+
/** Enable MSI Auto calibration
171+
*/
172+
HAL_RCCEx_EnableMSIPLLModeSelection(RCC_MSIKPLL_MODE_SEL);
173+
HAL_RCCEx_EnableMSIPLLMode();
174+
HAL_RCCEx_EnableMSIPLLFastStartup();
175+
170176
return 1; // OK
171177
}
172178
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U5A5xJ/system_clock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
219219
*/
220220
HAL_RCCEx_EnableMSIPLLModeSelection(RCC_MSIKPLL_MODE_SEL);
221221
HAL_RCCEx_EnableMSIPLLMode();
222+
HAL_RCCEx_EnableMSIPLLFastStartup();
222223

223224
return 1; // OK
224225
}

0 commit comments

Comments
 (0)