Version 1

Dependencies:   mbed-os-retarget-segger-rtt SPI_MX25R

Files at this revision

API Documentation at this revision

Comitter:
d4rth_j0k3r
Date:
Fri Sep 04 13:36:18 2020 +0000
Parent:
2:1f796b4529df
Commit message:
Fnish

Changed in this revision

mbed-os-retarget-segger-rtt.lib Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
source/main.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1f796b4529df -r 3e570f67f243 mbed-os-retarget-segger-rtt.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os-retarget-segger-rtt.lib	Fri Sep 04 13:36:18 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/0x6d61726b/code/mbed-os-retarget-segger-rtt/#7fca1bf48117
diff -r 1f796b4529df -r 3e570f67f243 source/main.cpp
--- a/source/main.cpp	Wed Aug 12 09:43:52 2020 +0000
+++ b/source/main.cpp	Fri Sep 04 13:36:18 2020 +0000
@@ -32,8 +32,13 @@
                 test_flash_2();
                 MS_State = ST_P3;
                 break;
+            
+            case ST_P3 :
+                test_flash_3();
+                MS_State = ST_P4;
+                break;
                 
-            case ST_P3 :
+            case ST_P4 :
                 test_ADC();
                 MS_State = ST_END;
                 break;             
@@ -41,9 +46,9 @@
             case ST_END :
                 printf("\n\r==== TESTS RESULTS ====\n\n\r");
                 printf("Test done with %d data\n\r",MAX_DATA);
-                printf("1. Flash 1-by-1 : %d\n\r",nr_error[0]);
-                printf("2. Flash array  : %d\n\r",nr_error[1]);
-                printf("3. ADC          : %d\n\r",nr_error[2]);
+                printf("1. Flash 1-by-1             : %d\n\r",nr_error[0]);
+                printf("2. Flash array              : %d\n\r",nr_error[1]);
+                printf("3. Flash multiples arrays   : %d\n\r",nr_error[1]);
                 printf("\nRestart test session (0/1)?\n\r") ;
                 printf("> ") ;
                 scanf("%d", &go_out) ;
@@ -66,6 +71,8 @@
     printf("> ") ;
     scanf("%d", &MAX_DATA) ;
     
+    start_add = 0;
+    
     // Resistance to size of 0
     MAX_DATA = (MAX_DATA == 0) ? 16 : MAX_DATA;
     printf("\n\rTest with %d bytes\n\r",MAX_DATA);
@@ -74,8 +81,9 @@
         nr_error[i] = 0;
     }
     
+    button.rise(&flip_led); // Button Interrupt
+    
     // Next State
-    
     MS_State = ST_P1;
 }
 
