Skip to content

SAMD21: Compiling

Paciente8159 edited this page Apr 17, 2023 · 5 revisions

µCNC for SAMD21can be built this way

Method one - PlatformIO (preferred)

  1. Get Visual Studio Code and install it.
  2. Install the PlatformIO extension.
  3. Open uCNC folder in VSCode.
  4. Edit cnc_config.h file and cnc_hal_config.h file to fit your needs and board.
  5. f needed edit the platformio.ini file environment for your board. Compile the sketch and upload it to your board.

Method two - Arduino IDE (easiest)

WARNING: Arduino IDE will produce a larger output file. The makefile method has better compilation optimizations that produce a smaller binary file.

  1. Get Arduino IDE and install it.
  2. If you are using µCNC v1.6 or newer you also have to add the tinyUSB library for µCNC. Download the latest zipped version form here and on Arduino IDE add the library by going to Sketch>Include Library>Add .ZIP library
  3. If you don't have install Arduino SAM boards via board manager
  4. Go to uCNC folder and open uCNC.ino sketch.
  5. Edit cnc_config.h file and cnc_hal_config.h file to fit your needs and board.
  6. Compile the sketch and upload it to your board.

Method three - Using the makefile (optimized binary alternative)

  1. Download and install GCC tools for ARM inside your PC. You can download the latest version of GCC tool for ARM from here.
    • If your are compiling with this method on a Windows machine you will also need to install Make. You can download Make for Windows from here and CoreUtils here.
  2. Go to the uCNC folder and edit the board cnc_config.h file if you need to select a different ARM board. µCNC is configured by default to mimic Grbl pin configuration in the Arduino UNO board.
  3. If your board has/doesn't have a bootloader then the linker script samd21.ld file must be modified too. By default the firmware will be loaded to address 0x2000. This is modified in line 14 of the file (the ORIGIN parameter must be adjusted, LENGTH parameter can be left unchanged). FLASH (rx) : ORIGIN = 0x00002000, LENGTH = 248K
  4. Open a command console inside makefiles/samd21 folder and run make clean all
  5. If everything went well you should have a hex file inside makefiles/samd21/build folder.
  6. Now just upload µCNC to your board using an appropriate tool and programmer. I use BOSSA to upload the firmware via bootloader. DO NOT FORGET TO SET THE PROPER OFFSET FOR YOUR BOARD OR YOU WILL ERASE THE BOOTLOADER