Building a static library

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

nad
Posts: 30
Joined: Fri Dec 16, 2011 9:20 am

Re: Building a static library

Postby nad » Fri Aug 01, 2014 9:08 am

ok this is perfect.
If there is a way to ifdef out main.c when building the lib. This way we can have the Makefile more generic.
It's not so crucial but since you are adding this you might as well...

I don't think we should move the vectors file to the application side as it was mentioned earlier, but it depends how ChibiOS is being used. It works for what I need now, but might not be applicable for others.

Thank you for the help.

lechndo
Posts: 2
Joined: Mon Mar 21, 2016 8:02 am

Re: Building a static library

Postby lechndo » Mon Apr 18, 2016 10:03 am

Hi,

although this thread looks a bit outdated it seems to be the right place to put my findings.

I was playing around with ChibiOS and static library builds and experienced the same problems that Tectu mentioned in his post at thread start but finally I found a way to build a working ChibiOS kernel library including startup code and interrupt vector table.

I attached an example showing how the library can be built. I tried to modify an existing ChibiOS demo to show how it can be done.
On my hardware this approach works quite well but unfortunately I could not test the attached example itself because I don't have any of the boards used for the ChibiOS demos. Nonetheless I think the idea behind is clear and understandable.

Summing up my findings:
  • To overcome the problem with the missing vectors table I modified the linker script by adding the following line before the sections block:

    Code: Select all

    EXTERN(_vectors)
  • For building the library, smart build has to be disabled in the makefile (USE_SMART_BUILD = no)
  • If only the ChibiOS kernel is built as library the tickless mode can not be used because it uses timer support from the HAL. Therfore the tickless mode must be deactivated in chconf.h

    Code: Select all

    define CH_CFG_ST_TIMEDELTA 0

    If the ChibiOS and the HAL are built together it should be possible to use the tickless mode but this was not tested yet.
  • To achieve optimal code size LTO has to be enabled but in case of the used toolchain (GNU ARM Embedded Toolchain, gcc-arm-none-eabi-5_2-2015q4) this required the use of "gcc-ar" instead of "ar". It seems that "ar" is missing the plugin for handling LTO objects.

I hope this will be useful for others.

@Giovanni:
  • Maybe an example like this could be added to the demos to demonstrate the library build feature?
  • Do you think my solution for the vectors table problem is correct?

Dominik
Attachments
chibilib-demo.tar.gz
ChibiOS static library example source code and patch
(17.08 KiB) Downloaded 70 times

User avatar
Giovanni
Site Admin
Posts: 12949
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 733 times
Been thanked: 609 times
Contact:

Re: Building a static library

Postby Giovanni » Mon Apr 18, 2016 10:12 am

Hi,

Probably the tickless mode could be used but the timer code has to be provided by a module outside the library, note that it does not have to be the HAL, there are just few timer functions to implement.

I would try building the RT library without the startups and vectors table, there should be no dependencies. There is a problem with inclusion of cmparams.h however.

Giovanni

User avatar
Giovanni
Site Admin
Posts: 12949
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 733 times
Been thanked: 609 times
Contact:

Re: Building a static library

Postby Giovanni » Mon Apr 18, 2016 11:04 am

I decided to make changes to the makefiles in order to make this easier, device informations will have to be separated by startup files because both startup and ports have a dependency on that cmparam.h.

It will take some time however.

Giovanni

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: Building a static library

Postby Tectu » Wed Apr 27, 2016 12:29 pm

Glad to hear that this is getting easier in the future!


~ Tectu


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 5 guests