Repository navigation
stm32: add support for the Nations N32G45x - #189
loss-and-quick wants to merge 4 commits into
Conversation
79f50a8 to
5eb80db
Compare
3203ec7 to
0555704
Compare
|
I now have an n32g455 board running, so this is tested on hardware instead of just built. Bringing it up turned up one thing missing from the clock setup. The chip keeps its adc, sdio, qspi, opamp, comp and can2 behind an "ex mode" bit in PWR_CTRL3. Until that bit is set those peripherals have no clock at all and their RCC enable bits do not even latch - writing all ones to RCC_AHBPCLKEN reads back 0x00000057 here, and 0x0002fa57 once ex mode is on. The vendor SystemInit() in system_n32g45x.c sets it before configuring any clock, so I have folded that into the clock configuration commit rather than adding a separate one. Katapult itself does not use those peripherals, but the bootloader should leave the chip in the same state the vendor code does, and can2 is behind the same bit. The matching Klipper side is in Klipper3d/klipper#7362. |
|
Status update: this is tested on an n32g455 board now, not just built. The Klipper side of the same work has been reviewed and largely merged upstream (Klipper3d/klipper#7347), so the clock setup here matches what is now in Klipper: a separate Let me know if you'd like anything reshaped before this is considered for merging. |
|
Thanks. Am I correct that all pending work has been merged in Klipper? If so, I'll merge this and its companion PR. |
|
FYI, I merged another pending PR that created a merge conflict in the README. You can resolve it if you prefer, or I can resolve it before merging. |
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>
0555704 to
995d83a
Compare
|
Yes, the Klipper side is done - the clock setup (Klipper3d/klipper#7347) and the adc fixes (Klipper3d/klipper#7362) are both merged. During review Kevin simplified the clock defaults to running the n32g45x at 144Mhz on every standard crystal, with usb at 144Mhz/3, so I've updated this PR to match - the n32g45x clock code here is now the same as in Klipper. I've also rebased onto master and resolved the README conflict, and rebased #190 on top of it. On #190: its Klipper counterpart, Klipper3d/klipper#7363, is still open because Kevin said he'd follow whatever Katapult decides. So if you merge #190, the Klipper one should follow on the Klipper side. The two need to be flashed together, since the bootloader and the application derive the uuid from the same bytes. |
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>
995d83a to
20de9d2
Compare
akarkou1
left a comment
There was a problem hiding this comment.
looks good, confirmed to be functional on my end. well done
Adds support for the Nations N32G45x (N32G452 / N32G455), a Cortex-M4 part that is pin- and register-compatible with the stm32f103 but differs in its flash controller and clock tree. The clock setup is the same as what is now merged in Klipper (Klipper3d/klipper#7347, Klipper3d/klipper#7362).
clock_setup_n32g45x(), dispatched alongside the untouchedclock_setup(). 5-bit PLL multiplier, flash wait states that scale in 32MHz steps, both APB busses divided by the same amount soget_pclock_frequency()stays uniform, and the "ex mode" bit set so the adc and can2 blocks get a clock.MACH_STM32F1variant reusing the stm32f103xe headers, matching Klipper, plus a 64KiB app-start offset matching Klipper's bootloader offsets for this chip.The stm32f103 path is untouched; everything n32g45x-specific sits behind
CONFIG_MACH_N32G45x.Testing
CFGR = 0x08052D00(0x08C52D00with usb), 12MHz0x00292D00, flashACR = 0x14(4 wait states).test/configs/n32g45x.config(usb) andn32g45x-canbus.configcover both build paths.