Skip to content

Commit c575e05

Browse files
raiden00plxiaoxiang781216
authored andcommitted
boards/arm/stm32u3: Add NUCLEO-U3C5ZI-Q support
initial support for NUCLEO-U3C5ZI-Q Assisted-by: OpenAI Codex:gpt-5 Signed-off-by: raiden00pl <raiden00@railab.me>
1 parent d548cff commit c575e05

17 files changed

Lines changed: 814 additions & 21 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
======================
2+
ST NUCLEO-U3C5ZI-Q
3+
======================
4+
5+
.. tags:: chip:stm32, chip:stm32u3, chip:stm32u3c5
6+
7+
The `NUCLEO-U3C5ZI-Q <https://www.st.com/en/evaluation-tools/nucleo-u3c5zi-q.html>`_
8+
is an STM32 Nucleo-144 board featuring an STM32U3C5ZI microcontroller with
9+
2 MiB of Flash and 640 KiB of SRAM. The board includes an ST-LINK debugger
10+
and programmer with a virtual COM port.
11+
12+
Clocking
13+
========
14+
15+
NuttX runs at 96 MHz from the internal MSIRC0 oscillator. The initial port
16+
runs as a flat, nonsecure image with TrustZone disabled.
17+
18+
Configurations
19+
==============
20+
21+
nsh
22+
---
23+
24+
Configures the NuttShell with USART1 as the serial console.
25+
26+
jumbo
27+
-----
28+
29+
Enables a broad set of NuttX features to provide additional build and runtime
30+
coverage.

‎arch/arm/src/stm32u3/stm32u3xx_rcc.c‎

Lines changed: 100 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <nuttx/config.h>
2828

29+
#include <assert.h>
30+
2931
#include <arch/board/board.h>
3032

3133
#include "arm_internal.h"
@@ -34,6 +36,25 @@
3436
#include "hardware/stm32_flash.h"
3537
#include "hardware/stm32u3xx_pwr.h"
3638

39+
/****************************************************************************
40+
* Pre-processor Definitions
41+
****************************************************************************/
42+
43+
#ifndef CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
44+
45+
static_assert(CONFIG_BOARD_LOOPSPERMSEC != -1,
46+
"Configure BOARD_LOOPSPERMSEC to a non-default value");
47+
48+
/* Allow up to 100 milliseconds for each clock or regulator transition. */
49+
50+
#define CLOCK_READY_TIMEOUT (100 * CONFIG_BOARD_LOOPSPERMSEC)
51+
52+
#ifndef STM32_BOARD_USEMSIS
53+
# error stm32_stdclockconfig() requires MSIS board configuration
54+
#endif
55+
56+
#endif
57+
3758
/****************************************************************************
3859
* Public Functions
3960
****************************************************************************/
@@ -42,68 +63,127 @@
4263
* Name: stm32_stdclockconfig
4364
*
4465
* Description:
45-
* Configure the STM32U3 system clock from MSIRC0 at 96 MHz.
66+
* Configure the STM32U3 system clock from the settings in board.h.
4667
*
4768
****************************************************************************/
4869

