Skip to content

Commit 007a8bd

Browse files
authored
Merge pull request hathach#2672 from tinic/master
Add support for STM32U535xx/STM32U545xx
2 parents edf1ef6 + a6d3e2a commit 007a8bd

File tree

12 files changed

+220
-17
lines changed

12 files changed

+220
-17
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(MCU_VARIANT stm32u545xx)
2+
set(JLINK_DEVICE stm32u545re)
3+
4+
function(update_board TARGET)
5+
target_compile_definitions(${TARGET} PUBLIC
6+
STM32U545xx
7+
)
8+
endfunction()
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2023, Ha Thach (tinyusb.org)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
* This file is part of the TinyUSB stack.
25+
*/
26+
27+
#ifndef BOARD_H_
28+
#define BOARD_H_
29+
30+
#ifdef __cplusplus
31+
extern "C"
32+
{
33+
#endif
34+
35+
// LED GREEN
36+
#define LED_PORT GPIOA
37+
#define LED_PIN GPIO_PIN_5
38+
#define LED_STATE_ON 1
39+
40+
// BUTTON
41+
#define BUTTON_PORT GPIOC
42+
#define BUTTON_PIN GPIO_PIN_13
43+
#define BUTTON_STATE_ACTIVE 1
44+
45+
// UART Enable for STLink VCOM
46+
#define UART_DEV LPUART1
47+
#define UART_CLK_EN __HAL_RCC_LPUART1_CLK_ENABLE
48+
#define UART_GPIO_PORT GPIOA
49+
#define UART_GPIO_AF GPIO_AF8_LPUART1
50+
#define UART_TX_PIN GPIO_PIN_2
51+
#define UART_RX_PIN GPIO_PIN_3
52+
53+
//--------------------------------------------------------------------+
54+
// RCC Clock
55+
//--------------------------------------------------------------------+
56+
57+
static void SystemClock_Config(void) {
58+
RCC_OscInitTypeDef RCC_OscInitStruct = { 0 };
59+
RCC_ClkInitTypeDef RCC_ClkInitStruct = { 0 };
60+
RCC_PeriphCLKInitTypeDef PeriphClkInit = { 0 };
61+
62+
/* Enable Power Clock */
63+
__HAL_RCC_PWR_CLK_ENABLE();
64+
65+
/** Configure the main internal regulator output voltage
66+
*/
67+
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
68+
69+
/** Initializes the CPU, AHB and APB buses clocks
70+
*/
71+
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_HSI;
72+
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
73+
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
74+
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
75+
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
76+
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
77+
RCC_OscInitStruct.PLL.PLLMBOOST = RCC_PLLMBOOST_DIV1;
78+
RCC_OscInitStruct.PLL.PLLM = 1;
79+
RCC_OscInitStruct.PLL.PLLN = 10;
80+
RCC_OscInitStruct.PLL.PLLP = 2;
81+
RCC_OscInitStruct.PLL.PLLQ = 2;
82+
RCC_OscInitStruct.PLL.PLLR = 1;
83+
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLLVCIRANGE_1;
84+
RCC_OscInitStruct.PLL.PLLFRACN = 0;
85+
HAL_RCC_OscConfig(&RCC_OscInitStruct);
86+
87+
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_CLK48;
88+
PeriphClkInit.IclkClockSelection = RCC_CLK48CLKSOURCE_HSI48;
89+
90+
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
91+
92+
/** Initializes the CPU, AHB and APB buses clocks
93+
*/
94+
RCC_ClkInitStruct.ClockType =
95+
RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 | RCC_CLOCKTYPE_PCLK3;
96+
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
97+
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
98+
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
99+
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
100+
RCC_ClkInitStruct.APB3CLKDivider = RCC_HCLK_DIV1;
101+
102+
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4);
103+
}
104+
105+
static void SystemPower_Config(void) {
106+
}
107+
108+
#ifdef __cplusplus
109+
}
110+
#endif
111+
112+
#endif /* BOARD_H_ */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CFLAGS += \
2+
-DSTM32U545xx \
3+
4+
# All source paths should be relative to the top level.
5+
LD_FILE = ${FAMILY_PATH}/linker/STM32U545xx_FLASH.ld
6+
7+
SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32u545xx.s
8+
9+
MCU_VARIANT = stm32u545xx
10+
# For flash-jlink target
11+
JLINK_DEVICE = stm32u545re

