chipKIT® Development Platform

Inspired by Arduino™

Problems with HardwareSerial.cpp (here we go again! you say)

Created Fri, 17 Apr 2015 05:05:51 +0000 by OldBikerPete


OldBikerPete

Fri, 17 Apr 2015 05:05:51 +0000

I'm beginning to write a sketch which makes use of interrupt-driven RS232 serial I/O on my ChipKit Uno32. Since it already exists and is part of the MPIDE PIC32 core, I thought I'd test the waters with the simplest of sketches - an 'echo' program which simply returns all characters it receives. What could possibly go wrong?

Well. Here's the sketch cut down from a test sketch that 'demolishun' posted a while ago while developing the routines to support 5Mb/sec. BTW, I'm using the 'official' version of HardwareSerial, not any patched version.

#ifndef BOOL #define BOOL unsigned char #endif //BOOL

#include "wiring.h" #include "HardwareSerial.h" #include "HardwareSerial.cpp"

BOOL toggle = LOW;

void setup() { unsigned long tempLong;

Serial.begin(38400);
Serial.write("\r\n");
Serial.write("__PIC32_pbClk: ");
Serial.print(__PIC32_pbClk);
Serial.write("\r\n");
Serial.write("Baud Rate Reg Value: ");
tempLong = ((__PIC32_pbClk / 4 / 38400) - 1);
Serial.print(tempLong,16);
Serial.write("\r\n");

}

void loop() { unsigned char data;

if(Serial.available()){
    toggle = !toggle;
    while(Serial.available()){
        data = Serial.read();
        Serial.write(&data,1);
    }
}
digitalWrite(43,toggle);

}

Simple, no?

Well, the ChipKit version of MPIDE 0023 returns the following error list when I try to compile.

In file included from Echo.cpp:8:0: /HardwareSerial.cpp: In function 'void IntSer0Handler()': /HardwareSerial.cpp:772:2: error 'Serial' was not declared in this scope /HardwareSerial.cpp: In function 'void IntSer1Handler()': /HardwareSerial.cpp:797:2: error 'Serial1' was not declared in this scope

I've examined the HardwareSerial .cpp and .h files until I'm cross-eyed but I can't see any reason for the errors to occur

UNLESS

the HardwareSerial objects 'Serial0',' Serial', 'Serial1', etc. are all constructed within a _cplusplus context and will probably have have their names mangled by the c++ compiler, as is normal.

the intSer?Handler functions are all compiled within an extern "C" { } context and name mangling shouldn't happen in there. Is the compiler/linker not handling the dichotomy properly or am I completely stupid?

Please help.

Peter.


majenko

Fri, 17 Apr 2015 08:52:48 +0000

I'm not surprised. There is absolutely no need to include things like HarwareSerial.h and wiring.h in your sketch, and absolutely no call to include HardwareSerial.cpp.


OldBikerPete

Fri, 17 Apr 2015 09:35:03 +0000

I'm not surprised. There is absolutely no need to include things like HarwareSerial.h and wiring.h in your sketch, and absolutely no call to include HardwareSerial.cpp.

OK. Originally, I only had #include "HardwareSerial.h"

and MPIDE kept complaining about items not defined. The error list I posted is the shortest I have experienced since beginning this project. Can you direct me to ANY example of a sketch which simply works using HarwareSerial ?

PS: I just deleted all the #includes and it compiles OK. First hurdle done. Thanks for the tip.

PPS: Why does #include'ing HardwareSerial.h cause problems? It shouldn't in an ideal world.

Peter.


majenko

Fri, 17 Apr 2015 09:47:12 +0000

It causes problems because it's not meant for a mere mortal to include. It's already included in the core. There is nothing in the core that ever needs to be included by anyone.