Page 1 of 1

Salvo Pro - Compiled Library Missing Functions

PostPosted: Sat May 24, 2014 5:58 pm
by jc_hsfl
Hi, I'm having a problem using the compiled libraries with Salvo Pro for MCC30. I use the standard CSK libraries (dspic 4.2.2), and my program compiles without any problems. But then when I use my own compiled libraries, they're missing the following functions:


I'm trying to compile it using XC16, so I had to modify the makefile at the following location:

Code: Select all
MCC30-V3-HOME      ="C:/Program Files (x86)/Microchip/xc16/v1.21"
PUMPKIN            ="c:/Pumpkin"
MCC30-CC-V3        =$(MCC30-V3-HOME)/bin/xc16-gcc
MCC30-AS-V3        =$(MCC30-V3-HOME)/bin/xc16-as
MCC30-LIB-V3       =$(MCC30-V3-HOME)/bin/xc16-ar

I compile with Cygwin using "make -f Makefile dspic". The same problem also occurs when using a CLC option.

It seems like the library consistently is missing the functions contained in salvoportmcc30-lm.s/salvoportmcc30-sm.s.

Here's my salvoclc1.h, using "make -f Makefile dspic CLC=1":
Code: Select all
#undef OSCOMPILER             
#undef OSEVENTS               
#undef OSEVENT_FLAGS         
#undef OSEVENTS               
#undef OSMESSAGE_QUEUES       
#undef OSTASKS               
#undef OSBIG_SEMAPHORES       
#undef OSBYTES_OF_COUNTS       
#undef OSBYTES_OF_TICKS       
#undef OSCLEAR_GLOBALS         

#define OSCOMPILER              OSMPLAB_C30
#define OSEVENTS                20
#define OSEVENT_FLAGS           20
#define OSEVENTS                20
#define OSMESSAGE_QUEUES        20
#define OSTASKS                 20
#define OSBIG_SEMAPHORES        TRUE    // 16-bit Sempahores
#define OSBYTES_OF_COUNTS       4       // 32 bit Counters
#define OSBYTES_OF_DELAYS       4       // 32 bit Delays
#define OSBYTES_OF_EVENT_FLAGS  4       // 32 bit Event Flags
#define OSBYTES_OF_TICKS        4       // 32 bit OS Ticks
#define OSCALL_OSCREATEEVENT    OSFROM_BACKGROUND   // Events only in mainline code
#define OSCLEAR_GLOBALS         TRUE    // Clear all globals at init
#define OSCLEAR_UNUSED_POINTERS TRUE    // Null out unused TCBP/ECBP
#define OSCOLLECT_LOST_TICKS    TRUE    // Collect lost ticks

Am I missing a step or some sort of #define that only the C30 compiler has?

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Thu May 29, 2014 8:43 am
by aek
I posted a question on the forums just in case it was a FAQ that you get (so feel free to respond on the forums if it might help others). I still haven't figured out why I'm certain MCC30 assembly functions (e.g. context switch, os delay) aren't recognized when I compile my application code (library and app compiled with XC16 v1.21). When I switch to your stock libraries, the application compiles just fine.

When I do a 'string' dump of my custom library archives, I see the compiled assembly object was included for the appropriate large/small memory model. Here's what it returns:

--begin string dump snippit from custom lib--
--end string dump--

In your library, the closest pattern of strings I could find was this:

--begin string dump snippit from dspic 4.2.2 lib--
--end string dump--

Quite different from what I've got. Have you seen this problem before?

As a note, the only reason I'm compiling from source is to see if it helps with strange problems I'm having with my application code resetting. I've followed the 3 rules very carefully, but still have strange problems (thankfully my code either immediately works or it doesn't, and when it works, it works great!).

For reference, I've included my modified Makefile for Salvo the MCC30 port (Salvo pro dspic 4.2.2), custom library config file, and library archive. I'm going for a large code/data model library. I'm using Cygwin to compile this.

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Thu May 29, 2014 8:55 am
by aek
That is odd.

I would try a few things:

1) Observe the make process in cygwin to ensure that the assembly of the .s file(s) is successful.

2) I would reduce the under of #defines and corresponding #undefs in the salvoclc1.h file just to keep the test case simple.

3) Sometimes, assemblers and compilers are unhappy assembling/compiling more than a single function ("module") per file. But I am pretty perplexed as to why OSCtxSw() would not get picked up when others are.

