SDCC and pic18fregs problem

Help
copperclad
2006-06-06
2013-03-12
  • copperclad
    copperclad
    2006-06-06

    hi
    i have been trying to work with a "C" program i found in an article in nuts & volts magazine
    "USB DEVICE CONTROL" and the author uses SDCC and GPUTILS , i am on an XP system and have downloaded and installed SDCC and GPUTILS and they run the test programs fine , in the article the author has supplied a hex file ( which loaded and ran fine ) and a main.c program i would like to compile

    my problem is when i try to compile main.c with sdcc main.c i get errors telling me it can't find
    the include files , i have tried --search-path-dirs and it lists fine , here is the top part of main.c , any help as to what is wrong or what to try would be great , thanks , dana 

    --------------------------------------------------
    // Demonstration code of USB I/O on PIC 18F2455 (and siblings) -
    // turn LED on/off and echo a buffer back to host.
    //
    // Copyright (C) 2005 Alexander Enzmann
    //
    // This library is free software; you can redistribute it and/or
    // modify it under the terms of the GNU Lesser General Public
    // License as published by the Free Software Foundation; either
    // version 2.1 of the License, or (at your option) any later version.
    //
    // This library is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    // Lesser General Public License for more details.
    //
    // You should have received a copy of the GNU Lesser General Public
    // License along with this library; if not, write to the Free Software
    // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    //

    #include <pic18fregs.h>
    #include <stdio.h>
    #include <usart.h>
    #include "usb.h"

    // Note: there are timing related problems associated with GET_FEATURE
    // when run at less than 48 MHz
    #define CLK_48MHZ 1
    --------------------------------------------------

     
    • Raphael Neider
      Raphael Neider
      2006-06-06

      You might have to post more information: exact error message, exact command line used, SDCC version number.

      Potentially you just need to use
      sdcc -mpic16 -p18f2455 main.c
      instead of just sdcc main.c
      You may also try adding
      -I c:\programs\sdcc\include\pic16
      (or wherever the pic18fregs.h file may be located) to the command line.
      Last you might want to check if the installer still provides you with the pic16 includes... that is... you did use the installer, didn't you? There are also snapshots available, which surely require you set up your paths manually...

      Good luck,
      Raphael

       
    • copperclad
      copperclad
      2006-06-06

      hi Raphael
      yes i started reading some of the other posts on the forum and i am thinking it is just a problem with the command line i am trying

      i used the installer for both SDCC and GPUTILS

      and after trying sdcc -mic16 -p18f2455 main.c
      i get
      -----------------------------------------------

      C:\Program Files\SDCC\dana>sdcc -mpic16 -p18f2455 main.c
      Processor: 18f2455
      '18f2455' was not found.
      Valid devices are:
      p18f242   p18f248   p18f252   p18f258
      p18f442   p18f448   p18f452   p18f458
      p18f1220  p18f2220  p18f2550  p18f4331
      p18f4455  p18f6520  p18f6620  p18f6680
      p18f6720  p18f8520  p18f8620  p18f8680
      p18f8720

      C:\Program Files\SDCC\dana>
      --------------------------------------------------

      i am thinking it is finding pic18fregs now , if i try using a command line like
      sdcc -mpic16 -p18f2550 main.c
      i get
      -------------------------------------------------

      C:\Program Files\SDCC\dana>sdcc -mpic16 -p18f2550 main.c
      Processor: 18f2550
      In file included from main.c:21:
      C:/Program Files/SDCC/include/pic16/pic18fregs.h:74:4: #error Unsupported proces
      sor
      main.c:187: error 20: Undefined identifier 'TRISA'
      main.c:187: error 20: Undefined identifier 'TRISA'
      main.c:187: error 103: code not generated for 'UserInit' due to previous errors
      main.c:211: error 103: code not generated for 'USBEcho' due to previous errors
      main.c:222: error 20: Undefined identifier 'UCONbits'
      main.c:222: error 25: Structure/Union expected left of '.->'
      main.c:226: error 103: code not generated for 'ProcessIO' due to previous errors

      -:0: error 103: code not generated for 'SetupFeatureReport' due to previous erro
      rs
      main.c:255: error 20: Undefined identifier 'PORTAbits'
      main.c:255: error 25: Structure/Union expected left of '.->'
      -:0: error 103: code not generated for 'SetFeatureReport' due to previous errors

      main.c:271: error 20: Undefined identifier 'PORTA'
      -:0: error 103: code not generated for 'GetFeatureReport' due to previous errors

      -:0: error 103: code not generated for 'SetupOutputReport' due to previous error
      s
      -:0: error 103: code not generated for 'SetOutputReport' due to previous errors
      -:0: error 103: code not generated for 'GetInputReport' due to previous errors
      main.c:330: error 20: Undefined identifier 'ADCON1'
      main.c:330: error 20: Undefined identifier 'ADCON1'
      main.c:333: error 20: Undefined identifier 'UCFG'
      main.c:349: error 20: Undefined identifier 'UCFGbits'
      main.c:349: error 25: Structure/Union expected left of '.->'
      -:0: error 103: code not generated for 'main' due to previous errors

      -------------------------------------------------
      i know this is still not correct but after banging my head against it for a few days , i see this as progress , i have worked with other compilers and microcontrollers but i am new to pics and the sdcc environment , do you think this is a problem with the directories , or is my command line still wrong , thanks for helping me with this  , dana

       
      • Raphael Neider
        Raphael Neider
        2006-06-06

        You are probably using a too old version of SDCC. For me, "sdcc -mpic16 -p18f2455" executes and compiles my sample code happily.

        Please check you are using SDCC 2.5.6 via sdcc -v, or download a recent snapshot/installer. If you are using SDCC 2.5.0 (latest official release), support for the given chip is possibly not yet included.

        Regards,
        Raphael

         
    • copperclad
      copperclad
      2006-06-06

      hi
      here is a link to the file
      http://www.nutsvolts.com/ftpindex.htm
      at the top under june 2006 it is called USB.zip
      the file i am trying to compile is in the directory PICHID there are about ten files , i assume are suport files and a hex file built from it , in the article the author just states that covering compiling would be beyond the scope of the article :) , thanks , dana

       
    • copperclad
      copperclad
      2006-06-06

      hi Raphael
      thanks , i will get on and check it out , thanks again for helping out , dana

       
    • copperclad
      copperclad
      2006-06-06

      hi Raphael
      yes , i have the version 2.6.0 from http://sourceforge.net/
      do you have a link where i can find v-2.5.6 and snapshot/installer , i only know of the sourceforge site , thanks again , dana

       
    • copperclad
      copperclad
      2006-06-06

      hi Raphael
      i just got back on sourceforge and see where the snapshots are , i am downloading the latest and will give it a try , thanks again dana

       
    • copperclad
      copperclad
      2006-06-07

      hi Raphael
      good work! that was the ticket! , it looked like it had some errors with main.o , but when it was done main.lst showed no errors and there was main.asm :-) , now i am just needing to find out , my copy of gputils seems to be the latest the site lists , v-0.13.3-2 but i am not sure how to run it . is the command line just ?
      gpasm main.asm
      or do i need to tell it the device too

      thanks a million for taking the time to help , dana

       
    • copperclad
      copperclad
      2006-06-07

      hi Raphael
      looks like i'm not out of the woods yet , when i run
      sdcc -mpic16 -p18f2455 main.c
      it will give me a main.lst and a main.asm
      but i get these errors
      -----------------------------------------------

      C:\Program Files\SDCC\PICHID>sdcc -mpic16 -p18f2455 main.c
      warning: processor mismatch in "C:\Program Files\SDCC\bin\..\lib\pic16\crt0i.o"
      message: using default linker script "C:\Program Files\gputils\lkr\18f2455.lkr"
      warning: processor mismatch in "pic18f2455.o"
      warning: processor mismatch in "stack.o"
      error: missing definition for symbol "_currentConfiguration", required by "main.
      o"
      error: missing definition for symbol "_HIDTxBuffer", required by "main.o"
      error: missing definition for symbol "_HIDRxBuffer", required by "main.o"
      error: missing definition for symbol "_ProcessUSBTransactions", required by "mai
      n.o"
      error: missing definition for symbol "_HIDRxReport", required by "main.o"
      error: missing definition for symbol "_HIDTxReport", required by "main.o"
      error: missing definition for symbol "_EnableUSBModule", required by "main.o"
      error: missing definition for symbol "_ep1Bi", required by "main.o"
      error: missing definition for symbol "_outPtr", required by "main.o"
      error: missing definition for symbol "_wCount", required by "main.o"
      error: missing definition for symbol "_deviceState", required by "main.o"
      error: missing definition for symbol "_inPtr", required by "main.o"
      error: missing definition for symbol "_remoteWakeup", required by "main.o"

      C:\Program Files\SDCC\PICHID>
      ---------------------------------------------

      it looks like it is trying to do the gpasm at the same time as the asm build , not sure what is happening , but if i then run
      gpasm main.asm
      i get no main.hex and it removes a main.o it had made , dana

       
    • copperclad
      copperclad
      2006-06-07

      hi
      i just ran it with the line
      sdcc -mpic16 -p18f2455 -c main.c
      and it runs clean , no errors , curser just comes back to a new dos line , and in the dir are a main.lst showing no errors and no warnings , and a main.asm file

      so am i right that my problem is now with the linker ,

      if i then try
      gpasm main.asm

      i get about a hundred errors and no main.hex

      dana

       
      • Raphael Neider
        Raphael Neider
        2006-06-07

        OK, looked at the code...

        Hint: I strongly encourage you to use some build environment: a Visual Studio project file is included in USB.zip; GNU make for Windows or even Cygwin might also help. You need to compile multiple files and link them together.
        Doing it by hand generally requires the following steps (recommended steps to follow below!):

        Typical work flow:
        1. Compile .c files to .o using
        sdcc -mpic16 -p18f2550 <more options?> -c foo.c
        </cmd>
        This also runs the assembler, no need to do this manually (in fact, sdcc creates .asm from .c, gpasm creates .o from .asm).

        2. Link all the generated .o files plus SDCC libraries using
        <cmd>
        gplink -I path\to\sdcc\pic16\libraries -t 128 -o usbdemo.hex -w main.o usb.o libsdcc.lib pic18f2550.lib libio18f2550.lib libc18f.lib crt0iz.o -s 18f2550.lkr -o USBHID.hex
        </cmd>

        (The supplied Makefile follows the this approach.)

        Recommended work flow for this particular project:
        <cmd>
        sdcc -mpic16 -p18f2550 -I path\to\pic16\includes -c usb.c

        sdcc -mpic16 -p18f2550 -I path\to\pic16\includes -L path\to\pic16\libraries -Wl,"-t 128 -w -s 18f2550.lkr" main.c usb.o
        </cmd>

        The first command will compile usb.c into usb.o, the second will compile main.c into main.o and link it against all libraries from above and usb.o to produce main.hex. This approach saves you a lot of bugs resulting from not linking against required libraries...

        ATTENTION: The code is written a year ago, some header files changed.
        In particular, all references to UIE.ACTVIE or ACTVIF in usb.c must be replaced with ACTIVIE or ACTIVIF respectively ("I" introduced after ACT).

        HTH,
        Raphael

         
    • copperclad
      copperclad
      2006-06-07

      hi Raphael
      i made the changes to usb.c and thought to try it as you suggested but assuming it could find all the directories and here is what i got

      -------------------------------------------------

      C:\Program Files\SDCC\PICHID>dir
      Volume in drive C has no label.
      Volume Serial Number is 000F-43F0

      Directory of C:\Program Files\SDCC\PICHID

      06/07/2006  07:14 AM    <DIR>          .
      06/07/2006  07:14 AM    <DIR>          ..
      05/29/2005  11:13 PM               658 Blink2550.hex
      07/20/2005  07:44 AM             1,309 callbacks.h
      06/21/2005  09:49 AM             1,496 HIDReportDesc.h
      06/21/2005  09:47 AM               254 HIDReportDesc.hid
      07/25/2005  02:43 PM            10,301 main.c
      06/16/2005  04:52 PM             1,081 Makefile
      06/03/2006  08:53 PM                75 pichid.mcs
      07/21/2005  01:41 PM             2,358 PICHID.vcproj
      06/07/2006  06:55 AM            35,025 usb.c
      07/27/2005  08:16 AM             5,241 usb.h
      08/03/2005  07:49 AM            12,118 USBHID.hex
      06/06/2006  08:33 AM                75 wwwqqq.mcs
                    12 File(s)         69,991 bytes
                     2 Dir(s)   1,887,641,600 bytes free

      C:\Program Files\SDCC\PICHID>sdcc -mpic16 -p18f2455 -c usb.c
      usb.c:704: warning 110: conditional flow changed by optimizer: so said EVELYN th
      e modified DOG

      C:\Program Files\SDCC\PICHID>sdcc -mpic16 -p18f2455 main.c usb.o
      warning: processor mismatch in "C:\Program Files\SDCC\bin\..\lib\pic16\crt0i.o"
      message: using default linker script "C:\Program Files\gputils\lkr\18f2455.lkr"
      warning: processor mismatch in "pic18f2455.o"
      warning: processor mismatch in "stack.o"
      warning: processor mismatch in "gptrput1.o"
      warning: processor mismatch in "gptrget1.o"

      C:\Program Files\SDCC\PICHID>dir
      Volume in drive C has no label.
      Volume Serial Number is 000F-43F0

      Directory of C:\Program Files\SDCC\PICHID

      06/07/2006  07:18 AM    <DIR>          .
      06/07/2006  07:18 AM    <DIR>          ..
      05/29/2005  11:13 PM               658 Blink2550.hex
      07/20/2005  07:44 AM             1,309 callbacks.h
      06/21/2005  09:49 AM             1,496 HIDReportDesc.h
      06/21/2005  09:47 AM               254 HIDReportDesc.hid
      06/07/2006  07:18 AM            16,486 main.asm
      07/25/2005  02:43 PM            10,301 main.c
      06/07/2006  07:18 AM            41,984 main.cod
      06/07/2006  07:18 AM            16,422 main.hex
      06/07/2006  07:18 AM           246,417 main.lst
      06/07/2006  07:18 AM            19,622 main.o
      06/16/2005  04:52 PM             1,081 Makefile
      06/03/2006  08:53 PM                75 pichid.mcs
      07/21/2005  01:41 PM             2,358 PICHID.vcproj
      06/07/2006  07:17 AM            64,445 usb.asm
      06/07/2006  06:55 AM            35,025 usb.c
      07/27/2005  08:16 AM             5,241 usb.h
      06/07/2006  07:17 AM           176,238 usb.lst
      06/07/2006  07:17 AM            86,301 usb.o
      08/03/2005  07:49 AM            12,118 USBHID.hex
      06/06/2006  08:33 AM                75 wwwqqq.mcs
                    20 File(s)        737,906 bytes
                     2 Dir(s)   1,886,932,992 bytes free

      C:\Program Files\SDCC\PICHID>
      --------------------------------------------
      it looks like i got a warning from evelyn the dog :-) and then compiling main.c i get a few more about processor mismatch , but it does give me main.hex

      i haven't tried downloading it to the chip yet but i am for sure miles ahead of where i was yesterday , i can see i never would have gotten here without your help and patience , thanks again , dana

       
      • Raphael Neider
        Raphael Neider
        2006-06-07

        Congratulations, you have completed your task.

        The warnings concerning EVELYN can be ignored.
        The warnings on processor mismatches can be
        ignored as well (they stem from the pic16 libraries, which are compiled for the pi18f452 but compatible with the whole family); the latter can even be suppressed wit the -w switch to the linker, e.g. using
        sdcc -Wl,-w <other options>

        Happy PICcing, glad I could help,
        Raphael

         
        • frank_lane
          frank_lane
          2006-06-07

          Hi,
          I have to ask, Does anyone know who Evelyn actually is? Does she really exist, or just something humorous?

          Thanks,
          Frank

           
    • copperclad
      copperclad
      2006-06-07

      hi Raphael
      quote " Hint: I strongly encourage you to use some build environment: a Visual Studio project file is included "
      i am going to try downloading visual C++ and useing the project file to compile this hex file too , thanks again , dana

       
    • copperclad
      copperclad
      2006-06-08

      hi Raphael
      i have been trying to use the visual c++ makefile and have a question for you

      i get a U1077 error which when i look it up tells me i can use /I to ignore it

      i am not sure where to edit in /I , do i do this in the makefile , or in a vc++ dialog box

      here is a copy of the build report , thanks , dana

      -------------------------------------------
      Performing Makefile project actions
      Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
      Copyright (C) Microsoft Corporation.  All rights reserved.
      gplink.exe -I. -I\lib -m -t 128 pic18f2550.lib libio18f2550.lib libc18f.lib libsdcc.lib crt0.o main.o usb.o  -s 18f2550.lkr -o USBHID.hex
      warning: processor mismatch in "main.o"
      warning: processor mismatch in "usb.o"
      error: _stack symbol already exists
      NMAKE : fatal error U1077: '"C:\Program Files\gputils\bin\gplink.exe"' : return code '0x1'
      Stop.
      Project : error PRJ0019: A tool returned an error code from "Performing Makefile project actions"
      ______________________________________________

       
    • Shaiton
      Shaiton
      2007-06-15

      Hi,
      sorry but I have the same errors.
      And i don't read any solution (i am french...).

      i am using SDCC 2.7.0 on Linux with Piklab.
      And I would like too  compile an HID project .
      It s the same project
      " here is a link to the file 
      http://www.nutsvolts.com/ftpindex.htm
      at the top under june 2006 it is called USB.zip "

      I have those errors:
      sdcc -mpic16 -p18f2550 -V -I/user/kraymond/Desktop/picLXemetteur/recepteur/PICHID/ -Wl-omain.hex -Wl-m -Wl-ainhx32 main.c
      message: using default linker script "/usr/share/gputils/lkr/18f2550.lkr"
      error: missing definition for symbol "_currentConfiguration", required by "main.o"
      error: missing definition for symbol "_HIDTxBuffer", required by "main.o"
      error: missing definition for symbol "_HIDRxBuffer", required by "main.o"
      error: missing definition for symbol "_ProcessUSBTransactions", required by "main.o"
      error: missing definition for symbol "_HIDRxReport", required by "main.o"
      error: missing definition for symbol "_HIDTxReport", required by "main.o"
      error: missing definition for symbol "_EnableUSBModule", required by "main.o"
      error: missing definition for symbol "_ep1Bi", required by "main.o"
      error: missing definition for symbol "_outPtr", required by "main.o"
      error: missing definition for symbol "_wCount", required by "main.o"
      error: missing definition for symbol "_deviceState", required by "main.o"
      error: missing definition for symbol "_inPtr", required by "main.o"
      error: missing definition for symbol "_remoteWakeup", required by "main.o"
      + "/usr/local/bin/sdcpp" -nostdinc -Wall -std=c99 -I"/user/kraymond/Desktop/picLXemetteur/recepteur/PICHID/" -Dpic18f2550 -D__18f2550 -DSTACK_MODEL_SMALL -obj-ext=.o -DSDCC_MODEL_SMALL -DSDCC=270 -DSDCC_pic16 -D__pic16 -I"/usr/local/bin/../share/sdcc/include/pic16" -I"/usr/local/share/sdcc/include/pic16" -I"/user/kraymond/Desktop/picLXemetteur/recepteur/PICHID/"  "main.c"
      + "gpasm" -DSDCC_MODEL_SMALL -Dpic18f2550 -D__18F2550 -DSTACK_MODEL_SMALL -c "main.asm" -o "main.o"
      + "gplink" -I"/usr/local/bin/../share/sdcc/lib/pic16" -I"/usr/local/share/sdcc/lib/pic16"  -omain.hex -m -ainhx32  -w -r -o main main.o  crt0i.o pic18f2550.lib libsdcc.lib libc18f.lib libio18f2550.lib
      *** Sortie avec le code : 1 ***

      I had rename     UIEbits.ACTIVIE and  UIRbits.ACTIVIF but it doesn't work.
      What can i do please ?

       
      • Raphael Neider
        Raphael Neider
        2007-06-15

        Hi,

        Had you scanned all postings in this thread (especially https://sourceforge.net/forum/message.php?msg_id=3765876, 2006-06-07 07:56), the answer would have been before you: main.c uses variables defined in usb.c, so you must link main.o with usb.o to get main.hex. For this to work, you MUST at first prevent SDCC from trying to link main.o into a .hex file using the -c switch to sdcc. If Piklab cannot do this, I'd switch to a plain Makefile-based build environment (I am sure, though, that Piklab somehow let's you set things up correctly: Compiling/assembling first using the compiler's -c switch and linking afterwards by involing the linker directly is rather common in multi-source projects...).

        So, in short, use the following commands to compile your project (on the command line/shell):
        <cmd>
        sdcc -mpic16 -p18f2550 -I path\to\pic16\includes -c usb.c

        sdcc -mpic16 -p18f2550 -I path\to\pic16\includes -L path\to\pic16\libraries -Wl,"-w -s 18f2550.lkr" main.c usb.o
        </cmd>

        HTH,
        Raphael

         
    • Shaiton
      Shaiton
      2007-06-15

      YEs! thank you very much. It works (I can heard you "Of course" !!! :p)
      I had read all posts but I do a mistake.. (i did not compile usb.c but main.c).

      It s really great! I hope it will be OK monday.. (I am on my own computer now...)

      Thanks,
      best regards