hw/bsp/stm32u5/boards/stm32u575eval/board.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ LD_FILE = ${FAMILY_PATH}/linker/STM32U575xx_FLASH.ld
66

77
SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32u575xx.s
88

9+
MCU_VARIANT = stm32u575xx
910
# For flash-jlink target
1011
JLINK_DEVICE = stm32u575ai

hw/bsp/stm32u5/boards/stm32u575nucleo/board.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ LD_FILE = ${FAMILY_PATH}/linker/STM32U575xx_FLASH.ld
66

77
SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32u575xx.s
88

9+
MCU_VARIANT = stm32u575xx
910
# For flash-jlink target
1011
JLINK_DEVICE = stm32u575zi

hw/bsp/stm32u5/boards/stm32u5a5nucleo/board.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ LD_FILE = ${BOARD_PATH}/STM32U5A5ZJTXQ_FLASH.ld
77

88
SRC_S += $(ST_CMSIS)/Source/Templates/gcc/startup_stm32u5a5xx.s
99

10+
MCU_VARIANT = stm32u5a5xx
1011
# For flash-jlink target
1112
JLINK_DEVICE = stm32u575zi

hw/bsp/stm32u5/family.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ void board_init(void) {
7272
__HAL_RCC_GPIOC_CLK_ENABLE();
7373
__HAL_RCC_GPIOD_CLK_ENABLE();
7474
__HAL_RCC_GPIOE_CLK_ENABLE();
75+
#ifdef GPIOF
7576
__HAL_RCC_GPIOF_CLK_ENABLE();
77+
#endif
7678
__HAL_RCC_GPIOG_CLK_ENABLE();
7779
__HAL_RCC_GPIOH_CLK_ENABLE();
7880

@@ -140,6 +142,17 @@ void board_init(void) {
140142
GPIO_InitStruct.Alternate = GPIO_AF10_USB;
141143
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
142144

145+
#ifdef USB_DRD_FS
146+
// STM32U535/STM32U545
147+
148+
/* Enable USB power on Pwrctrl CR2 register */
149+
HAL_PWREx_EnableVddUSB();
150+
151+
/* USB clock enable */
152+
__HAL_RCC_USB_FS_CLK_ENABLE();
153+
154+
#endif
155+
143156
#ifdef USB_OTG_FS
144157
#if CFG_TUSB_OS == OPT_OS_FREERTOS
145158
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
@@ -170,7 +183,9 @@ void board_init(void) {
170183
/* USB clock enable */
171184
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
172185

173-
#else
186+
#endif
187+
188+
#ifdef USB_OTG_HS
174189
// STM59x/Ax/Fx/Gx only have 1 USB HS port
175190

176191
#if CFG_TUSB_OS == OPT_OS_FREERTOS

hw/bsp/stm32u5/family.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,16 @@ function(family_configure_example TARGET RTOS)
102102

103103
# Add TinyUSB target and port source
104104
family_add_tinyusb(${TARGET} OPT_MCU_STM32U5 ${RTOS})
105-
target_sources(${TARGET}-tinyusb PUBLIC
106-
${TOP}/src/portable/synopsys/dwc2/dcd_dwc2.c
107-
#${TOP}/src/portable/st/typec/typec_stm32.c
108-
)
105+
if ((${MCU_VARIANT} STREQUAL "stm32u535xx") OR (${MCU_VARIANT} STREQUAL "stm32u545xx"))
106+
target_sources(${TARGET}-tinyusb PUBLIC
107+
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
108+
)
109+
else ()
110+
target_sources(${TARGET}-tinyusb PUBLIC
111+
${TOP}/src/portable/synopsys/dwc2/dcd_dwc2.c
112+
#${TOP}/src/portable/st/typec/typec_stm32.c
113+
)
114+
endif ()
109115
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
110116

111117
# Link dependencies

hw/bsp/stm32u5/family.mk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,28 @@ LDFLAGS_GCC += \
2727
--specs=nosys.specs --specs=nano.specs
2828

2929
SRC_C += \
30-
src/portable/synopsys/dwc2/dcd_dwc2.c \
3130
$(ST_CMSIS)/Source/Templates/system_stm32$(ST_FAMILY)xx.c \
3231
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal.c \
3332
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_cortex.c \
3433
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_gpio.c \
35-
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_icache.c \
34+
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_icache.c \
3635
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr.c \
3736
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_pwr_ex.c \
3837
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc.c \
3938
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_rcc_ex.c \
4039
$(ST_HAL_DRIVER)/Src/stm32$(ST_FAMILY)xx_hal_uart.c
4140

41+
ifeq ($(MCU_VARIANT),stm32u545xx)
42+
SRC_C += \
43+
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
44+
else ifeq ($(MCU_VARIANT),stm32u535xx)
45+
SRC_C += \
46+
src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
47+
else
48+
SRC_C += \
49+
src/portable/synopsys/dwc2/dcd_dwc2.c
50+
endif
51+
4252
INC += \
4353
$(TOP)/lib/CMSIS_5/CMSIS/Core/Include \
4454
$(TOP)/$(ST_CMSIS)/Include \

src/common/tusb_mcu.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,24 @@
271271
#define TUP_DCD_ENDPOINT_MAX 8
272272

273273
#elif TU_CHECK_MCU(OPT_MCU_STM32U5)
274-
#define TUP_USBIP_DWC2
275-
#define TUP_USBIP_DWC2_STM32
274+
#if defined (STM32U535xx) || defined (STM32U545xx)
275+
#define TUP_USBIP_FSDEV
276+
#define TUP_USBIP_FSDEV_STM32
277+
#define TUP_DCD_ENDPOINT_MAX 8
276278

277-
// U59x/5Ax/5Fx/5Gx are highspeed with built-in HS PHY
278-
#if defined(STM32U595xx) || defined(STM32U599xx) || defined(STM32U5A5xx) || defined(STM32U5A9xx) || \
279-
defined(STM32U5F7xx) || defined(STM32U5F9xx) || defined(STM32U5G7xx) || defined(STM32U5G9xx)
280-
#define TUP_DCD_ENDPOINT_MAX 9
281-
#define TUP_RHPORT_HIGHSPEED 1
282-
#define TUP_USBIP_DWC2_TEST_MODE
283279
#else
284-
#define TUP_DCD_ENDPOINT_MAX 6
280+
#define TUP_USBIP_DWC2
281+
#define TUP_USBIP_DWC2_STM32
282+
283+
// U59x/5Ax/5Fx/5Gx are highspeed with built-in HS PHY
284+
#if defined(STM32U595xx) || defined(STM32U599xx) || defined(STM32U5A5xx) || defined(STM32U5A9xx) || \
285+
defined(STM32U5F7xx) || defined(STM32U5F9xx) || defined(STM32U5G7xx) || defined(STM32U5G9xx)
286+
#define TUP_DCD_ENDPOINT_MAX 9
287+
#define TUP_RHPORT_HIGHSPEED 1
288+
#define TUP_USBIP_DWC2_TEST_MODE
289+
#else
290+
#define TUP_DCD_ENDPOINT_MAX 6
291+
#endif
285292
#endif
286293

287294
#elif TU_CHECK_MCU(OPT_MCU_STM32L5)

0 commit comments

Comments
 (0)