4) One thing you can do is leave salvoportmcc30.s out of the library, and add it to the project to assemble it as part of your project. This is sort of a "split" build, and is legal, assuming you can ensure that whatever settings were used to build the library also apply to the project project-wide ... Does the app then build successfully / are all requisite functions found? You can even add salvoportmcc30.s to the project with it already in the library -- the linker should prefer the "outside" one over the "library" one, if i) that's the default linker behavior, or ii) the functions are declared as weak in the .s file and the assembler supports the weak keyword (it is in the compiler, I dunno re the assembler, assemblers are usually more brute-force).

5) There is a small chance that the file has hidden characters that are causing a problem -- you could copy (in an editor) the contents of salvoportmcc30.s, paste it into a new file, and try adding that into the library.

As for the deeper problem, ensure that you have not enabled an incompatible optimization (see the RM-MCC30.PDF reference manual). And of course, make sure your salvocfg.h has OSTASKS etc. set high enough for your run-time usage.

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Fri May 30, 2014 1:25 am
by jc_hsfl
Ok, looks like the missing functions were due to my custom library configuration, and perhaps some strange issues using Cygwin and the modifications I did to use XC16.

Note that instead of going through the Makefiles to generate library archives, I just went for a straight source build of my application code. Using MPLAB IDE v2.10 w/ C30 v3.31, I added in all the source files and the appropriate large memory model assembly port file. As mentioned in the user manual, I set all large models for code/data, and also did scalars. Then defined preprocessor macro OSMCC30_LARGE_CM.

Here's what my final salvocfg.h looked like by the time I was able to successfully compile the application:
Code: Select all
// Library Specification
#define OSUSE_LIBRARY        FALSE
//#define OSLIBRARY_TYPE       OSL

// Compile Time Options
//#define OSCOMPILER              OSMPLAB_C30
#define OSEVENTS                4
#define OSEVENT_FLAGS           4
#define OSMESSAGE_QUEUES        4
#define OSTASKS                 20

#define OSBYTES_OF_COUNTS       2       // 16 bit counters
#define OSBYTES_OF_DELAYS       2       // 16 bit delays
#define OSBYTES_OF_EVENT_FLAGS  2    // 16 bit event flags
#define OSBYTES_OF_TICKS        4       // 32 bit os ticks

#define OSCLEAR_GLOBALS             TRUE    // Clear all gobals at init
#define OSCLEAR_UNUSED_POINTERS     TRUE    // Null out unused tcb/ecb
#define OSENABLE_DELAYS             TRUE
#define OSENABLE_TIMEOUTS           TRUE

This resolves my resetting issue where my task table was corrupted in this thread:

For completeness, I switched the IDE compiler to XC16 v1.21. The code successfully compiled and it runs the same application code well too.

Everything now works like a charm (hopefully it stays that way!).

Thanks again!

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Fri May 30, 2014 2:44 pm
by Andrew
You fixed the error of overlapping tcbs on tasks 1-4?

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Fri May 30, 2014 6:11 pm
by jc_hsfl
Yes, my original application code was actually correct. But the code I wrote to debug (and posted) had the overlapping TCBP's.

After compiling from source, all the original application code worked as originally written.

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Fri May 30, 2014 7:35 pm
by jc_hsfl

After more work spent on trying to build custom static libraries using MPLAB X v2.10 w/ XC16 v1.21, it looks like the problem is that XC16 defaults to a ELF/DWARF format output. When using this default output type, the library inclusion in MPLAB does not pick up the missing functions.

Salvo Pro Static Library Project: MPLAB X Project Properties:

When setting the static library project's output option to output to COFF, the static library now works successfully when included into application projects.

Re: Salvo Pro - Compiled Library Missing Functions

PostPosted: Fri May 30, 2014 7:57 pm
by jc_hsfl
Ok, scratch that. After using the static library, the task table is corrupted again. Also, this time I'm getting resets with the IOPUWR flag set, instead of TRAPR.

Custom static lib task table:
Code: Select all
Salvo 4.2.2  Ticks: 151
EligQ:    ,   ,   ,   ,   ,
DelayQ:    ,t1  Total delay: 301 ticks
task stat prio    addr   t->  e->  d-> delay
  1  wait   3  00000256    .  e 1    .   109
  4   to    8  00000000    .    .
  7  stop   4  00000000    .    .

evnt type t->    value
  1  BSem t 1        0
  2  BSem   .        0
  3  BSem   .        1
  4  BSem   .        1
  5  dstr
  6  dstr
  7  dstr
  8  dstr

I'll need to drop the static library method for now and move on. But would be interested in figuring this out for the future for a faster compilation of app code.