Teensy 3.1 and printf

Status
Not open for further replies.

KurtE

Senior Member+
I know that parts of this have been discussed in a few different threads, but it would be nice if there was a simple fix that was part of the system and did not require other work a rounds.

Arduino 1.0.5, 1.20rc2...

Simple Program:
Code:
void setup() {
  Serial.begin(38400);
}

void loop() {
  printf("Hello World");
  delay(250);
}

You try to compile for Teensy 3.1 and it gives you an error:
Code:
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.5 (Windows 7), Board: "Teensy 3.1"
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text+0x16): undefined reference to `_write'
collect2.exe: error: ld returned 1 exit status

I know that on other threads, a solution to specific library was to create your own printf function, that uses sprintf, to a buffer and then do a Serial.print of that buffer, but would be nice if you did not have to do that.
 
Really??? Maybe I should have put in a more fun version like: printf("Version: %04d\n\r", wVersion); ;)

Sorry maybe I should have put this under bug report/suggestion....

But my posted program was trying to give a simple program to reproduce the issues...

There have been a few different libraries that members here have tried to import into their Teensy 3/3.1 to be hit by this. Example RF24 library, which I have been playing with recently. If you do a search on your forum you will see that several people have been hit by this. If you try to use this library, you will find several minor things that you keep it from compiling and linking:

a) First off it will not compile because it used fdevopen, which does not exist in the header files.

b) You comment it out or the like and get the stuff to compile, and try linking, you end up with some cryptic link error about segments overlapping. This caused by this library trying to avoid the warning messages about PROGMEM defines...
#undef PROGMEM
#define PROGMEM __attribute__(( section(".progmem.data") ))
#undef PSTR
#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
#endif

c) Finally if you figure that part out, you run into the link issue I mention in this posting.

When I submitted this posting Just personally thinking it would be great if there was some simple fix that would make the Teensy 3/3.1 even more compatible. Especially if all it needs is some simple function _write to be defined. My guess is that this function is probably passed either a character or a buffer and length, that you then simply call off to Serial.print or Serial.write. But if this is not desired, no problem...

Kurt

P.S. - Luckily in the case of the RF24 library, the member pico, edited the library and example programs to work :). More details and download in the thread: http://forum.pjrc.com/threads/25922...L01-lib-updated-for-Teensy-3-x?highlight=rf24
 
Thanks,

That actually works! I keep forgetting to look to see what things that are added like printf as part of the print class....

I also tried updating the modified version of the RF24 library I mentioned in #3, to simply do this define instead of mapping printf to RFPrintf and then have RFPrintf do the vsnprintf to a static buffer and then use Serial.write to output it. The test app GettingStarted2 still works...

Kurt
 
Anyone had success with the maniacbug.github.com/RF24 libraries in current builds? Hangs in radio.begin(); on GettingStarted sample for me. I came to this after the included RadioHead samples for nRF24L01 failed to start.
 
Facing similar issue

Anyone had success with the maniacbug.github.com/RF24 libraries in current builds? Hangs in radio.begin(); on GettingStarted sample for me. I came to this after the included RadioHead samples for nRF24L01 failed to start.


Let us know what you did to get it working !
 
ravi_kj : This is an old thread on another topic - and my post #6 was out of place - I abandoned the RF24 when I saw the ESP8266 as a better solution. Getting those working now that I'm back to it.
 
Status
Not open for further replies.
Back
Top