STM32Fx: Compiling - Paciente8159/uCNC GitHub Wiki

µCNC for STM32F1x/STM32F4x can be built this way

IMPORTANT NOTE

On version 1.6.1 and newer, MCU variants compatibility was improved. But in some cases, there is and important setting that you might need to add, to make it work on your board, and that is the size of the Flash memory.

For example some Bluepill variants have 64Kb, but they share the same library file of the 128Kb version. By default compilation is done with the flash size specified in these libraries. And that might actually not be the case of your board.

The 64k firmware version will work on the 128k MCU but not the other way around.

Also keep in mind that if you add extra modules, and the final binary extends to a region were the emulated EEPROM overlaps, you will overwrite the firmware and have all kinds of issues.

I strongly advise to use the ENABLE_EXTRA_SYSTEM_CMDS option to control EEPROM write/erase calls.

Flash size can be defined by simply adding the definition in cnc_config.h file or in the case of PlatformIO add the build flag needed

On cnc_config.h file simply add a line with the FLASH_SIZE size in bytes

// for example for 64kb in hexadecimal
#define FLASH_SIZE 0x10000

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 STM32duino with Arduino board manager has explained here
  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 (via maple bootloader or other method).

Notes: Your board should have USART and USB support options disabled. µCNC takes care of these by it's own.

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 and cnc_hal_config.h file if you need to select a different ARM board or different functionalities. µCNC is configured by default to mimic Grbl pin configuration in the Arduino UNO board.
  3. Open a command console inside makefiles/stm32f1x / makefiles/stm32f4x folder and run make clean all
  4. If everything went well you should have a hex file inside makefiles/stm32f1x/build / makefiles/stm32f4x/buildfolder.
  5. Now just upload µCNC to your board using an appropriate tool and programmer.