70+
#ifndef CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG
4971
void stm32_stdclockconfig(void)
5072
{
5173
uint32_t regval;
74+
volatile int32_t timeout;
5275

5376
/* The EPOD booster and voltage scaling control require the PWR clock. */
5477

5578
modifyreg32(STM32_RCC_AHB1ENR2, 0, RCC_AHB1ENR2_PWREN);
5679

57-
/* Supply the EPOD booster from undivided MSIS. */
80+
/* Select the board regulator and wait until the transition completes. */
81+
82+
modifyreg32(STM32_PWR_CR3, PWR_CR3_REGSEL, STM32_PWR_CR3_REGSEL);
83+
for (timeout = CLOCK_READY_TIMEOUT; timeout > 0; timeout--)
84+
{
85+
if ((getreg32(STM32_PWR_SVMSR) & PWR_SVMSR_REGS) ==
86+
STM32_PWR_CR3_REGSEL)
87+
{
88+
break;
89+
}
90+
}
91+
92+
if (timeout == 0)
93+
{
94+
return;
95+
}
96+
97+
/* Configure and enable the EPOD booster. */
5898

5999
regval = getreg32(STM32_RCC_CFGR4);
60100
regval &= ~(RCC_CFGR4_BOOSTSEL_MASK | RCC_CFGR4_BOOSTDIV_MASK);
61-
regval |= RCC_CFGR4_BOOSTSEL_MSIS;
101+
regval |= STM32_RCC_CFGR4_BOOSTSEL | STM32_RCC_CFGR4_BOOSTDIV;
62102
putreg32(regval, STM32_RCC_CFGR4);
63103

64-
modifyreg32(STM32_PWR_VOSR, 0, PWR_VOSR_BOOSTEN);
65-
while ((getreg32(STM32_PWR_VOSR) & PWR_VOSR_BOOSTRDY) == 0)
104+
modifyreg32(STM32_PWR_VOSR, 0, STM32_PWR_VOSR_BOOST);
105+
for (timeout = CLOCK_READY_TIMEOUT; timeout > 0; timeout--)
106+
{
107+
if ((getreg32(STM32_PWR_VOSR) & PWR_VOSR_BOOSTRDY) != 0)
108+
{
109+
break;
110+
}
111+
}
112+
113+
if (timeout == 0)
66114
{
115+
return;
67116
}
68117

69-
/* Select voltage scale 1 and wait until it is active. */
118+
/* Select the board voltage scale and wait until it is active. */
119+
120+
modifyreg32(STM32_PWR_VOSR, PWR_VOSR_R1EN | PWR_VOSR_R2EN,
121+
STM32_PWR_VOSR_RANGE);
122+
for (timeout = CLOCK_READY_TIMEOUT; timeout > 0; timeout--)
123+
{
124+
if ((getreg32(STM32_PWR_VOSR) &
125+
(PWR_VOSR_R1RDY | PWR_VOSR_R2RDY)) ==
126+
STM32_PWR_VOSR_RANGERDY)
127+
{
128+
break;
129+
}
130+
}
70131

71-
modifyreg32(STM32_PWR_VOSR, PWR_VOSR_R2EN, PWR_VOSR_R1EN);
72-
while ((getreg32(STM32_PWR_VOSR) &
73-
(PWR_VOSR_R1RDY | PWR_VOSR_R2RDY)) != PWR_VOSR_R1RDY)
132+
if (timeout == 0)
74133
{
134+
return;
75135
}
76136

77-
/* Three wait states are required before raising HCLK to 96 MHz. */
137+
/* Configure FLASH before raising HCLK. */
78138

79139
modifyreg32(STM32_FLASH_ACR, FLASH_ACR_LATENCY_MASK,
80-
FLASH_ACR_LATENCY(3));
140+
STM32_FLASH_ACR_LATENCY);
81141

82-
/* Select MSIRC0 divided by one and use it as the 96 MHz system clock. */
142+
/* Configure and start MSIS. */
83143

84144
regval = getreg32(STM32_RCC_ICSCR1);
85145
regval &= ~(RCC_ICSCR1_MSISSEL | RCC_ICSCR1_MSISDIV_MASK);
86-
regval |= RCC_ICSCR1_MSIRGSEL;
146+
regval |= RCC_ICSCR1_MSIRGSEL | STM32_RCC_ICSCR1_MSISSEL |
147+
STM32_RCC_ICSCR1_MSISDIV;
87148
putreg32(regval, STM32_RCC_ICSCR1);
88149

89150
modifyreg32(STM32_RCC_CR, 0, RCC_CR_MSISON);
90-
while ((getreg32(STM32_RCC_CR) & RCC_CR_MSISRDY) == 0)
151+
for (timeout = CLOCK_READY_TIMEOUT; timeout > 0; timeout--)
91152
{
153+
if ((getreg32(STM32_RCC_CR) & RCC_CR_MSISRDY) != 0)
154+
{
155+
break;
156+
}
92157
}
93158

