Skip to content

Instantly share code, notes, and snippets.

@SteveGotthardt
Last active March 3, 2024 00:04
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveGotthardt/2ed249f197f5928eaf5c3d3877d55503 to your computer and use it in GitHub Desktop.
Save SteveGotthardt/2ed249f197f5928eaf5c3d3877d55503 to your computer and use it in GitHub Desktop.
Voxelab Aquila HC32 Klipper

FFP0173_Aquila_Main_Board_V1.0.3 w/HC32F460

H32 only - does not work on G32 or N32 my effort Klipper on HC32

Status:


Documents


HC32F460 interrupts

The system interrupts on the HC32 are the same as CM4. But the peripheral interrupts are mapped to interrupts with a register write instead of being assiged to a specific vector number. Example for USART: There is no: USART1_IRQn in HC32 - instead choose a vector and program it

void IrqRegistration(en_int_src_t irqSrc, IRQn_Type irqType)
{
    stc_intc_sel_field_t *stcIntSel = (stc_intc_sel_field_t *)
        ((uint32_t)(&M4_INTC->SEL0) + (4u * irqType));

    // what is the source of the selected interrupt? (USART, etc...)
    stcIntSel->INTSEL = irqSrc;

    // set priority and enable
    NVIC_SetPriority(irqType, IRQ_PRIORITY_DEFAULT);
    NVIC_ClearPendingIRQ(irqType);
    NVIC_EnableIRQ(irqType);
}

Called by:
IrqRegistration(INT_USART1_RI, Int000_IRQn);

The INT_USART_RI and Int000_IRQn are found in hc32f460.h Int000_IRQn is picked by the programmer, it could be 000-031 Note for Klipper: use DECL_ARMCM_IRQ(IRQ000_Handler, Int000_IRQn); That will allocate a vector in the table

The new firmware is loaded from an SD card (8GB is what I use)

  • in a directory named firmware
  • from a file named firmware.bin (other names work too)
  • the file is then deleted from the SD card directory
  • The firmware is loaded into flash at 0XC000 the vector table relocated by VTOR to 0xC000 The firmware needs to be linked with FLASH_START = 0xC000

Loader code

  • The loader code sets up the ICG area so no ICG area is needed for firmware build
  • The loader sets up flash and ram wait states
  • Clock handoff:
  • CMU_XTALCFGR(8) @ 0x40054410 0xA0 (0b1010_0000) = SUPDRV, !XTALMS (osc mode), XTALDRV(Small Drive 8-16MHz)
  • CMU_PLLCFGR(32) @ 0x40054100 0x11102900 => MPLLN[8:0] b16-b8 = 0x029 (0b000101001), use xtal, divide by 1 before
  • So it looks like clock is 8 / 1 * 42 / 2? 168MHz
  • CMU_CKSWR(8) @ 0x40054026 = 0x05 = Select MPLL as system clock

HC32F460 notes

  • needs an ICG area (provided by loader)
  • Cortex M4 ARM core ID: 0x2BA01477
  • interrupts for peripherals are not hard vector numbers
  • There is 32K 'fast' SRAMH below the typical 0x20000000 at 0x1FFF_8000 ~ 0x1FFF_FFFF
  • PWC_RAMPC0.RAMPDC3
  • IO is slow and needs wait states if running at 200MHz
  • USART uses 5 separate interrupts unlike STM32

Tools

USART port

  • PA09 - set as TX - connected to LED and pin 2 of CH340
  • PA15 - set to RX - connected to pin 3 of CH340
  • PC0 and PC1 can be used for direct serial connection (see LCD connector)

PWM for Fan speed, Head heater, Bed heater

  • Fan PA0 TIMA_2 PWM 1
  • Head PA1 TIMA_2 PWM 2
  • Bed PA2 TIMA_2 PWM 3

Filament Runout pins

  • Pin 1: connected to PA4
  • Pin 2: GND
  • Pin 3: 3.3V

