Porting Marlin to STM32.

What are you developing?
victor_pv
Posts: 1868
Joined: Mon Apr 27, 2015 12:12 pm

Porting Marlin to STM32.

Post by victor_pv » Thu Jun 29, 2017 4:39 pm

UPDATED 10/26/2017:
In the last 2 days xC000005 and me have completed successful prints with Marlin for STM32F1, with the stm32duino-libmaple core, he printed a cat, and I printed a little Yoda-Budha.
During tests I was able to get about 50000khz pulses as max speed, which seems inline with other 32 bit platforms, and much faster than most printers should ever need. Which means at slower rates we have quite a few CPU cycles left to do other things.
We haven't start with the LCD parts, but so far ADC, steppers and sdcard work, so printing from a computer is fully functional.


UPDATED 07/07/2017:
First version of my port to libmaple based cores. Should work on an F4 too, but so far I have just tested it with the F1, and only that it runs and there is serial communication, but not the steppers driving or the SDCard.
Compiled with Sloeber 4.1 and gcc 4.8.3. Should compile in the Arduino IDE but not tested.
I have tested it with an RCT6 MCU, but should fit fine in a maple mini as far as RAM and Flash
https://github.com/victorpv/Marlin-STM32-libmaple

==============================
Original post.

I'm starting this new thread to document the effort of porting Marlin to stm32 arduino cores.
-Shield with stepper connections etc, RAMPS can be modified: -Boards: too many to list
  • My effort will go first to libmaple. Chriss Bar has a version based on STM32GENERIC core. Both cores work on some F1, F3 and F4 MCUs
-Software:
There are at least 2 ports running in STM32. My plan:
Take Chriss code and make it compile in sloeber.
Once so, take it to Danieleff core, and make it compile and resolve any issue.
Test it with a Nucleo board and generic boards.
Add HAL for libmaple core

All the above should be feasible from a first look at the code.
We already have:
-Arduino compatible pin functions.
-Arduino compatible spi functions.
-Arduino compatible ADC functions (with more resolution, may need to trim)
-PWM functions (even if with some different parameters and setup than Arduino, still same functionality or more)

What needs to be done:
-Go thru each file in the HAL and modify/optimize for stm (just a few things)
Stepper control
Temperature probes and hotbed control
Memory usage.
Pin access.
Timers setup and usage.
Last edited by victor_pv on Fri Jul 07, 2017 11:27 pm, edited 3 times in total.

User avatar
ahull
Posts: 1730
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Porting Marlin to STM32.

Post by ahull » Thu Jun 29, 2017 4:45 pm

Hi. This might provide the motivation I need to start constructing a 3D printer from scratch, which is a project I have been meaning to undertake for a while.

Do you envisage this being doable with say a bluepill or MM, a hand full of ebay stepper motors and stepper driver boards?
- Andy Hull -

victor_pv
Posts: 1868
Joined: Mon Apr 27, 2015 12:12 pm

Re: Porting Marlin to STM32.

Post by victor_pv » Thu Jun 29, 2017 6:45 pm

ahull wrote:
Thu Jun 29, 2017 4:45 pm
Hi. This might provide the motivation I need to start constructing a 3D printer from scratch, which is a project I have been meaning to undertake for a while.