94-
modifyreg32(STM32_RCC_CFGR1, RCC_CFGR1_SW_MASK, RCC_CFGR1_SW_MSIS);
95-
while ((getreg32(STM32_RCC_CFGR1) & RCC_CFGR1_SWS_MASK) !=
96-
RCC_CFGR1_SWS_MSIS)
159+
if (timeout == 0)
97160
{
161+
return;
98162
}
99163

100-
/* Keep all bus clocks undivided. */
164+
/* Configure the AHB and APB prescalers. */
101165

102166
modifyreg32(STM32_RCC_CFGR2,
103167
RCC_CFGR2_HPRE_MASK | RCC_CFGR2_PPRE1_MASK |
104-
RCC_CFGR2_PPRE2_MASK, 0);
105-
modifyreg32(STM32_RCC_CFGR3, RCC_CFGR3_PPRE3_MASK, 0);
168+
RCC_CFGR2_PPRE2_MASK,
169+
STM32_RCC_CFGR2_HPRE | STM32_RCC_CFGR2_PPRE1 |
170+
STM32_RCC_CFGR2_PPRE2);
171+
modifyreg32(STM32_RCC_CFGR3, RCC_CFGR3_PPRE3_MASK,
172+
STM32_RCC_CFGR3_PPRE3);
173+
174+
/* Use MSIS as the system clock and wait for the switch to complete. */
175+
176+
modifyreg32(STM32_RCC_CFGR1, RCC_CFGR1_SW_MASK, RCC_CFGR1_SW_MSIS);
177+
for (timeout = CLOCK_READY_TIMEOUT; timeout > 0; timeout--)
178+
{
179+
if ((getreg32(STM32_RCC_CFGR1) & RCC_CFGR1_SWS_MASK) ==
180+
RCC_CFGR1_SWS_MSIS)
181+
{
182+
break;
183+
}
184+
}
106185
}
186+
#endif
107187

