Small program to read the Part ID and Device Serial Number using IAP commands.

Dependencies:   mbed

Committer:
dminear
Date:
Fri Nov 09 04:04:47 2012 +0000
Revision:
0:ec398694bd6f
Initial release of code to get the device serial number.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dminear 0:ec398694bd6f 1 /*
dminear 0:ec398694bd6f 2 * How to read LPC1768 part ID and device serial number
dminear 0:ec398694bd6f 3 * Dan Minear
dminear 0:ec398694bd6f 4 * 2012-11-08
dminear 0:ec398694bd6f 5 */
dminear 0:ec398694bd6f 6
dminear 0:ec398694bd6f 7 #include "mbed.h"
dminear 0:ec398694bd6f 8
dminear 0:ec398694bd6f 9 #define IAP_LOCATION 0x1FFF1FF1
dminear 0:ec398694bd6f 10
dminear 0:ec398694bd6f 11 typedef void (*IAP)(unsigned long [], unsigned long[] );
dminear 0:ec398694bd6f 12 IAP iap_entry = (IAP) IAP_LOCATION;
dminear 0:ec398694bd6f 13
dminear 0:ec398694bd6f 14 DigitalOut myled(LED1);
dminear 0:ec398694bd6f 15
dminear 0:ec398694bd6f 16 int main() {
dminear 0:ec398694bd6f 17 unsigned long command[5] = {0,0,0,0,0};
dminear 0:ec398694bd6f 18 unsigned long result[5] = {0,0,0,0,0};
dminear 0:ec398694bd6f 19
dminear 0:ec398694bd6f 20 printf("\r\nStart...\r\n");
dminear 0:ec398694bd6f 21
dminear 0:ec398694bd6f 22 // See User Manual section 32.8.5
dminear 0:ec398694bd6f 23 command[0] = 54; // partID
dminear 0:ec398694bd6f 24 printf("\r\nPart ID: (should be 0x2601 3F37 for LPC1768)\r\n");
dminear 0:ec398694bd6f 25 iap_entry(command, result);
dminear 0:ec398694bd6f 26 if (result[0] == 0) {
dminear 0:ec398694bd6f 27 for(int i = 1; i < 2; i++) {
dminear 0:ec398694bd6f 28 printf( "0x%x\r\n", result[i] );
dminear 0:ec398694bd6f 29 }
dminear 0:ec398694bd6f 30 } else {
dminear 0:ec398694bd6f 31 printf("Status error!\r\n");
dminear 0:ec398694bd6f 32 }
dminear 0:ec398694bd6f 33
dminear 0:ec398694bd6f 34 // See User Manual section 32.8.7
dminear 0:ec398694bd6f 35 command[0] = 58; // read device serial number
dminear 0:ec398694bd6f 36 printf("\r\nSerial number:\r\n");
dminear 0:ec398694bd6f 37 iap_entry(command, result);
dminear 0:ec398694bd6f 38 if (result[0] == 0) {
dminear 0:ec398694bd6f 39 for(int i = 1; i < 5; i++) {
dminear 0:ec398694bd6f 40 printf( "0x%x\r\n", result[i] );
dminear 0:ec398694bd6f 41 }
dminear 0:ec398694bd6f 42 } else {
dminear 0:ec398694bd6f 43 printf("Status error!\r\n");
dminear 0:ec398694bd6f 44 }
dminear 0:ec398694bd6f 45
dminear 0:ec398694bd6f 46 printf( "\r\nEnd\r\n" );
dminear 0:ec398694bd6f 47
dminear 0:ec398694bd6f 48 // and now back to the default new project, just flash a LED
dminear 0:ec398694bd6f 49 while(1) {
dminear 0:ec398694bd6f 50 myled = 1;
dminear 0:ec398694bd6f 51 wait(0.2);
dminear 0:ec398694bd6f 52 myled = 0;
dminear 0:ec398694bd6f 53 wait(0.2);
dminear 0:ec398694bd6f 54 }
dminear 0:ec398694bd6f 55 }