Complex code on several files and folders: no serial output?

Lesept

Member
Hi
I'm having a weird problem With a code that uses several files in several folders.
I use the Arduino IDE v2.3.2 and Teensy 4.1 with 8MB PSRAM and 256MB Flash.

In the main directory I have the ino file and a src folder with the rest of the code, in several files and folders. When I compile there is no problem:
Code:
Memory Usage on Teensy 4.1:
  FLASH: code:35268, data:5064, headers:8816   free for files:8077316
   RAM1: variables:5920, code:32576, padding:192   free for local variables:485600
   RAM2: variables:12416  free for malloc/new:511872
Then it is loaded on the board, but there is nothing in the serial monitor, although the ino code is the following:
Code:
#include "src/main.h"
void setup() {
  Serial.begin(115200);
  Serial.println("\nExecuting CPP export");
  elapsedMicros chrono = 0;
  main();
  Serial.printf("Execution time: %.3f ms\n", (float)chrono / 1000.0);
}
void loop() {
}
If I remove the #include and main() lines, together with all the files other than the ino file, I get the output. So is it due to this complex files hierarchy? Are there some rules I don't know to execute a complex code on a Teensy?
Thanks for your help.
 
main() is a standard starting point for the c++ program...
That is there is: main.cpp has
Code:
#include <Arduino.h>

extern "C" int main(void)
{
#ifdef USING_MAKEFILE

    // To use Teensy 4.0 without Arduino, simply put your code here.
    // For example:

    pinMode(13, OUTPUT);
    while (1) {
        digitalWriteFast(13, HIGH);
        delay(500);
        digitalWriteFast(13, LOW);
        delay(500);
    }


#else
    // Arduino's main() function just calls setup() and loop()....
    setup();
    while (1) {
        loop();
        yield();
    }
#endif
}
So I have no idea what you code will do:
That is since the main symbol has been solved, the main.cpp file may not be included within the
build. But instead, probably your main will be called in instead... And none of your sketch code here
will run...

That is, neither Setup nor loop will be called


But just guessing
 
Oh yes, I should have told you before : I tried to rename main() to main0() and the same for main.cpp and main.h
But same result.

Actually, on ESP32, I do this (call main() inside the ino file) and there is no problem at all.

Is it possible to upload a zip file with the whole code on this forum?
 
I should also mention, that with code like:
Code:
void setup() {
  Serial.begin(115200);
  Serial.println("\nExecuting CPP export");
  elapsedMicros chrono = 0;
  main();
  Serial.printf("Execution time: %.3f ms\n", (float)chrono / 1000.0);
}
void loop() {
}
It is possible that the Serial.println and the like happened fast enough, before the USB was
handshake between the PC and the Teensy completed and as such the data would be lost.

I typically add in a check for Serial object with a timeout.
Something like:
Code:
void setup() {
  Serial.begin(115200);
  while(!Serial && (millis() < 4000)) {} // wait up to 4 seconds for the host to be ready...
  Serial.println("\nExecuting CPP export");
  elapsedMicros chrono = 0;
  main();
  Serial.printf("Execution time: %.3f ms\n", (float)chrono / 1000.0);
}
void loop() {
}
 
Thanks for your help, however, it didn't solve the problem.

Here is the compile output:

Code:
FQBN: teensy:avr:teensy41
Using board 'teensy41' from platform in folder: C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0
Using core 'teensy4' from platform in folder: C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0


