06/21/18

Fork of rtos_threading_with_callback by mbed_example

Revision:
4:61f1412310af
Parent:
3:3e8c16b6620c
diff -r 3e8c16b6620c -r 61f1412310af EasyFuse_Prog.cpp
--- a/EasyFuse_Prog.cpp	Thu Jun 21 22:11:25 2018 +0000
+++ b/EasyFuse_Prog.cpp	Thu Apr 02 17:44:59 2020 +0000
@@ -121,7 +121,7 @@
         
 void i2c_write_fn(I2C *i2c_obj, char ptr, char write_data) {
     int flag1;
-    wait_us(10);
+    wait_us(20);
     (*i2c_obj).start();
     flag1 = (*i2c_obj).write(dev_addr);
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack for dev addr :(");
@@ -129,7 +129,7 @@
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack reg pointer :(");    
     flag1 = (*i2c_obj).write(write_data); 
     if (flag1 != 1) pc.printf("\n\n\r\tNo Ack data :(");           
-    wait_us(5);
+    wait_us(20);
     (*i2c_obj).stop();
 }
 
@@ -158,7 +158,8 @@
     char reg_ptr = 0x00;
     char reg_data[10];
     char data;
-    uint8_t NVM_READ        = 0x70 ;  
+    uint8_t NVM_PWR_ON      = 0x20 ;
+    uint8_t NVM_READ        = 0x90 ; 
     uint8_t NVM_CTLR_ADR    = 0x0a ;  //Register address for NVM CTRL
     uint64_t NVM_data = 0x0000000000000000;
     
@@ -189,8 +190,9 @@
     pc.printf("\n\n\r\tSwitching to faster clock before reading the NVM");    
     i2c_write_fn(i2c_obj,0x02,0x01); //switching to faster clock for NVM read
     i2c_write_fn(i2c_obj,0x03,0x01); //switching to faster clock for NVM read
+    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_PWR_ON);
     wait_ms(1);
-    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,NVM_READ); //Perform a complete read; will be sucessful only if NVM is not empty    
+    i2c_write_fn(i2c_obj,NVM_CTLR_ADR,(NVM_PWR_ON + NVM_READ)); //Perform a complete read; will be sucessful only if NVM is not empty    
     wait_ms(100);
 
     //check if tm_nvm_read bit has cleared itself
@@ -280,11 +282,11 @@
     uint8_t adc_op_mode = 0x01;
 
     // NVM Register Control Bit locations; PWR_ON set in all the definitions
-    uint8_t NVM_RESET       = 0x31 ;
+    uint8_t NVM_RESET       = 0x01 ;
     uint8_t NVM_PWE1        = 0x02 ;
-    uint8_t NVM_CLK1        = 0x34 ;
-    uint8_t NVM_PWR_ON      = 0x30 ;
-    uint8_t NVM_READ        = 0x70 ;
+    uint8_t NVM_CLK1        = 0x04 ;
+    uint8_t NVM_PWR_ON      = 0x20 ;
+    uint8_t NVM_READ        = 0x90 ;//unpdated in Rev1.0
     
     uint8_t NVM_CTLR_ADR     = 0x0a ;  //Register address for NVM CTRL
      
@@ -343,20 +345,20 @@
         return;
     }
     //EasyFuse Empty check