Do you envisage this being doable with say a bluepill or MM, a hand full of ebay stepper motors and stepper driver boards?
I haven't done a pin count, but I think a maple mini will most likely do, at least for a printer with 1 extruder and 3 axis.
Quick pin count:
4 steppers, 2 pins each, 8 pins.
Bed heater and thermistor: 2 pins. (1 ADC + 1 PWM)
Extruder heater and thermistor: 2 pins (1 ADC + 1 PWM)
SD card if needed 4-5 pins (don't remember of the top of my head).
Display: There are several options, I think common ones take 4-6 pins.
USB port: 2 pins
Optional: serial, connected to wifi printer bridge, 2 pins.

All this run in an AVR, I dont see how it wouldn't run in a mini as far as RAM and Flash.

Optional hardware not critical to have:
-Rather than use a bunch of pins for an LCD, use the same SPI as the card and 1 extra CS pin, but this would involve writing an LCD interface.
-Serial not needed, but would be nice to connect an ESP8266 programmed with this (I have compiled and uploaded it with Eclipse/Sloeber successfully):
https://github.com/luc-github/ESP3D
-Sd card interface: You can instead print from the host. I actually never connected my printer to a host, ever, just print with the sd card so I dont have to keep a host connected for a 4 hour print.

User avatar
ahull
Posts: 1730
Joined: Mon Apr 27, 2015 11:04 pm
Location: Sunny Scotland
Contact:

Re: Porting Marlin to STM32.

Post by ahull » Thu Jun 29, 2017 7:26 pm

Sounds doable, don't forget, we get USB serial on a MM or Bluepill which you don't get on an AVR.
I think this sounds like a pretty useful idea.
- Andy Hull -

victor_pv
Posts: 1868
Joined: Mon Apr 27, 2015 12:12 pm

Re: Porting Marlin to STM32.

Post by victor_pv » Thu Jun 29, 2017 9:18 pm

ahull wrote:
Thu Jun 29, 2017 7:26 pm
Sounds doable, don't forget, we get USB serial on a MM or Bluepill which you don't get on an AVR.
I think this sounds like a pretty useful idea.
I think so. Not only doable, but we should end up with a nice controller, and using an RET6 MCU we should have ram and pins to spare for any expansion, but even the CB ones should fit the current Marlin.
Do you want to help spread the load?
I recently bought a 3d printer for my kids, which I am enjoying much more than then, specially building it up, so I can give you some advise on parts and what not.
EDIT:
From reprap.org
Firmware binary size between around 50 kB and 100 kB, depending on options.

victor_pv
Posts: 1868
Joined: Mon Apr 27, 2015 12:12 pm

Re: Porting Marlin to STM32.

Post by victor_pv » Fri Jun 30, 2017 4:00 am

I did a pin count and with a maple mini we should have enought pins for the following:
  • sd card
    sd card detection switch
    serial 1
    USB
    3 axis steppers
    3 extruder steppers (or any conbination of the 6, such as 4 axis and 2 extruders
    3 extruders temp probes
    3 extruders heaters
    bed temp probe
    bed steppers
    2 CS pins for SPI, for sdcard and a display
    1 pin left (could be used as CS for a touch panel in SPI)
    PB2 and PB8 not used (can be used as outputs once the mcu is booted, so we should be able to use them)
I haven't looked in detail to all the peripherals needed, but I think we have enough timers,and definitely enough PWM pins.

ag123
Posts: 854
Joined: Thu Jul 21, 2016 4:24 pm

Re: Porting Marlin to STM32.

Post by ag123 » Fri Jun 30, 2017 5:54 am

ahull wrote:
Thu Jun 29, 2017 4:45 pm
Hi. This might provide the motivation I need to start constructing a 3D printer from scratch, which is a project I have been meaning to undertake for a while.

Do you envisage this being doable with say a bluepill or MM, a hand full of ebay stepper motors and stepper driver boards?
imho a simplier approach is to buy one of those cheap 3d printer kit and later swap the controller board
i've been contemplating creating a delta-3d from scratch but later find that it would be too much efforts to create the individual components to the precise dimensions and the total costs of purchasing the parts say from ebay actually exceeds that of buying a kit which these days go for $200 and even below.

some of those things has been discussed in this thread
http://www.stm32duino.com/viewtopic.php?f=45&t=2082

my thoughts are that we should perhaps target the f407vet6 or zet6,zgt6 board directly rather than stick with stm32f103 (though it is a possibility as well). the main thing is that m4 (f407) has 2 fpu in the cores and that would significantly speed up path computations and of course the f407vet boards has a good number of gpio pins to do all that interfacing and has a good amount of sram and flash to play with. in addition a good number of those f4 boards from ebay has that micro sd card slot built on board which is an additional convenience
for stm32f103 the 'common' boards apparently are blue pills & maple mini while for the bigger boards e.g. vet and zet, the price differential pull so narrow compared (some priced same or higher) to say f407vet6 black. it would literally make sense to simply get f407 boards directly in that case given the much higher performance

with f407 i'd even envision that one day it may be possible to simply send it an 'STL' 3d model file, the f407 do all that slicing & 3d print it on the fly! that's possible due to the fast fpu

ag123
Posts: 854
Joined: Thu Jul 21, 2016 4:24 pm

Re: Porting Marlin to STM32.

Post by ag123 » Fri Jun 30, 2017 6:06 am

we could also perhaps create a thread in marlin firmware forums so that interested individuals there could join the effort
http://forums.reprap.org/list.php?415
this thread would actually make sense to belong 'there' given it is about running Marlin on stm32
but the forumers there would likely be less familiar with available stm32 boards and features 'out there' and its 'technicalities' compared to us here
we could also get various tips / from the '3d printing people' as beyond just the electricals / electronics. 3d printing is really a domain on its own
things like dealing with bed leveling, extrusion speed, head movements acceleration / deceleration, delta 3d movements, types of materials and the 3d printing problems etc are really quite specialised domains of knowledge which the '3d printing experts' are probably familiar with

the other idea is to start with RAMPS
http://reprap.org/wiki/Arduino_Mega_Pololu_Shield
as the interface board as this board and the pololu motor control socket modules is actually sold on ebay and readily available (decently low costs as well)

ag123
Posts: 854
Joined: Thu Jul 21, 2016 4:24 pm

Re: Porting Marlin to STM32.

Post by ag123 » Fri Jun 30, 2017 6:28 am

victor_pv wrote:
Fri Jun 30, 2017 4:00 am
I did a pin count and with a maple mini we should have enought pins for the following:
  • sd card
    sd card detection switch
    serial 1
    USB
    3 axis steppers
    3 extruder steppers (or any conbination of the 6, such as 4 axis and 2 extruders
    3 extruders temp probes
    3 extruders heaters
    bed temp probe
    bed steppers
    2 CS pins for SPI, for sdcard and a display
    1 pin left (could be used as CS for a touch panel in SPI)
    PB2 and PB8 not used (can be used as outputs once the mcu is booted, so we should be able to use them)
I haven't looked in detail to all the peripherals needed, but I think we have enough timers,and definitely enough PWM pins.
there could be up to 6 end stops (limit switches) in addition, if we use 1 gpio pin for each, that alone takes 6 pins
and more than likely we'd still want to interface our ILI9341 LCD display, i think the total pin count considering all that would lead us to run out of pins on blue pill or maple mini

racemaniac
Posts: 699
Joined: Sat Nov 07, 2015 9:09 am

Re: Porting Marlin to STM32.

Post by racemaniac » Fri Jun 30, 2017 7:02 am

would we then want to go for a bigger board? or go for 2 bluepills/maple minis and have one be a slave of the other (i can imagine on the main board to just initiate a circular dma spi communication with the slave via DMA, so the slave keeps transmitting a region of its memory (containing limitswitches/temp probes/ other easy things to share) to the master, solving the pin count problem :)

Post Reply