Robin2:
PaulS:
I don't understand why you think that there should be a HardwareSerial0 file, with any extension, anywhere.
Because it exists and it is the file that connects to the UART0_UDRE_vect interrupt vector.
It's simple enough to find out, just search your Arduino installation. On mine, there is no HardwareSerial0 of any sort. It's all handled by HardwareSerial.cpp and HardwareSerial.h. Possibly this depends on which version of IDE you have.
Following a bit more reading the problem may be my ignorance of the C/C++ compiling process.
I have always assumed that the code #include "myFile.h" is the thing that also brings into the project in the associated myFile.cpp. In other words, without that #include neither file would be part of the project.
But I'm beginning to think I am wrong about this and the .cpp files get compiled regardless of the existence (or not) of a similarly named .h file.
Indeed, in general there is no relation between header files and source files, as far as C/C++ is concerned, naming conventions are purely for the programmer. C/C++ compilers perform separate compilation of object files, there is no concept of modules.
However the Arduino IDE does a little extra stuff to include library code if you include the header file, but that is a quite non-standard feature.
I can get what I want to happen by making copies of the relevant HardwareSerial files and renaming them. I was just hoping there might be a simpler way. If I don't rename them I get duplicate definitions even after the #include <HardwareSerial.h> is commented out in Arduino.h. If I could prevent the Library copy of HardwareSerial0.cpp from being compiled I could use my own copy without needing to rename it.
I don't think you can get around renaming, unless you go in and change how the Arduino libs are built.
One way to provide your own defintions for HardwareSerial is to put the following line before including Arduino.h :
#define HardwareSerial_h // trick to disable the standard HWserial
The Marlin firmware uses this to override the standard hardware serial implementation.