-    pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents");
+    pc.printf("\n\n\r\tPerforming NVM Empty check by trying to load register with NVM contents. Connect 4.5V at PROG pin");
     i2c_write_fn(&i2c,0x02,0x01); //switching to faster clock for NVM read
     i2c_write_fn(&i2c,0x03,0x01); //switching to faster clock for NVM read
     wait_ms(1);
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_READ); //Perform a complete read; will be sucessful only if NVM is not empty    
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_READ + NVM_PWR_ON)); //Force NVM load    
     wait_ms(100);
     
     //check if tm_nvm_read bit has cleared itself
     temp = 0;
     while (temp == 0){
         reg_data = i2c_read_fn(&i2c,NVM_CTLR_ADR);
-        reg_data = reg_data & 0x40;
+        reg_data = reg_data & 0x80; //updated in Rev1.0; checking for tm_ld_shdw
         if (reg_data == 0x00) {
-                pc.printf("\n\n\r\ttm_nvm_read has cleared; so loading Register with NVM complete");
+                pc.printf("\n\n\r\ttm_ld_shdw has cleared; so loading Register with NVM contents complete");
                 temp = 1;
         }
         else wait_ms(100);
@@ -366,7 +368,7 @@
     reg_data = reg_data<<4;
     reg_data = reg_data | i2c_read_fn(&i2c,0x03);
     if (reg_data == 0xff) pc.printf("  |\033[%dm  Register read might not be sucessfull \033[%dm ",45,40);
-    if (reg_data == 0x11) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //no change at address 0x02 & 0x03
+    if (reg_data == 0x00) pc.printf("\n\n\r\t\033[%dm EasyFuse empty \033[%dm",44,40); //address 0x02 & 0x03 changed to 0
     else {
         pc.printf("\n\n\r\t\033[%dm EasyFuse not empty \033[%dm",45,40);
         pc.printf("\n\n\r\t Better to abort the test.. :(");
@@ -383,7 +385,8 @@
         pc.printf("\n\n\r\tAborting.. :(");
         return;
     }
-    pc.printf("\n\n\r\tEnabled 'fc_enable' & driver1. Monitor the oscillator at the output of comparator");     
+    i2c_write_fn(&i2c,0x00,0x08); //setting Vout_max to 4.6
+    pc.printf("\n\n\r\tEnabled 'fc_enable' & driver1. Set VINP to 4.0V. Monitor the oscillator at the output of comparator");     
     i2c_write_fn(&i2c,0x0c,0x22);   
 osc_trim:
     i2c_write_fn(&i2c,0x02,high_time_prog); //Recommended clocks period 
@@ -425,25 +428,35 @@
     pc.printf("\n\n\n\r\tAll set to program the EasyFuse, time to blow up some ploy fuses! ..**BOOOM**\n\n\r"); 
     i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //turn ON supply to EasyFuse
     wait_ms(100);    
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_RESET); //turn ON supply to EasyFuse & RESETN = 1
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON)); //turn ON supply to EasyFuse & RESETN = 1
     wait_ms(1);
     i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_PWR_ON); //RESETN = 0, Prog mode enabled: CKL1 = 0 during RESETN = 0,
     temp = 0;
-    pc.printf("\n\n\n\r\tConnect PROG to 5V and press 'c' to continue"); 
+    pc.printf("\n\n\n\r\tConnect PROG to 4.5V & VINP to 5V and press 'c' to continue"); 
     while ( temp!='c') {
         temp = pc.getc();
     }    
+    pc.printf("\n\n\n\r\t");
     wait_us(delay2);
-    i2c_write_fn(&i2c,NVM_CTLR_ADR,NVM_RESET);  //RESETN = 1,
+    i2c_write_fn(&i2c,NVM_CTLR_ADR,(NVM_RESET + NVM_PWR_ON));  //RESETN = 1,
     wait_us(delay2);           
     for ( i = 0; i < 64; i = i+1) {
-        temp =  NVM_RESET + (((NVM_data>>i) & 0x01)?(NVM_PWE1):0); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted
+        if ( ((NVM_data>>i) & 0x0000000000000001) == 1 ) {
+            temp = NVM_PWE1;
+            pc.printf("1");
+        }
+        else { 
+            temp = 0x00;
+            pc.printf("0");
+        }
+        temp =  (temp | NVM_RESET | NVM_PWR_ON); //NVM_PWE1 if NVM_data[i]=1 & CLK1 de-asserted
+        pc.printf("\n\n\n\n\r\ttemp = 0x%2.2X",temp);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp);
         wait_us(delay2);
-        temp =  NVM_RESET;
+        temp =  (NVM_RESET | NVM_PWR_ON);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //de-assert NVM_PWE1
         wait_us(delay2);          
-        temp =  NVM_RESET + NVM_CLK1;
+        temp =  (NVM_RESET | NVM_CLK1 | NVM_PWR_ON);
         i2c_write_fn(&i2c,NVM_CTLR_ADR,temp); //assert CLK1
         wait_us(delay2); 
     }