mitxela.com forum
Welcome. Please log in or register.

Compiling Precision Clock Mk IV
julian Posted: 4 Jul 2025, 02:02 PM
Avatar


Member
Posts: 3
Joined: 3-July 25
Hi,

I'm trying to document the way on how to import the source code for the clock4 in STM32CubeIDE, as it was not that straight forward.
This was all on done on a Fedora machine and might work differently on other systems.

# Get the code
git clone https://github.com/mitxela/clock4

# Get and install STM32CubeIDE, I choose the -RPM variant (I used latest, as of now: 1.18.1)
https://www.st.com/en/development-tools/stm32cubeide.html

# Create and login for STM32Cube updates, you need to setup a "myST" account for this
Help -> STM32Cube updates -> Connection to myST

# Import the project with this:
File -> Import -> General -> Existing Projects into Workspace

(User posted image)


Now comes the interesting part as at least I could not build the project yet.
(The next steps are just for the mk4-time project)

What I found out works is: Double-click on the .ioc file, the following dialog should pop-up:

(User posted image)


I choosed continue to stay with the same version

Then: Project -> Generate Code
It will download additional software packages (therefore the need for the myST account)

Now you should finally be able to see two build configurations:
Project -> Build Configurations -> Set Active (should show Debug and Release)

But not so fast, back to the cmdline and check any changes with git status mk4-time:


Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .mxproject
modified: .settings/stm32cubeide.project.prefs
modified: Core/Inc/stm32l4xx_hal_conf.h
modified: Core/Src/main.c
modified: FATFS/App/fatfs.c
modified: FATFS/App/fatfs.h
modified: Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h
modified: Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c
modified: Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c
modified: Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c
modified: Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
modified: Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
modified: STM32L476RGTX_FLASH.ld
modified: USB_DEVICE/App/usb_device.c
modified: USB_DEVICE/App/usbd_desc.c
modified: USB_DEVICE/Target/usbd_conf.c
modified: USB_DEVICE/Target/usbd_conf.h
modified: mk4-time.ioc

Untracked files:
(use "git add <file>..." to include in what will be committed)
STM32L476RGTX_RAM.ld

no changes added to commit (use "git add" and/or "git commit -a")


Some changes are expected:
.mxproject has changed path separators and changed paths to header files, that seems ok.
But there are also modifications to the application code, a new file (STM32L476RGTX_RAM.ld) etc. so I decided to revert these changes like this:


git restore mk4-time/Core/Inc/stm32l4xx_hal_conf.h mk4-time/Core/Src/main.c mk4-time/FATFS/App/fatfs.c mk4-time/FATFS/App/fatfs.h mk4-time/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h mk4-time/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc.c mk4-time/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_bot.c mk4-time/Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Src/usbd_msc_scsi.c mk4-time/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h mk4-time/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c mk4-time/STM32L476RGTX_FLASH.ld mk4-time/USB_DEVICE/App/usb_device.c mk4-time/USB_DEVICE/App/usbd_desc.c mk4-time/USB_DEVICE/Target/usbd_conf.h mk4-time/USB_DEVICE/Target/usbd_conf.c


and delete the new file:
rm mk4-time/STM32L476RGTX_RAM.ld

You should only see these three files as modified:

modified: mk4-time/.mxproject
modified: mk4-time/.settings/stm32cubeide.project.prefs
modified: mk4-time/mk4-time.ioc


With that I hit "Build Project":


...
15:30:41 **** Incremental Build of configuration Debug for project mk4-time ****
make -j12 all
arm-none-eabi-gcc "../USB_DEVICE/Target/usbd_conf.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DDEBUG -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -DSTM32L476xx -c -I../FATFS/Target -I../FATFS/App -I../USB_DEVICE/App -I../USB_DEVICE/Target -I../Core/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc -I../Drivers/STM32L4xx_HAL_Driver/Inc/Legacy -I../Middlewares/Third_Party/FatFs/src -I../Middlewares/ST/STM32_USB_Device_Library/Core/Inc -I../Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc -I../Drivers/CMSIS/Device/ST/STM32L4xx/Include -I../Drivers/CMSIS/Include -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -fcyclomatic-complexity -MMD -MP -MF"USB_DEVICE/Target/usbd_conf.d" -MT"USB_DEVICE/Target/usbd_conf.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "USB_DEVICE/Target/usbd_conf.o"
...
In file included from ../USB_DEVICE/App/usbd_cdc_if.c:23:
../USB_DEVICE/App/usbd_cdc_if.h:31:10: fatal error: usbd_cdc.h: No such file or directory
31 | #include "usbd_cdc.h"
| ^~~~~~~~~~~~
compilation terminated.
make: *** [USB_DEVICE/App/subdir.mk:28: USB_DEVICE/App/usbd_cdc_if.o] Error 1
make: *** Waiting for unfinished jobs....
../USB_DEVICE/App/usb_device.c:27:10: fatal error: usbd_cdc.h: No such file or directory
27 | #include "usbd_cdc.h"
| ^~~~~~~~~~~~
compilation terminated.
../USB_DEVICE/Target/usbd_conf.c:27:10: fatal error: usbd_cdc.h: No such file or directory
27 | #include "usbd_cdc.h"
| ^~~~~~~~~~~~
compilation terminated.
make: *** [USB_DEVICE/App/subdir.mk:28: USB_DEVICE/App/usb_device.o] Error 1
make: *** [USB_DEVICE/Target/subdir.mk:19: USB_DEVICE/Target/usbd_conf.o] Error 1
In file included from ../USB_DEVICE/App/usbd_storage_if.h:31,
from ../USB_DEVICE/App/usbd_storage_if.c:23:
../Middlewares/ST/STM32_USB_Device_Library/Class/MSC/Inc/usbd_msc.h:62:10: fatal error: usbd_msc_cdc.h: No such file or directory
62 | #include "usbd_msc_cdc.h"
| ^~~~~~~~~~~~~~~~
compilation terminated.
make: *** [USB_DEVICE/App/subdir.mk:28: USB_DEVICE/App/usbd_storage_if.o] Error 1
../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c: In function 'USBD_GetDescriptor':
../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c:434:14: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
434 | pbuf = pdev->pClass->GetHSConfigDescriptor(&len);
| ^
../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c:439:14: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
439 | pbuf = pdev->pClass->GetFSConfigDescriptor(&len);
| ^
../Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c:553:14: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
553 | pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
| ^
"make -j12 all" terminated with exit code 2. Build might be incomplete.

