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

Thread: teensy 3 MAC address

  1. #76
    I wish my brain would work binary like yours and other peoples here.
    Things i need hours or days you do in minutes.

    Serial output looks nice now:
    Code:
    The radio frequency is 868 Mhz, Kenneth!
    RFM69 ATC Enabled (Auto Transmission Control)
    
    I2C Address Scanning ...
    Found i2c Device Address: 32 (0x20)
    Found i2c Device Address: 33 (0x21)
    Scanning done!
    Found 2 device(s).
    
    Reading MAC from hardware...
    Success! Setting MAC address:
      Ethernet MAC = 04 E9 E5 03 A7 AE
    
    Starting Network...
      Connected to Network!
      IPv4 address: 192.168.0.246
    
    Syncing with NTP Server...
    Transmitting NTP Request...
    Receiving NTP Response...
    RTC has set the system time
    Time: 6:01:18 22 1 2017

  2. #77
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Great that it works now :-)

    You can print the MAC without loop, too:
    Code:
     Serial.printf("Ethernet MAC = %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
    These are, again, format-strings. "%02X" means print the number as 2-digit hexadecimal, with leading zero, uppercase. ("%02x" would be lowercase)
    Last edited by Frank B; 01-22-2017 at 10:21 AM.

  3. #78
    Junior Member
    Join Date
    Sep 2016
    Posts
    16
    I have made a new library called TeensID based on the TeensyMAC lib from frank.
    You can find it at https://github.com/sstaub/TeensyID
    I have extended the library with pointers and strings for MAC, USB#, Serial# and ChipID
    It is only tested for Teensy 3.5
    Last edited by sstaub; 02-13-2017 at 10:06 AM.

  4. #79
    Glancing at the code it looks like it has FrankB's work to get serial # before hsrun_disable was introduced for T_3.6 - that catching it in startup. Though that code is also there? The core of the code needs only do the work below to get the Serial #.

    The PJRC code to set the Serial Number is here: teensy3/usb_desc.c#L1294

    void usb_init_serialnumber(void)
    {
    char buf[11];
    uint32_t i, num;

    // ...

  5. #80
    Junior Member
    Join Date
    Sep 2016
    Posts
    16
    Yes I have added the kinetis_hsrun_disable / _enable from the PJRC code to the code of FrankB, so it is nearly the same code. For me the goal is to get an unique mac address and also an UUID (RFC4122), I have to work on next.

  6. #81
    Junior Member
    Join Date
    Sep 2016
    Posts
    16
    Quote Originally Posted by defragster View Post
    Glancing at the code it looks like it has FrankB's work to get serial # before hsrun_disable was introduced for T_3.6 - that catching it in startup. Though that code is also there? The core of the code needs only do the work below to get the Serial #.

    The PJRC code to set the Serial Number is here: teensy3/usb_desc.c#L1294
    So, when I really understood, you mean that this part of the code can deleted!?

    Code:
    #if defined(HAS_KINETIS_FLASH_FTFE) && (F_CPU > 120000000)
    
    	extern "C" void startup_early_hook(void) {
    		#if defined(KINETISK)
      		WDOG_STCTRLH = WDOG_STCTRLH_ALLOWUPDATE;
    		#elif defined(KINETISL)
      		SIM_COPC = 0;  // disable the watchdog
    		#endif
    		*(uint32_t*)(MY_SYSREGISTERFILE) = _getserialhw();
    		}

  7. #82
    Yes, that is the part that caught my eye. If that was indeed from the Beta posting - it was to get the SN before the hsrun state was entered and that value went 'offline'

  8. #83
    Junior Member
    Join Date
    Sep 2016
    Posts
    16
    Quote Originally Posted by defragster View Post
    Yes, that is the part that caught my eye. If that was indeed from the Beta posting - it was to get the SN before the hsrun state was entered and that value went 'offline'
    Thank you for your advices, I have rewritten and optimized the code and published it. Also added a UUID (RFC4122) function.

  9. #84
    Senior Member
    Join Date
    Nov 2012
    Location
    Salt Lake City, UT, USA
    Posts
    246

    TeensyID now tested on Teensy 3.2, example added

    Quote Originally Posted by sstaub View Post
    I have made a new library called TeensID based on the TeensyMAC lib from frank.
    You can find it at https://github.com/sstaub/TeensyID
    I have extended the library with pointers and strings for MAC, USB#, Serial# and ChipID
    It is only tested for Teensy 3.5
    I forked your repo, fixed a decl in the example code, made an Arduino library example folder, tested on T3.2, added to the readme, and issued a pull request. Here is output with T3.2:
    USB Serialnumber: 1244570
    Array Serialnumber: 00-01-E6-29
    String Serialnumber: 00-01-e6-29
    Array MAC Address: 04:E9:E5:01:E6:29
    String MAC Address: 04:e9:e5:01:e6:29
    Array 128-bit UniqueID from chip: C7210000-714D001E-00496017-31384E45
    String 128-bit UniqueID from chip: c7210000-714d001e-00496017-31384e45
    Array 128-bit UUID RFC4122: 00496017-3138-404E-8045-04E9E501E629
    String 128-bit UUID RFC4122: 00496017-3138-404e-8045-04e9e501e629
    Last edited by bboyes; 02-28-2017 at 08:10 PM.

  10. #85
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    Quote Originally Posted by sstaub View Post
    I have made a new library called TeensID based on the TeensyMAC lib from frank.
    You can find it at https://github.com/sstaub/TeensyID
    I have extended the library with pointers and strings for MAC, USB#, Serial# and ChipID
    It is only tested for Teensy 3.5
    tested on T3.6 and LC. ok

  11. #86
    Junior Member
    Join Date
    Sep 2016
    Posts
    16
    I have done a new release v1.1.1 with the pull request from bboyes. Thanks for your help.

  12. #87
    Quote Originally Posted by Frank B View Post
    I've created a library that helps to retrieve the Serial and MAC from within your sketch:

    https://github.com/FrankBoesing/TeensyMAC

    Works with Teensy LC, Teensy 3.0 .. 3.6 and in HS_RUN-Mode.

    usage: see "readme"
    Hi Frank,
    I think there is a issue somewhere. I was debugging other stuff with wireshark and I saw my teensy sending out the last 3 MAC digits as 00:00:00
    then I had a look around and found this:

    - at the first run after loading teensy software I get the right SN and MAC
    - if I unplug and replug teensy then I get 0 as a SN and 0x04E9E5000000 as a mac.

    This also happens with the example in your github, so don't think is related with my code.

    Any suggestions?

  13. #88
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Quote Originally Posted by lorenzofattori View Post
    Hi Frank,
    I think there is a issue somewhere. I was debugging other stuff with wireshark and I saw my teensy sending out the last 3 MAC digits as 00:00:00
    then I had a look around and found this:

    - at the first run after loading teensy software I get the right SN and MAC
    - if I unplug and replug teensy then I get 0 as a SN and 0x04E9E5000000 as a mac.

    This also happens with the example in your github, so don't think is related with my code.

    Any suggestions?
    Which Teensy ?

  14. #89
    Quote Originally Posted by Frank B View Post
    Which Teensy ?
    woups, sorry.... Teensy 3.6

  15. #90
    Quote Originally Posted by lorenzofattori View Post
    Hi Frank,
    I think there is a issue somewhere. I was debugging other stuff with wireshark and I saw my teensy sending out the last 3 MAC digits as 00:00:00
    then I had a look around and found this:

    - at the first run after loading teensy software I get the right SN and MAC
    - if I unplug and replug teensy then I get 0 as a SN and 0x04E9E5000000 as a mac.

    This also happens with the example in your github, so don't think is related with my code.

    Any suggestions?
    Tried also with another Teensy 3.6, same thing. First boot everything ok, then the mac is 00:00:00 on the last 3 bytes.
    Both teensy have something saved in the EEPROM, can be related?

  16. #91
    Moderator Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    4,347
    Quote Originally Posted by lorenzofattori View Post
    Tried also with another Teensy 3.6, same thing. First boot everything ok, then the mac is 00:00:00 on the last 3 bytes.
    Both teensy have something saved in the EEPROM, can be related?
    Hi, at the moment, I can not reproduce this issue. It works well, for me, after power-off/on, too. On the other hand, I don't use the EEPROM.
    For >120MHZ, the code kicks in early, and reads the MAC at "early startup", before initializing anything other, and stores it in the "System Register File" for later usage. I'd be surprised if this does not work with EEPROM, but who knows...
    Last edited by Frank B; 07-04-2017 at 06:16 PM.

  17. #92
    Quote Originally Posted by Frank B View Post
    Hi, at the moment, I can not reproduce this issue. It works well, for me, after power-off/on, too. On the other hand, I don't use the EEPROM.
    For >120MHZ, the code kicks in early, and reads the MAC at "early startup", before initializing anything other, and stores it in the "System Register File" for later usage. I'd be surprised if this does not work with EEPROM, but who knows...
    I will try to erase the eeprom and see if something changes, but seems strange.
    where is the MAC address stored?

  18. #93
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,895
    Quote Originally Posted by lorenzofattori View Post
    where is the MAC address stored?
    Every Kinetis chip has a small, very special "write once" memory, which is used for the mac address. This memory has 8 words of 64 bits. The other chips have slightly different size memory and some are 32 bit words, but they all work the same way. It start as all 1s when Freescale makes the chip. There's a special command to write to this memory, one word at a time. After the word is written, changing any of its bits from 1 or 0, the entire 64 bits are forever locked. If you try to write again, the chip returns an error status and does not change any bits. Erasing the chip does not erase this very special memory. Once written, it's permanent. Well, at least as permanent as the flash memory retains data, which is at least 20 years at extreme temperature and probably hundreds of years at room temperature.

    As each Teensy is tested, PJRC's test gear programs 64 bits of that special "write once" memory with PJRC's IEEE-assigned OUI (mac address upper 24 bits) and a unique serial number. All the other bits of that memory are not touched. But those 64 bits with the mac address are programmed here and can never be altered, even if you fully erase the chip.

  19. #94
    Quote Originally Posted by PaulStoffregen View Post
    Every Kinetis chip has a small, very special "write once" memory, which is used for the mac address. This memory has 8 words of 64 bits. The other chips have slightly different size memory and some are 32 bit words, but they all work the same way. It start as all 1s when Freescale makes the chip. There's a special command to write to this memory, one word at a time. After the word is written, changing any of its bits from 1 or 0, the entire 64 bits are forever locked. If you try to write again, the chip returns an error status and does not change any bits. Erasing the chip does not erase this very special memory. Once written, it's permanent. Well, at least as permanent as the flash memory retains data, which is at least 20 years at extreme temperature and probably hundreds of years at room temperature.

    As each Teensy is tested, PJRC's test gear programs 64 bits of that special "write once" memory with PJRC's IEEE-assigned OUI (mac address upper 24 bits) and a unique serial number. All the other bits of that memory are not touched. But those 64 bits with the mac address are programmed here and can never be altered, even if you fully erase the chip.
    Good to know, thanks Paul.
    I was thinking was saved somewhere in the EEPROM, and loading my stuff the EEPROM could cause issues retrive the MAC. But i think this is not related.

    Both my teensy 3.6 behave the same even with the example of Frank's library.
    After being programmed they are showing the entire MAC correctly, if I unplug and re-plug the USB then the last 3 digits of the MAC are 00.
    I suppose something is wrong in getting the data, maybe some delay is needed before accessing this special memory?

  20. #95
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,895
    Before I look into this, can you tell me which OS you're using, and which version of Arduino and Teensyduino you have (click Help > About to check)? These details can really matter for investigating startup speed issues.

  21. #96
    Quote Originally Posted by PaulStoffregen View Post
    Before I look into this, can you tell me which OS you're using, and which version of Arduino and Teensyduino you have (click Help > About to check)? These details can really matter for investigating startup speed issues.
    Just re-tried with my default configuration: MacOS 10.11 El capitan - Arduino 1.8.2 - Teensyduino 1.36
    Tried to place a delay(10000) before the code and still the same behavior, when I unplug and replug Teensy the MAC is wrong

    Serial: 0
    MAC: 0x04E9E5000000
    Update:
    I lowered down the CPU speed at 120MHz and now is working fine all the time!
    at 144 and 180 is not working after first reboot
    Last edited by lorenzofattori; 07-08-2017 at 01:34 PM. Reason: update

  22. #97
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    15,895
    I tried just now with a Teensy 3.6 at 180 MHz and default settings running Frank's code. I don't have El Capitan, so I tested on a Macbook Air running Sierra 10.12.5.

    Click image for larger version. 

Name:	sc.png 
Views:	26 
Size:	157.9 KB 
ID:	10970

    I unplugged and reconnected the cable several time. I can't get it to reproduce the problem. Every time I plug it in, the serial monitor shows the correct info. This screenshot was after plugging in several times.

  23. #98
    Quote Originally Posted by PaulStoffregen View Post
    I tried just now with a Teensy 3.6 at 180 MHz and default settings running Frank's code. I don't have El Capitan, so I tested on a Macbook Air running Sierra 10.12.5.

    Click image for larger version. 

Name:	sc.png 
Views:	26 
Size:	157.9 KB 
ID:	10970

    I unplugged and reconnected the cable several time. I can't get it to reproduce the problem. Every time I plug it in, the serial monitor shows the correct info. This screenshot was after plugging in several times.
    I also have a Ubuntu laptop, I will give it a try and let you know

  24. #99
    Quote Originally Posted by PaulStoffregen View Post
    I tried just now with a Teensy 3.6 at 180 MHz and default settings running Frank's code. I don't have El Capitan, so I tested on a Macbook Air running Sierra 10.12.5.

    Click image for larger version. 

Name:	sc.png 
Views:	26 
Size:	157.9 KB 
ID:	10970

    I unplugged and reconnected the cable several time. I can't get it to reproduce the problem. Every time I plug it in, the serial monitor shows the correct info. This screenshot was after plugging in several times.
    Tested now With Ubuntu 17.04 - Teensy 3.6 - Arduino 1.8.3 and Teensyduino 1.37
    Same issue here running at 180Mhz

    Settings:
    USB Type: Serial or Serial+Midi
    CPU Speed: 180MHz
    Optimize: Faster (edit: tried also Debug, same issue)


    If you have any idea to test, I'm really willing to do that, I need to make this work
    Lorenzo

  25. #100
    Senior Member manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,196
    Using ubuntu 16.04, IDE 1.8.3/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
    Last edited by manitou; 07-11-2017 at 06:01 PM.

Posting Permissions

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