@@ -83,12 +91,10 @@
 void test_flash_1(){
     printf("\n\r==== 1. Flash Memory Test 1-by-1 ====\n\n\r");
     clear_memory();
-    reset_leds();
-    myled_2.write(0);
     
     uint8_t data_in, data_out;
 
-    for (int address = 0; address < MAX_DATA; address++){
+    for (int address = start_add; address < MAX_DATA; address++){
         // Generating data to be written
         data_in = rand() % 256;
         data_out = 0;
@@ -100,8 +106,8 @@
         
         // Read data written
         data_out = spi_mem.read8(address);
-        nr_error[0] = error_check(address, data_in, data_out);
-        if (nr_error[0]) break;
+        nr_error[0] += error_check(address, data_in, data_out);
+        //if (nr_error[0]) break;
     }
 
     read_range(MAX_DATA);
@@ -114,31 +120,29 @@
 void test_flash_2(){
     printf("\n\n\r==== 2. Flash Memory Test Array ====\n\n\r");
     clear_memory();
-    reset_leds();
-    myled_3.write(0);
     
     uint8_t data_in[MAX_DATA], data_out[MAX_DATA];
     int address;
     
     // Generating data to be written
-    for (address = 0; address < MAX_DATA; address++){
+    for (address = start_add; address < MAX_DATA; address++){
         data_in[address] = rand() % 256;
         data_out[address] = 0;
     }
     
     // Send data
     spi_mem.writeEnable();
-    spi_mem.programPage(0, data_in, MAX_DATA);
+    spi_mem.programPage(start_add, data_in, MAX_DATA);
     while(spi_mem.readStatus() & 0x01){} // Check status
     printf("[INFO] Data sent\n\r");
     
     // Read data written
-    printf("Checking in/Out Data ");
-    for (address = 0; address < MAX_DATA; address++){
+    printf("Checking In/Out Data ");
+    for (address = start_add; address < MAX_DATA; address++){
         printf(".");
         data_out[address] = spi_mem.read8(address);
-        nr_error[1] = error_check(address, data_in[address], data_out[address]);
-        if (nr_error[1]) break;
+        nr_error[1] += error_check(address, data_in[address], data_out[address]);
+        //if (nr_error[1]) break;
     }
     printf("\n\r");
     
@@ -148,18 +152,62 @@
     }
 }
 
+// ==== TEST FLASH 3 ====
+void test_flash_3(){
+    printf("\n\n\r==== 3. Flash Memory Test Multiple Arrays ====\n\n\r");
+    clear_memory();
+    
+    uint8_t data_size = 4;
+    uint8_t data_in[256*data_size], data_out[256*data_size];
+    uint8_t buffer[256];
+    int address;
+          
+    // Generating data to be written
+    for (int iter = 0; iter < 256*data_size; iter++){
+        data_in[iter] = rand() % 256;
+        data_out[iter] = 0;
+    }
+    for (int iter = 0; iter < 256; iter++){
+        buffer[iter] = 0;
+    }
+        
+    for (int nbr = 0; nbr < data_size; nbr++){
+        // Send data
+        for (int idx = 0; idx < 256; idx++){
+            buffer[idx] = data_in[nbr*256+idx];
+        }
+        spi_mem.writeEnable();
+        spi_mem.programPage(nbr*256, buffer, 256);
+        while(spi_mem.readStatus() & 0x01){} // Check status
+    }
+    printf("[INFO] Data sent\n\r");
+        
+    // Read data written
+    printf("Checking In/Out Data ");
+    for (address = 0; address < data_size*256; address++){
+        printf(".");
+        data_out[address] = spi_mem.read8(address);
+        nr_error[2] += error_check(address, data_in[address], data_out[address]);
+        //if (nr_error[1]) break;
+    }
+    printf("\n\r");
+    
+    read_range(data_size*256);
+    if (!nr_error[2]){
+        printf("Test passed successfully\n\r");
+    }
+}
+
 // ==== TEST ADC ====
 void test_ADC(){
-    printf("\n\n\r==== 3. ADC Test ====\n\n\r");
+    printf("\n\n\r==== 4. ADC Test ====\n\n\r");
     clear_memory();
-    reset_leds();
-    myled_4.write(0);
     
     // ADC 12 bits framerate 200 ksps during 10 sec : 4 Mo
     
     uint8_t data_in[2], data_out[2];
     float analog_in, analog_out;
-    int max_adc = 64;
+    int max_adc = 32;
     
     // Generating data to be written
     for (int i = 0; i < max_adc; i++){
@@ -179,6 +227,9 @@
 
 // =========================
 // ==== OTHER FUNCTIONS ====
+void flip_led(){
+    myled = !myled;
+}
 
 void read_range(int max_data){
     printf("[INFO] Memory State :");
@@ -195,17 +246,10 @@
     printf("\n\n\r");
 }
 
-void reset_leds(){
-    myled_1.write(1);
-    myled_2.write(1);
-    myled_3.write(1);
-    myled_4.write(1);
-}
-
 void clear_memory(){
     spi_mem.writeEnable();
     spi_mem.sectorErase(0);
-    read_range(MAX_DATA);
+    while(spi_mem.readStatus() & 0x01){} // Check status
     printf("[INFO] Memory Cleared\n\r");
 }
 
diff -r 1f796b4529df -r 3e570f67f243 source/main.h
--- a/source/main.h	Wed Aug 12 09:43:52 2020 +0000
+++ b/source/main.h	Fri Sep 04 13:36:18 2020 +0000
@@ -4,14 +4,15 @@
  */
 
 // ==== PROTOTYPES ====
-void reset_leds();
 void clear_memory();
 void read_range(int max_data);
 
 void init();
+void flip_led();
 void bluetooth();
 void test_flash_1();
 void test_flash_2();
+void test_flash_3();
 void test_ADC();
 
 bool error_check(int index, unsigned char data_in, unsigned char data_out);
@@ -20,6 +21,7 @@
 // ==== GLOBAL VARIABLES ====
 bool nr_error[3];
 int MAX_DATA;
+int start_add;
 
 enum States
 {
@@ -27,18 +29,17 @@
     ST_P1,
     ST_P2,
     ST_P3,
+    ST_P4,
     ST_END
 };
 States MS_State;
 
 // ==== INPUT / OUTPUT ====
-// Digital Outputs
-//DigitalOut myled(LED_1);
-DigitalOut myled(P0_13);
+// Interrupt
+InterruptIn button(P0_12);
 
-// Digital Inputs
-DigitalIn button(P0_12);
-//DigitalIn button(BUTTON_2);
+// Digital Outputs
+DigitalOut myled(P0_13);
 
 // Analogs Inputs
 AnalogIn Mic_Amb(P0_2);