Benchmark Sute based on Arduino speed benchmark, adapted and modified for ARM Cortex-M7 ST Nucleo-144 STM32F767 and STM32F746 MCU's by Jovan Ivković 2017. https://hackaday.io/JovanE (Work based on Original Arduino Speed Test Benchmark Program by Dan Watson modified by Chester Lowrey)

Dependencies:   STM32F4_RNG mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //************************************************************
00002 //**   Benchmark Sute based on Arduino bench.           ******
00003 //**  adapted and mod. for ARM Cortex-M7 ST Nucleo-144  ******
00004 //**  Stm32F767 and STM32F746 MCU's by                  ******
00005 //**           Jovan Ivkovic 2016.                      ******
00006 //**         JovanEps (jovan.eps@gmail.com).            ******
00007 //************************************************************
00008 #include "mbed.h"
00009 #include "STM32F4_RNG.h"
00010 //DigitalOut myled(LED1);
00011 PwmOut PD13(PA_5); //PWM Out to simulate Arduino Analog.Write
00012 //AnalogIn analog_value(A0);
00013 AnalogIn analog_value(PA_3);
00014 AnalogOut DACout(PA_4); //Full DAC - analog out (write)
00015 Serial pc(USBTX, USBRX);
00016 DigitalOut PD7(PF_13);  //introduce D7 pin-out *-Clear port it ping faster :)
00017 DigitalIn PD8(PF_12);
00018 DigitalInOut PD5(PE_11);
00019 Timer timer;            //Timer
00020 
00021 #include <math.h>
00022 #define delay   wait_ms
00023 #define delayMicroseconds   wait_us
00024 #define millis()  timer.read_ms()
00025 #define digitalWrite    DigitalOut
00026 #define HIGH    1
00027 #define LOW    0
00028 
00029 // Arduino Speed Test Benchmarking Program
00030 // Original Program Credit: Arduino.cc
00031 // Modified By: Dan Watson
00032 // synchannel.blogspot.com
00033 // 1-29-2015
00034 
00035 // Modified By: Chester Lowrey
00036 // easybotics.com hilo90mhz.com
00037 // 2016-12-1
00038 
00039 // This sketch is the speed test portion of the Arduino Show Info program
00040 // http://playground.arduino.cc/Main/ShowInfo
00041 
00042 // Certain tests may not compile/run for all boards. Comment them out as necessary:
00043 //  * analogReference()
00044 //  * dtostrf()
00045 //  * bitSet()
00046 //  * y |= (1<<x)
00047 
00048 // For the Arduino Zero, "Serial." needs to be "SerialUSB.". A find and replace is the easiest way
00049 // to fix this. The program may also run in forked IDEs (such as Mpide for the chipKIT boards).
00050 
00051 // All configuration options listed below for reference
00052 
00053 // PIN_1 is used for digitalRead
00054 // PIN_2 is used for digitalWrite / pinMode / analogWrite (PWM)
00055 // Analog read is hardcoded to 0/1
00056 
00057 #define noTitle        // define to remove titles - easier to paste results into comparison spreadsheet
00058 //#define noAnalog       // define to remove analog read/write for ICs without this function
00059 #define noAnalogRef    // define to remove analogRef test that some cores do not support 
00060 //#define noDtostrfTest  // define to remove the dtostrf test that some cores do not support
00061 //#define noBvTest       // define to remove bv test that some cores do not support
00062 //#define USBserialWait  // define to force the main sketch to wait for USB to Serial connection - needed on some native serial boards
00063 //#define noLtoaTest     // define to remove Itoa test that some cores do not support
00064 
00065 // Uncomment only one of the below configurations for your specifc board, or make a new one
00066 
00067 /*
00068 // Arduino ATMEGA328
00069 #define PIN_1 3
00070 #define PIN_2 4
00071 */
00072 
00073 /*
00074 // Arduino Leonardo
00075 #define PIN_1 2
00076 #define PIN_2 3
00077 #define noBvTest
00078 #define USBserialWait
00079 */
00080 
00081 
00082 // Nucleo STM32F103RB - not tested yet /WE DO NOT USE THOSE SETINGS
00083 #define PIN_1 12
00084 #define PIN_2 13
00085 #define noAnalog
00086 #define noBvTest
00087 #define noLtoaTest
00088 
00089 /*
00090 // Arduino Due
00091 #define PIN_1 2
00092 #define PIN_2 3
00093 #define noDtostrfTest
00094 #define noBvTest
00095 #define USBserialWait
00096 */
00097 
00098 /*
00099 // Arduino Zero Pins
00100 #define PIN_1 2
00101 #define PIN_2 3
00102 #define noBvTest
00103 #define noDtostrfTest
00104 #define USBserialWait
00105 */
00106 
00107 /*
00108 // ESP8266 Pins
00109 #define PIN_1 4
00110 #define PIN_2 5
00111 #define PIN_3 12
00112 */
00113 
00114 /*
00115 // ESP32 Pins
00116 #define PIN_1 25
00117 #define PIN_2 26
00118 #define PIN_3 27
00119 #define noAnalog
00120 */
00121 
00122 /*
00123 // NRF52/51 Pins
00124 #define PIN_1 17
00125 #define PIN_2 18
00126 #define PIN_3 19
00127 #define noDtostrfTest
00128 #define noBvTest
00129 */
00130 
00131 void setup()
00132 {
00133     //Serial.begin(9600);
00134     pc.baud(9600);
00135 
00136     /*
00137     #ifdef USBserialWait
00138      while (!Serial) {
00139        ; // wait for serial port to connect. Needed for native USB
00140      }
00141     #endif
00142 
00143 
00144      pinMode(PIN_1, OUTPUT);
00145      pinMode(PIN_2, INPUT);
00146 
00147      pc.printfln("Speed Test will begin momentarily.");
00148      pc.printfln("");
00149 
00150      wait_ms(1000);
00151 
00152      speedTest();
00153      */
00154 }
00155 
00156 void speedTest(void)
00157 {
00158     register int i,j;
00159     volatile unsigned char c1,c2;
00160     volatile int v;
00161     volatile long l1,l2;
00162     volatile float f1,f2;
00163     int p,q;
00164     long int r;
00165     unsigned long m,n;
00166     float d, overhead;
00167     char buffer[30];
00168     int digitalRead;
00169     float meas; //Analog readings
00170 #define F_CPU 216000000
00171 #define DEC 10
00172 
00173 
00174 //#ifndef noTitle
00175     pc.printf("\n\r");
00176     pc.printf("Speed test \n\r");
00177     pc.printf("---------- \n\r");
00178     pc.printf("F_CPU = ");
00179 //#endif
00180     pc.printf("%d",F_CPU/1000000);
00181     pc.printf(" MHz \n\r");
00182 //#ifndef noTitle
00183     pc.printf("1/F_CPU = ");
00184 //#endif
00185     pc.printf("%.4f",(1000000.0/(float)F_CPU));
00186     pc.printf("us \n\r");
00187           
00188     
00189     wait(0.5);    // Allow the Serial text to be transmitted
00190 //#ifndef noTitle
00191     pc.printf("\n\r Start benchmarks");
00192     pc.printf("\n\r ------------------------------");
00193     wait_ms(70);     // Allow the Serial text to be transmitted
00194     pc.printf("\n\r\n\r  NOP                       : ");
00195 //#endif
00196 //*************************
00197 // Start timer
00198 //*************************
00199     timer.start();
00200 //*************************
00201 //    wait_ms(70);     // Allow the Serial text to be transmitted
00202     m = timer.read_ms();
00203     for (i=0; i<100; i++) {
00204         for (j=0; j<10000; j++) {
00205             asm volatile ("nop");
00206             asm volatile ("nop");
00207             asm volatile ("nop");
00208             asm volatile ("nop");
00209             asm volatile ("nop");
00210             asm volatile ("nop");
00211             asm volatile ("nop");
00212             asm volatile ("nop");
00213             asm volatile ("nop");
00214             asm volatile ("nop");
00215             asm volatile ("nop");
00216             asm volatile ("nop");
00217             asm volatile ("nop");
00218             asm volatile ("nop");
00219             asm volatile ("nop");
00220             asm volatile ("nop");
00221             asm volatile ("nop");
00222             asm volatile ("nop");
00223             asm volatile ("nop");
00224             asm volatile ("nop");
00225         }
00226     }
00227     n = timer.read_ms();
00228     d = ((float)n - (float)m) / ((float)i * (float)j);
00229     d *= 1000.0;           // in micro seconds
00230     // Calculate overhead with 'nop' instruction per loop in microseconds
00231     overhead = d - (20.0 * (1000000.0/(float)F_CPU));
00232     d -= overhead;
00233     d /= 20.0;             // per instruction
00234     pc.printf("%.3f us \n\r",d);
00235     pc.printf("\n\r------------------------");
00236 
00237 //#ifndef noTitle
00238     pc.printf("\n\r  digitalRead               : ");
00239 //#endif
00240     wait_ms(70);     // Allow the Serial text to be transmitted
00241     m = timer.read_ms();
00242     for (i=0; i<2; i++) {
00243         for (j=0; j<10000; j++) {
00244 
00245             digitalRead = PD8;
00246             digitalRead = PD8;
00247 
00248             digitalRead = PD8;
00249             digitalRead = PD8;
00250 
00251             digitalRead = PD8;
00252             digitalRead = PD8;
00253 
00254             digitalRead = PD8;
00255             digitalRead = PD8;
00256 
00257             digitalRead = PD8;
00258             digitalRead = PD8;
00259 
00260             digitalRead = PD8;
00261             digitalRead = PD8;
00262 
00263             digitalRead = PD8;
00264             digitalRead = PD8;
00265 
00266             digitalRead = PD8;
00267             digitalRead = PD8;
00268 
00269             digitalRead = PD8;
00270             digitalRead = PD8;
00271 
00272             digitalRead = PD8;
00273             digitalRead = PD8;
00274 
00275             digitalRead = PD8;
00276             digitalRead = PD8;
00277         }
00278     }
00279     n = timer.read_ms();
00280     d = ((float)n - (float)m) / ((float)i * (float)j);
00281     d *= 1000.0;
00282     d -= overhead;
00283     d /= 20.0;
00284     pc.printf("%.3f us \n\r",d);
00285     pc.printf("\n\r");
00286 
00287 
00288 //#ifndef noTitle
00289     pc.printf("\n\r  digitalWrite              : ");
00290 //#endif
00291     wait_ms(70);     // Allow the Serial text to be transmitted
00292     m = timer.read_ms();
00293     for (i=0; i<2; i++) {
00294         for (j=0; j<10000; j++) {
00295             PD7 = HIGH;
00296             PD7 = LOW;
00297 
00298             PD7 = HIGH;
00299             PD7 = LOW;
00300 
00301             PD7 = HIGH;
00302             PD7 = LOW;
00303 
00304             PD7 = HIGH;
00305             PD7 = LOW;
00306 
00307             PD7 = HIGH;
00308             PD7 = LOW;
00309 
00310             PD7 = HIGH;
00311             PD7 = LOW;
00312 
00313             PD7 = HIGH;
00314             PD7 = LOW;
00315 
00316             PD7 = HIGH;
00317             PD7 = LOW;
00318 
00319             PD7 = HIGH;
00320             PD7 = LOW;
00321 
00322             PD7 = HIGH;
00323             PD7 = LOW;
00324         }
00325     }
00326     n = timer.read_ms();
00327     d = ((float)n - (float)m) / ((float)i * (float)j);
00328     d *= 1000.0;
00329     d -= overhead;
00330     d /= 20.0;
00331     pc.printf("%.3f us \n\r",d);
00332     pc.printf("\n\r");
00333 
00334 
00335 //#ifndef noTitle
00336     pc.printf("\n\r  pinMode                   : ");
00337 //#endif
00338     wait_ms(70);     // Allow the Serial text to be transmitted
00339     m = timer.read_ms();
00340     for (i=0; i<2; i++) {
00341         for (j=0; j<10000; j++) {
00342 
00343             digitalRead = PD5.read();
00344             PD5.write(digitalRead);
00345 
00346             digitalRead = PD5.read();
00347             PD5.write(digitalRead);
00348 
00349             digitalRead = PD5.read();
00350             PD5.write(digitalRead);
00351 
00352             digitalRead = PD5.read();
00353             PD5.write(digitalRead);
00354 
00355             digitalRead = PD5.read();
00356             PD5.write(digitalRead);
00357 
00358             digitalRead = PD5.read();
00359             PD5.write(digitalRead);
00360 
00361             digitalRead = PD5.read();
00362             PD5.write(digitalRead);
00363 
00364             digitalRead = PD5.read();
00365             PD5.write(digitalRead);
00366 
00367             digitalRead = PD5.read();
00368             PD5.write(digitalRead);
00369 
00370             digitalRead = PD5.read();
00371             PD5.write(digitalRead);
00372 
00373             digitalRead = PD5.read();
00374             PD5.write(digitalRead);
00375         }
00376     }
00377     n = timer.read_ms();
00378     d = ((float)n - (float)m) / ((float)i * (float)j);
00379     d *= 1000.0;
00380     d -= overhead;
00381     d /= 20.0;
00382     pc.printf("%.3f us \n\r",d);
00383     pc.printf("\n\r");
00384 
00385 
00386 
00387 //#ifndef noTitle
00388     pc.printf("\n\r  multiply byte             : ");
00389 //#endif
00390     c1 = 2;
00391     c2 = 3;
00392     wait_ms(70);     // Allow the Serial text to be transmitted
00393     m = timer.read_ms();
00394     for (i=0; i<20; i++) {
00395         for (j=0; j<10000; j++) {
00396             c1 *= c2;
00397             c1 *= c2;
00398             c1 *= c2;
00399             c1 *= c2;
00400             c1 *= c2;
00401             c1 *= c2;
00402             c1 *= c2;
00403             c1 *= c2;
00404             c1 *= c2;
00405             c1 *= c2;
00406             c1 *= c2;
00407             c1 *= c2;
00408             c1 *= c2;
00409             c1 *= c2;
00410             c1 *= c2;
00411             c1 *= c2;
00412             c1 *= c2;
00413             c1 *= c2;
00414             c1 *= c2;
00415             c1 *= c2;
00416         }
00417     }
00418     n = timer.read_ms();
00419     d = ((float)n - (float)m) / ((float)i * (float)j);
00420     d *= 1000.0;
00421     d -= overhead;
00422     d /= 20.0;
00423     pc.printf("%.3f us \n\r",d);
00424     pc.printf("\n\r");
00425 
00426 
00427 //#ifndef noTitle
00428     pc.printf("\n\r  divide byte               : ");
00429 //#endif
00430     c1 = 253;
00431     c2 = 3;
00432     wait_ms(70);     // Allow the Serial text to be transmitted
00433     m = timer.read_ms();
00434     for (i=0; i<2; i++) {
00435         for (j=0; j<10000; j++) {
00436             c1 /= c2;
00437             c1 /= c2;
00438             c1 /= c2;
00439             c1 /= c2;
00440             c1 /= c2;
00441             c1 /= c2;
00442             c1 /= c2;
00443             c1 /= c2;
00444             c1 /= c2;
00445             c1 /= c2;
00446             c1 /= c2;
00447             c1 /= c2;
00448             c1 /= c2;
00449             c1 /= c2;
00450             c1 /= c2;
00451             c1 /= c2;
00452             c1 /= c2;
00453             c1 /= c2;
00454             c1 /= c2;
00455             c1 /= c2;
00456         }
00457     }
00458     n = timer.read_ms();
00459     d = ((float)n - (float)m) / ((float)i * (float)j);
00460     d *= 1000.0;
00461     d -= overhead;
00462     d /= 20.0;
00463     pc.printf("%.3f us \n\r",d);
00464     pc.printf("\n\r");
00465 
00466 
00467 //#ifndef noTitle
00468     pc.printf("\n\r  add byte                  : ");
00469 //#endif
00470     c1 = 1;
00471     c2 = 2;
00472     wait_ms(70);     // Allow the Serial text to be transmitted
00473     m = timer.read_ms();
00474     for (i=0; i<20; i++) {
00475         for (j=0; j<10000; j++) {
00476             c1 += c2;
00477             c1 += c2;
00478             c1 += c2;
00479             c1 += c2;
00480             c1 += c2;
00481             c1 += c2;
00482             c1 += c2;
00483             c1 += c2;
00484             c1 += c2;
00485             c1 += c2;
00486             c1 += c2;
00487             c1 += c2;
00488             c1 += c2;
00489             c1 += c2;
00490             c1 += c2;
00491             c1 += c2;
00492             c1 += c2;
00493             c1 += c2;
00494             c1 += c2;
00495             c1 += c2;
00496         }
00497     }
00498     n = timer.read_ms();
00499     d = ((float)n - (float)m) / ((float)i * (float)j);
00500     d *= 1000.0;
00501     d -= overhead;
00502     d /= 20.0;
00503     pc.printf("%.3f us \n\r",d);
00504     pc.printf("\n\r");
00505 
00506 
00507 //#ifndef noTitle
00508     pc.printf("\n\r  multiply integer          : ");
00509 //#endif
00510     volatile int x,y;
00511     x = 2;
00512     y = 3;
00513     wait_ms(70);     // Allow the Serial text to be transmitted
00514     m = timer.read_ms();
00515     for (i=0; i<10; i++) {
00516         for (j=0; j<10000; j++) {
00517             x *= y;
00518             x *= y;
00519             x *= y;
00520             x *= y;
00521             x *= y;
00522             x *= y;
00523             x *= y;
00524             x *= y;
00525             x *= y;
00526             x *= y;
00527             x *= y;
00528             x *= y;
00529             x *= y;
00530             x *= y;
00531             x *= y;
00532             x *= y;
00533             x *= y;
00534             x *= y;
00535             x *= y;
00536             x *= y;
00537         }
00538     }
00539     n = timer.read_ms();
00540     d = ((float)n - (float)m) / ((float)i * (float)j);
00541     d *= 1000.0;
00542     d -= overhead;
00543     d /= 20.0;
00544     pc.printf("%.3f us \n\r",d);
00545     pc.printf("\n\r");
00546 
00547 
00548 //#ifndef noTitle
00549     pc.printf("\n\r  divide integer            : ");
00550 //#endif
00551     x = 31415;
00552     y = 3;
00553     wait_ms(70);     // Allow the Serial text to be transmitted
00554     m = timer.read_ms();
00555     for (i=0; i<1; i++) {
00556         for (j=0; j<10000; j++) {
00557             x /= y;
00558             x /= y;
00559             x /= y;
00560             x /= y;
00561             x /= y;
00562             x /= y;
00563             x /= y;
00564             x /= y;
00565             x /= y;
00566             x /= y;
00567             x /= y;
00568             x /= y;
00569             x /= y;
00570             x /= y;
00571             x /= y;
00572             x /= y;
00573             x /= y;
00574             x /= y;
00575             x /= y;
00576             x /= y;
00577         }
00578     }
00579     n = timer.read_ms();
00580     d = ((float)n - (float)m) / ((float)i * (float)j);
00581     d *= 1000.0;
00582     d -= overhead;
00583     d /= 20.0;
00584     pc.printf("%.3f us \n\r",d);
00585     pc.printf("\n\r");
00586 
00587 
00588 //#ifndef noTitle
00589     pc.printf("\n\r  add integer               : ");
00590 //#endif
00591     x = 1;
00592     y = 3;
00593     wait_ms(70);     // Allow the Serial text to be transmitted
00594     m = timer.read_ms();
00595     for (i=0; i<10; i++) {
00596         for (j=0; j<10000; j++) {
00597             x += y;
00598             x += y;
00599             x += y;
00600             x += y;
00601             x += y;
00602             x += y;
00603             x += y;
00604             x += y;
00605             x += y;
00606             x += y;
00607             x += y;
00608             x += y;
00609             x += y;
00610             x += y;
00611             x += y;
00612             x += y;
00613             x += y;
00614             x += y;
00615             x += y;
00616             x += y;
00617         }
00618     }
00619     n = timer.read_ms();
00620     d = ((float)n - (float)m) / ((float)i * (float)j);
00621     d *= 1000.0;
00622     d -= overhead;
00623     d /= 20.0;
00624     pc.printf("%.3f us \n\r",d);
00625     pc.printf("\n\r");
00626 
00627 
00628 //#ifndef noTitle
00629     pc.printf("\n\r  multiply long             : ");
00630 //#endif
00631     l1 = 2;
00632     l2 = 3;
00633     wait_ms(70);     // Allow the Serial text to be transmitted
00634     m = timer.read_ms();
00635     for (i=0; i<2; i++) {
00636         for (j=0; j<10000; j++) {
00637             l1 *= l2;
00638             l1 *= l2;
00639             l1 *= l2;
00640             l1 *= l2;
00641             l1 *= l2;
00642             l1 *= l2;
00643             l1 *= l2;
00644             l1 *= l2;
00645             l1 *= l2;
00646             l1 *= l2;
00647             l1 *= l2;
00648             l1 *= l2;
00649             l1 *= l2;
00650             l1 *= l2;
00651             l1 *= l2;
00652             l1 *= l2;
00653             l1 *= l2;
00654             l1 *= l2;
00655             l1 *= l2;
00656             l1 *= l2;
00657         }
00658     }
00659     n = timer.read_ms();
00660     d = ((float)n - (float)m) / ((float)i * (float)j);
00661     d *= 1000.0;
00662     d -= overhead;
00663     d /= 20.0;
00664     pc.printf("%.3f us \n\r",d);
00665     pc.printf("\n\r");
00666 
00667 
00668 //#ifndef noTitle
00669     pc.printf("\n\r  divide long               : ");
00670 //#endif
00671     l1 = 2000000000L;
00672     l2 = 3;
00673     wait_ms(70);     // Allow the Serial text to be transmitted
00674     m = timer.read_ms();
00675     for (i=0; i<1; i++) {
00676         for (j=0; j<2000; j++) {
00677             l1 /= l2;
00678             l1 /= l2;
00679             l1 /= l2;
00680             l1 /= l2;
00681             l1 /= l2;
00682             l1 /= l2;
00683             l1 /= l2;
00684             l1 /= l2;
00685             l1 /= l2;
00686             l1 /= l2;
00687             l1 /= l2;
00688             l1 /= l2;
00689             l1 /= l2;
00690             l1 /= l2;
00691             l1 /= l2;
00692             l1 /= l2;
00693             l1 /= l2;
00694             l1 /= l2;
00695             l1 /= l2;
00696             l1 /= l2;
00697         }
00698     }
00699     n = timer.read_ms();
00700     d = ((float)n - (float)m) / ((float)i * (float)j);
00701     d *= 1000.0;
00702     d -= overhead;
00703     d /= 20.0;
00704     pc.printf("%.3f us \n\r",d);
00705     pc.printf("\n\r");
00706 
00707 
00708 //#ifndef noTitle
00709     pc.printf("\n\r  add long                  : ");
00710 //#endif
00711     l1 = 500000000L;
00712     l2 = 123;
00713     wait_ms(70);     // Allow the Serial text to be transmitted
00714     m = timer.read_ms();
00715     for (i=0; i<4; i++) {
00716         for (j=0; j<10000; j++) {
00717             l1 += l2;
00718             l1 += l2;
00719             l1 += l2;
00720             l1 += l2;
00721             l1 += l2;
00722             l1 += l2;
00723             l1 += l2;
00724             l1 += l2;
00725             l1 += l2;
00726             l1 += l2;
00727             l1 += l2;
00728             l1 += l2;
00729             l1 += l2;
00730             l1 += l2;
00731             l1 += l2;
00732             l1 += l2;
00733             l1 += l2;
00734             l1 += l2;
00735             l1 += l2;
00736             l1 += l2;
00737         }
00738     }
00739     n = timer.read_ms();
00740     d = ((float)n - (float)m) / ((float)i * (float)j);
00741     d *= 1000.0;
00742     d -= overhead;
00743     d /= 20.0;
00744     pc.printf("%.3f us \n\r",d);
00745     pc.printf("\n\r");
00746 
00747 
00748 //#ifndef noTitle
00749     pc.printf("\n\r  multiply float            : ");
00750 //#endif
00751     f1 = 3.24;
00752     f2 = 1.25;
00753     wait_ms(70);     // Allow the Serial text to be transmitted
00754     m = timer.read_ms();
00755     for (i=0; i<2; i++) {
00756         for (j=0; j<10000; j++) {
00757             f1 *= f2;
00758             f1 *= f2;
00759             f1 *= f2;
00760             f1 *= f2;
00761             f1 *= f2;
00762             f1 *= f2;
00763             f1 *= f2;
00764             f1 *= f2;
00765             f1 *= f2;
00766             f1 *= f2;
00767             f1 *= f2;
00768             f1 *= f2;
00769             f1 *= f2;
00770             f1 *= f2;
00771             f1 *= f2;
00772             f1 *= f2;
00773             f1 *= f2;
00774             f1 *= f2;
00775             f1 *= f2;
00776             f1 *= f2;
00777         }
00778     }
00779     n = timer.read_ms();
00780     d = ((float)n - (float)m) / ((float)i * (float)j);
00781     d *= 1000.0;
00782     d -= overhead;
00783     d /= 20.0;
00784     pc.printf("%.3f us \n\r",d);
00785     pc.printf("\n\r");
00786 
00787 
00788 //#ifndef noTitle
00789     pc.printf("\n\r  divide float              : ");
00790 //#endif
00791     f1 = 312645.24;
00792     f2 = 1.21;
00793     wait_ms(70);     // Allow the Serial text to be transmitted
00794     m = timer.read_ms();
00795     for (i=0; i<1; i++) {
00796         for (j=0; j<2000; j++) {
00797             f1 /= f2;
00798             f1 /= f2;
00799             f1 /= f2;
00800             f1 /= f2;
00801             f1 /= f2;
00802             f1 /= f2;
00803             f1 /= f2;
00804             f1 /= f2;
00805             f1 /= f2;
00806             f1 /= f2;
00807             f1 /= f2;
00808             f1 /= f2;
00809             f1 /= f2;
00810             f1 /= f2;
00811             f1 /= f2;
00812             f1 /= f2;
00813             f1 /= f2;
00814             f1 /= f2;
00815             f1 /= f2;
00816             f1 /= f2;
00817         }
00818     }
00819     n = timer.read_ms();
00820     d = ((float)n - (float)m) / ((float)i * (float)j);
00821     d *= 1000.0;
00822     d -= overhead;
00823     d /= 20.0;
00824     pc.printf("%.3f us \n\r",d);
00825     pc.printf("\n\r");
00826 
00827 
00828 //#ifndef noTitle
00829     pc.printf("\n\r  add float                 : ");
00830 //#endif
00831     f1 = 9876.54;
00832     f2 = 1.23;
00833     wait_ms(70);     // Allow the Serial text to be transmitted
00834     m = timer.read_ms();
00835     for (i=0; i<1; i++) {
00836         for (j=0; j<10000; j++) {
00837             f1 += f2;
00838             f1 += f2;
00839             f1 += f2;
00840             f1 += f2;
00841             f1 += f2;
00842             f1 += f2;
00843             f1 += f2;
00844             f1 += f2;
00845             f1 += f2;
00846             f1 += f2;
00847             f1 += f2;
00848             f1 += f2;
00849             f1 += f2;
00850             f1 += f2;
00851             f1 += f2;
00852             f1 += f2;
00853             f1 += f2;
00854             f1 += f2;
00855             f1 += f2;
00856             f1 += f2;
00857         }
00858     }
00859     n = timer.read_ms();
00860     d = ((float)n - (float)m) / ((float)i * (float)j);
00861     d *= 1000.0;
00862     d -= overhead;
00863     d /= 20.0;
00864     pc.printf("%.3f us \n\r",d);
00865     pc.printf("\n\r");
00866 
00867 
00868     /*
00869     //#ifndef noTitle
00870         pc.printf("  itoa()                    : ");
00871     //#endif
00872         wait_ms(70);     // Allow the Serial text to be transmitted
00873         m = timer.read_ms();
00874         for (i=0; i<1; i++) {
00875             for (j=0; j<10000; j++) {
00876                 itoa(i,buffer,10);
00877                 itoa(i,buffer,10);
00878                 itoa(i,buffer,10);
00879                 itoa(i,buffer,10);
00880                 itoa(i,buffer,10);
00881                 itoa(i,buffer,10);
00882                 itoa(i,buffer,10);
00883                 itoa(i,buffer,10);
00884                 itoa(i,buffer,10);
00885                 itoa(i,buffer,10);
00886                 itoa(i,buffer,10);
00887                 itoa(i,buffer,10);
00888                 itoa(i,buffer,10);
00889                 itoa(i,buffer,10);
00890                 itoa(i,buffer,10);
00891                 itoa(i,buffer,10);
00892                 itoa(i,buffer,10);
00893                 itoa(i,buffer,10);
00894                 itoa(i,buffer,10);
00895                 itoa(i,buffer,10);
00896             }
00897         }
00898         n = timer.read_ms();
00899         d = ((float)n - (float)m) / ((float)i * (float)j);
00900         d *= 1000.0;
00901         d -= overhead;
00902         d /= 20.0;
00903         pc.printf("%.3f",d);
00904         pc.printf(" us");
00905     */
00906 
00907     /*
00908     #ifndef noLtoaTest
00909         long int l = 314159L;
00910     //#ifndef noTitle
00911         pc.printf("  ltoa()                    : ");
00912     //#endif
00913         wait_ms(70);     // Allow the Serial text to be transmitted
00914         m = timer.read_ms();
00915         for (i=0; i<1; i++) {
00916             for (j=0; j<500; j++) {
00917                 ltoa(l,buffer,10);
00918                 ltoa(l,buffer,10);
00919                 ltoa(l,buffer,10);
00920                 ltoa(l,buffer,10);
00921                 ltoa(l,buffer,10);
00922                 ltoa(l,buffer,10);
00923                 ltoa(l,buffer,10);
00924                 ltoa(l,buffer,10);
00925                 ltoa(l,buffer,10);
00926                 ltoa(l,buffer,10);
00927                 ltoa(l,buffer,10);
00928                 ltoa(l,buffer,10);
00929                 ltoa(l,buffer,10);
00930                 ltoa(l,buffer,10);
00931                 ltoa(l,buffer,10);
00932                 ltoa(l,buffer,10);
00933                 ltoa(l,buffer,10);
00934                 ltoa(l,buffer,10);
00935                 ltoa(l,buffer,10);
00936                 ltoa(l,buffer,10);
00937             }
00938         }
00939         n = timer.read_ms();
00940         d = ((float)n - (float)m) / ((float)i * (float)j);
00941         d *= 1000.0;
00942         d -= overhead;
00943         d /= 20.0;
00944         pc.printf("%.3f",d);
00945         pc.printf(" us");
00946     //#endif
00947     */
00948 
00949     /*
00950     #ifndef noDtostrfTest
00951     //#ifndef noTitle
00952         pc.printf("  dtostrf()                 : ");
00953     //#endif
00954         float d3;
00955         d3 = 3.14159265;
00956         wait_ms(70);     // Allow the Serial text to be transmitted
00957         m = timer.read_ms();
00958         for (i=0; i<2; i++) {
00959             for (j=0; j<1000; j++) {
00960                 dtostrf (d3, 6, 2, buffer);
00961                 dtostrf (d3, 6, 2, buffer);
00962                 dtostrf (d3, 6, 2, buffer);
00963                 dtostrf (d3, 6, 2, buffer);
00964                 dtostrf (d3, 6, 2, buffer);
00965                 dtostrf (d3, 6, 2, buffer);
00966                 dtostrf (d3, 6, 2, buffer);
00967                 dtostrf (d3, 6, 2, buffer);
00968                 dtostrf (d3, 6, 2, buffer);
00969                 dtostrf (d3, 6, 2, buffer);
00970                 dtostrf (d3, 6, 2, buffer);
00971                 dtostrf (d3, 6, 2, buffer);
00972                 dtostrf (d3, 6, 2, buffer);
00973                 dtostrf (d3, 6, 2, buffer);
00974                 dtostrf (d3, 6, 2, buffer);
00975                 dtostrf (d3, 6, 2, buffer);
00976                 dtostrf (d3, 6, 2, buffer);
00977                 dtostrf (d3, 6, 2, buffer);
00978                 dtostrf (d3, 6, 2, buffer);
00979                 dtostrf (d3, 6, 2, buffer);
00980             }
00981         }
00982         n = timer.read_ms();
00983         d = ((float)n - (float)m) / ((float)i * (float)j);
00984         d *= 1000.0;
00985         d -= overhead;
00986         d /= 20.0;
00987         pc.printf("%.3f",d);
00988         pc.printf(" us");
00989     #endif
00990     */
00991 
00992 //**************************
00993 //****      Randomize
00994 //**************************
00995     STM32F4_RNG rnd;
00996     unsigned long num;
00997 //#ifndef noTitle
00998     pc.printf("\n\r  random()                  : ");
00999 //#endif
01000     wait_ms(70);     // Allow the Serial text to be transmitted
01001     m = timer.read_ms();
01002     for (i=0; i<2; i++) {
01003         for (j=0; j<1000; j++) {
01004             //r=random(-2147483647,2147483647);
01005             num = rnd.Get();
01006             num = rnd.Get();
01007             num = rnd.Get();
01008             num = rnd.Get();
01009             num = rnd.Get();
01010             num = rnd.Get();
01011             num = rnd.Get();
01012             num = rnd.Get();
01013             num = rnd.Get();
01014             num = rnd.Get();
01015             num = rnd.Get();
01016             num = rnd.Get();
01017             num = rnd.Get();
01018             num = rnd.Get();
01019             num = rnd.Get();
01020             num = rnd.Get();
01021             num = rnd.Get();
01022             num = rnd.Get();
01023             num = rnd.Get();
01024             num = rnd.Get();
01025 
01026         }
01027     }
01028     n = timer.read_ms();
01029     d = ((float)n - (float)m) / ((float)i * (float)j);
01030     d *= 1000.0;
01031     d -= overhead;
01032     d /= 20.0;
01033     pc.printf("%.3f us \n\r",d);
01034     pc.printf("\n\r");
01035 
01036 //#ifndef noBvTest
01037 //#ifndef noTitle
01038     pc.printf("\n\r  y |= (1<<x)               : ");
01039 //#endif
01040     wait_ms(70);     // Allow the Serial text to be transmitted
01041     m = timer.read_ms();
01042     for (i=0; i<20; i++) {
01043         for (j=0; j<10000; j++) {
01044             //v |= _BV(12);
01045             v |= (1 << 12);
01046             v |= (1 << 12);
01047             v |= (1 << 12);
01048             v |= (1 << 12);
01049             v |= (1 << 12);
01050             v |= (1 << 12);
01051             v |= (1 << 12);
01052             v |= (1 << 12);
01053             v |= (1 << 12);
01054             v |= (1 << 12);
01055             v |= (1 << 12);
01056             v |= (1 << 12);
01057             v |= (1 << 12);
01058             v |= (1 << 12);
01059             v |= (1 << 12);
01060             v |= (1 << 12);
01061             v |= (1 << 12);
01062             v |= (1 << 12);
01063             v |= (1 << 12);
01064             v |= (1 << 12);
01065 
01066         }
01067     }
01068     n = timer.read_ms();
01069     d = ((float)n - (float)m) / ((float)i * (float)j);
01070     d *= 1000.0;
01071     d -= overhead;
01072     d /= 20.0;
01073     pc.printf("%.3f us \n\r",d);
01074     pc.printf("\n\r");
01075     
01076 //#endif
01077 
01078     /*
01079     //#ifndef noTitle
01080         pc.printf("  bitSet()                  : ");
01081     //#endif
01082         wait_ms(70);     // Allow the Serial text to be transmitted
01083         m = timer.read_ms();
01084         for (i=0; i<20; i++) {
01085             for (j=0; j<10000; j++) {
01086                 bitSet (v, 12);
01087                 bitSet (v, 12);
01088                 bitSet (v, 12);
01089                 bitSet (v, 12);
01090                 bitSet (v, 12);
01091                 bitSet (v, 12);
01092                 bitSet (v, 12);
01093                 bitSet (v, 12);
01094                 bitSet (v, 12);
01095                 bitSet (v, 12);
01096                 bitSet (v, 12);
01097                 bitSet (v, 12);
01098                 bitSet (v, 12);
01099                 bitSet (v, 12);
01100                 bitSet (v, 12);
01101                 bitSet (v, 12);
01102                 bitSet (v, 12);
01103                 bitSet (v, 12);
01104                 bitSet (v, 12);
01105                 bitSet (v, 12);
01106             }
01107         }
01108         n = timer.read_ms();
01109         d = ((float)n - (float)m) / ((float)i * (float)j);
01110         d *= 1000.0;
01111         d -= overhead;
01112         d /= 20.0;
01113         pc.printf("%.3f",d);
01114         pc.printf(" us");
01115     */
01116 
01117     /*
01118     //#ifndef noAnalogRef
01119     //#ifndef noTitle
01120         pc.printf("  analogReference()         : ");
01121     //#endif
01122         wait_ms(70);     // Allow the Serial text to be transmitted
01123         m = timer.read_ms();
01124         for (i=0; i<20; i++) {
01125             for (j=0; j<10000; j++) {
01126                 analogReference (EXTERNAL);
01127                 analogReference (DEFAULT);
01128                 analogReference (EXTERNAL);
01129                 analogReference (DEFAULT);
01130                 analogReference (EXTERNAL);
01131                 analogReference (DEFAULT);
01132                 analogReference (EXTERNAL);
01133                 analogReference (DEFAULT);
01134                 analogReference (EXTERNAL);
01135                 analogReference (DEFAULT);
01136                 analogReference (EXTERNAL);
01137                 analogReference (DEFAULT);
01138                 analogReference (EXTERNAL);
01139                 analogReference (DEFAULT);
01140                 analogReference (EXTERNAL);
01141                 analogReference (DEFAULT);
01142                 analogReference (EXTERNAL);
01143                 analogReference (DEFAULT);
01144                 analogReference (EXTERNAL);
01145                 analogReference (DEFAULT);
01146             }
01147         }
01148         n = timer.read_ms();
01149         d = ((float)n - (float)m) / ((float)i * (float)j);
01150         d *= 1000.0;
01151         d -= overhead;
01152         d /= 20.0;
01153         pc.printf("%.3f",d);
01154         pc.printf(" us");
01155     //#endif
01156     */
01157 
01158 //#ifndef noAnalog
01159 //#ifndef noTitle
01160     pc.printf("\n\r  analogRead()              : ");
01161 //#endif
01162     wait_ms(70);     // Allow the Serial text to be transmitted
01163     m = timer.read_ms();
01164     for (i=0; i<1; i++) {
01165         for (j=0; j<1000; j++) {
01166             meas = analog_value.read();
01167             meas = analog_value.read();
01168             meas = analog_value.read();
01169             meas = analog_value.read();
01170             meas = analog_value.read();
01171             meas = analog_value.read();
01172             meas = analog_value.read();
01173             meas = analog_value.read();
01174             meas = analog_value.read();
01175             meas = analog_value.read();
01176             meas = analog_value.read();
01177             meas = analog_value.read();
01178             meas = analog_value.read();
01179             meas = analog_value.read();
01180             meas = analog_value.read();
01181             meas = analog_value.read();
01182             meas = analog_value.read();
01183             meas = analog_value.read();
01184             meas = analog_value.read();
01185             meas = analog_value.read();
01186 
01187         }
01188     }
01189     n = timer.read_ms();
01190     d = ((float)n - (float)m) / ((float)i * (float)j);
01191     d *= 1000.0;
01192     d -= overhead;
01193     d /= 20.0;
01194     pc.printf("%.3f us \n\r",d);
01195     pc.printf("\n\r");
01196 
01197 
01198 //#ifndef noTitle
01199     pc.printf("\n\r  PWM analogWrite()         : ");
01200 //#endif
01201     // Using pin 13 (system led) for output.
01202     wait_ms(70);     // Allow the Serial text to be transmitted
01203     m = timer.read_ms();
01204     for (i=0; i<1; i++) {
01205         for (j=0; j<10000; j++) {
01206             PD13 = 0.5;
01207             PD13 = 0.995;
01208             PD13 = 0.005;
01209             PD13 = 0.35;
01210             PD13 = 0.85;
01211             PD13 = 0.5;
01212             PD13 = 0.995;
01213             PD13 = 0.005;
01214             PD13 = 0.35;
01215             PD13 = 0.85;
01216             PD13 = 0.5;
01217             PD13 = 0.995;
01218             PD13 = 0.005;
01219             PD13 = 0.35;
01220             PD13 = 0.85;
01221             PD13 = 0.5;
01222             PD13 = 0.995;
01223             PD13 = 0.005;
01224             PD13 = 0.35;
01225             PD13 = 0.85;
01226         }
01227     }
01228     n = timer.read_ms();
01229     d = ((float)n - (float)m) / ((float)i * (float)j);
01230     d *= 1000.0;
01231     d -= overhead;
01232     d /= 20.0;
01233     pc.printf("%.3f us \n\r",d);
01234     pc.printf("\n\r");
01235 //#endif
01236 
01237 
01238 //#ifndef noTitle
01239     pc.printf("\n\r  DAC analogWrite()         : ");
01240 //#endif
01241     // Using pin 13 (system led) for output.
01242     wait_ms(70);     // Allow the Serial text to be transmitted
01243     m = timer.read_ms();
01244     for (i=0; i<1; i++) {
01245         for (j=0; j<10000; j++) {
01246             DACout = 0.5;
01247             DACout = 0.995;
01248             DACout = 0.005;
01249             DACout = 0.35;
01250             DACout = 0.85;
01251             DACout = 0.5;
01252             DACout = 0.995;
01253             DACout = 0.005;
01254             DACout = 0.35;
01255             DACout = 0.85;
01256             DACout = 0.5;
01257             DACout = 0.995;
01258             DACout = 0.005;
01259             DACout = 0.35;
01260             DACout = 0.85;
01261             DACout = 0.5;
01262             DACout = 0.995;
01263             DACout = 0.005;
01264             DACout = 0.35;
01265             DACout = 0.85;
01266         }
01267     }
01268     n = timer.read_ms();
01269     d = ((float)n - (float)m) / ((float)i * (float)j);
01270     d *= 1000.0;
01271     d -= overhead;
01272     d /= 20.0;
01273     pc.printf("%.3f us \n\r",d);
01274     pc.printf("\n\r");
01275 //#endif
01276 
01277 
01278 //#ifndef noTitle
01279     pc.printf("\n\r  wait_ms(1)                  : ");
01280 //#endif
01281     wait_ms(70);     // Allow the Serial text to be transmitted
01282     m = timer.read_ms();
01283     for (i=0; i<1; i++) {
01284         for (j=0; j<100; j++) {
01285             wait_ms(1);
01286             wait_ms(1);
01287             wait_ms(1);
01288             wait_ms(1);
01289             wait_ms(1);
01290             wait_ms(1);
01291             wait_ms(1);
01292             wait_ms(1);
01293             wait_ms(1);
01294             wait_ms(1);
01295             wait_ms(1);
01296             wait_ms(1);
01297             wait_ms(1);
01298             wait_ms(1);
01299             wait_ms(1);
01300             wait_ms(1);
01301             wait_ms(1);
01302             wait_ms(1);
01303             wait_ms(1);
01304             wait_ms(1);
01305         }
01306     }
01307     n = timer.read_ms();
01308     d = ((float)n - (float)m) / ((float)i * (float)j);
01309     d *= 1000.0;
01310     d -= overhead;
01311     d /= 20.0;
01312     pc.printf("%.3f us \n\r",d);
01313     pc.printf("\n\r");
01314 
01315 
01316 //#ifndef noTitle
01317     pc.printf("\n\r  wait_ms(100)                : ");
01318 //#endif
01319     wait_ms(70);     // Allow the Serial text to be transmitted
01320     m = timer.read_ms();
01321     for (i=0; i<1; i++) {
01322         for (j=0; j<2; j++) {
01323             wait_ms(100);
01324             wait_ms(100);
01325             wait_ms(100);
01326             wait_ms(100);
01327             wait_ms(100);
01328             wait_ms(100);
01329             wait_ms(100);
01330             wait_ms(100);
01331             wait_ms(100);
01332             wait_ms(100);
01333             wait_ms(100);
01334             wait_ms(100);
01335             wait_ms(100);
01336             wait_ms(100);
01337             wait_ms(100);
01338             wait_ms(100);
01339             wait_ms(100);
01340             wait_ms(100);
01341             wait_ms(100);
01342             wait_ms(100);
01343         }
01344     }
01345     n = timer.read_ms();
01346     d = ((float)n - (float)m) / ((float)i * (float)j);
01347     d *= 1000.0;
01348     d -= overhead;
01349     d /= 20.0;
01350     pc.printf("%.3f us \n\r",d);
01351     pc.printf("\n\r");
01352 
01353 
01354 //#ifndef noTitle
01355     pc.printf("\n\r  wait_us(2)      : ");
01356 //#endif
01357     wait_ms(70);     // Allow the Serial text to be transmitted
01358     m = timer.read_ms();
01359     for (i=0; i<30; i++) {
01360         for (j=0; j<1000; j++) {
01361             wait_us(2);
01362             wait_us(2);
01363             wait_us(2);
01364             wait_us(2);
01365             wait_us(2);
01366             wait_us(2);
01367             wait_us(2);
01368             wait_us(2);
01369             wait_us(2);
01370             wait_us(2);
01371             wait_us(2);
01372             wait_us(2);
01373             wait_us(2);
01374             wait_us(2);
01375             wait_us(2);
01376             wait_us(2);
01377             wait_us(2);
01378             wait_us(2);
01379             wait_us(2);
01380             wait_us(2);
01381         }
01382     }
01383     n = timer.read_ms();
01384     d = ((float)n - (float)m) / ((float)i * (float)j);
01385     d *= 1000.0;
01386     d -= overhead;
01387     d /= 20.0;
01388     pc.printf("%.3f us \n\r",d);
01389     pc.printf("\n\r");
01390 
01391 
01392 //#ifndef noTitle
01393     pc.printf("\n\r  wait_us(5)      : ");
01394 //#endif
01395     wait_ms(70);     // Allow the Serial text to be transmitted
01396     m = timer.read_ms();
01397     for (i=0; i<5; i++) {
01398         for (j=0; j<1000; j++) {
01399             //pc.printfln ("Working");
01400             wait_us(5);
01401             wait_us(5);
01402             wait_us(5);
01403             wait_us(5);
01404             wait_us(5);
01405             wait_us(5);
01406             wait_us(5);
01407             wait_us(5);
01408             wait_us(5);
01409             wait_us(5);
01410             wait_us(5);
01411             wait_us(5);
01412             wait_us(5);
01413             wait_us(5);
01414             wait_us(5);
01415             wait_us(5);
01416             wait_us(5);
01417             wait_us(5);
01418             wait_us(5);
01419             wait_us(5);
01420         }
01421     }
01422     n = timer.read_ms();
01423     d = ((float)n - (float)m) / ((float)i * (float)j);
01424     d *= 1000.0;
01425     d -= overhead;
01426     d /= 20.0;
01427     pc.printf("%.3f us \n\r",d);
01428     pc.printf("\n\r");
01429 
01430 
01431 //#ifndef noTitle
01432     pc.printf("\n\r  wait_us(100)    : ");
01433 //#endif
01434     wait_ms(70);     // Allow the Serial text to be transmitted
01435     m = timer.read_ms();
01436     for (i=0; i<1; i++) {
01437         for (j=0; j<1000; j++) {
01438             wait_us(100);
01439             wait_us(100);
01440             wait_us(100);
01441             wait_us(100);
01442             wait_us(100);
01443             wait_us(100);
01444             wait_us(100);
01445             wait_us(100);
01446             wait_us(100);
01447             wait_us(100);
01448             wait_us(100);
01449             wait_us(100);
01450             wait_us(100);
01451             wait_us(100);
01452             wait_us(100);
01453             wait_us(100);
01454             wait_us(100);
01455             wait_us(100);
01456             wait_us(100);
01457             wait_us(100);
01458         }
01459     }
01460     n = timer.read_ms();
01461     d = ((float)n - (float)m) / ((float)i * (float)j);
01462     d *= 1000.0;
01463     d -= overhead;
01464     d /= 20.0;
01465     pc.printf("%.3f us \n\r",d);
01466     pc.printf("\n\r");
01467 
01468     //*************************
01469     //**    Stop timer      ***
01470     //*************************
01471     timer.stop();
01472     //*************************
01473     pc.printf("-----  END --------");
01474     pc.printf("-------------------");
01475     wait(0.3);
01476 }
01477 
01478 //*********************************
01479 //**         MAIN block          **
01480 //*********************************
01481 int main()
01482 {
01483     setup();
01484     do {
01485         pc.printf("\n\r Speed Test will begin momentarily \n\r");
01486         pc.printf("\n\r");
01487         wait(0.3);
01488         speedTest();
01489         wait(3);
01490     } while (true);
01491 }