Menu

Fail to compile basic test

Help
2014-09-10
2014-09-10
  • Electropepper

    Electropepper - 2014-09-10

    Hello im using only linux, VIM and makefile,
    My test1.c is :

    #define __16f88
    #include "./pic/pic16f88.h"
    
    /* Setup chip configuration */
    __code int __at(_CONFIG1) __CONFIG = _CP_OFF &
     _WDT_OFF &
     _BODEN_OFF &
     _PWRTE_OFF &
     _EXTRC_CLKOUT &
     _MCLR_ON &
     _LVP_OFF;
    
    #define b1 0x02 /* pin 1 on PORTB */
    #define B_OUTPUTS 0xFD /* value used to setup TRISB */
    
    void main(void) {
    
     /* PORTB.1 is an output pin */
     TRISB = B_OUTPUTS;
    
     while(1) { /* Loop forever */
    
     /* toggle bit 1 */
     PORTB = (PORTB ^ b1);
    
     }
    }
    

    My make file flags are :

    FLAGS  = -mpic14 -p16f88
    LDFLAGS = -c -r -w -m I /usr/share/sdcc/lib/ -s /usr/share/gputils/lkr/16f88.lkr
    

    The output of the make command is :

    [COMPILING] test1.o
    [LINKING] t1
    make: *** [t1] Segmentation fault
    

    This is a very basic test i still dont understand where am i getting it wrong.

     

    Last edit: Raphael Neider 2014-09-10
  • Electropepper

    Electropepper - 2014-09-10

    I also want to add that before i came up with a makefile if i simply type on the command line :
    sdcc -mpic14 -p16f88 test1.c
    I get on the output :
    pic16f88.lib: No such file or directory

     
  • Raphael Neider

    Raphael Neider - 2014-09-10

    sdcc -mpic14 -p16f88 --use-non-free test1.c

    should do what you need.

    Toggling the port is tricky - especially at that frequency, you never know if you will read the proper value. For PIC16, one would toggle LATB, for PIC14 I recommend to introduce a variable:

    unsigned char o = PORTB;
    while (1) {
      o ^= b1;
      PORTB = o;
      // ideally, you introduce some delay here
    } 
    
     
  • Electropepper

    Electropepper - 2014-09-10

    Hello Raphael but i just tried to compile the code :

    void main (void) {
    }

    And i get the exact same result, so i don't think the problem is in the code.

     
  • Raphael Neider

    Raphael Neider - 2014-09-10

    I did not mean to imply that the errors you already see originate in your code. The port access stuff was just some free advice to prevent future problems.

    Did you already try the --use-non-free command line option? That was the more important part of my previous post.

     
  • Electropepper

    Electropepper - 2014-09-10

    Ow didn't understand that, thank you.
    I've just added the --use-non-free, but the exact same problem persist.

    sdcc -mpic14 -p16f88 --use-non-free -o test2.o -c test2.c
    gplink -c -r -w -m I /usr/share/sdcc/lib/pic14/ test2.o -o t1
    make: *** [t1] Segmentation fault

     
  • Raphael Neider

    Raphael Neider - 2014-09-10

    GPLINK crashes -- this is probably the wrong forum; that would be gputils.sf.net. How about letting SDCC invoke gplink for you? You need to provide libraries and flags, and some of them need to be in the right order ... SDCC knows how to do that.

    sdcc -mpic14 -p16f88 --use-non-free test2.c

    If need be, you can pass -L/usr/share/sdcc/lib/pic14 to sdcc as well to make gplink find pic16f88.lib.

    You can also add -V (or -v?) to see how SDCC invokes gplink.

    If that does not work, please update (or downgrade) gputils to get rid of the crash.

    If you still get 'pic16f88.lib not found' errors, please build SDCC from source or use a snapshot (http://sdcc.sourceforge.net/snap.php#Linux). At least the Debian packages do not include pre-built PIC14/16 libraries due to licensing uncertainties.

    Which versions of gputils and SDCC are you using? What source (Debian packages, source, snapshot, other)?

     

    Last edit: Raphael Neider 2014-09-10
  • Electropepper

    Electropepper - 2014-09-10

    Hello, Finally i got it to give me the .hex :)
    I had to remove sdcc which i had installed with aptitude, and reinstalled the latest manually, then like you said i let sdcc invoke gplink for me, so i removed the linker and linker flags from the Makefile and voilá, it works, but i guess there's a bug somewhere between sdcc and gplink, which is a bit annoying i like to make the makefile all the way.
    Thank you for the precious help.

     

Log in to post a comment.