Skip to content

Commit 724c378

Browse files
committed
STM32U5 : STM32U5xxxxx sub-families
1 parent f45b189 commit 724c378

File tree

9 files changed

+538
-6
lines changed

9 files changed

+538
-6
lines changed

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xG/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ target_include_directories(mbed-stm32u575xg
1919
target_sources(mbed-stm32u575xg
2020
INTERFACE
2121
${STARTUP_FILE}
22+
system_clock.c
2223
)
2324

2425
mbed_set_linker_script(mbed-stm32u575xg ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xG/cmsis_nvic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
#endif
2323

2424
#if !defined(MBED_ROM_SIZE)
25-
#define MBED_ROM_SIZE 0x0 // 0 B
25+
#define MBED_ROM_SIZE 0x100000 // 1 MB
2626
#endif
2727

2828
#if !defined(MBED_RAM_START)
2929
#define MBED_RAM_START 0x20000000
3030
#endif
3131

3232
#if !defined(MBED_RAM_SIZE)
33-
#define MBED_RAM_SIZE 0x0 // 0 B
33+
#define MBED_RAM_SIZE 0xC0000 // 768 KB
3434
#endif
3535

3636
#define NVIC_NUM_VECTORS 141
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/* mbed Microcontroller Library
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
******************************************************************************
4+
*
5+
* Copyright (c) 2015-2021 STMicroelectronics.
6+
* All rights reserved.
7+
*
8+
* This software component is licensed by ST under BSD 3-Clause license,
9+
* the "License"; You may not use this file except in compliance with the
10+
* License. You may obtain a copy of the License at:
11+
* opensource.org/licenses/BSD-3-Clause
12+
*
13+
******************************************************************************
14+
*/
15+
16+
/**
17+
* This file configures the system clock depending on config from targets.json:
18+
*-----------------------------------------------------------------------------
19+
* System clock source | 1- USE_PLL_HSE_EXTC (external clock)
20+
* | 2- USE_PLL_HSE_XTAL (external xtal)
21+
* | 3- USE_PLL_HSI (internal 16 MHz)
22+
* | 4- USE_PLL_MSI (internal 100kHz to 48 MHz)
23+
*-----------------------------------------------------------------------------
24+
* SYSCLK(MHz) | 160
25+
* AHBCLK (MHz) | 160
26+
* APB1CLK (MHz) | 160
27+
* APB2CLK (MHz) | 160
28+
* APB3CLK (MHz) | 160
29+
* USB capable | TODO
30+
*-----------------------------------------------------------------------------
31+
**/
32+
33+
#include "stm32u5xx.h"
34+
#include "mbed_error.h"
35+
36+
// clock source is selected with CLOCK_SOURCE in json config
37+
#define USE_PLL_HSE_EXTC 0x8 // Use external clock (OSC_IN)
38+
#define USE_PLL_HSE_XTAL 0x4 // Use external xtal (OSC_IN/OSC_OUT)
39+
#define USE_PLL_HSI 0x2 // Use HSI internal clock
40+
#define USE_PLL_MSI 0x1 // Use MSI internal clock
41+
42+
#if ( ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) )
43+
uint8_t SetSysClock_PLL_HSE(uint8_t bypass);
44+
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */
45+
46+
#if ((CLOCK_SOURCE) & USE_PLL_HSI)
47+
uint8_t SetSysClock_PLL_HSI(void);
48+
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */
49+
50+
#if ((CLOCK_SOURCE) & USE_PLL_MSI)
51+
uint8_t SetSysClock_PLL_MSI(void);
52+
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */
53+
54+
55+
/**
56+
* @brief Configures the System clock source, PLL Multiplier and Divider factors,
57+
* AHB/APBx prescalers and Flash settings
58+
* @note This function is called in mbed_sdk_init() function (targets/TARGET_STM/mbed_overrides.c)
59+
* and after each deepsleep period in hal_deepsleep() (targets/TARGET_STM/sleep.c)
60+
* @param None
61+
* @retval None
62+
*/
63+
64+
MBED_WEAK void SetSysClock(void)
65+
{
66+
#if ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC)
67+
/* 1- Try to start with HSE and external clock */
68+
if (SetSysClock_PLL_HSE(1) == 0)
69+
#endif
70+
{
71+
#if ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL)
72+
/* 2- If fail try to start with HSE and external xtal */
73+
if (SetSysClock_PLL_HSE(0) == 0)
74+
#endif
75+
{
76+
#if ((CLOCK_SOURCE) & USE_PLL_HSI)
77+
/* 3- If fail start with HSI clock */
78+
if (SetSysClock_PLL_HSI() == 0)
79+
#endif
80+
{
81+
#if ((CLOCK_SOURCE) & USE_PLL_MSI)
82+
/* 4- If fail start with MSI clock */
83+
if (SetSysClock_PLL_MSI() == 0)
84+
#endif
85+
{
86+
{
87+
error("SetSysClock failed\n");
88+
}
89+
}
90+
}
91+
}
92+
}
93+
}
94+
95+
#if ( ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) )
96+
/******************************************************************************/
97+
/* PLL (clocked by HSE) used as System clock source */
98+
/******************************************************************************/
99+
MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
100+
{
101+
return 0;
102+
}
103+
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */
104+
105+
#if ((CLOCK_SOURCE) & USE_PLL_HSI)
106+
/******************************************************************************/
107+
/* PLL (clocked by HSI) used as System clock source */
108+
/******************************************************************************/
109+
uint8_t SetSysClock_PLL_HSI(void)
110+
{
111+
return 0; // TODO
112+
}
113+
#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */
114+
115+
#if ((CLOCK_SOURCE) & USE_PLL_MSI)
116+
/******************************************************************************/
117+
/* PLL (clocked by MSI) used as System clock source */
118+
/******************************************************************************/
119+
MBED_WEAK uint8_t SetSysClock_PLL_MSI(void)
120+
{
121+
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
122+
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
123+
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
124+
125+
__HAL_RCC_PWR_CLK_ENABLE();
126+
HAL_PWREx_DisableUCPDDeadBattery(); /* Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */
127+
HAL_PWREx_EnableVddA();
128+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
129+
130+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSI
131+
| RCC_OSCILLATORTYPE_MSI;
132+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
133+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
134+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
135+
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
136+
RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
137+
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
138+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
139+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
140+
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV4;
141+
RCC_OscInitStruct.PLL.PLLM = 3;
142+
RCC_OscInitStruct.PLL.PLLN = 10;
143+
RCC_OscInitStruct.PLL.PLLP = 2;
144+
RCC_OscInitStruct.PLL.PLLQ = 2;
145+
RCC_OscInitStruct.PLL.PLLR = 1;
146+
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
147+
RCC_OscInitStruct.PLL.PLLFRACN = 0;
148+
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
149+
return 0; // FAIL
150+
}
151+
152+
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
153+
| RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2
154+
| RCC_CLOCKTYPE_PCLK3;
155+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
156+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
157+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
158+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
159+
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
160+
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
161+
return 0; // FAIL
162+
}
163+
164+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RNG;
165+
PeriphClkInit.RngClockSelection = RCC_RNGCLKSOURCE_HSI48;
166+
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) {
167+
return 0; // FAIL
168+
}
169+
170+
HAL_ICACHE_ConfigAssociativityMode(ICACHE_1WAY);
171+
HAL_ICACHE_Enable();
172+
173+
return 1; // OK
174+
}
175+
#endif /* ((CLOCK_SOURCE) & USE_PLL_MSI) */

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xI/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4+
add_subdirectory(TARGET_NUCLEO_U575ZI_Q EXCLUDE_FROM_ALL)
5+
46
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
57
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32u575xx.S)
68
set(LINKER_FILE TOOLCHAIN_GCC_ARM/stm32u575xi.ld)
@@ -19,6 +21,7 @@ target_include_directories(mbed-stm32u575xi
1921
target_sources(mbed-stm32u575xi
2022
INTERFACE
2123
${STARTUP_FILE}
24+
system_clock.c
2225
)
2326

2427
mbed_set_linker_script(mbed-stm32u575xi ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

targets/TARGET_STM/TARGET_STM32U5/TARGET_STM32U575xI/cmsis_nvic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
#endif
2323

2424
#if !defined(MBED_ROM_SIZE)
25-
#define MBED_ROM_SIZE 0x0 // 0 B
25+
#define MBED_ROM_SIZE 0x200000 // 2 MB
2626
#endif
2727

2828
#if !defined(MBED_RAM_START)
2929
#define MBED_RAM_START 0x20000000
3030
#endif
3131

3232
#if !defined(MBED_RAM_SIZE)
33-
#define MBED_RAM_SIZE 0x0 // 0 B
33+
#define MBED_RAM_SIZE 0xC0000 // 768 KB
3434
#endif
3535

3636
#define NVIC_NUM_VECTORS 141

0 commit comments

Comments
 (0)