LCD connector - 10 pin numbering by IDC standard

  • Pin 1: 5V
  • Pin 2: GND
  • Pin 3: PB15 - 'A'
  • Pin 4: PB12 - 'B'
  • Pin 5: PB13 - 'Beep'
  • Pin 6: PB14 - 'Enter'
  • Pin 7: PC1 - for TX/RX
  • Pin 8: PC0 - for TX/RX
  • Pin 9: PB2 - NC?
  • Pin 10: PC6 - NC?

BL-Touch 5 pin

  • Pin 1: GND - square pad
  • Pin 2: 5V
  • Pin 3: PB0
  • Pin 4: GND
  • Pin 5: PB1

Running mainsail

The only RPi flavor I have left is a B+. I was able to get MainsailOS to work on the B+ but the system is burdened. So, I also have a Rock64 https://wiki.pine64.org/index.php?title=ROCK64 running https://www.armbian.com/rock64/ The rock64 won't boot with the RPi mainsailOS image so I tried manual install. It goes ok but when trying to get the webpage up I get 403 - forbidden. This is because nginx can't stat the mainsail directory. I installed as user 'pi' hoping it would work but I had to add www-data to group 'pi' and then restart nginx

    sudo usermod -a -G pi www-data
    nginx -s reload  

Octoprint + OctoKlipper module

I use octoprint on all (4) of my printers. Two have Raspberry Pi 3 and the other two are rock64. Adding the octoklipper module is easy. Adding Klipper is a little more involved. To run klipper, the host must be running: Octoprint+octoklipper module and Klippy from the Klipper repository.

Klipper on the host - pre-merge of H32

There are many vids and articles on getting Klipper going from the Klipper repository. Use the Klipper H32 release (https://github.com/SteveGotthardt/klipper/releases) to prorgram the printer mainboard via SD card (not built from klipper since it's not there yet). And since the H32 config is not yet merged there are different steps to take:

  • connect to the host (RPi, rock64, etc) via SSH (windows or Linux, mac)

  • clone (using git) the Klipper repository: git clone https://github.com/Klipper3d/klipper.git

  • initialize the environment for klippy to run: klipper/scripts/install-octopi.sh or install-debian.sh or appropriate

  • open the octoprint page (octoklipper already installed) and then open the config editor

  • copy the config contents from: https://github.com/SteveGotthardt/klipper/blob/hc32f460_work/config - look for the Voxelab entries for the C2 and O1 (original Aquila)

@cringegnere
Copy link

So, no UART, not even in TX only mode, right?
Is there no common UART pin that can be used to TX configuration to at least disable stealthChop?

@noob4722019
Copy link

hi all, when flashing klipper on the Aquila H32, do we need to flash firmware on the LCD? I can't find any details on that.

@SteveGotthardt
Copy link
Author

@noob4722019
I don't think klipper supports that LCD (yet?) I removed the LCD and just use PC interface.

@kcalbxof
Copy link

Hi! Was waiting for the support of screen on Anycubic Kobra Neo (1st, old version), is it still not done yet? What are the challenges? Appreciate the work, nonetheless!

@inventor96
Copy link

I'm new to Klipper, and wanted to try it out on my Aquila X2 H32 with the v1.0.3 board. Thanks @SteveGotthardt for your work on this! I built the firmware after a fresh Klipper installation on an old laptop running Linux Mint 21 (I decided to not use the build on the releases page here in order to ensure I was using the latest version).

I had some troubles getting them to communicate, and after I ensured that braille (or any equivalent) was not installed, and came to conclusion that I wasn't selecting the right "Communication interface" during the make menuconfig process. I came across https://github.com/Klipper3d/klipper/blob/master/src/hc32f460/serial.c#L23, which says I need to select the PA15 & PA09 option. Once I built the firmware with that selected, there were no more communication issues. Figured I'd mention it here to help anyone else who encounters this issue.

I found the choices for the rest of the options here, but for the sake of unification, for my printer (Aquila X2 H32 with the v1.0.3 board, connected to the laptop via USB), these are my selections:

  • Enable extra low-level configuration options: disabled
  • Micro-controller Architecture: Huada Semiconductor HC32F460
  • Communication interface: Serial (PA15 & PA09)
  • Application Address: 0x00C000
  • Clock Speed: 168 MHz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment