g992 / flashforge-ad5m-5mpro-research

Hardware and software researches and upgrades for Flashforge adventurer M5/M5 PRO
54 stars 5 forks source link

Mainsail and Moonraker for Flashforge AD5M #6

Closed xblax closed 4 months ago

xblax commented 5 months ago

Let's talk a bit about the options to get Mainsail and Moonraker working with the Flashforge 5M (Pro). I think we could consider the following options:

a) Install Mainsail+Moonraker on the Flashforge 5M after rooted into the existing image. As I understand the 128MB ram of the integrated ARM board are a bit limited to run Mainsail+Moonraker but maybe that's still worth trying out. Looks like some initial work to install missing components was already done here https://github.com/Stone-Time/Flashforge-Adventure-5M-Pro-Klipper-SSH

Either use the existing Klipper or install a clean rebuild. It looks like the printer comes with a more ore less stock Klipper 0.11, see https://github.com/FlashforgeOfficial/AD5M_Series_Klipper

b) Try to reverse engineer boot loader, run a different Linux image with Klipper etc. that is loaded from the USB Stick. I think that option takes too much effort.

c) Run Mainsail+Moonraker on a separate device, keep (stock) Klipper as is on the Flashforge. Moonraker connects to Klipper via a Unix Domain Socket that is forwarded via Openssh to another host.

d) Only have the Klipper MCU part running on the integrated controller, Run Clipper (Python part), Moonraker, Mainsail externally.

I would probably prefer a solution that is non-invasive and does not break the built-in printer interface. Not sure about Klippers capabilities, but maybe multiple clients can connect to Klippers API server in parallel: https://www.klipper3d.org/API_Server.html

nitronov commented 5 months ago

Эта нерешенная проблема не давала мне покоя, поэтому мне пришлось перепроектировать этот код... кажется, они написали собственный загрузчик. Я проверил описания загрузчика STM и Nations, но они не были похожи на то, что было отправлено.

После запуска Eboard-MCU периодически отправляет:

Ready.
Ready.
Ready.
Ready.
...

Это определяется кодом инициализации, и с помощью команды «A» (0x41) загрузчик запускает приложение. Эта команда подтверждается загрузчиком с помощью байта 0x06 (Ascii ACK). Я обновил Gist с помощью C-кода для выполнения этой инициализации: https://gist.github.com/xblax/2287bc83f399d2144952cd345518cf78

Теперь я могу запустить Klipper, Moonraker и т. д. после загрузки 😎 Постараюсь в ближайшее время подготовить для вас что-нибудь для тестирования.

I'm still trying to flash another bootloader, I can't find the address of the cell where the u-boot is located to erase it

xblax commented 5 months ago

@nitronov

I'm still trying to flash another bootloader, I can't find the address of the cell where the u-boot is located to erase it

Do know if the device is using u-boot at all? I didn't check it, but @jlodew0 wrote earlier that T113-S3 doesn't support u-boot:

I only did embedded projects with u-boot in the past. Seems like only awboot and xboot are working atm acording to this page: https://linux-sunxi.org/T113-s3

nitronov commented 5 months ago

@nitronov

I'm still trying to flash another bootloader, I can't find the address of the cell where the u-boot is located to erase it

Do know if the device is using u-boot at all? I didn't check it, but @jlodew0 wrote earlier that T113-S3 doesn't support u-boot:

I only did embedded projects with u-boot in the past. Seems like only awboot and xboot are working atm acording to this page: https://linux-sunxi.org/T113-s3

U-boot version 2018.05 installed

g992 commented 5 months ago

That unsolved problem didn't let me rest so I had to reverse engineer that code ... seems they have written a custom bootloader. I had checked STM and Nations Bootloader descriptions, but that didn't look like what was sent.

What the Eboard-MCU does after start, is to periodically send:

Ready.
Ready.
Ready.
Ready.
...

That is detected by the initialization code and with command 'A' (0x41) the boot loader starts the application. This command is acknowledged by the bootloader with byte 0x06 (Ascii ACK). I have updated the Gist with C-Code to do that initialization: https://gist.github.com/xblax/2287bc83f399d2144952cd345518cf78

Now I can start Klipper, Moonraker etc. after boot 😎 Will try to get something ready for testing for you soon.

Niiice, better, man

jlodew0 commented 4 months ago

@nitronov and @xblax

I didn't have any time on spare yet to thinker with my 5m yet. So I'm just refering to what I find online. Support for u-boot was being worked on end 2022/beginning of 2023 --> https://lore.kernel.org/u-boot/20221206004549.29015-1-andre.przywara@arm.com/ Anyway, why would you want to get rid of u-boot?

p.s. @g992 do you use a rpi 4? Because I read that you used ch340 based uart's, rpi has 6 uart's (5 usable because uart 0 and 1 shares the same gpio's). https://raspberrypi.stackexchange.com/questions/104464/where-are-the-uarts-on-the-raspberry-pi-4

I think I'm going the rpi route as well. That way, I don't have to worry about limited resources.

xblax commented 4 months ago

@g992 @nitronov @gpo123 @jlodew0 I've now manged to put a first alpha release together for my mod. The repository is still private, but I've added you as collaborators for now. Please don't commit anything there, I think that is just the easiest way do a first release with a closed group of testers. If some can confirm that it works - especially also on the 5M Pro, then I will make the repo fully public.

https://github.com/xblax/flashforge_adm5_klipper_mod Here is a public copy of the README.md for everyone else who is interested: https://gist.github.com/xblax/81fbb8c5671c206276f9f6070ef0cafa

If someone else want's to try this out already, maybe leave a comment here. The mod has no WiFi yet, only Ethernet LAN. Probably that's a deal-breaker for some.

I think I'm going the rpi route as well. That way, I don't have to worry about limited resources.

It really seems to work fine for me. The mod has no camera integration yet so that will add a bit to resource usage, but I've ordered the camera kit for the 5M and will try this out.

AJolly commented 4 months ago

Add me, I should get mine in a week.

KaruroChori commented 4 months ago

That's great news! If you need additional testers I can do it. I have a 5m with root access, already updated to the latest firmware and working via ethernet, and I cannot wait to stop using that UI on the small touchscreen :D.

ellaleks commented 4 months ago

Я тоже хочу протестировать. В наличии Adventurer 5M. Буду благодарен за доверие.

xblax commented 4 months ago

@AJolly @KaruroChori @ellaleks Added you as well as collaborators to the repo.

NokHook commented 4 months ago

Please

Also wants to test. I have AD5M)

Moonfizzle commented 4 months ago

Happy to do some testing also. I have a rooted 5M and a camera installed

xblax commented 4 months ago

@NokHook @Moonfizzle Added you.

I've also enabled the Discussions section in the repo: https://github.com/xblax/flashforge_adm5_klipper_mod/discussions That can be used for discussing the mod. Or open an issue in the mod repo if something that should work does not.

I'm not sure if @g992 is happy if we completely spam this issue here with comments.

@Moonfizzle mjpg-streamer is available in the mod, you can try to start it manually via SSH. But maybe some dependencies for camera support are still missing.

x2o commented 4 months ago

@xblax I'd be happy to test as well if you need more people on the Alpha release, rooted AD5M

stenny92 commented 4 months ago

@xblax I just started following this thread. I would like to be a tester for this.

mpolr commented 4 months ago

@xblax pls add me, I have adm5 with camera

consp commented 4 months ago

@xblax keep up the good work!

It's a bit of a shame though this thread is now hijacked to discuss the mod, so a minor suggestion: You can also create two repo's and lock it down as needed by keeping code in the private and readme/info in the public repository (create two remotes locally, only push the public branch to the public one). That way the issue and discussion systems are available for the world to see and you can sync the branches if the time arises.

My printer will only arrive by the weekend but it will definitely be open before the calibration has finished. (no need to add me)

xblax commented 4 months ago

@x2o @stenny92 @mpolr Added you. Please check discussions and open issues in repo before testing. There are some improvements in the printer config not yet in the alpha build. You can update the configs manually in mainsail. Currently working on the bed leveling routine. Printer profile in Slicer software should be adjusted for Klipper before trying a print.

Will now wait a bit before adding more for testing.

xblax commented 4 months ago

@consp I think it's too late to split this up now, but mod related discussions and issues around it should be kept together long-term anyway. I don't want to keep this closed for too long, but also don't want to publish anything where I assume people could accidentally break something or get the printer into a non-functional state that is hard to resolve.

I just accidentally messed up the load cell calibration for bed leveling by setting an output pin that is in the original Klipper config. Nozzle kept crashing into the bed when attempting bed leveling after that, even with stock software. Had to reverse engineer the original software software and find a hidden calibration menu to fix this. Original Flashforge software does much trough G-Code commands sent to Klipper, i.e. setting certain output pins before bed leveling. But I'm getting an understand how this works, bit by bit.

Feel free to continue technical discussion around Klipper here as well. I intended this as an open-ended discussion and my mod is just what came out of it so far.

khayrulinnikita commented 4 months ago

@xblax, please add me

consp commented 4 months ago

I think it's too late to split this up now, but mod related discussions and issues around it should be kept together long-term anyway. I don't want to keep this closed for too long, but also don't want to publish anything where I assume people could accidentally break something or get the printer into a non-functional state that is hard to resolve.

Makes sense. Though when I do that I usually add a point like "now use to flash the data" which scares off people who do not know what they are doing.

I just accidentally messed up the load cell calibration for bed leveling by setting an output pin that is in the original Klipper config. Nozzle kept crashing into the bed when attempting bed leveling after that, even with stock software. Had to reverse engineer the original software software and find a hidden calibration menu to fix this. Original Flashforge software does much trough G-Code commands sent to Klipper, i.e. setting certain output pins before bed leveling. But I'm getting an understand how this works, bit by bit.

Interesting as well, sounds like a hack, but hacks you can use in your own code. You definitely do not want to screw load cell calibration if you can. For those testing: Get a mains power switch nearby so you have an emergency power-off in case of head crashes.

@xblax Do you know if the "debug" pins on the board are ttyS3 which is the serial console (from memory so actual tty might be off)? Since if it is you can reuse it for other serial communication.

xblax commented 4 months ago

Interesting as well, sounds like a hack, but hacks you can use in your own code. You definitely do not want to screw load cell calibration if you can. For those testing: Get a mains power switch nearby so you have an emergency power-off in case of head crashes.

Yes. I think load cell calibration with a reference weight is done once at factory. Then for leveling we must only set the load cell tare after heating the bed. But at least I do now know how that works.

Do you know if the "debug" pins on the board are ttyS3 which is the serial console (from memory so actual tty might be off)? Since if it is you can reuse it for other serial communication.

No idea. I only know that it has a debug serial console, but never used it myself https://www.reddit.com/r/FlashForge/comments/1ahwari/shell_access_password_for_flashforge_printers/kordy9a/

But there are plenty of USB ports available according to the excellent hardware documentation already done by @g992 You can attach an USB to Serial converter there if needed.

g992 commented 4 months ago

Do you know if the "debug" pins on the board are ttyS3 which is the serial console (from memory so actual tty might be off)? Since if it is you can reuse it for other serial communication.

the debug port on the board is just an access to the linux terminal, I connected to it via a usb serial adapter and got a full-fledged terminal. it can be used to access the terminal, but I do not know why it is when there is access via telnet/ssh . Once it was useful to me when I clogged the file system and telnet/ssh simply could not start, then I deleted the extra files through this terminal

consp commented 4 months ago

the debug port on the board is just an access to the linux terminal

I guessed as much from the firmware images, ttyS3 is bound to it.

Once it was useful to me when I clogged the file system and telnet/ssh simply could not start, then I deleted the extra files through this terminal

I'm pretty sure that is the reason, it's labled debug. I might also be handy if uboot was used (or any other bootloader). Mine will arrive in about 2 hours so fingers crossed.

Ross922 commented 4 months ago

Forgive my ignorance but do you think its possible a company like BTT will come out with a new MB for the 5M Pro if it gains enough traction? That way the weak cpu and MB package can be bypassed etc? Note: I am not familiar with what it takes to put klipper onto this machine nor root and mod for klipper to work on the stock HW, im just asking what is likely an uninformed general question :-)

g992 commented 4 months ago

Forgive my ignorance but do you think its possible a company like BTT will come out with a new MB for the 5M Pro if it gains enough traction? That way the weak cpu and MB package can be bypassed etc? Note: I am not familiar with what it takes to put klipper onto this machine nor root and mod for klipper to work on the stock HW, im just asking what is likely an uninformed general question :-)

I don’t think so, only if in an official collab. The stock CPU is enough to run clipper + moonraker + mainsale + fluidd. There are also hopes that it will be enough to run clipperscreen, then we will get a full-fledged printer

consp commented 4 months ago

also hopes that it will be enough to run clipperscreen

Running X will be a stretch, klipperscreen is designed for hardware an order of magnitude faster (ok, not that much but you get the idea). Anything which uses a bitmapped framebuffer might work. Afaik the application (firmwareExe) is a Qt4.8.6 applet outputting to the fb with the qt embedded display driver, from what I can tell with a quick look.

The device is a simple 800x960 pixel framebuffer so no technical limitations there. Should be doable (at least if gives nice noise when doing dd if=/dev/urandom bs=1 count=3072000 > /dev/fb0)

I already had the original FW crash on me once so hopefully you can get it working.

Other thing of note I came across: the power switch is a file. I'll test it after I finished printing.

[INFO]1970/01/01 00:00:15 set QT_QPA_PLATFORM: linuxfb:tty=/dev/fb0:size=480x800:mmsize=115x170:offset=0 success
[INFO]1970/01/01 00:00:15 set QWS_DISPLAY: transformed:rot0:LinuxFB:mmWidth115:mmHeight170:0 success

So it's the embedded fb driver from qt.

KaruroChori commented 4 months ago

I am writing a demo in C++ using lvgl, and few other support libraries to do read data from moonraker. It seems to work, but I am having unrelated issues building the project with meson.

As I documented in a different discussion, we have access to the screen via framebuffer /dev/fb0, we can disable it via blank echo 4 > /sys/class/graphics/fb0/blank (but I am not able to find any control for the backlight), and the touchscreen is /dev/input/event0.

It is likely that we can similarly use the buzzer to make noises if needed, but I have not investigated it further.

consp commented 4 months ago

As I documented in a different discussion

Is this public?

It is likely that we can similarly use the buzzer to make noises if needed, but I have not investigated it further.

# echo 1 > enable
# echo 0 > enable
# pwd
/sys/class/pwm/pwmchip0/pwm6

duty_cycle and period are relevant

note: earplugs might be required.

The play command simply modifies those.

KaruroChori commented 4 months ago

No, I don't think it is, but I just reported any piece of information I was able to find out :).

Nice to know we can have the buzzer working as well. Ideally it can be used to signal a finished print, the filament snapping or other hardware issues. Or to output the doom soundtrack.

consp commented 4 months ago

Or to output the doom soundtrack

Why stop at the soundtrack?

KaruroChori commented 4 months ago

We also have many motors. We can disable microstepping and interpolation and go polyphonic.

Why stop at the soundtrack?

:laughing:

xblax commented 4 months ago

@consp @khayrulinnikita I invited you to the mod repo. I believe most safety issues are already resolved with installing, so probably it should become public soon. If you install the last build, update the printer configs from git before using it.

I will start a discussion there sometime later this weekend if anything else should be resolved before making it public.

Regarding the buzzer: you can look at the 'play' executable from Flashforge. I thing it uses multiple GPIOs for polyphonic tones. In Ghidra I could see that the program already has some tunes built-in ( I think it was Bethoven )

consp commented 4 months ago

I think it was Bethoven

tune_error
tune_startup
tune_print_done
tune_makerbot_tv
tune_beethoven_5th
tune_filament_start
tune_pause
tune_sailfish_startup
xblax commented 4 months ago

Running X will be a stretch, klipperscreen is designed for hardware an order of magnitude faster (ok, not that much but you get the idea). Anything which uses a bitmapped framebuffer might work. Afaik the application (firmwareExe) is a Qt4.8.6 applet outputting to the fb with the qt embedded display driver, from what I can tell with a quick look.

The device is a simple 800x960 pixel framebuffer so no technical limitations there. Should be doable (at least if gives nice noise when doing dd if=/dev/urandom bs=1 count=3072000 > /dev/fb0)

The actual display is a bit smaller, i think it was 800x480. But you can png to framebuffer image like this

convert -size 800x960 xc:none $img -geometry +0+0 -composite -depth 8 bgra:- | xz -c > "./fb/$(basename $img .png).img.xz"
consp commented 4 months ago

The actual display is a bit smaller

Yes, see below (480x800), it's double buffer. Doesn't really matter, you don't need the double buffer anyways with the low framerate.

[INFO]1970/01/01 00:00:15 set QT_QPA_PLATFORM: linuxfb:tty=/dev/fb0:size=480x800:mmsize=115x170:offset=0 success
Ross922 commented 4 months ago

Forgive my ignorance but do you think its possible a company like BTT will come out with a new MB for the 5M Pro if it gains enough traction? That way the weak cpu and MB package can be bypassed etc? Note: I am not familiar with what it takes to put klipper onto this machine nor root and mod for klipper to work on the stock HW, im just asking what is likely an uninformed general question :-)

I don’t think so, only if in an official collab. The stock CPU is enough to run clipper + moonraker + mainsale + fluidd. There are also hopes that it will be enough to run clipperscreen, then we will get a full-fledged printer

Just imagine this HW on a Rpi3+/4 and a good MB... I got the pro for $439 on Amazon for the ASA capability given the continued issues with K1-series reviews and a recall on my Bambu A1 left me without a printer haha.

g992 commented 4 months ago

Just imagine this HW on a Rpi3+/4 and a good MB... I got the pro for $439 on Amazon for the ASA capability given the continued issues with K1-series reviews and a recall on my Bambu A1 left me without a printer haha.

if u have tablet, stock hw is awesome, i use only web interface to control printer

jtenniswood commented 4 months ago

I just got my 5M, amazing machine, would love to help test.

consp commented 4 months ago

Running X will be a stretch

Boy was I wrong.

Got X going with GTK3 (and thus GL) and touch. Not working perfectly as expected but the gtk3-demo app runs, albite a bit compressed image wise and some issues with the default touch settings. It needs refinement. KlipperScreen might just work (if we can keep the memory hogging down).

Not even close to public ready so wait a while but there is hope.

Also: no real music, pretty much 8086 PC speaker sounds only and very limited at that. If you spam the pwm driver too much it will just drop dead and ignore you (yes I tried playing the doom music at about 10sample/sec, it stops after about 1s and sounds horrible).

KaruroChori commented 4 months ago

Too bad. At least we can use the speaker to make sound effects and use the stepper motors for the soundtrack :D.

Sunflex616 commented 4 months ago

@xblax don't wanna be THAT guy but are there any updates regarding an ETA for going public? If not I'd really appreciate if I could be added to the repo as well :)

consp commented 4 months ago

Also: no real music, pretty much 8086 PC speaker sounds only and very limited at that. If you spam the pwm driver too much it will just drop dead and ignore you (yes I tried playing the doom music at about 10sample/sec, it stops after about 1s and sounds horrible).

Wrong again, though it's stil very limited and definitely not production ready.

https://github.com/g992/flashforge-ad5m-5mpro-research/assets/6802998/180bec5b-8110-4c68-80f5-921450cad6ca

I'll know it's good enough when there is a copyright strike.

Ross922 commented 4 months ago

Found this on my recommended: https://www.reddit.com/r/FlashForge/comments/1b1vjgk/klipperscreen_running_on_ad5m/

KaruroChori commented 4 months ago

It is the same person before your post.

consp commented 4 months ago

It is the same person before your post.

Internet always goes full circle.

Ross922 commented 4 months ago

It is the same person before your post.

Oh haha... their video clip is showing as 0:00/0:00 for me... no video available... my bad :P

consp commented 4 months ago

It is the same person before your post.

Oh haha... their video clip is showing as 0:00/0:00 for me... no video available... my bad :P

Might be since it was posted in a private repo first. Has been fixed

jtenniswood commented 4 months ago

How's the working going? I'm excited to see klipper running on my new 5M.

consp commented 4 months ago

How's the working going?

No headcrashes yet, so if you consider that good news then it's going great. Currently running a 3h print and monitoring, let's see how it goes. The goal is to get most of the "you can destroy your printer with it" stuff out of the way.