Detecting libraries used...
C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\11.3.1/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\cores\teensy4 C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\Aidge_Teensy_LeNet.ino.cpp -o nul
Using cached library dependencies for file: C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\src\dnn\src\forward.cpp
Using cached library dependencies for file: C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\src\main.cpp
Generating function prototypes...
C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\tools\teensy-compile\11.3.1/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\cores\teensy4 C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\Aidge_Teensy_LeNet.ino.cpp -o C:\Users\fa125436\AppData\Local\Temp\1295585233\sketch_merged.cpp
C:\Users\fa125436\AppData\Local\Arduino15\packages\builtin\tools\ctags\5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives C:\Users\fa125436\AppData\Local\Temp\1295585233\sketch_merged.cpp
Compiling sketch...
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/precompile_helper" "C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.59.0/cores/teensy4" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92" "C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.59.0/cores/teensy4" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/pch/Arduino.h" -o "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/pch/Arduino.h.gch"
Using previously compiled file: C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\pch\Arduino.h.gch
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++17 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO=10607 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/pch" "-IC:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.59.0\\cores\\teensy4" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92\\sketch\\Aidge_Teensy_LeNet.ino.cpp" -o "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92\\sketch\\Aidge_Teensy_LeNet.ino.cpp.o"
Using previously compiled file: C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\src\dnn\src\forward.cpp.o
Using previously compiled file: C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92\sketch\src\main.cpp.o
Compiling libraries...
Compiling core...
Using precompiled core: C:\Users\fa125436\AppData\Local\Temp\arduino\cores\teensy_avr_teensy41_usb_serial,speed_600,opt_o2std,keys_en-us_50d3b0596634d969818e6c14bce20a4c\core.a
Linking everything together...
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-gcc" -O2 -Wl,--gc-sections,--relax "-TC:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\hardware\\avr\\1.59.0\\cores\\teensy4/imxrt1062_t41.ld" -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -o "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92\\sketch\\Aidge_Teensy_LeNet.ino.cpp.o" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92\\sketch\\src\\dnn\\src\\forward.cpp.o" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92\\sketch\\src\\main.cpp.o" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/..\\..\\cores\\teensy_avr_teensy41_usb_serial,speed_600,opt_o2std,keys_en-us_50d3b0596634d969818e6c14bce20a4c\\core.a" "-LC:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92" -larm_cortexM7lfsp_math -lm -lstdc++
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objcopy" -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.eep"
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objcopy" -O ihex -R .eeprom "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.hex"
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/teensy_secure" encrypthex TEENSY41 "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.hex"
No key .pem file found, skipping .ehex encryption
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/teensy_post_compile" -file=Aidge_Teensy_LeNet.ino "-path=C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92" "-tools=C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/" -board=TEENSY41
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/stdout_redirect" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.sym" "C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objdump" -t -C "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf"
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/teensy_size" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf"
Memory Usage on Teensy 4.1:
  FLASH: code:35268, data:5064, headers:8816   free for files:8077316
   RAM1: variables:5920, code:32576, padding:192   free for local variables:485600
   RAM2: variables:12416  free for malloc/new:511872
"C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\1.59.0/stdout_redirect" "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.lst" "C:\\Users\\fa125436\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objdump" -d -S -C "C:\\Users\\fa125436\\AppData\\Local\\Temp\\arduino\\sketches\\B4B16A4F64589B5F3E443A7CAC1BEE92/Aidge_Teensy_LeNet.ino.elf"


"C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.59.0/teensy_post_compile" "-file=Aidge_Teensy_LeNet.ino" "-path=C:\Users\fa125436\AppData\Local\Temp\arduino\sketches\B4B16A4F64589B5F3E443A7CAC1BEE92" "-tools=C:\Users\fa125436\AppData\Local\Arduino15\packages\teensy\tools\teensy-tools\1.59.0" "-board=TEENSY41" -reboot "-port=usb:20000/0/0/1/2/1/2/4" "-portlabel={serial.port.label}" "-portprotocol={serial.port.protocol}"

But still nothing on the serial monitor. I attach the code if you want to have a look...
 

Attachments

  • Aidge_Teensy_LeNet.zip
    13.3 KB · Views: 29
I have changed the ino file to blink the LED :
Code:
#include "src/main.h"
int ledPin = 13;
int duree = 1000;

void setup() {
  Serial.begin(115200);
  while (!Serial && (millis() < 4000)) {}
  pinMode(ledPin, OUTPUT);
  Serial.println("\nExecuting CPP export");
  elapsedMicros chrono = 0;
  digitalWrite(ledPin, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(duree);                      // wait for a second
  main();
  digitalWrite(ledPin, LOW);   // turn the LED off by making the voltage LOW
  Serial.printf("Execution time: %.3f ms\n", (float)chrono / 1000.0);
}
void loop() {
}
But, the LED does not light up. So the problem must come from somewhere else, maybe a memory problem.
Even if the code begins with the LED instructions, the result is the same:
Code:
void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);  // turn the LED on (HIGH is the voltage level)
  Serial.begin(115200);
 ...
 
@KurtE : I tried again to change the name of the main function to main0, together with your second suggestion of checking the Serial and now it works !
Thanks a lot for your help!
 
Back
Top