Compiling Bootloader

Hello,

I am looking to compile the artekit stm32 bootloader. I read on another post that Eclipse CDT with the ARM Cortex Plugin compiles with GCC? Is there any particular instructions to go about this or things to watch for? Also i’m compiling for a STM32F405 instead of a STM32401, so I know about adjusting the pins for my particular setup. Anything else to be aware of?

Thank you.

Hello @5mc

We don’t have a tutorial for setting up the Eclipse environment but instructions can be easily found on Google by searching stm32 eclipse gcc.

Then you import the bootloader project directly from the IDE and you can compile it from there.

Thanks for the quick response. I will give it a try today and report back.

@Oluwadara_Olaifa @5mc

It seems the Ecplise project files for the bootloader were missing. I’ve just pushed them to Github. See here. You can copy the .project and .cproject files yourselves or clone/update the repository, which is what I recommend.

Then in Eclipse, right-click in your workspace and select Import. Then Existing Projects into Workspace. Browse to the project folder and select “Bootloader”. This will import the project into eclipse.

I tried this and it worked. I pressed ctrl + b and it just compiled.

Also, right-clicking project you can see the compiler settings, like flags and preprocessor so you can create your own project using alternative methods or newer IDEs. I know Eclipse was cool like 10 years ago when this project started but now there may be better IDEs.

If you want to build the bootloader for PropBoard or WaveTooEasy you need to change this value, between BOOTLOADER_PROPBOARD and BOOTLOADER_WAVETOOEASY.

I hope it helps.

The system clock is initialized by the bootloader, and that’s where the HSE_VALUE makes sense (if I recall correctly).

The UART in core files (UARTClass.cpp) is configured using the ST library (no direct handling of registers).

If you are not using the bootloader then you are going to initialize the clocks in the core files and that includes recompiling libstm32f4xx.a or including the files you need from the ST peripheral library.

The bootloader has its own copy of the stm32fxx library. The pre compiled library is just there for convenience since the core files are compiled with the Arduino IDE, which likes to rebuild everything often and that takes time.

The pre compiled library should have been compiled with the clock settings to run with a 10MHz quartz on an stm32f401. That includes HSE_VALUE and all PLL settings.

HSE_VALUE definition on core files it’s probably being ignored and I think it could be removed from compilation.

BRR settings on USARTs depend on PCLK frequency (PCLK2 for USART 1 and 6) and not directly from the system clock frequency. When configured correctly on our boards (PLL settings) PCLK2 runs at 84MHz, which is the max speed for APB2. I recommend you to use CubeMX to see the clock tree and get the right clock settings and values for your quartz.

Clocks are usually initialized by the very first lines of code, which in our boards is the bootloader. The bootloader calls SystemInit from startup_stm32f401xx.S. The possibility of skipping the bootloader is there, and doing that will call SystemInit from core files (which will point to the precompiled library at this point).

Long story short, you must either recompile the precompiled library, or you can modify how the core files are built and include your own stm32 library (sources, not precompiled).

I know it’s inconvenient but it just how the ST libraries are made. There should be a way to change the clock after but you don’t want to start up the system with the wrong settings. Also, HSE_VALUE is used for some peripheral settings like I2S.

I can check if there is project files for the precompiled library but I am not in the lab today.

If the bootloader initializes the clocks correctly and the UART works, then the UART should also work when opened by the core files (because core files don’t initialize the clocks, unless you comment WITH_BOOTLOADER). The UART source code in the ST library gets the clocks timings dynamically so it shouldn’t depend on fixed values (which is not the case of I2S because it does use HSE_VALUE).

The core doesn’t compile what’s inside system/stm32f4xx and uses the precompiled library for the reasons I said in my previous post. You can modify how the core is built to also compile system/stm32f4xx and use the clock settings you need.

@5mc

Please find the project files for libstm32f4xx here: https://github.com/Artekit/artekit_stm32f401-core/tree/master/system

Your clocks are off for some reason. Your system will misbehave.

PLL_N is set to 168 so I can divide it by 7 (PLL_Q) and get 48MHz for SDIO, otherwise you get 42MHz.

PLL_P is set to 4, so 168 / 4 = 84 / 2.

Regarding the LED timer: it uses TIM1 configured like this.

Change 42000 to a value that suits a 1ms timer in your system (I guess it’s the double).

This is true. PPLI2S_* values are configured in this function

The modification should work. I don’t know which core you are using (PropBoard or WaveTooEasy), so you have to modify the file of the correct core.

Regarding GPIO clocks, if the LED blinks, then the GPIO is clocked.

@5mc, sorry for the late reply.

I’m glad you found the issue.