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:
Sun Jan 08 04:36:55 2017 +0000
Revision:
5:8c37a47ac34c
Parent:
4:36ad7c7d0400
Abolish function:due to mbed library revision up "nrf radio test example"  does NOT work anymore. Deleted unused files.

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 5:8c37a47ac34c 4 * Copyright (c) 2016,'17 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 5:8c37a47ac34c 8 * Revised: January 8th, 2017
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 0:08c935d6c28f 22 #include "nrf_soc.h" // for internal Thermo sensoer
kenjiArai 0:08c935d6c28f 23 #include "nRF51_Vdd.h" // Read nRF51 Vdd voltage
kenjiArai 5:8c37a47ac34c 24 #include "nrf_delay.h"
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 4:36ad7c7d0400 29 DigitalOut p_out(P0_1);
kenjiArai 4:36ad7c7d0400 30
kenjiArai 0:08c935d6c28f 31 // Definition ------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 32
kenjiArai 0:08c935d6c28f 33 // RAM -------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 34
kenjiArai 0:08c935d6c28f 35 // ROM / Constant data ---------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 36
kenjiArai 0:08c935d6c28f 37 // Function prototypes ---------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 38 extern void cpu_sys(void);
kenjiArai 4:36ad7c7d0400 39 extern int trx_control(void);
kenjiArai 0:08c935d6c28f 40 void debug_core(void);
kenjiArai 2:6a659d71d71f 41 void ble_stack_stop(void);
kenjiArai 0:08c935d6c28f 42
kenjiArai 0:08c935d6c28f 43 //-------------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 44 // Control Program
kenjiArai 0:08c935d6c28f 45 //-------------------------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 46 // Help Massage
kenjiArai 0:08c935d6c28f 47 void msg_hlp (void)
kenjiArai 0:08c935d6c28f 48 {
kenjiArai 0:08c935d6c28f 49 PRINTF(mon_msg);
kenjiArai 0:08c935d6c28f 50 put_rn();
kenjiArai 5:8c37a47ac34c 51 PRINTF(" RESET -> Press [Alt]+B");
kenjiArai 5:8c37a47ac34c 52 put_rn();
kenjiArai 0:08c935d6c28f 53 PRINTF("c - CPU VDD & Temp info");
kenjiArai 0:08c935d6c28f 54 put_rn();
kenjiArai 4:36ad7c7d0400 55 PRINTF("l - Low current (Sleep Mode)");
kenjiArai 4:36ad7c7d0400 56 put_rn();
kenjiArai 5:8c37a47ac34c 57 #if 0
kenjiArai 4:36ad7c7d0400 58 PRINTF("t - Test Radio module");
kenjiArai 4:36ad7c7d0400 59 put_rn();
kenjiArai 5:8c37a47ac34c 60 #endif
kenjiArai 0:08c935d6c28f 61 PRINTF("s - CPU system info");
kenjiArai 0:08c935d6c28f 62 put_rn();
kenjiArai 0:08c935d6c28f 63 PRINTF("r - Reset(by Software)");
kenjiArai 0:08c935d6c28f 64 put_rn();
kenjiArai 0:08c935d6c28f 65 PRINTF("x - Goto HW monitor");
kenjiArai 0:08c935d6c28f 66 put_rn();
kenjiArai 0:08c935d6c28f 67 PRINTF("q - Return to main");
kenjiArai 0:08c935d6c28f 68 put_rn();
kenjiArai 4:36ad7c7d0400 69 PRINTF("New function (Number 1,2...)");
kenjiArai 4:36ad7c7d0400 70 put_rn();
kenjiArai 4:36ad7c7d0400 71 PRINTF("1 - Try new function");
kenjiArai 4:36ad7c7d0400 72 put_rn();
kenjiArai 0:08c935d6c28f 73 }
kenjiArai 0:08c935d6c28f 74
kenjiArai 0:08c935d6c28f 75 // ---------- Program starts here! ---------------------------------------------------------------
kenjiArai 0:08c935d6c28f 76 void debug_interface(uint8_t mode)
kenjiArai 0:08c935d6c28f 77 {
kenjiArai 0:08c935d6c28f 78 BAUD(BAUD_RATE);
kenjiArai 0:08c935d6c28f 79 if (mode){
kenjiArai 0:08c935d6c28f 80 debug_core();
kenjiArai 0:08c935d6c28f 81 } else {
kenjiArai 0:08c935d6c28f 82 if(READABLE()){
kenjiArai 0:08c935d6c28f 83 unsigned char c = GETC(); // dummy read
kenjiArai 0:08c935d6c28f 84 debug_core();
kenjiArai 0:08c935d6c28f 85 }
kenjiArai 0:08c935d6c28f 86 }
kenjiArai 0:08c935d6c28f 87 }
kenjiArai 0:08c935d6c28f 88
kenjiArai 4:36ad7c7d0400 89 void step_by_step(char c)
kenjiArai 4:36ad7c7d0400 90 {
kenjiArai 4:36ad7c7d0400 91 PRINTF("Waiting key input");
kenjiArai 4:36ad7c7d0400 92 while (!READABLE()){;}
kenjiArai 4:36ad7c7d0400 93 PRINTF("--- step %c", c);
kenjiArai 4:36ad7c7d0400 94 put_rn();
kenjiArai 4:36ad7c7d0400 95 c = GETC(); // dummy read
kenjiArai 4:36ad7c7d0400 96 }
kenjiArai 4:36ad7c7d0400 97
kenjiArai 0:08c935d6c28f 98 void debug_core(void)
kenjiArai 0:08c935d6c28f 99 {
kenjiArai 0:08c935d6c28f 100 char *ptr;
kenjiArai 0:08c935d6c28f 101 int32_t p_temp;
kenjiArai 0:08c935d6c28f 102 float temperature;
kenjiArai 0:08c935d6c28f 103
kenjiArai 4:36ad7c7d0400 104 uint32_t n;
kenjiArai 4:36ad7c7d0400 105
kenjiArai 0:08c935d6c28f 106 put_rn();
kenjiArai 0:08c935d6c28f 107 put_rn();
kenjiArai 0:08c935d6c28f 108 PRINTF("%s [Help:'?' key]", mon_msg);
kenjiArai 0:08c935d6c28f 109 put_rn();
kenjiArai 0:08c935d6c28f 110 for (;;) {
kenjiArai 0:08c935d6c28f 111 put_r();
kenjiArai 0:08c935d6c28f 112 PUTC('>');
kenjiArai 0:08c935d6c28f 113 ptr = linebuf;
kenjiArai 0:08c935d6c28f 114 get_line(ptr, sizeof(linebuf));
kenjiArai 4:36ad7c7d0400 115 put_r();
kenjiArai 0:08c935d6c28f 116 switch (*ptr++) {
kenjiArai 0:08c935d6c28f 117 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 118 // CPU VDD Voltage and Chip temperature
kenjiArai 0:08c935d6c28f 119 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 120 case 'c' :
kenjiArai 2:6a659d71d71f 121 NRF_TEMP->TASKS_START = 1;
kenjiArai 2:6a659d71d71f 122 while (NRF_TEMP->EVENTS_DATARDY == 0){;}
kenjiArai 2:6a659d71d71f 123 NRF_TEMP->EVENTS_DATARDY = 0;
kenjiArai 2:6a659d71d71f 124 if ((NRF_TEMP->TEMP & 0x00000200) != 0){
kenjiArai 2:6a659d71d71f 125 p_temp = (NRF_TEMP->TEMP | 0xFFFFFC00);
kenjiArai 2:6a659d71d71f 126 } else {
kenjiArai 2:6a659d71d71f 127 p_temp = NRF_TEMP->TEMP;
kenjiArai 2:6a659d71d71f 128 }
kenjiArai 2:6a659d71d71f 129 NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */
kenjiArai 0:08c935d6c28f 130 temperature = float(p_temp) / 4; // Original = float(p_temp)/4.0f - 16.0f;
kenjiArai 0:08c935d6c28f 131 PRINTF("nRF51\r\nChip temperature: %+4.1fdegC", temperature);
kenjiArai 0:08c935d6c28f 132 put_rn();
kenjiArai 0:08c935d6c28f 133 // Vdd voltage
kenjiArai 0:08c935d6c28f 134 PRINTF("Vdd: %4.3fV", vdd_mon.read_real_value());
kenjiArai 0:08c935d6c28f 135 put_rn();
kenjiArai 0:08c935d6c28f 136 break;
kenjiArai 5:8c37a47ac34c 137 #if 0 // Nobember 1st, 2016
kenjiArai 5:8c37a47ac34c 138 // Timer1 IRQ handaler dupulicated error is occured dur to revision change.
kenjiArai 5:8c37a47ac34c 139 // I cannot control Radio module.
kenjiArai 0:08c935d6c28f 140 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 141 // Test Radio module
kenjiArai 4:36ad7c7d0400 142 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 143 case 't' :
kenjiArai 4:36ad7c7d0400 144 trx_control();
kenjiArai 4:36ad7c7d0400 145 break;
kenjiArai 5:8c37a47ac34c 146 #endif
kenjiArai 4:36ad7c7d0400 147 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 148 // Something new and try new functions
kenjiArai 4:36ad7c7d0400 149 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 150
kenjiArai 4:36ad7c7d0400 151 // Please see following file
kenjiArai 4:36ad7c7d0400 152 #include "debugging_nRF51.h"
kenjiArai 4:36ad7c7d0400 153
kenjiArai 4:36ad7c7d0400 154 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 155 // Go to Low current (Sleep mode)
kenjiArai 4:36ad7c7d0400 156 //---------------------------------------------------------------------------------
kenjiArai 4:36ad7c7d0400 157 case 'l' :
kenjiArai 5:8c37a47ac34c 158 PRINTF("Enter Sleep mode (Please push RESET button on the board");
kenjiArai 5:8c37a47ac34c 159 PRINTF(" or Press [Alt]+B from PC)");
kenjiArai 4:36ad7c7d0400 160 put_rn();
kenjiArai 4:36ad7c7d0400 161 while(true){
kenjiArai 4:36ad7c7d0400 162 sleep();
kenjiArai 4:36ad7c7d0400 163 //__WFI();
kenjiArai 4:36ad7c7d0400 164 //__WFE();
kenjiArai 4:36ad7c7d0400 165 }
kenjiArai 4:36ad7c7d0400 166 // SCB->AIRCR = 0x05fa0004; // System RESET!!
kenjiArai 4:36ad7c7d0400 167 //break;
kenjiArai 4:36ad7c7d0400 168 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 169 // CPU system info
kenjiArai 0:08c935d6c28f 170 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 171 case 's' :
kenjiArai 0:08c935d6c28f 172 cpu_sys();
kenjiArai 0:08c935d6c28f 173 break;
kenjiArai 0:08c935d6c28f 174 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 175 // System reset
kenjiArai 0:08c935d6c28f 176 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 177 case 'r' :
kenjiArai 0:08c935d6c28f 178 SCB->AIRCR = 0x05fa0004; // System RESET!!
kenjiArai 0:08c935d6c28f 179 // Not come here (Just in case)
kenjiArai 0:08c935d6c28f 180 deepsleep();
kenjiArai 0:08c935d6c28f 181 break;
kenjiArai 0:08c935d6c28f 182 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 183 // help
kenjiArai 0:08c935d6c28f 184 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 185 case '?' :
kenjiArai 0:08c935d6c28f 186 msg_hlp();
kenjiArai 0:08c935d6c28f 187 break;
kenjiArai 0:08c935d6c28f 188 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 189 // Go to special command
kenjiArai 0:08c935d6c28f 190 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 191 case 'x' :
kenjiArai 0:08c935d6c28f 192 mon_hw();
kenjiArai 0:08c935d6c28f 193 PRINTF("->Came back monitor\r\n");
kenjiArai 0:08c935d6c28f 194 break;
kenjiArai 0:08c935d6c28f 195 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 196 // Go back to main()
kenjiArai 0:08c935d6c28f 197 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 198 case 'q' : // Quit
kenjiArai 0:08c935d6c28f 199 PRINTF("\rReturn to main\r\n");
kenjiArai 0:08c935d6c28f 200 //PRINTF("cannot control anymore from here\r\n");
kenjiArai 0:08c935d6c28f 201 return;
kenjiArai 0:08c935d6c28f 202 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 203 // no support
kenjiArai 0:08c935d6c28f 204 //---------------------------------------------------------------------------------
kenjiArai 0:08c935d6c28f 205 default:
kenjiArai 0:08c935d6c28f 206 PUTC('?');
kenjiArai 0:08c935d6c28f 207 put_rn();
kenjiArai 0:08c935d6c28f 208 break;
kenjiArai 0:08c935d6c28f 209 }
kenjiArai 0:08c935d6c28f 210 }
kenjiArai 0:08c935d6c28f 211 }
kenjiArai 0:08c935d6c28f 212
kenjiArai 0:08c935d6c28f 213 #endif // defined(TARGET_NRF51822)
kenjiArai 5:8c37a47ac34c 214
kenjiArai 5:8c37a47ac34c 215