Libopencm3 as sub module?

Hello everyone,
I have a question concerning the usage of the libopencm3 framework. I saw that libopencm3 offers a template repository that initializes the framework’s source files as git sub module whereas PlatformIO has some version included as .o files in the .pio/build folder of a newly created project.
To me it seems that the sub module method is the cleaner solution as the library can easily be cloned with the project and always has the same version. It can be updated in the git repository and as the source files themselves are included I can always have a look in the definition of the framework’s functions. I would also be able to use updates of the framework right after they have been merged.
PlatformIOs solution’s upsides are that it works without any configuration and might cause less problems later on (as it is the default and intended way of including the framework) and it doesn’t clutter the project’s git with library files.

My question(s):

  • Are there any up/downsides that I forgot about?
  • What do you see as the more elegant solution?
  • If you think that including libopencm3 as a sub module is more elegant, how would I configure the pio project to tell the compiler what to find where?

Thanks for your help,
Oskar

Can you link to that repo? Also no, the .pio folder is the folder in which compiled object files are put. libopencm3 is compiled from source. If you e.g. have a look at platform-ststm32/examples/libopencm3-blink at develop · platformio/platform-ststm32 · GitHub you will see that when compiling, it’s using the package framework-libopencm3, located in PlatformIO’s pacakge folder C:\Users\<user>\.platformio\packages\framework-libopencm3 usually.

Also see build log.

Processing nucleo_f103rb (platform: ststm32; framework: libopencm3; board: nucleo_f103rb)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/nucleo_f103rb.html
PLATFORM: ST STM32 (10.0.1) > ST Nucleo F103RB
HARDWARE: STM32F103RBT6 72MHz, 20KB RAM, 128KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, cmsis-dap, jlink)
PACKAGES:
 - framework-libopencm3 1.10000.200730 (1.0.0)
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\nucleo_f103rb\src\main.o
Generating linker script .pio\build\nucleo_f103rb\generated.stm32f103rb.ld
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\adc.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\adc_common_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\can.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\crc_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\dac_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\desig_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\desig_common_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\dma_common_l1f013.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\exti_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\flash.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\flash_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\flash_common_f.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\flash_common_f01.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\gpio.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\gpio_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\i2c_common_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\iwdg_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\pwr_common_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\rcc.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\rcc_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\rtc.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\spi_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\spi_common_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\f1\timer.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\timer_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\usart_common_all.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\usart_common_f124.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\ethernet\mac.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\ethernet\mac_stm32fxx7.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\ethernet\phy.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\ethernet\phy_ksz80x1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_control.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_standard.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_msc.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_hid.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_dwc_common.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\usb\usb_f107.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\common\st_usbfs_core.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\stm32\st_usbfs_v1.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\vector.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\systick.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\scb.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\nvic.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\assert.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\sync.o
Compiling .pio\build\nucleo_f103rb\FrameworkLibOpenCM3\lib\cm3\dwt.o
Archiving .pio\build\nucleo_f103rb\libFrameworkLibOpenCM3.a
Indexing .pio\build\nucleo_f103rb\libFrameworkLibOpenCM3.a
Linking .pio\build\nucleo_f103rb\firmware.elf
Building .pio\build\nucleo_f103rb\firmware.bin
Checking size .pio\build\nucleo_f103rb\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [          ]   0.0% (used 0 bytes from 20480 bytes)
Flash: [          ]   0.5% (used 688 bytes from 131072 bytes)
================= [SUCCESS] Took 2.58 seconds =================

This is perfectly possible with PlatformIO, too. Just specify another source for the framework-libopencm3 package, see docs.

In PlatformIO you choose libopencm3 as your framework by doing framework = libopencm3 in the platformio.ini, no need to put the source code of it in the project itself or work with git submodules. As said above, the source files for that package / framework can be changed, too.

Thanks, that was very helpful.
I don’t have time to look into it in detail right now but I could’t find a ‘package.json’ file in the libopencm3 repository. But if there is a way to substitute the framework with that command I’ll go with the default PIO config for now.
This is the link to the template repository provided by libopencm3: GitHub - libopencm3/libopencm3-template: Simple empty template to base your poject on

Thanks again,
Oskar

Yes that is maintained by the PlatformIO developers during packaging. Can be seen in the package at the bintray, current content is

{
  "name": "framework-libopencm3",
  "version": "1.10000.200730",
  "description": "Open source ARM Cortex-M microcontroller library",
  "keywords": [
    "framework",
    "arm"
  ],
  "homepage": "http://www.libopencm3.org/",
  "license": "GPL-3.0-or-later",
  "repository": {
    "type": "git",
    "url": "https://github.com/libopencm3/libopencm3"
  }
}

so you can always fork libopencm3, add that file with adapted version info and point to it using platform_packages, if you do need the latest bleeding edge version.

Yep the way the original framework does it, with its Makefiles and all, they do it as a submodule. As said, PlatformIO has a nice package management system and knows about this framework already, so that’s what should be used in a PlatformIO development environment.

Hi, i’ve been using libOpenCM3 for a while with and without PlatformIO. The example template is IDE’s agnostic, so you can simply use VSCode with a Makefile manager extension (or whatever you want) if you need a portable and last merge version of libOpenCM3 that’s a good practice. You can clone the project making the adjustments as qzvxjp2c said to use it with PlatformIO as well.

The PlatformIO version of libOpenCM3 was updated last august, and I think it’s all right to use it.

Hope this helps, happy new year!