Compiling Marlin

(This is a work in progress and isn't complete)

### Preparation:

Create a folder where you are going to store the source of marlin firmware and the configuration (example on windows create a folder c:\Source\Marlin)

Open your favorite terminal or command prompt and go to your newly created folder with the following command (all the commands are for Windows users):

```
cd c:\Source\Marlin

```
Now we are going to "clone" the main Marlin repository and Marlin configuration repository to your folder:

```
git clone https://github.com/MarlinFirmware/Marlin.git
git clone https://github.com/MarlinFirmware/Configurations.git

```

Now you have to choose if you want the bleeding edge(could have problems but you will have more functionality) Marlin firmware or the more stable Marlin firmware(has less bugs but also less functionality)

#### Stable:

Go to Marlin releases and find the latest version (at the moment of writing it's 2.0.7.2)

```
cd Configurations
git checkout <version number>

```

#### Bleeding edge:

```
cd Marlin
git checkout bugfix-2.0.x
cd ..
cd Configurations
git checkout bugfix-2.0.x

```

### Configuration

Go to the C:\Source\Marlin\Configurations\config\examples folder and search for your printer brand and type (and maybe board type)
Copy all the \*.h files to C:\Source\Marlin\Marlin\Marlin (overwrite any existing files)

Edit Configuration.h and Configuration\_adv.h to your needs (if you have a stock printer you probably don't need to change anything)

(following step is only necessary if you don't use Auto Build Marlin)

The last edit is to select the environment and I will explain you in a few steps how to select and find the right environment for your printer:

1. Open the Configuration.h file and search for '#define MOTHERBOARD'
2. Take note of the board that is defined after '#define MOTHERBOARD'
3. Open the file Marlin/src/pins/pins.h
4. Search for the board you found after '#define MOTHERBOARD' without the BOARD\_
5. Take note of the env: text and copy everything after the :
6. Open the platformio.ini file and replace the default\_envs value with the value you just found

##### Example Creality 4.2.7 Board:

Configuration.h file:

```
#define MOTHERBOARD BOARD\_CREALITY\_V427

```
So copy CREALITY\_V427 and search for it in the pins.h file:

```
#elif MB(CREALITY\_V427)
 #include "stm32f1/pins\_CREALITY\_V427.h" // STM32F1 env:STM32F103RET6\_creality

```
Here you will find this and the environment is: 'STM32F103RET6\_creality' so the platformio.ini file will have that value as default\_envs:

```
default\_envs = STM32F103RET6\_creality

```

### Compiling

Now that you have copied and edited the files needed it's time to compile the firmware!

With Auto Build Marlin:

1. Open Visual Studio Code and click File => Open Folder and select the Marlin folder (not the Marlin Configurations folder)
2. Click on the M icon in the left bar
3. Show ABM Panel
4. In the Build tab click on Build
5. Click on the folder icon to open the folder with the compile firmware in it

Without Auto Build Marlin:

1. Open Visual Studio Code and click File => Open Folder and select the Marlin folder (not the Marlin Configurations folder)
2. If everything went right it should open the folder and after a few seconds you should see the Welcome to PlatformIO screen
3. Click on the checkmark in the bottom left corner:

### Uploading:

Uploading depends on which type off printer you have:

#### Ender 3 V2:

Uploading the new firmware to a Ender 3 V2 is pretty simple:

1. In the main Marlin folder go to following folder: .pio/build/[environment you found in the steps above]
2. This folder should contain a bin file with following name: firmware-todays date-the hour.bin
3. Copy this file onto a SD-card
4. Put the SD-card in to the printer and turn it on
5. The bootscreen should appear after several seconds
6. You have successfully flashed your printer!

If the bootscreen never appears you should format the SD-card in FAT32 with 4096 byte allocation and try again