Skip to content

Commit 76cbf62

Browse files
committed
[stm32] Separate ULPI clock from OTGHS clock
To run the OTGHS port in FS mode the ULPI clock must be disabled.
1 parent dd1ad5c commit 76cbf62

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

ext/st/module.lb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ def common_peripherals(env):
178178
all_peripherals.add(dname)
179179
if dname == "Dma" and d["type"] == "stm32-mux":
180180
all_peripherals.add("Dmamux1")
181+
if dname == "Usbotghs":
182+
all_peripherals.add("Usbotghsulpi")
181183

182184
all_peripherals.discard(None)
183185
all_peripherals = sorted(list(all_peripherals))

src/modm/platform/clock/stm32/module.lb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ def build(env):
177177
# Fix USBOTG OTG
178178
if target.family == "u5" and per == "OTG":
179179
per = "Usbotgfs"
180-
if "Usbotgfs" in all_peripherals and per.startswith("OTG"):
181-
if per == "OTGH":
182-
per = "OTGHS"
180+
if ("Usbotgfs" in all_peripherals or "Usbotghs" in all_peripherals) and per.startswith("OTG"):
181+
if per == "OTGH": per = "OTGHS"
183182
per = "USB"+per
184-
if "Usbotgfs" in all_peripherals and per.startswith("USB"):
183+
if ("Usbotgfs" in all_peripherals or "Usbotghs" in all_peripherals) and per.startswith("USB"):
185184
per = per.replace("USB1", "USB").replace("USB2", "USB")
186185
if target.family == "l5" and per == "USBFS":
187186
per = "Usb"
@@ -190,7 +189,7 @@ def build(env):
190189
if "EN" in mode:
191190
rcc_enable[per.capitalize()] = (nper, mode["EN"])
192191
if "RST" in mode:
193-
rcc_reset[nper] = mode["RST"]
192+
rcc_reset[per.capitalize()] = (nper, mode["RST"])
194193

195194
env.substitutions.update({
196195
"rcc_enable": rcc_enable,

src/modm/platform/clock/stm32/rcc_impl.hpp.in

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021 Niklas Hauser
2+
* Copyright (c) 2019, 2021, 2024, Niklas Hauser
33
*
44
* This file is part of the modm project.
55
*
@@ -123,13 +123,12 @@ Rcc::enable()
123123
__DSB();
124124
%% for peripheral, (st_per, bus) in rcc_enable.items() | sort
125125
if constexpr (peripheral == Peripheral::{{ peripheral }})
126-
if (not Rcc::isEnabled<peripheral>()) {
127-
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}EN;{% if st_per in rcc_reset %} __DSB();
128-
RCC->{{rcc_reset[st_per]}} |= RCC_{{rcc_reset[st_per]}}_{{st_per}}RST; __DSB();
129-
RCC->{{rcc_reset[st_per]}} &= ~RCC_{{rcc_reset[st_per]}}_{{st_per}}RST;{% endif %}{% if peripheral == "Eth" %} __DSB();
126+
{% if peripheral in rcc_reset %}if (not Rcc::isEnabled<peripheral>()) {% endif %}{
127+
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}EN;{% if peripheral in rcc_reset %} __DSB();
128+
RCC->{{rcc_reset[peripheral][1]}} |= RCC_{{rcc_reset[peripheral][1]}}_{{rcc_reset[peripheral][0]}}RST; __DSB();
129+
RCC->{{rcc_reset[peripheral][1]}} &= ~RCC_{{rcc_reset[peripheral][1]}}_{{rcc_reset[peripheral][0]}}RST;{% endif %}{% if peripheral == "Eth" %} __DSB();
130130
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}RXEN; __DSB();
131-
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}TXEN;{% elif peripheral == "Usbotghs" %} __DSB();
132-
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}ULPIEN;{% endif %}
131+
RCC->{{bus}} |= RCC_{{bus}}_{{st_per}}TXEN;{% endif %}
133132
}
134133
%% endfor
135134
__DSB();
@@ -147,8 +146,7 @@ Rcc::disable()
147146
if constexpr (peripheral == Peripheral::{{ peripheral }}) {
148147
RCC->{{bus}} &= ~RCC_{{bus}}_{{st_per}}EN;{% if peripheral == "Eth" %} __DSB();
149148
RCC->{{bus}} &= ~RCC_{{bus}}_{{st_per}}RXEN; __DSB();
150-
RCC->{{bus}} &= ~RCC_{{bus}}_{{st_per}}TXEN;{% elif peripheral == "Usbotghs" %} __DSB();
151-
RCC->{{bus}} &= ~RCC_{{bus}}_{{st_per}}ULPIEN;{% endif %}
149+
RCC->{{bus}} &= ~RCC_{{bus}}_{{st_per}}TXEN;{% endif %}
152150
}
153151
%% endfor
154152
__DSB();

0 commit comments

Comments
 (0)