15:30:41 Build Failed. 9 errors, 3 warnings. (took 441ms)
...


I added the missing include path with right-click and Add/remove include path...
I also needed to add MSC_CDC/Inc.

(User posted image)


With that I was left with this:


../Core/Src/sysmem.c:38:1: error: unknown type name 'caddr_t'
38 | caddr_t _sbrk(int incr)
| ^~~~~~~
../Core/Src/sysmem.c: In function '_sbrk':
../Core/Src/sysmem.c:51:25: error: 'caddr_t' undeclared (first use in this function)
51 | return (caddr_t) -1;
| ^~~~~~~


Fixed with https://community.st.com/t5/stm32cubeide-mcus/core-src-sysmem-c-38-1-error-unknown-type-name-caddr-t/td-p/56309

Which I solved by adding that include:

diff --git a/mk4-time/Core/Src/sysmem.c b/mk4-time/Core/Src/sysmem.c
index 4665417..ba110ef 100644
--- a/mk4-time/Core/Src/sysmem.c
+++ b/mk4-time/Core/Src/sysmem.c
@@ -24,6 +24,7 @@
/* Includes */
#include <errno.h>
#include <stdio.h>
+#include <sys/types.h>

/* Variables */
extern int errno;


And with that, finally:


Finished building target: mk4-time.elf

arm-none-eabi-size mk4-time.elf
arm-none-eabi-objdump -h -S mk4-time.elf > "mk4-time.list"
text data bss dec hex filename
125376 952 22064 148392 243a8 mk4-time.elf
Finished building: default.size.stdout

Finished building: mk4-time.list

15:35:49 Build Finished. 0 errors, 1 warnings. (took 589ms)


Is there a better way of doing it, first time using STM32CubeIDE.
Hope it helps if someone else wants to experiment with it.


-------------
[top]
mit Posted: 4 Jul 2025, 03:59 PM
Avatar
yeah whatever

Admin
Posts: 625
Joined: 4-May 16
Wow, I am sorry about that - it is definitely not supposed to be that difficult. The whole reason for sticking with their stupid IDE was to make it easier for people to set up the toolchain.

There are a few things here, mostly my fault, let's break it down.

I have stubbornly refused to get a "myST" account, they only started enforcing that recently and it's awful. You can still manually acquire the files and add them via Help > Manage embedded software packages > from local. However all of the driver files are committed to the repo, so there is no reason to acquire any further files. Similarly, you definitely don't want to "Generate Code", the code is already there. I made a vague effort to have the .ioc match the project, but as you saw if it's generating new code especially with a different version of the firmware it's going to change a lot of files.

The intended way to compile is to go File > Open projects from filesystem, select the project and then click build.

(User posted image)

That should have been enough. I notice now that the build configuration is missing. That is my fault for adding them to the gitignore with this commit. If you check out just before that commit, the .cproject files are present and it will compile. I'll fix that shortly.

The second problem you encountered is apparently to do with compiling with a different toolchain. It's possible to select a specific toolchain under project > properties > C/C++ build > settings > MCU/MPU Toolchain. I didn't realise that this was saved to the "workspace" by default instead of to the project.

(User posted image)

The Toolchain Manager doesn't require a log-in, but it also is so glitchy that I couldn't get it to properly install different versions, so it's probably not worth bothering with. The fix you posted of that extra include is probably best.

I'll commit these changes momentarily. Again, sorry you had to go through that!

I have a strong impulse to just abandon STM32CubeIDE and go back to makefiles...





-------------
[top]
julian Posted: 4 Jul 2025, 05:27 PM
Avatar


Member
Posts: 3
Joined: 3-July 25
Thank you for your reply, as I suspected sth. was missing, but hey, in the end it worked out for me.
I also don't get it why so many vendor IDEs are...suboptimal.
If I find some time I'll have a look at some other options.

The documentation of every other aspect of this project is just outstanding, I can't imagine how much effort went into it. Building the kit was almost too easy.

-------------
[top]
julian Posted: 5 Jul 2025, 07:54 AM
Avatar


Member
Posts: 3
Joined: 3-July 25
I just tried latest commit, all looking good, none of my extra steps needed.
Thanks so much!

-------------
[top]

Sign in to post a reply.