Simple project using libopencm3 in SES

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Simple project using libopencm3 in SES

      I'm trying to build a simple blinker hello world project using libopencm3. It is a big complicated project and it's using Makefile to build. So far I tried compiling it with SEGGER compiler as CC parameter for the Makefile and creating a Library project in SES importing all the code that I need, but couldn't get it built.

      My target microcontroller is STM32F103C8T6 and the code is based on this example:

      C Source Code: main.c

      1. #include <libopencm3/stm32/rcc.h>
      2. #include <libopencm3/stm32/gpio.h>
      3. static void gpio_setup() {
      4. rcc_periph_clock_enable(RCC_GPIOC);
      5. gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
      7. }
      8. int main() {
      9. gpio_setup();
      10. while (1) {
      11. gpio_toggle(GPIOC, GPIO12);
      12. for (int i = 0; i < 800000; i++)
      13. __asm__("nop");
      14. }
      15. return 0;
      16. }
      Display All
      What would be the correct approach to compile this in SES using libopencm3?
    • tpimh wrote:

      I tried compiling it with SEGGER compiler
      I thought Segger just uses the GCC Compiler ?

      tpimh wrote:

      It is a big complicated project
      Are you familiar with working on big complicated tools with other IDEs ?

      Have you been able to build simple projects using SES ?

      It's always best to start with simple projects to learn how to use a new tool ...

      tpimh wrote:

      couldn't get it built
      What problem(s) did you have?

      It's hard to help you solve the problems when you don't say what those problems are!
    • Sorry for late reply, I have successfully built libopencm3. Here is my solution (it's not perfect, but it seems to work):

      XML Source Code: libopencm3.emProject

      1. <!DOCTYPE CrossStudio_Project_File>
      2. <solution Name="libopencm3" target="8" version="2">
      3. <project Name="libopencm3">
      4. <configuration
      5. Name="Common"
      6. arm_core_type="Cortex-M3"
      7. project_directory=""
      8. project_type="Library" />
      9. <configuration
      10. Name="Debug"
      11. c_preprocessor_definitions="STM32F1"
      12. c_user_include_directories="include" />
      13. <folder Name="lib">
      14. <folder Name="cm3">
      15. <file file_name="lib/cm3/assert.c" />
      16. <file file_name="lib/cm3/dwt.c" />
      17. <file file_name="lib/cm3/nvic.c" />
      18. <file file_name="lib/cm3/scb.c" />
      19. <file file_name="lib/cm3/sync.c" />
      20. <file file_name="lib/cm3/systick.c" />
      21. <file file_name="lib/cm3/vector.c" />
      22. </folder>
      23. <folder Name="stm32">
      24. <folder Name="f1">
      25. <file file_name="lib/stm32/f1/adc.c" />
      26. <file file_name="lib/stm32/f1/flash.c" />
      27. <file file_name="lib/stm32/f1/gpio.c" />
      28. <file file_name="lib/stm32/f1/rcc.c" />
      29. <file file_name="lib/stm32/f1/rtc.c" />
      30. <file file_name="lib/stm32/f1/timer.c" />
      31. </folder>
      32. <folder Name="common">
      33. <file file_name="lib/stm32/common/adc_common_v1.c" />
      34. <file file_name="lib/stm32/common/crc_common_all.c" />
      35. <file file_name="lib/stm32/common/dac_common_all.c" />
      36. <file file_name="lib/stm32/common/dma_common_l1f013.c" />
      37. <file file_name="lib/stm32/common/exti_common_all.c" />
      38. <file file_name="lib/stm32/common/flash_common_all.c" />
      39. <file file_name="lib/stm32/common/flash_common_f01.c" />
      40. <file file_name="lib/stm32/common/flash_common_f.c" />
      41. <file file_name="lib/stm32/common/gpio_common_all.c" />
      42. <file file_name="lib/stm32/common/i2c_common_v1.c" />
      43. <file file_name="lib/stm32/common/iwdg_common_all.c" />
      44. <file file_name="lib/stm32/common/pwr_common_v1.c" />
      45. <file file_name="lib/stm32/common/rcc_common_all.c" />
      46. <file file_name="lib/stm32/common/spi_common_all.c" />
      47. <file file_name="lib/stm32/common/spi_common_v1.c" />
      48. <file file_name="lib/stm32/common/st_usbfs_core.c" />
      49. <file file_name="lib/stm32/common/timer_common_all.c" />
      50. <file file_name="lib/stm32/common/usart_common_all.c" />
      51. <file file_name="lib/stm32/common/usart_common_f124.c" />
      52. </folder>
      53. <file file_name="lib/stm32/can.c" />
      54. <file file_name="lib/stm32/desig.c" />
      55. <file file_name="lib/stm32/st_usbfs_v1.c" />
      56. </folder>
      57. <folder Name="ethernet">
      58. <file file_name="lib/ethernet/mac.c" />
      59. <file file_name="lib/ethernet/phy.c" />
      60. <file file_name="lib/ethernet/phy_ksz80x1.c" />
      61. <file file_name="lib/ethernet/mac_stm32fxx7.c" />
      62. </folder>
      63. <folder Name="usb">
      64. <file file_name="lib/usb/usb.c" />
      65. <file file_name="lib/usb/usb_control.c" />
      66. <file file_name="lib/usb/usb_dwc_common.c" />
      67. <file file_name="lib/usb/usb_f107.c" />
      68. <file file_name="lib/usb/usb_msc.c" />
      69. <file file_name="lib/usb/usb_standard.c" />
      70. </folder>
      71. </folder>
      72. </project>
      73. <configuration
      74. Name="Debug"
      75. c_preprocessor_definitions="DEBUG"
      76. gcc_debugging_level="Level 3"
      77. gcc_optimization_level="None" />
      78. <configuration
      79. Name="Release"
      80. c_preprocessor_definitions="NDEBUG"
      81. gcc_debugging_level="None"
      82. gcc_omit_frame_pointer="Yes"
      83. gcc_optimization_level="Level 1" />
      84. </solution>
      Display All
      It only works for STM32F1 now and needs to be modified to build for other targets.

      awneil wrote:

      I thought Segger just uses the GCC Compiler ?
      SES comes bundled with both GCC and Clang, but as far as I know it doesn't provide GCC-compatible frontend. gcc/arm-none-eabi/bin/cc1 is indeed GNU C17 (GCC) version 8.3.1 20190703 (release) [gcc-8-branch revision 273027] (arm-none-eabi), but bin/cc is SEGGER's own interface for it: SEGGER Embedded Studio for ARM cc - Release 4.30b.

      awneil wrote:

      Are you familiar with working on big complicated tools with other IDEs ?
      Other IDEs I used supported Makefiles, so no problems there.

      awneil wrote:

      Have you been able to build simple projects using SES ?
      I can blink my LED by manipulating the registers directly, but with libopencm3 it's just so much more convenient.

      awneil wrote:

      What problem(s) did you have?
      I had had several problems unrelated to each other, but all solved now. My question was more of a request for a working solution to build the library than a request to solve individual problems for me. So I'm publishing my solution here and hope someone might find it useful.
    • Hello,

      Thank you for your inquiry.
      Great to hear that you found a solution to implement the library in your project.
      For completion for other users that stumble upon this thread, Embedded Studio comes with a CPU support package manager that uses CMSIS packages from silicon vendors so when starting with a CPU you do not have to do everything from scratch.
      More information about this can be found here:…o/technology/cpu-support/
      There are currently over 3000 devices available via the package manager.

      Via the same package manager you also gain access to our Embedded Studio PRO packages that offer already finished BSP projects for different boards that come with sample projects for nearly all of SEGGERs embedded software solutions:…io/editions/pro-cortex-m/
      So if your board is upon these packages seting and clearing an LED is a simple as calling:

      BSP_SetLED(0) or BSP_ClearLED(0).

      These projects run with our RTOS embOS which also offers numerous start projects for different boards that uses a timer, multi-tasking and easy LED setting:…cortex-m-embedded-studio/

      Best regards,

      Please read the forum rules before posting: Forum Rules

      Keep in mind, this is not a support forum. Its main purpose is user to user interaction.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system:

      Or you can contact us via e-mail.