2 years ago.

How can I factor mbed-os out of my (offline) project?

I'm working on creating a suite of mbed-os-based firmware images using an offline IDE. How can I build the mbed-os once, and link against it from multiple projects? That way I won't need to have another copy of the mbed-os source for each project, and build it for each.

Currently on Windows 10, I'm using mbed-cli to fetch code, and NXP MCUXpresso to build and debug. I'm open to using other tools, provided that I can debug on the target.

I've tried the following paths:

1. Used mbed-cli to import the mbed-os project, and exported it to mcuxpresso. I hoped to create a static library project that I could link other projects against, but the exporter creates an executable project. I don't think there are any mbed-cli exporter options to create a static library project instead of an executable, and there is no apparent way to convert an executable project to a static library project within MCUXpresso.

2. Used mbed-cli to import mbed-os, and to build mbed-os as a static library. I then also used mbed-cli to import the blinky example, exported to mcuxpresso. I tried to rip the mbed-os source out of that project and link against what I had built with mbed-cli, but it's not clear to me how to do this.

Comment on this question

1 Answer

1 year, 11 months ago.

Brendan,

Will all of your projects use the same version of mbed OS with the same config files and same target? If so then you can compile the mbed-os library as a .lib and then use that in all your projects.

The way you do this is in 2 parts

Part 1 - compile mbed-os into a library 1) cd mbed-os 2) mbed compile toolchain GCC_ARM target <TargetName> library 3) you now have a library file and associated header files in /BUILD/libraries/mbed-os/*, We will copy the entire mbed-os directory here in part 2

Part 2 - modify example code To use the compiled library generated in part 1 we need to modify the mbed-os directory. The Tools and targets.json need to be kept to enable the 'mbed compile' command. 1) keep the tools directory and the targets/targets.json file, everything else can be removed. 2) copy the mbed-os directory from part 1 to the root of your example project.

You should now be able to compile the example project and it will use the pre-built mbed-os library.

For reference Your project should look like this

/Example Project/
  |_main.cpp
  |_mbed-os/
    |_TargetName/GCC_ARM/*     <- copied from Part 1
    |_tools/*                                                <- mbed tools
    |_targets/
      |_targets.json                                   <- config settings for target

All the best,

mbed Austin

Austin,

Thanks for your assistance.

Austin Blackstone wrote:

Will all of your projects use the same version of mbed OS with the same config files and same target?

Yes, but...

Quote:

If so then you can compile the mbed-os library as a .lib and then use that in all your projects.

That's not quite what I'm trying to do. Here's what I'm really after:

  1. The built library should live in one place to be used by multiple projects, so the files don't have to be copied multiple times every time mbed-os is rebuilt.
  2. Each project should be exportable to an IDE (with the required relative references in the project info, so it knows where to look for the mbed-os library), so I can debug them.
  3. If possible, the option to step into mbed-os source when debugging would be nice.

Is this possible? (At least 1 & 2.) If so, how? If not, are there plans to implement these features?

For reference, I'm quoting your procedure below, with minor edits for clarity.

Quote:

Part 1 - compile mbed-os into a library

  1. cd mbed-os
  2. mbed compile --toolchain GCC_ARM --target <TargetName> --library
  3. You now have a library file and associated header files in /BUILD/libraries/mbed-os/*. We will copy the entire mbed-os directory here in part 2.

Part 2 - modify example code

To use the compiled library generated in part 1, we need to modify the mbed-os [sub]directory. The Tools and targets.json need to be kept to enable the mbed compile command.

  1. Keep the tools/ directory and the targets/targets.json file, everything else can be removed.
  2. Copy the mbed-os/ [sub]directory [created in] part 1 to the root of your example project.

You should now be able to compile the example project and it will use the pre-built mbed-os library.

For reference Your project should look like this Example Project:

/Example Project/
  |_main.cpp
  |_mbed-os/
    |_TargetName/GCC_ARM/*     <- copied from Part 1
    |_tools/*                  <- mbed tools
    |_targets/
      |_targets.json           <- config settings for target

posted by Brendan McDonnell 29 Nov 2017

Brendan,

Thank you for the clarification.

Quote:

The built library should live in one place to be used by multiple projects, so the files don't have to be copied multiple times every time mbed-os is rebuilt.

This is not possible currently. It is on the backlog as a usability enhancement but has not been scheduled as of yet.

Quote:

Each project should be exportable to an IDE (with the required relative references in the project info, so it knows where to look for the mbed-os library), so I can debug them.

Every project is exportable using the `mbed export` command. The exporter is a seperate tool from the project management, so it would function the same either way.

Quote:

If possible, the option to step into mbed-os source when debugging would be nice.

This should be possible by default with exported programs as you are compiling mbed-os from source and have the source locally. Are you not able to?

All the best,

-Austin

posted by Austin Blackstone 30 Nov 2017

Austin,

Sorry for the delay. I wasn't notified of your response to my comment.

Regarding #1, is that item in the backlog public (e.g. on github), such that I can monitor progress? If so, please provide a link. Is there an ETA on that feature?

Regarding #2 and #3, I think you've misunderstood the point. They make no sense without #1. Can you answer those again now that I've further clarified?

Note for #2, when I say the project should be exportable "with the required relative references in the project info, so [the IDE] knows where to look for the [already-built] mbed-os library", that is actually the important part. (I probably shouldn't put that in parentheses.)

posted by Brendan McDonnell 04 Dec 2017

Brendan,

Right, so 1 is not possible right now. There is not a publically available ticket, though there should be. I encourage you to open one here for visibility : https://github.com/armmbed/mbed-cli/issues

All the best,

-Austin

posted by Austin Blackstone 04 Dec 2017

Issue reported on github:

https://github.com/ARMmbed/mbed-cli/issues/580

posted by Brendan McDonnell 04 Dec 2017

You need to log in to post a question