This is a monitor program for BLE NRF51822 chip. You can check memory, register and system information.

Dependencies:   BLE_API mbed nRF51822 nRF51_Vdd

Please refer follows.
/users/kenjiArai/code/debug_tools/
/users/kenjiArai/notebook/ble--tytaiyo-yuden-module-for-mbed/

Committer:
kenjiArai
Date:
Thu Feb 11 05:45:28 2016 +0000
Revision:
2:6a659d71d71f
Parent:
0:08c935d6c28f
Child:
3:367a0d10f176
small modification(still on going)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:08c935d6c28f 1 /*
kenjiArai 0:08c935d6c28f 2 * mbed Application program
kenjiArai 0:08c935d6c28f 3 *
kenjiArai 0:08c935d6c28f 4 * Copyright (c) 2016 Kenji Arai / JH1PJL
kenjiArai 0:08c935d6c28f 5 * http://www.page.sannet.ne.jp/kenjia/index.html
kenjiArai 0:08c935d6c28f 6 * http://mbed.org/users/kenjiArai/
kenjiArai 0:08c935d6c28f 7 * Created: Feburary 1st, 2016
kenjiArai 0:08c935d6c28f 8 * Revised: Feburary 4th, 2016
kenjiArai 0:08c935d6c28f 9 *
kenjiArai 0:08c935d6c28f 10 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
kenjiArai 0:08c935d6c28f 11 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
kenjiArai 0:08c935d6c28f 12 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kenjiArai 0:08c935d6c28f 13 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenjiArai 0:08c935d6c28f 14 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kenjiArai 0:08c935d6c28f 15 */
kenjiArai 0:08c935d6c28f 16
kenjiArai 0:08c935d6c28f 17 #if defined(TARGET_NRF51822)
kenjiArai 0:08c935d6c28f 18
kenjiArai 0:08c935d6c28f 19 // Include ---------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 20 #include "mbed.h"
kenjiArai 0:08c935d6c28f 21 #include "debug_common.h"
kenjiArai 2:6a659d71d71f 22 #include "softdevice_handler.h"
kenjiArai 0:08c935d6c28f 23 #include "nrf_soc.h" // for internal Thermo sensoer
kenjiArai 0:08c935d6c28f 24 #include "nRF51_Vdd.h" // Read nRF51 Vdd voltage
kenjiArai 0:08c935d6c28f 25
kenjiArai 0:08c935d6c28f 26 // Object ----------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 27 nRF51_Vdd vdd_mon(3.6f, 2.6f);
kenjiArai 0:08c935d6c28f 28
kenjiArai 0:08c935d6c28f 29 // Definition ------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 30
kenjiArai 0:08c935d6c28f 31 // RAM -------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 32
kenjiArai 0:08c935d6c28f 33 // ROM / Constant data ---------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 34
kenjiArai 0:08c935d6c28f 35 // Function prototypes ---------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 36 extern void cpu_sys(void);
kenjiArai 0:08c935d6c28f 37 void debug_core(void);
kenjiArai 2:6a659d71d71f 38 void ble_stack_stop(void);
kenjiArai 0:08c935d6c28f 39
kenjiArai 0:08c935d6c28f 40 //-------------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 41 // Control Program
kenjiArai 0:08c935d6c28f 42 //-------------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 43 // Help Massage
kenjiArai 0:08c935d6c28f 44 void msg_hlp (void)
kenjiArai 0:08c935d6c28f 45 {
kenjiArai 0:08c935d6c28f 46 PRINTF(mon_msg);
kenjiArai 0:08c935d6c28f 47 put_rn();
kenjiArai 0:08c935d6c28f 48 PRINTF("c - CPU VDD & Temp info");
kenjiArai 0:08c935d6c28f 49 put_rn();
kenjiArai 2:6a659d71d71f 50 // PRINTF("d - Disable radio module");
kenjiArai 2:6a659d71d71f 51 // put_rn();
kenjiArai 0:08c935d6c28f 52 PRINTF("s - CPU system info");
kenjiArai 0:08c935d6c28f 53 put_rn();
kenjiArai 0:08c935d6c28f 54 PRINTF("r - Reset(by Software)");
kenjiArai 0:08c935d6c28f 55 put_rn();
kenjiArai 0:08c935d6c28f 56 PRINTF("x - Goto HW monitor");
kenjiArai 0:08c935d6c28f 57 put_rn();
kenjiArai 0:08c935d6c28f 58 PRINTF("q - Return to main");
kenjiArai 0:08c935d6c28f 59 put_rn();
kenjiArai 0:08c935d6c28f 60 }
kenjiArai 0:08c935d6c28f 61
kenjiArai 0:08c935d6c28f 62 // ---------- Program starts here! ---------------------------------------------------------------
kenjiArai 0:08c935d6c28f 63 void debug_interface(uint8_t mode)
kenjiArai 0:08c935d6c28f 64 {
kenjiArai 0:08c935d6c28f 65 BAUD(BAUD_RATE);
kenjiArai 0:08c935d6c28f 66 if (mode){
kenjiArai 0:08c935d6c28f 67 debug_core();
kenjiArai 0:08c935d6c28f 68 } else {
kenjiArai 0:08c935d6c28f 69 if(READABLE()){
kenjiArai 0:08c935d6c28f 70 unsigned char c = GETC(); // dummy read
kenjiArai 0:08c935d6c28f 71 debug_core();
kenjiArai 0:08c935d6c28f 72 }
kenjiArai 0:08c935d6c28f 73 }
kenjiArai 0:08c935d6c28f 74 }
kenjiArai 0:08c935d6c28f 75
kenjiArai 0:08c935d6c28f 76 void debug_core(void)
kenjiArai 0:08c935d6c28f 77 {
kenjiArai 0:08c935d6c28f 78 char *ptr;
kenjiArai 0:08c935d6c28f 79 int32_t p_temp;
kenjiArai 0:08c935d6c28f 80 float temperature;
kenjiArai 0:08c935d6c28f 81
kenjiArai 0:08c935d6c28f 82 put_rn();
kenjiArai 0:08c935d6c28f 83 put_rn();
kenjiArai 0:08c935d6c28f 84 PRINTF("%s [Help:'?' key]", mon_msg);
kenjiArai 0:08c935d6c28f 85 put_rn();
kenjiArai 0:08c935d6c28f 86 for (;;) {
kenjiArai 0:08c935d6c28f 87 put_r();
kenjiArai 0:08c935d6c28f 88 PUTC('>');
kenjiArai 0:08c935d6c28f 89 ptr = linebuf;
kenjiArai 0:08c935d6c28f 90 get_line(ptr, sizeof(linebuf));
kenjiArai 0:08c935d6c28f 91 switch (*ptr++) {
kenjiArai 0:08c935d6c28f 92 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 93 // CPU VDD Voltage and Chip temperature
kenjiArai 0:08c935d6c28f 94 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 95 case 'c' :
kenjiArai 0:08c935d6c28f 96 put_r();
kenjiArai 2:6a659d71d71f 97 NRF_TEMP->TASKS_START = 1;
kenjiArai 2:6a659d71d71f 98 while (NRF_TEMP->EVENTS_DATARDY == 0){;}
kenjiArai 2:6a659d71d71f 99 NRF_TEMP->EVENTS_DATARDY = 0;
kenjiArai 2:6a659d71d71f 100 if ((NRF_TEMP->TEMP & 0x00000200) != 0){
kenjiArai 2:6a659d71d71f 101 p_temp = (NRF_TEMP->TEMP | 0xFFFFFC00);
kenjiArai 2:6a659d71d71f 102 } else {
kenjiArai 2:6a659d71d71f 103 p_temp = NRF_TEMP->TEMP;
kenjiArai 2:6a659d71d71f 104 }
kenjiArai 2:6a659d71d71f 105 NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */
kenjiArai 0:08c935d6c28f 106 temperature = float(p_temp) / 4; // Original = float(p_temp)/4.0f - 16.0f;
kenjiArai 0:08c935d6c28f 107 PRINTF("nRF51\r\nChip temperature: %+4.1fdegC", temperature);
kenjiArai 0:08c935d6c28f 108 put_rn();
kenjiArai 0:08c935d6c28f 109 // Vdd voltage
kenjiArai 0:08c935d6c28f 110 PRINTF("Vdd: %4.3fV", vdd_mon.read_real_value());
kenjiArai 0:08c935d6c28f 111 put_rn();
kenjiArai 0:08c935d6c28f 112 break;
kenjiArai 0:08c935d6c28f 113 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 114 // CPU system info
kenjiArai 0:08c935d6c28f 115 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 116 case 's' :
kenjiArai 0:08c935d6c28f 117 put_r();
kenjiArai 0:08c935d6c28f 118 cpu_sys();
kenjiArai 0:08c935d6c28f 119 break;
kenjiArai 0:08c935d6c28f 120 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 121 // System reset
kenjiArai 0:08c935d6c28f 122 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 123 case 'r' :
kenjiArai 0:08c935d6c28f 124 put_r();
kenjiArai 0:08c935d6c28f 125 SCB->AIRCR = 0x05fa0004; // System RESET!!
kenjiArai 0:08c935d6c28f 126 // Not come here (Just in case)
kenjiArai 0:08c935d6c28f 127 deepsleep();
kenjiArai 0:08c935d6c28f 128 break;
kenjiArai 0:08c935d6c28f 129 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 130 // help
kenjiArai 0:08c935d6c28f 131 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 132 case '?' :
kenjiArai 0:08c935d6c28f 133 put_r();
kenjiArai 0:08c935d6c28f 134 msg_hlp();
kenjiArai 0:08c935d6c28f 135 break;
kenjiArai 0:08c935d6c28f 136 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 137 // Go to special command
kenjiArai 0:08c935d6c28f 138 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 139 case 'x' :
kenjiArai 0:08c935d6c28f 140 mon_hw();
kenjiArai 0:08c935d6c28f 141 PRINTF("->Came back monitor\r\n");
kenjiArai 0:08c935d6c28f 142 break;
kenjiArai 0:08c935d6c28f 143 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 144 // Go back to main()
kenjiArai 0:08c935d6c28f 145 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 146 case 'q' : // Quit
kenjiArai 0:08c935d6c28f 147 PRINTF("\rReturn to main\r\n");
kenjiArai 0:08c935d6c28f 148 //PRINTF("cannot control anymore from here\r\n");
kenjiArai 0:08c935d6c28f 149 return;
kenjiArai 0:08c935d6c28f 150 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 151 // no support
kenjiArai 0:08c935d6c28f 152 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 153 default:
kenjiArai 0:08c935d6c28f 154 put_r();
kenjiArai 0:08c935d6c28f 155 PUTC('?');
kenjiArai 0:08c935d6c28f 156 put_rn();
kenjiArai 0:08c935d6c28f 157 break;
kenjiArai 0:08c935d6c28f 158 }
kenjiArai 0:08c935d6c28f 159 }
kenjiArai 0:08c935d6c28f 160 }
kenjiArai 0:08c935d6c28f 161
kenjiArai 0:08c935d6c28f 162 #endif // defined(TARGET_NRF51822)