Library to pull unique device ID from CPU chip. functions to load into a string that can be used in IoT access point ID and another to send the ID back on serial port. Tested on KL46Z but should work on STM and others by changing address where ID is located.

Dependents:   stm32_print_unique_serial_number_copy bcsdk bcsdk bcsdk-sdchain

Committer:
joeata2wh
Date:
Wed Mar 30 14:49:03 2016 +0000
Revision:
2:08766dc8051a
Parent:
1:c7453c2b8a2f
update to use MIT license

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeata2wh 0:b9461291f915 1 /*
joeata2wh 2:08766dc8051a 2 By Joseph Ellsworth CTO of A2WH
joeata2wh 2:08766dc8051a 3 Take a look at A2WH.com Producing Water from Air using Solar Energy
joeata2wh 2:08766dc8051a 4 March-2016 License: https://developer.mbed.org/handbook/MIT-Licence
joeata2wh 0:b9461291f915 5 Please contact us http://a2wh.com for help with custom design projects.
joeata2wh 0:b9461291f915 6
joeata2wh 2:08766dc8051a 7
joeata2wh 0:b9461291f915 8 Most STM and Freescale ARM chips include a unique Serail Number embedded
joeata2wh 0:b9461291f915 9 in the CPU. This is a perfect number to use in IoT as a SSID. I use
joeata2wh 0:b9461291f915 10 this to produce the WIFi SID so I can walk up with a phone and download
joeata2wh 0:b9461291f915 11 telemetry. I found a blog discussion for mbed that suggested using the
joeata2wh 0:b9461291f915 12 MAC but this assumes mbed hardware whereas this version uses the serial
joeata2wh 0:b9461291f915 13 number built in to the CPU so it should work on native boards.
joeata2wh 0:b9461291f915 14 */
joeata2wh 0:b9461291f915 15
joeata2wh 0:b9461291f915 16 #ifndef uniqueCPUID_h
joeata2wh 0:b9461291f915 17 #define uniqueCPUID_h
joeata2wh 0:b9461291f915 18 #include "mbed.h"
joeata2wh 0:b9461291f915 19
joeata2wh 0:b9461291f915 20 #define uniqueSerialAdd_kl_freescale (unsigned long *)0x40048058
joeata2wh 0:b9461291f915 21 #define uniqueSerialAddr_stm32 (unsigned long *)0x1FFFF7E8
joeata2wh 0:b9461291f915 22
joeata2wh 0:b9461291f915 23 //TODO: Add logic to detect the different boards and select the correct
joeata2wh 0:b9461291f915 24 // CPU ID based on the active board.
joeata2wh 1:c7453c2b8a2f 25 //#define uniqueSerialAddr uniqueSerialAdd_kl_freescale
joeata2wh 1:c7453c2b8a2f 26 #define uniqueSerialAddr uniqueSerialAddr_stm32
joeata2wh 0:b9461291f915 27
joeata2wh 0:b9461291f915 28 // Change to enable for address for your chip family
joeata2wh 0:b9461291f915 29 // Note some ealry stm L3 chips were produced with all
joeata2wh 0:b9461291f915 30 // chip ID set to FFF. I have not seen any but did find
joeata2wh 0:b9461291f915 31 // it mentioned in a blog.
joeata2wh 0:b9461291f915 32
joeata2wh 0:b9461291f915 33
joeata2wh 0:b9461291f915 34 /* format the unique serial number as a string. we could use
joeata2wh 0:b9461291f915 35 as the router SID for Lot. Supress leading zeros to save
joeata2wh 0:b9461291f915 36 space */
joeata2wh 0:b9461291f915 37 void getUniqueIDAsStr(char *destStr);
joeata2wh 0:b9461291f915 38
joeata2wh 0:b9461291f915 39 /* Send unique device ID to serail port */
joeata2wh 0:b9461291f915 40 void printUniqueId(Serial pc);
joeata2wh 0:b9461291f915 41
joeata2wh 0:b9461291f915 42 #endif