cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ Creator & Designer

ricardoquesada
New Contributor II

Hi,

I have a workspace that has 2 "Design projects" and one "Library project".

The "Library project" is that one that contains the shared code. And from I'd like to call `CySysTickStart()` from it.

That functioned is declared in "CyLib.h", but I cannot include it from my "Library Project".

 

Question: How do I include CyLib.h (or for the matter, any other Cy* file  / cmsys* file) from a Library Project?

(Note: Those files seems that they get auto-generated by the "Design Project").

0 Likes
1 Solution
Len_CONSULTRON
Honored Contributor II

ricardo,

I guess I'm a bit confused.

Is your "Library project" a project with a shareable library code?   

Or is it an Cypress "Library Project"?   This is a special type of project that allows you to share library code with your other projects and with other people.  It also can contain custom components

If it is "a project with a shareable library code" then it is simplier.

Before I provide this method, with a name of "CyLib.h" you have a problem.   When you create your own project like DesignA or DesignB, it automatically creates a "CyLib.h" file in the "Generated_Source\cy_boot" directory of each of your projects.   

Since the C compiler will only allow one file with a specific name, you will need to rename your "shared" library .h file   "cyapi.h" is a decent name.   For the instructions below, let's use "cyapi.h" and the shared source file "cyapi.c"

To locally include the "cyapi.h"  into DesignA and DesignB there are two ways.

Method A: Copying the shared lib

  • On your workspace, expand the Library Project and DesignA.  
  • Click on cyapi.h in your Library Project and Copy (Ctrl-C)
  • Go to the "Header Files" directory of DesignA and Paste (Ctrl-V) on tis directory.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Click on cyapi.c in your Library Project and Copy (Ctrl-C)
  • Go to the "Source Files" directory of DesignA and Paste (Ctrl-V) on tis directory.

DesignA should now have a copy of your shared library .h and .c files

There are a potential problem.

  • If you change the original cyapi.h and/or cyapi.c, it will not be reflected in DesignA.

Method B: Add the shared lib without Copying it

  • On your workspace, expand DesignA.  
  • Go to the "Header Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
    Len_CONSULTRON_0-1634655998200.png

     

  • In the "Open" dialog window that appears, find the cyapi.h" in Library Project.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Go to the "Source Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
  • In the "Open" dialog window that appears, find the cyapi.c" in Library Project.

DesignA should now have reference to your shared library .h and .c files.

This reference instead of a copy allow you to change the .h and .c files in the Library Project WITHOUT needing to update them in the Design projects.

 

There is another method that modifies the BUILD definition for each Design Project.  This is a bit more complicated to get correct.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
4 Replies
Len_CONSULTRON
Honored Contributor II

ricardo,

To share your custom library (.cylib) with any of your other projects, follow these steps:

  1. Select the project that needs the shared library and Right-click the "Dependencies..." option 
    Len_CONSULTRON_0-1634562929146.png

     

  2. The Dependencies window will appear.  Now select the Len_CONSULTRON_1-1634563031547.png folder in the "User Dependencies" section in the bottom.

     

  3. In the "Open" window that appears, find and select the .cylib file for your custom library.  Select "Open".
  4. Back Dependencies window you will find your library file listed as a dependency.  Select "OK"

Now this project should reference your library project.   Additionally you will need to reference any of the appropriate .h files in your project code to determine prototypes for functions and external variables used by the library.

 

Len
"Engineering is an Art. The Art of Compromise."
0 Likes
ricardoquesada
New Contributor II

Thanks Len for the instructions. Although I think I missed something... it is not clear how can my "library project" include CyLib.h.

For simplicity, all my 3 projects belong to the same workspace. E.g:

I have a "MyWorkspace" workspace that has 3 projects: two design projects and one library project. The two design projects depend on the library project (I did that by changing the dependencies).... but it is not clear how "library project" can access "CyLib.h" file (which gets autogenerated when the Design projects get compiled)

  • MyWorkspace
    • DesignA project
    • DesignB project
    • Library project

My workaround was to create a file called "cyapi.h" where I include all the declarations that I need to call.

 

0 Likes
Len_CONSULTRON
Honored Contributor II

ricardo,

I guess I'm a bit confused.

Is your "Library project" a project with a shareable library code?   

Or is it an Cypress "Library Project"?   This is a special type of project that allows you to share library code with your other projects and with other people.  It also can contain custom components

If it is "a project with a shareable library code" then it is simplier.

Before I provide this method, with a name of "CyLib.h" you have a problem.   When you create your own project like DesignA or DesignB, it automatically creates a "CyLib.h" file in the "Generated_Source\cy_boot" directory of each of your projects.   

Since the C compiler will only allow one file with a specific name, you will need to rename your "shared" library .h file   "cyapi.h" is a decent name.   For the instructions below, let's use "cyapi.h" and the shared source file "cyapi.c"

To locally include the "cyapi.h"  into DesignA and DesignB there are two ways.

Method A: Copying the shared lib

  • On your workspace, expand the Library Project and DesignA.  
  • Click on cyapi.h in your Library Project and Copy (Ctrl-C)
  • Go to the "Header Files" directory of DesignA and Paste (Ctrl-V) on tis directory.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Click on cyapi.c in your Library Project and Copy (Ctrl-C)
  • Go to the "Source Files" directory of DesignA and Paste (Ctrl-V) on tis directory.

DesignA should now have a copy of your shared library .h and .c files

There are a potential problem.

  • If you change the original cyapi.h and/or cyapi.c, it will not be reflected in DesignA.

Method B: Add the shared lib without Copying it

  • On your workspace, expand DesignA.  
  • Go to the "Header Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
    Len_CONSULTRON_0-1634655998200.png

     

  • In the "Open" dialog window that appears, find the cyapi.h" in Library Project.
  • In the DesignA files that need the library, add "#include "cyapi.h"
  • Go to the "Source Files" directory of DesignA and Right-click and select  "Add/Existing Item..."
  • In the "Open" dialog window that appears, find the cyapi.c" in Library Project.

DesignA should now have reference to your shared library .h and .c files.

This reference instead of a copy allow you to change the .h and .c files in the Library Project WITHOUT needing to update them in the Design projects.

 

There is another method that modifies the BUILD definition for each Design Project.  This is a bit more complicated to get correct.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
ricardoquesada
New Contributor II

Thanks for the detailed answer Len.

It seems that there is no "simple" solution for this. In my ideal world, calling any of the CMSIS functions from a Library Project shouldn't require any change. In any case, not a big deal to create my own "cyapi.h" file and add the CMSIS definitions there.

0 Likes