0

Problem: Cannot understand why the project is not building with local library.

I am getting following error on my terminal while building the project:

Linking .pio/build/genericSTM32F103C8/firmware.elf
.pio/build/genericSTM32F103C8/src/main.o: In function `main':
main.c:(.text.startup.main+0x2): undefined reference to `clock_setup'
collect2: error: ld returned 1 exit status
*** [.pio/build/genericSTM32F103C8/firmware.elf] Error 1

My project tree looks like this:

Project tree

As per the platformio lib readme I have added the following in src/main.c

#include <clock.h>

My config for platform io is:

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = libopencm3
debug_tool = custom
debug_server =
  $PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd
  -f 
  /usr/local/share/openocd/scripts/interface/stlink-v2.cfg
  -f
  $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/target/stm32f1x.cfg
  lib_ldf_mode = chain+

clock.h contains:

#include <libopencm3/stm32/rcc.h>

BEGIN_DECLS

static void clock_setup(void);

END_DECLS

clock.c contains:

#include <libopencm3/stm32/rcc.h>
#include "clock.h"

static void clock_setup(void)
{
    /* Extenal 16 MHz clock set to 72MHz using PLL */
    rcc_clock_setup_in_hse_16mhz_out_72mhz();

    /* Enable clock for DI DO ADC UART */
    rcc_periph_clock_enable(RCC_GPIOA);
    rcc_periph_clock_enable(RCC_GPIOB);
    rcc_periph_clock_enable(RCC_GPIOC);

    /* Enable AFIO clock. */
    rcc_periph_clock_enable(RCC_AFIO);

    /* Enable Timer clock. */
    rcc_periph_clock_enable(RCC_TIM3);
    rcc_periph_clock_enable(RCC_TIM4);

    /* Enable UART clock. */
    rcc_periph_clock_enable(RCC_USART1);
    rcc_periph_clock_enable(RCC_USART2);

    /* Enable I2C clock. */
    rcc_periph_clock_enable(RCC_I2C2);

    /* Enable SPI2 clock. */
    rcc_periph_clock_enable(RCC_SPI2);

}
Tarick Welling
  • 3,119
  • 3
  • 19
  • 44
mattyyy
  • 13
  • 7
  • Replace "static void clock_setup(void) " by "void clock_setup(void)" static means that the function cannot be seen outside of file. – YvonBlais Jun 14 '20 at 22:21
  • @YvonBlais Still it doesn't seem to work. – mattyyy Jun 15 '20 at 17:42
  • Have you replaced it in the `.h` and the `.c`? And did you include `clock.h` properly? There is a big difference between `#include ` and `#include "clock.h"` Maybe add `#include "lib/CLOCK/src/clock.h` or if you really want to use `<>` notation: add the `lib/CLOCK/src/` to the linker path? – Tarick Welling Jun 15 '20 at 21:21

1 Answers1

0

My current lib folder looks like this and the platformio's LDF can now find my local libraries.

├── clock
│   ├── clock.c
│   └── clock.h
├── di
│   ├── di.c
│   └── di.h
├── do
│   ├── do.c
│   └── do.h
├── i2c
│   ├── adc_i2c.c
│   └── adc_i2c.h
├── spi
│   ├── spi.c
│   └── spi.h
└── uart
    ├── debug_uart.c
    ├── debug_uart.h
    ├── display_uart.c
    ├── display_uart.h
    ├── modbus_uart.c
    └── modbus_uart.h
mattyyy
  • 13
  • 7