Final Jacaranda Program; updated during Harald's visit; In NVM program, set tm_en_vout_mon =1 before updating the oscillator frequency.

Revision:
4:8afc50e5a7bc
Parent:
3:3e8c16b6620c
--- a/EasyFuse_Prog.cpp	Thu Jun 21 22:11:25 2018 +0000
+++ b/EasyFuse_Prog.cpp	Thu Apr 02 20:10:06 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
@@ -262,29 +264,29 @@
     uint64_t NVM_read_data;
     
     // Register variables
-    uint8_t max_Vout = 0x07;
+    uint8_t max_Vout = 0x04;
     uint8_t max_Vout_trim = 0x00;
-    uint8_t high_time = 0x12;
-    uint8_t low_time = 0x29;
-    uint8_t adc_samp_rate = 0x06;
+    uint8_t high_time = 0x0A;
+    uint8_t low_time = 0x53;
+    uint8_t adc_samp_rate = 0x01;
     uint8_t adc_range = 0x01;
     uint8_t adc_time_out = 0x02;
-    uint8_t comp_offset = 0x00;
-    uint8_t range_trim = 0x0f;
+    uint8_t comp_offset = 0x01;
+    uint8_t range_trim = 0x10;
     uint8_t PMOS_off = 0x08;
     uint8_t Driver2 = 0x08;
     uint8_t Driver3 = 0x08;
     uint8_t DMOS = 0x01;
     uint8_t CCM_threshold = 0x0f;
     uint8_t DMOS_ctrl_trim = 0x0c;
-    uint8_t adc_op_mode = 0x01;
+    uint8_t adc_op_mode = 0x00;
 
     // 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,8 +385,10 @@
         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);   
+    i2c_write_fn(&i2c,0x0b,0x08);      
 osc_trim:
     i2c_write_fn(&i2c,0x02,high_time_prog); //Recommended clocks period 
     i2c_write_fn(&i2c,0x03,low_time_prog); // for programming is 10us
@@ -425,25 +429,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); 
     }