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:
Fri Mar 11 03:24:53 2016 +0000
Revision:
1:c7453c2b8a2f
Parent:
0:b9461291f915
Child:
2:08766dc8051a
changing over to STM32 chips

Who changed what in which revision?

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