Repository navigation
stm32: read the n32g45x unique id from its documented address - #7348
Closed
loss-and-quick wants to merge 5 commits into
Closed
loss-and-quick wants to merge 5 commits into
loss-and-quick wants to merge 5 commits into
Conversation
loss-and-quick
force-pushed
the
n32g45x-uid-fix
branch
4 times, most recently
from
August 27, 2026 19:31
949befd to
89cace7
Compare
The n32g45x reused clock_setup(), which is invalid at the 128MHz it runs at: PPRE1_DIV2 leaves PCLK1 at 64MHz against a 36MHz limit, and the flash latency of two wait states is one short of what 128MHz needs. Give the n32g45x its own clock_setup_n32g45x(), keeping it isolated from the shared stm32f103 code path, so clock_setup() and the rest of the core stm32 code are unchanged. Divide both APB busses by the same amount, chosen from PCLK1's tighter limit, so every peripheral clock stays identical -- some stm32 code (e.g. hard_pwm.c) assumes get_pclock_frequency() returns one value for all peripherals. Scale flash wait states with HCLK, and widen the PLL multiplier encoding to five bits (PLLMUL[4] at bit 27) so multipliers above 16 can be reached. Signed-off-by: Lev Voronov <minicx@disroot.org>
USB was enabled for the n32g45x when it was introduced, but the USB prescaler bits were never programmed, leaving the reset divisor of PLLCLK/1.5 -- 85.33MHz from the default 128MHz clock, not the 48MHz the peripheral needs. Program the prescaler in clock_setup_n32g45x(), and lower the clock to 96MHz when USB is selected, since 128MHz can't produce 48MHz through any of this chip's divisors (1.5/1/2/3). CAN and uart builds keep 128MHz. An unsupported clock still fails the build with #error instead of producing a device that won't enumerate. The internal oscillator default is left at 64MHz. USB requires a crystal, so that path cannot be affected by this change, and raising it would be a hardware change that is not needed to fix this bug. Signed-off-by: Lev Voronov <minicx@disroot.org>
loss-and-quick
force-pushed
the
n32g45x-uid-fix
branch
4 times, most recently
from
August 29, 2026 09:14
efd7e67 to
5182969
Compare
The n32g45x PLL multiplies the crystal (or its half) by an integer, so a system clock rate is only reachable when it is an exact multiple of crystal / 2. The flat 128Mhz default silently produced 126Mhz from a 12Mhz crystal, 120Mhz from 20Mhz and 24Mhz crystals, and 125Mhz from a 25Mhz crystal - enough of an error to break uart baud rates without any build time indication. Pick per crystal defaults that the PLL can generate exactly: 128Mhz where it was already exact (8Mhz, 16Mhz), otherwise the highest exact rate the crystal supports (144Mhz for 12Mhz and 24Mhz, 140Mhz for 20Mhz, 125Mhz for 25Mhz). Fail the build if the requested rate is not an exact multiple of crystal / 2. Also stop offering usb on crystals that cannot produce its 48Mhz clock: no exact usb rate exists from a 20Mhz or 25Mhz crystal. Signed-off-by: Lev Voronov <minicx@disroot.org>
The n32g45x had no build coverage. Add a USB and a CAN config so CI compiles both the 96MHz and 128MHz clock paths. Signed-off-by: Lev Voronov <minicx@disroot.org>
The n32g45x builds against the stm32f103 headers and so inherits UID_BASE = 0x1FFFF7E8. On this chip the 96bit unique device id is documented to start at 0x1FFFF7F0, so only the first four of the twelve bytes that are read are actually part of the unique id. The remaining eight bytes come from an undocumented part of the system configuration block and may well be identical on every device. Override UID_BASE for the n32g45x so that the full unique id is used. Note that this changes the CAN uuid and the usb serial number reported by existing n32g45x boards. Katapult needs the matching change, and both must be flashed together, otherwise the uuid reported by the bootloader will no longer match the one reported by the application. Signed-off-by: Lev Voronov <minicx@disroot.org>
loss-and-quick
force-pushed
the
n32g45x-uid-fix
branch
from
August 29, 2026 10:12
5182969 to
9a4286d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #7347 — the diff below includes that PR's commits until it lands;
What this does
The n32g45x reuses the stm32f103xe headers and therefore inherits
UID_BASE = 0x1FFFF7E8. Per the N32G45x system-config-block map, that address only covers the last 4 of the 12 byteschipid.creads as the "unique ID" — the other 8 bytes come from an undocumented region of the system block, not the documented 96-bit UID (which starts at0x1FFFF7F0). OverrideUID_BASEforCONFIG_MACH_N32G45xso the full 96-bit UID is used.Why this is a draft
canbus_uuidinprinter.cfgwill need updating, and any/dev/serial/by-id/...udev rule keyed on the old serial breaks too.Testing
Compiled a standalone probe with the real build flags:
UID_BASEresolves to0x1FFFF7F0underMACH_N32G452, and is unchanged at0x1FFFF7E8underMACH_STM32F103. No other code referencesUID_BASE, so the diff is confined to this one macro.