curious errors porting a project from Arduino to Teensy

Status
Not open for further replies.

NikoTeen

Well-known member
[solved] curious errors porting a project from Arduino to Teensy

Hi,
I want to port a project from Arduino 2560 to Teensy 3.2 with a 3rd party library SimpleSDAudio from Arduino Playground.
I'm advancing step by step. Replacing fast PWM on Arduino with IntervalTimer and DAC works. Now I want to port the SD part which is a simplified version of SDFat and very fast because it reads blocks of 512 bytes sequentially from SD card.

The code of the first step is:
Code:
#include "audio.h"

//#include <sd_l2.h>

elapsedMicros blinkPrint=0;
uint16_t looping=0;

byte isr_disen =0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
  SdPlay.init();

  Serial.print("Symbol ARDUINO = ");Serial.println(ARDUINO);
}

void loop() {

  unsigned long blinkCopy;  // holds a copy of the blinkCount

  // to read a variable which the interrupt code writes, we
  // must temporarily disable interrupts, to be sure it will
  // not change while we are reading.  To minimize the time
  // with interrupts off, just quickly make a copy, and then
  // use the copy while allowing the interrupt to keep working.
 
  delay(50);
  if (blinkPrint > 1000000) { // every second
    blinkPrint = 0;
   
    noInterrupts();
    blinkCopy = SdPlay.blinkCount;
    interrupts();

    Serial.print("blinkCount = ");
    Serial.print(blinkCopy);

    Serial.print("  isr_disen=");Serial.println(isr_disen);
    if (isr_disen) {
      SdPlay.start();           // method 4
      isr_disen=0;
    }
    else {
      SdPlay.stop();            // method 4
      isr_disen=1;
    }
    looping++;
  }
}
It works. The IntervalTimer is started in setup() with SdPlay.init() and the LED is blinking for 1 sec, then stops blinking for 1 sec, and so on.

Next the line //#include <sd_l2.h> in the beginning is decommented. sd_l2.h doesn't contain any #include statements. In spite of that now the compiler reports a lot of errors in core libraries, like
Code:
...\arduino-1.8.4\hardware\tools\arm\arm-none-eabi\include\machine\_default_types.h: Assembler messages:

...\arduino-1.8.4\hardware\tools\arm\arm-none-eabi\include\machine\_default_types.h:27: Error: bad instruction `typedef signed char __int8_t'

...\arduino-1.8.4\hardware\tools\arm\arm-none-eabi\include\machine\_default_types.h:29: Error: bad instruction `typedef unsigned char __uint8_t'

The part of code in _default_types.h with the reported error of the example (lines 27, 29 marked):
Code:
/*
 *  $Id$
 */

#ifndef _MACHINE__DEFAULT_TYPES_H
#define _MACHINE__DEFAULT_TYPES_H

#include <sys/features.h>

/*
 * Guess on types by examining *_MIN / *_MAX defines.
 */
#if __GNUC_PREREQ (3, 3)
/* GCC >= 3.3.0 has __<val>__ implicitly defined. */
#define __EXP(x) __##x##__
#else
/* Fall back to POSIX versions from <limits.h> */
#define __EXP(x) x
#include <limits.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __INT8_TYPE__
typedef __INT8_TYPE__ __int8_t;                         <----------------line 27
#ifdef __UINT8_TYPE__
typedef __UINT8_TYPE__ __uint8_t;                      <----------------line 29
#else
typedef unsigned __INT8_TYPE__ __uint8_t;
#endif
...
Similar errors are reported in other header files of the core library.

Also such type of error is reported:
Code:
...\arduino-1.8.4\hardware\teensy\avr\cores\teensy3\kinetis.h:146: Error: bad instruction `enum IRQ_NUMBER_t {'

...\arduino-1.8.4\hardware\teensy\avr\cores\teensy3\kinetis.h:147: Error: junk at end of line, first unrecognized character is `,'

...\arduino-1.8.4\hardware\teensy\avr\cores\teensy3\kinetis.h:148: Error: junk at end of line, first unrecognized character is `,'

Lines 144 - 150 of kinetis.h where the errors are reported from:
Code:
// Teensy 3.1 & 3.2
#elif defined(__MK20DX256__)
enum IRQ_NUMBER_t {
	IRQ_DMA_CH0 =		0,
	IRQ_DMA_CH1 =		1,
	IRQ_DMA_CH2 =		2,
	IRQ_DMA_CH3 =		3,

I don't understand these error messages at all. What about such curious error messages in core libraries!
Compilation for Arduino is ok, but not for Teensy.

Is there a different compiler for Arduino and Teensy?
Even if so, the code where errors are reported is good C code. In the first example of error messages the text "Assembler messages:" is contained. Does this mean that the header file sd_l2.h has been sent to an Assembler? Why that, it is C code?

It's not a matter of non matching libraries. What to do now?
 
Last edited:
with a 3rd party library SimpleSDAudio from Arduino Playground.

Link?

Sorry, I'm rapidly going through a week of missed forum messages... don't have time to go digging & guessing to find this particular code. Since the exact code or a link to the code isn't in your message, I'm not actually looking at it.


Is there a different compiler for Arduino and Teensy?

Yes. There's even different compilers for Arduino, depending on whether you're using the older 8 bit AVR boards (Uno, Mega, etc) or newer 32 bit boards like Due, Zero, MKR1000.

Teensy LC & 3.x also use version 5.4 of the gcc compiler. As far as I know, Arduino is still using version 4.8.


It's not a matter of non matching libraries. What to do now?

Post a better question. When you have a compile problem like this, you should always provide the complete code and all other details to reproduce the problem. There's even a message in red text at the top of every forum page as a reminder.

Since this question didn't have the code, I spent the time I would have put into looking at the problem instead writing this less helpful message. But then again, learning how to ask an effective question might in the long term be more helpful?
 
Sorry for the inconvenience,
meantime the problem is solved:

In the Arduino version there was an assembler file .S included for the interrupt routine which is not necessary for the Teensy version. I didn't delete it because I believed that it will not be compiled when it is not used in the code. Now I learned that a .S file always is compiled even if it is not used. The .S file contained an include to avr/io.h. In the Arduino version there is a different path to avr/io.h than in the Teensy version. And in the Teensy version this header file is not compatible to assembler, resulting in the curious error messages. After deleting the .S file the project can be compiled.

If you are interested in SimpleSDAudio: http://www.hackerspace-ffm.de/wiki/index.php?title=SimpleSDAudio

Thank you for your explanations concerning the compilers

NikoTeen
 
Status
Not open for further replies.
Back
Top