Sample program showing a software method to initiate reload and subsequent reset of the target without pressing the reset button.

Dependencies:   mbed

Committer:
peterand
Date:
Wed Feb 15 15:27:25 2012 +0000
Revision:
0:0230dff6c24f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peterand 0:0230dff6c24f 1 #include "mbed.h"
peterand 0:0230dff6c24f 2
peterand 0:0230dff6c24f 3 /* connect a "wedge" between an arbitrary digital pin (p5 in this example) and nR (pin4)*/
peterand 0:0230dff6c24f 4
peterand 0:0230dff6c24f 5 Serial pc(USBTX, USBRX);
peterand 0:0230dff6c24f 6 DigitalInOut reset(p5);
peterand 0:0230dff6c24f 7 LocalFileSystem local("local");
peterand 0:0230dff6c24f 8 //FILE *fp;
peterand 0:0230dff6c24f 9
peterand 0:0230dff6c24f 10 int main() {
peterand 0:0230dff6c24f 11
peterand 0:0230dff6c24f 12 pc.baud(115200);
peterand 0:0230dff6c24f 13 char filename[64];
peterand 0:0230dff6c24f 14 int n = 0;
peterand 0:0230dff6c24f 15
peterand 0:0230dff6c24f 16 while(1) {
peterand 0:0230dff6c24f 17 sprintf(filename, "/local/reset%03d.txt", n);
peterand 0:0230dff6c24f 18 FILE *fp = fopen(filename, "r");
peterand 0:0230dff6c24f 19 if(fp == NULL) {
peterand 0:0230dff6c24f 20 break;
peterand 0:0230dff6c24f 21 }
peterand 0:0230dff6c24f 22 fclose(fp);
peterand 0:0230dff6c24f 23 n++;
peterand 0:0230dff6c24f 24 }
peterand 0:0230dff6c24f 25
peterand 0:0230dff6c24f 26 FILE *fp = fopen(filename, "w");
peterand 0:0230dff6c24f 27 fprintf(fp, "Reset # %d\n", n);
peterand 0:0230dff6c24f 28 fclose(fp);
peterand 0:0230dff6c24f 29
peterand 0:0230dff6c24f 30 pc.printf("\nThis was reset # %u\n", n);
peterand 0:0230dff6c24f 31 pc.printf("Press 'R' to reset (and reload) the target\n");
peterand 0:0230dff6c24f 32
peterand 0:0230dff6c24f 33 while(1) {
peterand 0:0230dff6c24f 34 if (pc.readable()){
peterand 0:0230dff6c24f 35 char c = pc.getc();
peterand 0:0230dff6c24f 36 if(c== 'R'){
peterand 0:0230dff6c24f 37 pc.printf("\nReset! Bye, bye...\n");
peterand 0:0230dff6c24f 38 reset.output();
peterand 0:0230dff6c24f 39 /* reset.write(0); not necessary*/
peterand 0:0230dff6c24f 40 }
peterand 0:0230dff6c24f 41 else pc.printf("Got %c\n",c);
peterand 0:0230dff6c24f 42 }
peterand 0:0230dff6c24f 43 }
peterand 0:0230dff6c24f 44 }