Kenji Arai / Mbed 2 deprecated debug_tools

Dependencies:   mbed CheckRTC

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug_nucleo_F4x1RE.cpp Source File

debug_nucleo_F4x1RE.cpp

00001 /*
00002  * mbed Application program
00003  *
00004  *  Copyright (c) 2010-2015 Kenji Arai / JH1PJL
00005  *  http://www.page.sannet.ne.jp/kenjia/index.html
00006  *  http://mbed.org/users/kenjiArai/
00007  *      Created:  May       15th, 2010
00008  *      Spareted: June      25th, 2014      mon() & mon_hw()
00009  *      Ported:   September 22nd, 2014      from L152RE, LP1114
00010  *      changed:  October   15th, 2014      mon.cpp to debug_xxx.cpp
00011  *      Revised:  April     25th, 2015      Bug fix ('o' command) pointed out by Topi Makinen
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
00014  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00015  * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 
00020 #if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_L152RE)
00021 
00022 //  Include ---------------------------------------------------------------------------------------
00023 #include "mbed.h"
00024 #include "debug_common.h"
00025 #include "CheckRTC.h"
00026 
00027 //  Object ----------------------------------------------------------------------------------------
00028 DigitalOut myled(LED1);
00029 DigitalIn usr_sw(PC_13);
00030 
00031 //  Definition ------------------------------------------------------------------------------------
00032 
00033 //  RAM -------------------------------------------------------------------------------------------
00034 
00035 //  ROM / Constant data ---------------------------------------------------------------------------
00036 
00037 //  Function prototypes ---------------------------------------------------------------------------
00038 extern void cpu_inf( char *ptr );
00039 extern void port_mco1_mco2_set(uint8_t n);
00040 extern void port_mco1_mco2_recover(void);
00041 
00042 //-------------------------------------------------------------------------------------------------
00043 //  Control Program
00044 //-------------------------------------------------------------------------------------------------
00045 //  Help Massage
00046 void msg_hlp (void)
00047 {
00048     PRINTF(mon_msg);
00049     put_rn();
00050     PRINTF("1 - goto step1 -> no connection all pins");
00051     put_rn();
00052     PRINTF("2 - goto step2 -> connects pin_x and pin_y");
00053     put_rn();
00054     PRINTF("t - Check and set RTC");
00055     put_rn();
00056     PRINTF("x - Goto HW monitor");
00057     put_rn();
00058     PRINTF("q - Return to main");
00059     put_rn();
00060 }
00061 
00062 // ---------- Program starts here! ---------------------------------------------------------------
00063 void debug_interface(void)
00064 {
00065     char c;
00066     char *ptr;
00067     uint8_t quitflag;
00068 
00069     BAUD(BAUD_RATE);
00070     put_rn();
00071     put_rn();
00072     PRINTF("%s [Help:'?' key]", mon_msg);
00073     put_rn();
00074     CheckRTC();
00075     for (;;) {
00076         put_r();
00077         PUTC('>');
00078         ptr = linebuf;
00079         get_line(ptr, sizeof(linebuf));
00080         switch (*ptr++) {
00081                 //---------------------------------------------------------------------------------
00082                 //  Debug Step1
00083                 //---------------------------------------------------------------------------------
00084             case '1' :
00085                 put_r();
00086                 PRINTF("Enter Step1: no connection all pins");
00087                 put_rn();
00088                 quitflag = 0;
00089                 for (; quitflag != 0xff;) {
00090                     PRINTF("1>");
00091                     ptr = linebuf;
00092                     get_line(ptr, buf_size);
00093                     put_r();
00094                     switch(*ptr++) {
00095                         case 'l' :
00096                             myled = 1;
00097                             PRINTF("Is LED on? -> enter y/n");
00098                             put_rn();
00099                             c = GETC();
00100                             if (c == 'y') {
00101                                 PRINTF("Okay");
00102                             } else {
00103                                 PRINTF("Are you sure? Check again!");
00104                                 for (c = 0; c < 30; c++) {
00105                                     myled = !myled;
00106                                     wait(0.2);
00107                                 }
00108                                 myled = 1;
00109                                 put_rn();
00110                                 PRINTF("Is LED on? -> enter y/n");
00111                                 put_rn();
00112                                 c = GETC();
00113                                 if (c == 'y') {
00114                                     PRINTF("Looks okay");
00115                                 } else {
00116                                     PRINTF("Please check LED line");
00117                                 }
00118                             }
00119                             put_rn();
00120                             myled = 0;
00121                             break;
00122                         case 'b' :
00123                             PRINTF("Please push [USER] button -> You can see LED on if you push a button");
00124                             put_rn();
00125                             PRINTF("Hit any key to exit");
00126                             while (true) {
00127                                 if (usr_sw == 0) {
00128                                     myled = 1;
00129                                 } else {
00130                                     myled = 0;
00131                                 }
00132                                 if (READABLE()) {
00133                                     break;
00134                                 }
00135                             }
00136                             GETC();
00137                             put_rn();
00138                             break;
00139                         case 's' :
00140                             PRINTF("----- CPU CLOCK Information -----");
00141                             put_rn();
00142                             c = 'f';
00143                             cpu_inf(&c);
00144                             PRINTF("----- CPU TYPE Information ------");
00145                             put_rn();
00146                             c = 'c';
00147                             cpu_inf(&c);
00148                             break;
00149 #if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
00150                         case 'o' : // Bug fix on April 25, 2015
00151                             PRINTF("----- CPU CLOCK output from PA8 & PC9 -----");
00152                             put_rn();
00153                             PRINTF("Please check that both PA8 & PC9 ");
00154                             PRINTF("are no connection with any peripheral I/O!!");
00155                             put_rn();
00156                             PRINTF("Are you okay? [y/n]");
00157                             put_rn();
00158                             c = GETC();
00159                             if (c == 'y') {
00160                                 port_mco1_mco2_set(0);
00161                                 port_mco1_mco2_set(1);
00162                                 PRINTF("Please measure frequency at PA8 & PC9 pins");
00163                                 put_rn();
00164                                 PRINTF("PA8: HSE/4");
00165                                 put_rn();
00166                                 PRINTF("PC9: SYSCLK/4");
00167                                 put_rn();
00168                                 PRINTF("Change requency (Please hit any key)");
00169                                 put_rn();
00170                                 c = GETC();
00171                                 port_mco1_mco2_set(2);
00172                                 PRINTF("PA8: HSE/1");
00173                                 put_rn();
00174                                 PRINTF("PC9: SYSCLK/2");
00175                                 put_rn();
00176                                 PRINTF("If you would like to finish, hit anykey");
00177                                 put_rn();
00178                                 c = GETC();
00179                                 port_mco1_mco2_recover();
00180                                 PRINTF("End");
00181                                 put_rn();
00182                             }
00183                             break;
00184 #endif      // defined(TARGET_NUCLEO_F401RE) 
00185                         case '?' :
00186                             PRINTF("l - Check LED");
00187                             put_rn();
00188                             PRINTF("b - Check button");
00189                             put_rn();
00190                             PRINTF("s - CPU system info & clock");
00191                             put_rn();
00192 #if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
00193                             PRINTF("o - CPU clock output");
00194                             put_rn();
00195 #endif      // defined(TARGET_NUCLEO_F401RE)                             
00196                             PRINTF("q - Return to all mode");
00197                             put_rn();
00198                             PRINTF("? - You know this");
00199                             put_rn();
00200                             break;
00201                         case 'q' :        // quit
00202                             PRINTF("Back to all mode");
00203                             quitflag = 0xff;
00204                             break;
00205                         default:
00206                             PUTC('?');
00207                             put_rn();
00208                     }
00209                 }
00210                 put_rn();
00211                 break;
00212                 //---------------------------------------------------------------------------------
00213                 //  check and set RTC
00214                 //---------------------------------------------------------------------------------
00215             case 't' :
00216                 put_r();
00217                 chk_and_set_time(ptr);
00218                 break;
00219                 //---------------------------------------------------------------------------------
00220                 //  help
00221                 //---------------------------------------------------------------------------------
00222             case '?' :
00223                 put_r();
00224                 msg_hlp();
00225                 break;
00226                 //---------------------------------------------------------------------------------
00227                 //  Go to special command
00228                 //---------------------------------------------------------------------------------
00229             case 'x' :
00230                 mon_hw();
00231                 PRINTF("->Came back monitor\r\n");
00232                 break;
00233                 //---------------------------------------------------------------------------------
00234                 //  Go back to main()
00235                 //---------------------------------------------------------------------------------
00236             case 'q' :        // Quit
00237                 PRINTF("\rReturn to main\r\n");
00238                 //PRINTF("cannot control anymore from here\r\n");
00239                 return;
00240                 //---------------------------------------------------------------------------------
00241                 //    no support
00242                 //---------------------------------------------------------------------------------
00243             default:
00244                 put_r();
00245                 PUTC('?');
00246                 put_rn();
00247                 break;
00248         }
00249     }
00250 }
00251 
00252 #endif // defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_L152RE)