108188
/****************************************************************************
109189
* Name: stm32_rcc_enableperipherals

‎boards/Kconfig‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3311,6 +3311,14 @@ config ARCH_BOARD_NUCLEO_U5A5ZJ_Q
33113311
MCU. The STM32U5A5 is a Cortex-M33 optimised for low-power operation
33123312
at up to 160MHz operation with 4MB Flash memory and 2.5MB SRAM.
33133313

3314+
config ARCH_BOARD_NUCLEO_U3C5ZI_Q
3315+
bool "STMicro NUCLEO-U3C5ZI-Q board"
3316+
depends on ARCH_CHIP_STM32U3C5ZI
3317+
---help---
3318+
STMicro NUCLEO-U3C5ZI-Q development board featuring the STM32U3C5ZI,
3319+
a Cortex-M33 MCU running at up to 96 MHz with 2 MiB Flash and
3320+
640 KiB SRAM.
3321+
33143322
config ARCH_BOARD_STM32L476VG_DISCO
33153323
bool "STMicro STM32L476VG -Discovery board"
33163324
depends on ARCH_CHIP_STM32L476RG
@@ -4176,6 +4184,7 @@ config ARCH_BOARD
41764184
default "nucleo-h563zi" if ARCH_BOARD_NUCLEO_H563ZI
41774185
default "nucleo-n657x0-q" if ARCH_BOARD_NUCLEO_N657X0_Q
41784186
default "nucleo-u5a5zj-q" if ARCH_BOARD_NUCLEO_U5A5ZJ_Q
4187+
default "nucleo-u3c5zi-q" if ARCH_BOARD_NUCLEO_U3C5ZI_Q
41794188
default "stm32l476vg-disco" if ARCH_BOARD_STM32L476VG_DISCO
41804189
default "stm32l476-mdk" if ARCH_BOARD_STM32L476_MDK
41814190
default "stm32l4r9ai-disco" if ARCH_BOARD_STM32L4R9AI_DISCO
@@ -4835,6 +4844,9 @@ endif
48354844
if ARCH_BOARD_NUCLEO_U5A5ZJ_Q
48364845
source "boards/arm/stm32u5/nucleo-u5a5zj-q/Kconfig"
48374846
endif
4847+
if ARCH_BOARD_NUCLEO_U3C5ZI_Q
4848+
source "boards/arm/stm32u3/nucleo-u3c5zi-q/Kconfig"
4849+
endif
48384850
if ARCH_BOARD_NUCLEO_L432KC
48394851
source "boards/arm/stm32l4/nucleo-l432kc/Kconfig"
48404852
endif
@@ -5460,7 +5472,7 @@ endif
54605472
if ARCH_CHIP_SAMV7
54615473
source "boards/arm/samv7/common/Kconfig"
54625474
endif
5463-
if ARCH_CHIP_STM32C0 || ARCH_CHIP_STM32F0 || ARCH_CHIP_STM32F1 || ARCH_CHIP_STM32F2 || ARCH_CHIP_STM32F3 || ARCH_CHIP_STM32F4 || ARCH_CHIP_STM32F7 || ARCH_CHIP_STM32G0 || ARCH_CHIP_STM32G4 || ARCH_CHIP_STM32L0 || ARCH_CHIP_STM32L1 || ARCH_CHIP_STM32H7 || ARCH_CHIP_STM32H5 || ARCH_CHIP_STM32L5 || ARCH_CHIP_STM32U0 || ARCH_CHIP_STM32U5 || ARCH_CHIP_STM32WB || ARCH_CHIP_STM32WL5 || ARCH_CHIP_STM32N6
5475+
if ARCH_CHIP_STM32C0 || ARCH_CHIP_STM32F0 || ARCH_CHIP_STM32F1 || ARCH_CHIP_STM32F2 || ARCH_CHIP_STM32F3 || ARCH_CHIP_STM32F4 || ARCH_CHIP_STM32F7 || ARCH_CHIP_STM32G0 || ARCH_CHIP_STM32G4 || ARCH_CHIP_STM32L0 || ARCH_CHIP_STM32L1 || ARCH_CHIP_STM32H7 || ARCH_CHIP_STM32H5 || ARCH_CHIP_STM32L5 || ARCH_CHIP_STM32U0 || ARCH_CHIP_STM32U3 || ARCH_CHIP_STM32U5 || ARCH_CHIP_STM32WB || ARCH_CHIP_STM32WL5 || ARCH_CHIP_STM32N6
54645476
source "boards/arm/common/stm32/Kconfig"
54655477
endif
54665478
if ARCH_CHIP_RP2040
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ##############################################################################
2+
# boards/arm/stm32u3/common/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_ARCH_BOARD_COMMON)
24+
add_subdirectory(${NUTTX_DIR}/boards/arm/common/stm32 stm32_common)
25+
endif()

‎boards/arm/stm32u3/common/Makefile‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#############################################################################
2+
# boards/arm/stm32u3/common/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
#############################################################################
22+
23+
include $(TOPDIR)/Make.defs
24+
25+
STM32_BOARD_COMMON_DIR := $(TOPDIR)$(DELIM)boards$(DELIM)arm$(DELIM)common$(DELIM)stm32
26+
STM32_COMMON_SRCDIR := $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)common$(DELIM)stm32
27+
28+
include board/Make.defs
29+
include $(STM32_BOARD_COMMON_DIR)$(DELIM)src$(DELIM)Make.defs
30+
31+
DEPPATH += --dep-path board
32+
33+
include $(TOPDIR)/boards/Board.mk
34+
35+
ARCHSRCDIR = $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src
36+
BOARDDIR = $(ARCHSRCDIR)$(DELIM)board
37+
CFLAGS += ${INCDIR_PREFIX}$(BOARDDIR)$(DELIM)include
38+
CFLAGS += ${INCDIR_PREFIX}$(STM32_COMMON_SRCDIR)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# ##############################################################################
2+
# boards/arm/stm32u3/nucleo-u3c5zi-q/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
add_subdirectory(src)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
if ARCH_BOARD_NUCLEO_U3C5ZI_Q
7+
8+
endif

0 commit comments

Comments
 (0)