Repository navigation
stm32: read the n32g45x unique id from its documented address - #190
loss-and-quick wants to merge 5 commits into
Conversation
aff9251 to
f1b31e4
Compare
|
Taking this out of draft now that I have an n32g455 board to test it on, and now that the Klipper side exists. The two have to land together: this changes the uuid the bootloader reports, and the application derives its own from the same bytes, so a mismatched pair would report two different uuids for one board. The Klipper side is Klipper3d/klipper#7363. Rebased on the current #189 branch, which now also enables ex mode. |
|
A small status note, since this one now gates a change on the Klipper side. The matching Klipper PR is Klipper3d/klipper#7363, and Kevin's position there is that he does not have a strong preference either way and will follow whatever Katapult decides:
So the decision on whether to read the n32g45x unique id from its documented address rests here. Both sides are written and tested on an n32g455 board, and they have to land together — the bootloader and the application derive their uuid from the same bytes, so a mismatched pair would report two different uuids for one board. Happy to adjust the change if you'd prefer it in a different form, or to drop it if you'd rather keep the current offset for compatibility with already-flashed boards. |
The N32G45x flash controller differs from the stm32f103: pages are always 2KiB, and programming only works at 32-bit width (not half-word). Add the corresponding page size and programming implementations; page erase is unchanged. Signed-off-by: Lev Voronov <minicx@disroot.org>
The N32G45x reuses the stm32f1 RCC layout but its clock tree differs: a 5-bit PLL multiplier, separate PCLK1/PCLK2 limits, flash wait states that scale in 32MHz steps, no ADC prescaler bits, and a 2-bit USB prescaler with non-integer divisors. It also keeps part of its peripheral set - the adc, sdio, qspi, opamp, comp and can2 - behind an "ex mode" bit in PWR_CTRL3. While that bit is clear those peripherals stay unclocked and their RCC enable bits read back as zero, so the vendor SystemInit() sets it before configuring any clock. 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. Enable ex mode the way the vendor code does, then 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. Signed-off-by: Lev Voronov <minicx@disroot.org>
f1b31e4 to
d9545c4
Compare
Add build support for the Nations N32G452 and N32G455, which are pin and register compatible with the stm32f103 but built around a Cortex-M4 core with 128KiB flash / 64KiB ram. They select MACH_STM32F1 and reuse the stm32f103xe headers, matching Klipper. Default system clock is 128MHz (96MHz with USB, since the prescaler can't produce 48MHz from 128MHz). The internal oscillator default of 64MHz matches the value Klipper has used for this chip since it was introduced. An additional 64KiB app-start offset is provided to match Klipper's bootloader offsets for this chip. Signed-off-by: Lev Voronov <minicx@disroot.org>
The n32g45x defaulted to 128Mhz, which is not reachable from a 12Mhz or 24Mhz crystal: the PLL takes the crystal or half of it, so only exact multiples of crystal / 2 can be generated, and a 12Mhz crystal silently ran the chip at 126Mhz instead. Run it at 144Mhz instead, the chip's rated maximum, which is an exact multiple of half of each of the 8, 12, 16, 24 and 32Mhz crystals. That includes usb builds: at 144Mhz the usb prescaler divides by 3 to give the 48Mhz the peripheral needs, so the separate 96Mhz usb rate is no longer required. Add a build time check so that a crystal which cannot produce the rate, such as 20Mhz or 25Mhz, fails to build instead of running at the wrong speed. This matches the clock setup now in Klipper. 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. Klipper 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>
d9545c4 to
d74a0e0
Compare
Depends on #189 — 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, matching the identical fix proposed for Klipper.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.