Forum Rule: Always post complete source code & details to reproduce any issue!
Page 5 of 5 FirstFirst ... 3 4 5
Results 101 to 114 of 114

Thread: teensy 3 MAC address

  1. #101
    Quote Originally Posted by manitou View Post
    Using ubuntu 16.04, IDE 1.8.8/1.37 on T3.6@180mhz, works for me with Fast Faster or Fastest using Frank's example
    Code:
    #include <TeensyMAC.h>
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      delay(500);
      Serial.printf("Serial: %u\n", teensySerial());
      Serial.printf("MAC: 0x%012llX\n", teensyMAC());
    }
    
    
    MAC: 0x04E9E5032337
    Serial: 2056230
    MAC: 0x04E9E5032337
    Serial: 2056230
    MAC: 0x04E9E5032337
    Serial: 2056230
    MAC: 0x04E9E5032337
    Serial: 2056230
    ...
    still works after unplugging/plugging USB cable.

    Tested on 2 different T3.6

    wow, this is super strange
    so, the only thing I have different is some data saved in the eeprom
    I will try to erase the entire eeprom and test again, but this is really funny...

  2. #102
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    perhaps you should post the sketch that is failing. And does the simple sketch above work for you ?

  3. #103
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    Yeah, verily. the following sketch on T3.6@180mhz exhibits the bad behavior you describe.
    Code:
    /*
      eeprom perf (cycle power to confirm)
    */
    #include <TeensyMAC.h>
    #include <EEPROM.h>
    
    
    unsigned long t;
    void setup()
    {
      int i,val,errs=0;
    
      Serial.begin(9600); while(!Serial); delay(5000);
      Serial.print("EEPROM length: "); 
      Serial.println(EEPROM.length());
      Serial.println("initial read");
    	for (i=0;i<100;i++) {
    		val = EEPROM.read(i);
    		if (val != i) {
    			Serial.print(val);
    			Serial.print(" should be ");
    			Serial.println(i);
          errs++;
    		}
    	}
      Serial.print("read errs "); Serial.println(errs);
    #if 0
    	t=micros();
    	for (i=0;i<100;i++) EEPROM.write(i, i);
    	t=micros()-t;
    	Serial.print("write "); Serial.println(t);
    #endif
    }
    
    void loop()
    {
    	int i,val;
    	t=micros();
    	for (i=0;i<100;i++) val = EEPROM.read(i);
    	t=micros()-t;
    	Serial.print("100 reads (us) "); Serial.println(t);
     Serial.println(val);  // reference val
       Serial.printf("Serial: %u\n", teensySerial());
      Serial.printf("MAC: 0x%012llX\n", teensyMAC());
    	delay(2000);
    }
    it runs correctly after compile/upload, but unplug/plug USB results in trailing 00's in MAC ?
    (you need to run it once with EEPROM write block enabled #if 1 if you want to pass my EEPROM read check in loop())

    I don't know why it fails with EEPROM (doesn't fail @120mhz)

    Frank's system register 0x40041000 reads 0 after the unplug/plug, instead of having the stored value of the MAC ?
    Last edited by manitou; 07-12-2017 at 10:29 AM.

  4. #104
    Moderator KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,139
    The sketch also works on my MAC running Mac Sierra Tried faster and Fastest with LTO at 180mhz. Also tried modifying and retrieved the serial number and MAC as first lines in code before Serial.begin()...

    Is there anything else different about your hardware? Like are you powering from USB or is there external power turning it on and off?

  5. #105
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,924
    Quote Originally Posted by lorenzofattori View Post
    so, the only thing I have different is some data saved in the eeprom
    You could have save us quite a bit of time, and had an answer much sooner, if only you had posted the actual code you were really using!

    This is why we have the "Forum Rule" about posting complete code. Please, follow this rule. It really is easy to post your *actual* code, and it really does make helping you much easier and faster.

  6. #106
    Quote Originally Posted by PaulStoffregen View Post
    You could have save us quite a bit of time, and had an answer much sooner, if only you had posted the actual code you were really using!

    This is why we have the "Forum Rule" about posting complete code. Please, follow this rule. It really is easy to post your *actual* code, and it really does make helping you much easier and faster.
    Sorry Paul, I didn't want to upset you. I always try to post the code, but this time the code is the same of Frank's library.

    Code:
    #include <TeensyMAC.h>
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      delay(500);
      Serial.printf("Serial: %u\n", teensySerial());
      Serial.printf("MAC: 0x%012llX\n", teensyMAC());
    }
    on post #90 I said that both teensy have something stored in the eeprom, but it's not used in the current Sketch
    I will try to wipe the eeprom and see if something changes

    Update: tried to clear the EEPROM with eeprom_clear but still not behaving correctly using Frank's code.
    Tested on Ubuntu with arduino 1.8.3 and teensyduino 1.37

    @KurtE: for this test is just teensy 3.6 with nothing connected, powered (and serial) over usb
    Last edited by lorenzofattori; 07-11-2017 at 09:01 PM.

  7. #107
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,924
    Ok, I've put this one on my list of bugs to investigate.

  8. #108
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    the sketch in post #103 exhibits the strange behavior ...

    the smallest test case is to just add #include <EEPROM.h> to Frank's small sketch
    Last edited by manitou; 07-12-2017 at 10:30 AM.

  9. #109
    Quote Originally Posted by manitou View Post
    the sketch in post #103 exhibits the strange behavior ...

    the smallest test case is to just add #include <EEPROM.h> to Frank's small sketch
    So you confirm you get the same behavior when using eeprom?

  10. #110
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    well, upon further review, Frank's sketch
    Code:
    #include <TeensyMAC.h>
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      delay(500);
      Serial.printf("Serial: %u\n", teensySerial());
      Serial.printf("MAC: 0x%012llX\n", teensyMAC());
    }
    on T3.6@180mhz works after compile/upload, but if you unplug/plug in USB power, then it reports 0 in lower bytes of MAC. (with no EEPROM refs). @120mhz MAC value is good across power cycles. ? this contradicts what i was getting in earlier posts??, using 1.8.3/1.37.

    EDIT: from the K66 beta test thread, this function
    Code:
    void mactst() {
        uint64_t num64;
        uint32_t num;
        __disable_irq();
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
        *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
        FTFL_FSTAT = FTFL_FSTAT_CCIF;
        while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
        num64 = *(uint64_t *)&FTFL_FCCOB7;
        __enable_irq();
        num = num64;
        Serial.println(num,HEX);
        num = num64>>32;
        Serial.println(num,HEX);
    }
    properly prints the MAC address across power cycles @180mhz (though i actually had remembered that it did not work @180mhz)



    EDIT: ARGH On another T3.6@180mhz, the simple sketch is working across power cycles ???? now i'm really confused.
    ? It will fail if EEPROM.h is present @180mhz, BUT after that, it fails across power cycles, even with EEPROM.h removed???
    this is getting above my pay grade
    Last edited by manitou; 08-06-2017 at 01:03 PM.

  11. #111
    @Manitou : How is the 'Power Cycle' done if not pulling USB? Perhaps a warm reset/restart?

    Where does the TeensyMAC.h in use come from?

    Before Paul did the edit for T_3.6's MAC under HSRUN I discovered the MAC could be read before HSRUN was enabled, once the MCU does that it is cached so a failure returns what was there on subsequent calls. That could explain it surviving until power loss, assuming re-programming is not HSRUN speed and leaves the value in the process - and that area isn't cleared.

  12. #112
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    Quote Originally Posted by defragster View Post
    @Manitou : How is the 'Power Cycle' done if not pulling USB? Perhaps a warm reset/restart?

    Where does the TeensyMAC.h in use come from?

    Before Paul did the edit for T_3.6's MAC under HSRUN I discovered the MAC could be read before HSRUN was enabled, once the MCU does that it is cached so a failure returns what was there on subsequent calls. That could explain it surviving until power loss, assuming re-programming is not HSRUN speed and leaves the value in the process - and that area isn't cleared.
    yes, by power-cycling i meant, closing the monitor, pulling the USB cable, then plugging it back in, and enabling the monitor.

    Frank's TeensyMAC https://github.com/FrankBoesing/TeensyMAC

    EEPROM.h does an init() that messes with the FTFL stuff as i recall

  13. #113
    Quote Originally Posted by manitou View Post
    EDIT: from the K66 beta test thread, this function
    Code:
    void mactst() {
        uint64_t num64;
        uint32_t num;
        __disable_irq();
          FTFL_FSTAT = FTFL_FSTAT_RDCOLERR | FTFL_FSTAT_ACCERR | FTFL_FSTAT_FPVIOL;
        *(uint32_t *)&FTFL_FCCOB3 = 0x41070000;
        FTFL_FSTAT = FTFL_FSTAT_CCIF;
        while (!(FTFL_FSTAT & FTFL_FSTAT_CCIF)) ; // wait
        num64 = *(uint64_t *)&FTFL_FCCOB7;
        __enable_irq();
        num = num64;
        Serial.println(num,HEX);
        num = num64>>32;
        Serial.println(num,HEX);
    }
    properly prints the MAC address across power cycles @180mhz (though i actually had remembered that it did not work @180mhz)
    I will give it a try with my code and see

  14. #114
    Quote Originally Posted by PaulStoffregen View Post
    Ok, I've put this one on my list of bugs to investigate.
    will be back on this issue in the next days, any chance that you already had a look on that?


    Thanks
    Lorenzo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •