can't build mBed project in lpcxpresso

03 Aug 2014

Hi

I'm trying to build an mBed project on the LPCxpresso Toolchain . My target device is the LPC1768 microcontroller board. I tested the program on the online compiler and it compiles well but it's not the case on LPCXpresso. I'm having build errors on some of the classes defined in the Vodafone USB Modem library. For instance in the class below, the compiler mainly complains about the use of the member functions getc() and putc()

IUSBHostSerial.h

/* IUSBHostSerial.h */

#ifndef IUSBHOSTSERIAL_H_
#define IUSBHOSTSERIAL_H_

/**
 * Generic interface to abstract 3G dongles' impl
 */

#include "IUSBHostSerialListener.h"

class IUSBHostSerial {
public:

    enum IrqType {
        RxIrq,
        TxIrq
    };

    /*
    * Get a char from the dongle's serial interface
    */
    virtual int getc() = 0;

    /*
    * Put a char to the dongle's serial interface
    */
    virtual int putc(int c) = 0;

    /*
     *  Read a packet from the dongle's serial interface, to be called after multiple getc() calls
     */
    virtual int readPacket() = 0;

    /*
     *  Write a packet to the dongle's serial interface, to be called after multiple putc() calls
     */
    virtual int writePacket() = 0;

    /**
    * Check the number of bytes available.
    *
    * @returns the number of bytes available
    */
    virtual int readable() = 0;

    /**
    * Check the free space in output.
    *
    * @returns the number of bytes available
    */
    virtual int writeable() = 0;

    /**
     *  Attach a handler to call when a packet is received / when a packet has been transmitted.
     *
     *  @param pListener instance of the listener deriving from the IUSBHostSerialListener
     */
    virtual void attach(IUSBHostSerialListener* pListener) = 0;

    /**
     * Enable or disable readable/writeable callbacks
     */
    virtual void setupIrq(bool en, IrqType irq = RxIrq) = 0;

};

#endif /* IUSBHOSTSERIAL_H_ */

Here's the list of errors that I'm getting for the line 23:

  • <<error>>expected ')' before '--' token<</error>>
  • <<error>expected unqualified-id before '--'<</error>>

and these are the errors that I'm getting for the line 28:

  • <<error>>'putc' declared as a virtual field<</quote>>
  • <<error>> macro "putc" requires 2 arguments, but only 1 given<</error>>

The build is also complaining of the use of these functions in the file 'USBSerialStream.cpp'.

getc function call

void USBSerialStream::readable() //Callback from m_serial when new data is available
{
  while(m_serial.readable())
  {
    
    m_inBuf.queue(m_serial.getc());
  }
  m_serial.readPacket(); //Start read of next packet
  m_availableSphre.release(); //Force exiting the waiting state
}

The following errors are obtained from line 6 of the code above:

  • <<error>>expected primary-expression before ')' token<</error>>
  • <<error>>expected unqualified-id before '(' token <</error>>

putc function call

void USBSerialStream::writeable() //Callback from m_serial when new space is available
{
  if(m_outBuf.isEmpty())
  {
    m_serialTxFifoEmpty = true;
  }
  else
  {
    m_serialTxFifoEmpty = false;
    while(m_serial.writeable() && !m_outBuf.isEmpty())
    {
      uint8_t c;
      m_outBuf.dequeue(&c);
      m_serial.putc((char)c);
    }
    m_serial.writePacket(); //Start packet write
  }
  if(!m_outBuf.isFull())
  {
    m_spaceSphre.release(); //Force exiting the waiting state
  }
}

Line 14 of the code above produces the following error:

  • <<error>> macro "putc" requires 2 arguments, but only 1 given<</error>>

I know that there are standard C functions named putc and getc which is probably what the compiler thinks I'm intending to use instead when I'm making the function calls. That might be why it's only complaining about these two functions among all the others defined in the IUSBHostSerial class but I don't think the <stdio.h> library has been included as that's where these functions are defined. I'm also thinking that some compilation options must be set, but I don't know which ones. Basically, how do I configure the project in the same exact way that it is configured for the online compiler?

Note: I'm working on a fairly old version of the VodafoneUSBModemLibrary, which I've imported from the program below. If you want to help me solve this, you just need to export this program to LPCXpresso as it already uses the library where I'm getting the errors from.

Import program

00001 // stuff to use DBG debug output
00002 #define __DEBUG__ 4 //Maximum verbosity
00003 #ifndef __MODULE__
00004 #define __MODULE__ "main.cpp"
00005 #endif
00006 
00007 // relevant headers
00008 #include "mbed.h"
00009 #include "VodafoneUSBModem.h"
00010 
00011 #define TEST_NUMBER "YOUR_NUMBER"
00012 #define MAX_SMS_LEN 256
00013 
00014 int main() {
00015    // setup debug macro
00016    DBG_INIT();
00017    DBG_SET_SPEED(115200);
00018    DBG_SET_NEWLINE("\r\n");
00019    
00020    // construct modem object
00021    VodafoneUSBModem modem;
00022     
00023    // locals
00024    size_t smCount = 0;
00025    char numBuffer[32], msgBuffer[256];
00026     
00027    // send a wake-up SMS
00028    DBG("Sending test SMS to %s",TEST_NUMBER);
00029    if(modem.sendSM(TEST_NUMBER,"Hello!")!=0) {
00030       DBG("Error sending test SMS!");
00031    }
00032     
00033    // loop forever printing received SMSs
00034    while(1) {
00035         
00036       // get SM count
00037       if(modem.getSMCount(&smCount)!=0) {
00038          DBG("Error receiving SMS count!");
00039          continue;
00040       }
00041        
00042       // if SMS in mailbox
00043       if(smCount>0) {
00044         
00045          // get SMS and sender
00046          if(modem.getSM(numBuffer,msgBuffer,MAX_SMS_LEN)!=0) {
00047             DBG("Error retrieving SMS from mailbox!");
00048             continue;
00049          }
00050            
00051          // print SMS and sender
00052          DBG("SMS: \"%s\", From: \"%s\"",msgBuffer,numBuffer);
00053            
00054       }
00055         
00056       // wait 1 second
00057       Thread::wait(1000);
00058    }
00059 }

I would be extremely grateful if anyone can help me with this as I want to develop this program in an external envrionment.