Skip to content

AVR: Compiling

Paciente8159 edited this page Nov 21, 2024 · 9 revisions

µCNC for AVR can be built in a several ways

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. With that in mind remember that some options can be activated using the makefile and others won't fit the device flash in Arduino IDE (UNO is already near max capabilities).

  1. Get Arduino IDE and install it.
  2. Go to uCNC folder and open uCNC.ino sketch.
  3. Edit cnc_config.h file and cnc_hal_config.h file to fit your needs and board.
  4. Compile the sketch and upload it to your board.

Method three - Using the makefile (optimized alternative)

  1. Download and install GCC tools for AVR inside your PC. You can download the latest version of GCC tool for AVR from Microchip 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 and cnc_hal_config.h file to fit your needs and board. µCNC is configured by default to mimic Grbl pin configuration in the Arduino UNO board.
  3. Go to the makefiles/avr folder.
    • The makefile is configured by default to compile the code for the MCU (atmega328p) and working frequency (16Mhz) in Arduino UNO board. If the chosen board has a different MCU/working frequency the makefile must be adjusted by modifying CPU = atmega328p and FREQ = 16000000UL
  4. Open a command console inside makefiles/avr folder and run make clean all
  5. If everything went well you should have a hex file inside makefiles/avr/build folder
  6. Now just upload µCNC to your board using an appropriate tool. xLoader for AVR is an easy tool to use.

Aditional Notes

Several UNO boards (including Mini and Nano variants) have been seen with some variants of the Atmega328P chip. Some boards come with Atmega328P others with Atmega328P(U/A/B) variants. Also some these chips have been fitted with the Urboot bootloader (instead of the original Arduino bootloader). They are not interchangeable as frequently you will get signature errors and byte mismatching errors during verification and programming You may need to adjust the board base config (extends = ) to match the flavor of your board.

By default the UNO board configs (UNO, Shield V3, etc..) are configured to use Arduino bootloader. For example:

[env:AVR-UNO]
extends = avr_arduino
build_flags = ${common_avr.build_flags} -D BOARD=\"src/hal/boards/avr/boardmap_uno.h\"

If your board has a MCU not supported by Arduino IDE you need to use the MiniCore version (for example the Atmega328PU). For this example this can be done like this.

[env:AVR-UNO]
extends = avr_minicore
board = Atmega328PB
build_flags = ${common_avr.build_flags} -D BOARD=\"src/hal/boards/avr/boardmap_uno.h\"