Skip to content

Latest commit

 

History

History
82 lines (65 loc) · 5.08 KB

File metadata and controls

82 lines (65 loc) · 5.08 KB

Building the firmware

⚠️ Use CubeIDE 1.12.1! ⚠️

Newer versions (Currently 1.13.0) are causing lots of issues.
Neither the firmware or the Build script work properly.
Until the issues are addressed up, keep using 1.12.1.

Video of building steps:
IMAGE ALT TEXT

First of all, download and install STM32CubeIDE.
Clone or download the source from this repository.
The source is stripped from ST own libraries and unnecessary stuff, only includes the very basic code owning to the project.
CubeMX will add the STM32 and CMSIS libraries automatically after a code generation.

There's a new automated build script for Windows (Building_script.bat) that allows a simple and fast way of copying and building the desired profile.
With it, all you need is to have CubeIDE installed in C:\ST (It's the default installation folder), it will search and execute the tools without requiring any user intervention.
JDK is no longer required, as I recently discovered CubeIDE packs its own.
Just open it, choose your profile, then select whether you want to only copy the files, run CubeMX (Generate the libraries) and/or compile the firmware.
After compiling, the binaries will be placed in their respective BOARDS/... folders.





If the build fails for no reason (No changes were made to the source), or CubeIDE complains about the project already existing the workspace (While it's not), try deleting this folder:

C:\Users\YOUR_USER\STM32CubeIDE\workspace_1.12.1\.metadata

If you want to build it within CubeIDE, first run Building_script.bat, choose your profile and select Copy files / Run CubeMX.
Open STM32CUBE IDE, click on Import/Existing project and select the project folder.
Disable "Search for nested projects", select only the project at the root of the folder.
After this, it'll be ready for compiling, click in the right arrow of the build button (Hammer icon) and select [Release]:


After a while you'll have the compiled bin/hex files inside Release folder.

If you want to modify the hardware initialization, double-click on [STM32SolderingStation.ioc] file:


CubeMX will open. Make you changes, then run code generation:


If the build fails with files no found or undeclared functions errors, check the Include search path:
Right click on project -> [Properties] -> [C/C++ Build] -> [Settings] -> [Tool Settings] -> [MCU GCC Compiler] -> [Include paths]
Select [All configurations] in [Configuration] dropdown menu.
Now ensure these are present:

  /Core/Inc
  /Core/Src
  /Drivers/generalIO
  /Drivers/graphics
  /Drivers/graphics/gui
  /Drivers/graphics/gui/screens
  /Drivers/graphics/u8g2
  /Drivers/STM32Fxxx_HAL_Driver/Inc
  /Drivers/STM32Fxxx_HAL_Driver/Inc/Legacy
  /Drivers/CMSIS/Device/ST/STM32Fxxx/Include
  /Drivers/CMSIS/Include

(STM32Fxxx matches your current mcu family, ex. STM32F0xx, STM32F1xx)

If any is missing, click on Add... Select Workspace and select the missing ones.
You can make multiple selection while holding the Control key:

At some point, the firmware might not fit into the flash when compiling for debugging, as running without optimizations will use a lot more space.
In that case, you'll need to force some optimization level, starting with "Optimize for debug" (Og), and going to higher levels if still being too big (O1, O2, Osize).
The settings can be changed in project Properties / Build / Settings / MCU GCC Compiler / Optimizations.
However, when debugging, it's desirable to completely disable optimizations to see the program flow clearly.
If you had to enable any level of global optimizations, you can still selectively disable build optimizations for any function, making debugging easier.
A line of code can be found at the start of main.h:

__attribute__((optimize("O0")))

Copy that line before a function to disable optimization, like this:

__attribute__((optimize("O0"))) void ThisFunctionWillNotBeOptimized(...)

If you want to retarget the project, avoid mixing different profile files, run Building_script.bat again so it cleans the project and copies the new files.

If you use an existing project template and modify it, the changes must be reflected in /Core/Inc/board.h.
All the project code takes the data from there. The file it's pretty much self-explaining.
So, any changes you make in CubeMX, ex. use PWM timer6 intead timer2, or SPI1 instead SPI2...all that should be configured in their respective define.
As long as the GPIO names are called the same way, no further changes are needed.