LoadCell_STM32_SDRAM_v1

Dependencies:   BSP_DISCO_F746NG DISCO-F746NG_SDRAMBlockDevice LCD_DISCO_F746NG mbed

Fork of LoadCell_STM32 by Tapio Valli

Committer:
tapiov
Date:
Sat Feb 24 11:31:09 2018 +0000
Revision:
4:5fe86291ba03
Parent:
3:22b1719c2b92
Child:
5:f8d3bcb187de
Recommiting for branching. Trying to make data element size to 16 bits to save memory

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tapiov 1:c3c61d08f31b 1 // LoadCell_STM32_RAM v2 main
tapiov 4:5fe86291ba03 2 // (C) Tapio Valli 2018-02-24
tapiov 0:b3e6088c873f 3
tapiov 1:c3c61d08f31b 4 #include "mbed.h"
tapiov 2:386f65563144 5 #include "mbed_stats.h"
tapiov 1:c3c61d08f31b 6
tapiov 1:c3c61d08f31b 7 #include "LCD_DISCO_F746NG.h"
tapiov 0:b3e6088c873f 8
tapiov 1:c3c61d08f31b 9 #include <stdint.h>
tapiov 1:c3c61d08f31b 10 #include <stdio.h>
tapiov 1:c3c61d08f31b 11 #include <stdlib.h>
tapiov 1:c3c61d08f31b 12 #include <string.h>
tapiov 1:c3c61d08f31b 13 #include <assert.h>
tapiov 1:c3c61d08f31b 14 #include <ctype.h>
tapiov 0:b3e6088c873f 15
tapiov 1:c3c61d08f31b 16 #include "main.h"
tapiov 0:b3e6088c873f 17
tapiov 1:c3c61d08f31b 18 // define the Serial object
tapiov 1:c3c61d08f31b 19 Serial pc1(USBTX, USBRX);
tapiov 1:c3c61d08f31b 20 LCD_DISCO_F746NG lcd1;
tapiov 0:b3e6088c873f 21
tapiov 0:b3e6088c873f 22 int main() {
tapiov 1:c3c61d08f31b 23
tapiov 1:c3c61d08f31b 24 char CmdBuffer[30];
tapiov 1:c3c61d08f31b 25 char Arg[30]=" ";
tapiov 1:c3c61d08f31b 26 char Cmd[30]=" ";
tapiov 2:386f65563144 27 size_t n=0;
tapiov 0:b3e6088c873f 28
tapiov 1:c3c61d08f31b 29 uint32_t NoOfPoints=19200;
tapiov 1:c3c61d08f31b 30 uint32_t AvgSize=10;
tapiov 1:c3c61d08f31b 31 uint32_t Period_us=100;
tapiov 1:c3c61d08f31b 32 uint32_t Count_ms=1000;
tapiov 2:386f65563144 33
tapiov 2:386f65563144 34 mbed_stats_heap_t heap_stats;
tapiov 1:c3c61d08f31b 35
tapiov 1:c3c61d08f31b 36 // Clear screen, set it up
tapiov 1:c3c61d08f31b 37 InitScreen(LCD_COLOR_BLACK,LCD_COLOR_WHITE);
tapiov 2:386f65563144 38
tapiov 1:c3c61d08f31b 39 //Initialize data storage
tapiov 1:c3c61d08f31b 40 Array Data;
tapiov 1:c3c61d08f31b 41 initArray(&Data,NoOfPoints); // initially 19200 elements
tapiov 0:b3e6088c873f 42
tapiov 2:386f65563144 43 while (!((strcmp(Cmd,"quit")==0)&&(n==1))) {
tapiov 1:c3c61d08f31b 44
tapiov 1:c3c61d08f31b 45 // Print Ready and current settings
tapiov 1:c3c61d08f31b 46 pc1.printf("Ready. Settings are Points = %u, Avg = %u, Period_us = %u, Count_ms = %u \r\n",
tapiov 1:c3c61d08f31b 47 NoOfPoints,AvgSize,Period_us,Count_ms);
tapiov 2:386f65563144 48
tapiov 2:386f65563144 49 mbed_stats_heap_get(&heap_stats);
tapiov 2:386f65563144 50 printf("Current heap: %lu\r\n", heap_stats.current_size);
tapiov 2:386f65563144 51 printf("Max heap size: %lu\r\n", heap_stats.max_size);
tapiov 1:c3c61d08f31b 52
tapiov 1:c3c61d08f31b 53 pc1.gets(CmdBuffer,30);
tapiov 1:c3c61d08f31b 54 // pc1.printf("I got %s \r\n", CmdBuffer);
tapiov 1:c3c61d08f31b 55 strcpy(Cmd," ");
tapiov 1:c3c61d08f31b 56 strcpy(Arg," ");
tapiov 1:c3c61d08f31b 57
tapiov 1:c3c61d08f31b 58 // Parse command and possible numeric arg
tapiov 1:c3c61d08f31b 59 char s[] = "Initial string";
tapiov 2:386f65563144 60 char ** word_array=NULL;
tapiov 1:c3c61d08f31b 61
tapiov 1:c3c61d08f31b 62 strcpy(s,CmdBuffer);
tapiov 2:386f65563144 63 n=string_parser(s,&word_array);
tapiov 1:c3c61d08f31b 64
tapiov 2:386f65563144 65 for ( size_t i=0;i<n;i++) {
tapiov 1:c3c61d08f31b 66 if (i==0) {strcpy(Cmd,word_array[i]);}
tapiov 1:c3c61d08f31b 67 if (i==1) {strcpy(Arg,word_array[i]);}
tapiov 1:c3c61d08f31b 68 if (i>1) {pc1.printf("Wrong number of arguments \r\n");}
tapiov 0:b3e6088c873f 69 }
tapiov 0:b3e6088c873f 70
tapiov 1:c3c61d08f31b 71 // pc1.printf("Cmd = %s Arg = %s \r\n",Cmd,Arg);
tapiov 2:386f65563144 72 for ( size_t i=0;i<n;i++) free( word_array[i] );
tapiov 2:386f65563144 73 free(word_array);
tapiov 1:c3c61d08f31b 74
tapiov 1:c3c61d08f31b 75 // Branch based on command
tapiov 1:c3c61d08f31b 76 // meas: Sample and plot a data set
tapiov 2:386f65563144 77 if((strcmp(Cmd,"meas")==0)&&(n==1)) {
tapiov 1:c3c61d08f31b 78
tapiov 1:c3c61d08f31b 79 // Countdown
tapiov 1:c3c61d08f31b 80 CountDown(Count_ms);
tapiov 1:c3c61d08f31b 81
tapiov 1:c3c61d08f31b 82 // Sample & plot data one time
tapiov 1:c3c61d08f31b 83 SamplePoints(&Data,NoOfPoints,Period_us);
tapiov 1:c3c61d08f31b 84 AvgAndPlotPoints(&Data,NoOfPoints,AvgSize);
tapiov 1:c3c61d08f31b 85 }
tapiov 0:b3e6088c873f 86
tapiov 1:c3c61d08f31b 87 // setpoints: Adjust sampled points
tapiov 2:386f65563144 88 else if((strcmp(Cmd,"setpoints")==0)&&(n==2)) {
tapiov 1:c3c61d08f31b 89 // Allocate more or less data space
tapiov 1:c3c61d08f31b 90 NoOfPoints=(uint32_t) strtol(Arg,NULL,10);
tapiov 3:22b1719c2b92 91 pc1.printf("Old Data size is %u New NoOfPOints = %u \r\n",Data.size,NoOfPoints);
tapiov 3:22b1719c2b92 92 //freeArray(&Data);
tapiov 3:22b1719c2b92 93 //initArray(&Data,NoOfPoints);
tapiov 3:22b1719c2b92 94 insertArray2(&Data,NoOfPoints);
tapiov 3:22b1719c2b92 95 pc1.printf("New Array size is %u \r\n",Data.size);
tapiov 1:c3c61d08f31b 96 }
tapiov 1:c3c61d08f31b 97
tapiov 1:c3c61d08f31b 98 // setavg: Adjust average amount in samples
tapiov 2:386f65563144 99 else if((strcmp(Cmd,"setavg")==0)&&(n==2)) {
tapiov 1:c3c61d08f31b 100 AvgSize=(uint32_t) strtol(Arg,NULL,10);
tapiov 1:c3c61d08f31b 101 }
tapiov 1:c3c61d08f31b 102
tapiov 1:c3c61d08f31b 103 // setperiod: Adjust sample period in us
tapiov 2:386f65563144 104 else if((strcmp(Cmd,"setperiod")==0)&&(n==2)) {
tapiov 1:c3c61d08f31b 105 Period_us=(uint32_t) strtol(Arg,NULL,10);
tapiov 1:c3c61d08f31b 106 }
tapiov 1:c3c61d08f31b 107
tapiov 1:c3c61d08f31b 108 // setcount: Adjust countdown period in ms
tapiov 2:386f65563144 109 else if((strcmp(Cmd,"setcount")==0)&&(n==2)) {
tapiov 1:c3c61d08f31b 110 Count_ms=(uint32_t) strtol(Arg,NULL,10);
tapiov 2:386f65563144 111 }
tapiov 2:386f65563144 112
tapiov 2:386f65563144 113 // quit: Exit on next while
tapiov 2:386f65563144 114 else if((strcmp(Cmd,"quit")==0)&&(n==1)) {
tapiov 2:386f65563144 115 // Do nothing yet
tapiov 2:386f65563144 116 }
tapiov 2:386f65563144 117 else {
tapiov 2:386f65563144 118 pc1.printf("Wrong command or argument \r\n");
tapiov 2:386f65563144 119 }
tapiov 1:c3c61d08f31b 120 }
tapiov 1:c3c61d08f31b 121
tapiov 1:c3c61d08f31b 122 // Free memory after quit
tapiov 1:c3c61d08f31b 123 freeArray(&Data);
tapiov 2:386f65563144 124 pc1.printf("Exit. Data freed. \r\n");
tapiov 1:c3c61d08f31b 125
tapiov 1:c3c61d08f31b 126 // Infinite loop
tapiov 1:c3c61d08f31b 127 while(1)
tapiov 1:c3c61d08f31b 128 {
tapiov 1:c3c61d08f31b 129 // Do nothing
tapiov 0:b3e6088c873f 130 }
tapiov 0:b3e6088c873f 131 }