Skip to content

Instantly share code, notes, and snippets.

@SteveGotthardt
Last active December 9, 2024 12:08
Show Gist options
  • 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:

@snkku
Copy link

snkku commented Jan 11, 2023

first, the drivers on the kobra go's board, they are not 2209. I removed the heat sink, there are 4 tmc2208. tmc2208 doesn't have address function, so uart won't work.

its a bad news :(

@xiaopeng12138
Copy link

xiaopeng12138 commented Jan 11, 2023

first, the drivers on the kobra go's board, they are not 2209. I removed the heat sink, there are 4 tmc2208. tmc2208 doesn't have address function, so uart won't work.

its a bad news :(

well, a lot people uses standalone mode with klipper. it doesn't have any major difference. the pressure advance and input shaping work just fine

@snkku
Copy link

snkku commented Jan 11, 2023

well, a lot people uses standalone mode with klipper. it doesn't have any major difference. the pressure advance and input shaping work just fine

can u share config of yours kobra go?

@xiaopeng12138
Copy link

well, a lot people uses standalone mode with klipper. it doesn't have any major difference. the pressure advance and input shaping work just fine

can u share config of yours kobra go?

https://cdn.discordapp.com/attachments/431559228050636820/1062463189960376400/anycubic_kobra_go_klipper.cfg

@xiaopeng12138
Copy link

Is it possible to add SPI support? because I want to make my display also work. The screen on the Kobra Go is an ST7796 TFT screen with a resolution of 320x240.

@snkku
Copy link

snkku commented Jan 26, 2023

well, a lot people uses standalone mode with klipper. it doesn't have any major difference. the pressure advance and input shaping work just fine

hi!
does it have method to make 2208 works via uart with some soldering? my extruder skip steps on fast printing... and i was forced to set max_extruder_velocity to 8 :(
Have u discord or telegram to talk outside github?:)

@SteveGotthardt
Copy link
Author

SteveGotthardt commented Jan 26, 2023

@xiaopeng12138

Is it possible to add SPI support? because I want to make my display also work. The screen on the Kobra Go is an ST7796 TFT screen with a resolution of 320x240.

Yes, SPI could be added - I have slowed development until Klipper project merges my PR (someday soon, I hope!)

@SteveGotthardt
Copy link
Author

SteveGotthardt commented Jan 26, 2023

@snkku
2208 should work as UART address 00 (fixed address)

Discord: FlyDog #1086
Telegram: @SteveGotthardt

@xiaopeng12138
Copy link

well, a lot people uses standalone mode with klipper. it doesn't have any major difference. the pressure advance and input shaping work just fine

hi! does it have method to make 2208 works via uart with some soldering? my extruder skip steps on fast printing... and i was forced to set max_extruder_velocity to 8 :( Have u discord or telegram to talk outside github?:)

I don't think you can. TMC2208 only has one uart address. If you want the uart working, you need to solder at least 4 jumper wires. And I can't guarantee if the board has uart pin trace or not. But there is some special sauce in the official marlin firmware. https://github.com/ANYCUBIC-3D/Kobra_Go/blob/e675180de25a622936be74ddf364f59715ec3943/source/Marlin/src/module/stepper/trinamic.cpp#L489
this TMC6609 part is very strange. (They defined it on the board config)

@tianer2820
Copy link

Can confirm this works on Aquila X2 H32. Thanks a lot for the amazing work!

@onceagain227
Copy link

Can confirm this works on Aquila X2 H32. Thanks a lot for the amazing work!

What BIN file did you use? cant get O1 or C2 to work on my X2 H32.

@tianer2820
Copy link

What BIN file did you use? cant get O1 or C2 to work on my X2 H32.

I used O1. By the way, my printer has the main board FFP0173_Aquila_Main_Board_V1.0.3, please check if yours has the same, I'm not sure if they use the same version for all X2.

@onceagain227
Copy link

FFP0173_Aquila_Main_Board_V1.0.2 for me.
Ill try the 01 a few more times/ways. Put most of my efforts into C2.

@svyatoslavmo
Copy link

@SteveGotthardt Hi! Was it merged into upstream?

@SteveGotthardt
Copy link
Author

@svyatoslavmo
Yes. The base code was. Now to add. Configs, etc

@hlyi
Copy link

hlyi commented Mar 27, 2023

@SteveGotthardt Thank you for porting H32 to Klipper. Your FW worked on my FFP0173_Aquila_Main_Board_V1.0.2 board. Do you plan to get display working on O1 firmware?

@hlyi
Copy link

hlyi commented Mar 27, 2023

FFP0173_Aquila_Main_Board_V1.0.2 for me. Ill try the 01 a few more times/ways. Put most of my efforts into C2.

@onceagain227 I have this version of board as well. Do you happen to know which step motor drivers it uses? is it TMC2208?

@onceagain227
Copy link

I ended up getting this working on my FFP0173_Aquila_Main_Board_V1.0.2 board Aquila X2 using the O1 firmware.
I will spare you most of the details: but in the end the issue was my Linux install.

"braille" services were 'stealing' the connection to the serial device, not allowing klipper to see it.

@jsanKale
Copy link

jsanKale commented Apr 9, 2023

the klipper now has the ability to compile the firmware for voxelab aquila X2 on an H32 processor, but if you flash it, the klipper does not see the printer. And the klipper_O1 firmware works well. why does the compiled firmware not work, how to make it work?

@jsanKale
Copy link

jsanKale commented Apr 9, 2023

I connected the adxl345 to the mcu via software spi and I get this error: This is often caused by running an older version
of the firmware on the microcontroller(s). Fix this by compiling and flashing
the firmware.
Your Klipper version: v0.11.0-169-g83308a10
MCU(s) to be updated:
mcu: Current version before merge-309-gda1b3906
Modern microcontrollers:
As soon as the main problem is fixed, use "REBOOT".
a command to reboot the configuration and restart the host software.
mcu 'mcu': Unknown command: spi_send
Firmware klipper_O1.bin on aquila X2 H32

@SteveGotthardt
Copy link
Author

@jsanKale
The O1 needs a FLASH_APPLICATION_ADDRESS of 0xC000
change the Kconfig in src/hc32f460/Kconfig from 0x8000 to 0xC000
then make menuconfig and generate new .config - check .config to be sure it is 0xC000
The display may work some day when support for DWIN is working.
(sorry for late response)

@Bertman29
Copy link

I have a question about the bltouch port. I see the port provides 5v to the bltouch. What voltage is being sent back on Pin 5 (PB1)? Is it 3.3v or can it handle a 5v input? Thanks

@SteveGotthardt
Copy link
Author

@Bertman29 The IO pin is 5V tolerant - and the working V is 3.6 according to HW dev guide. Does that help?

@Bertman29
Copy link

@Bertman29 The IO pin is 5V tolerant - and the working V is 3.6 according to HW dev guide. Does that help?

@SteveGotthardt yes that answered my question. Thank you for the info.

@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

@Casterluo1
Copy link

Hello, may I ask if the lower computer motherboard can communicate with the upper computer through usb after brushing into O1? Because I plan to copy the Android phone on the network and use the klipper as the upper computer, when using the mobile phone as the upper computer, I need to use the usb port connection to achieve communication.

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