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/
debug_tools/debugging_nRF51.h@4:36ad7c7d0400, 2016-02-14 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Feb 14 21:55:30 2016 +0000
- Revision:
- 4:36ad7c7d0400
- Child:
- 5:8c37a47ac34c
added some new functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 4:36ad7c7d0400 | 1 | /* |
kenjiArai | 4:36ad7c7d0400 | 2 | * mbed Application program |
kenjiArai | 4:36ad7c7d0400 | 3 | * |
kenjiArai | 4:36ad7c7d0400 | 4 | * Copyright (c) 2016 Kenji Arai / JH1PJL |
kenjiArai | 4:36ad7c7d0400 | 5 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 4:36ad7c7d0400 | 6 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 4:36ad7c7d0400 | 7 | * Created: Feburary 1st, 2016 |
kenjiArai | 4:36ad7c7d0400 | 8 | * Revised: Feburary 15th, 2016 |
kenjiArai | 4:36ad7c7d0400 | 9 | * |
kenjiArai | 4:36ad7c7d0400 | 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
kenjiArai | 4:36ad7c7d0400 | 11 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
kenjiArai | 4:36ad7c7d0400 | 12 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 4:36ad7c7d0400 | 13 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kenjiArai | 4:36ad7c7d0400 | 14 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 4:36ad7c7d0400 | 15 | */ |
kenjiArai | 4:36ad7c7d0400 | 16 | |
kenjiArai | 4:36ad7c7d0400 | 17 | //--------------------------------------------------------------------------------- |
kenjiArai | 4:36ad7c7d0400 | 18 | // Something new and try new functions |
kenjiArai | 4:36ad7c7d0400 | 19 | //--------------------------------------------------------------------------------- |
kenjiArai | 4:36ad7c7d0400 | 20 | #define NRF_RTC2_BASE 0x40024000UL |
kenjiArai | 4:36ad7c7d0400 | 21 | #define NRF_RTC2 ((NRF_RTC_Type *) NRF_RTC2_BASE) |
kenjiArai | 4:36ad7c7d0400 | 22 | |
kenjiArai | 4:36ad7c7d0400 | 23 | case '1' : |
kenjiArai | 4:36ad7c7d0400 | 24 | step_by_step('1'); |
kenjiArai | 4:36ad7c7d0400 | 25 | sd_power_system_off(); |
kenjiArai | 4:36ad7c7d0400 | 26 | step_by_step('2'); |
kenjiArai | 4:36ad7c7d0400 | 27 | NRF_RTC2->PRESCALER = 0; /* for no pre-scaling. */ |
kenjiArai | 4:36ad7c7d0400 | 28 | NRF_RTC2->TASKS_START = 1; |
kenjiArai | 4:36ad7c7d0400 | 29 | n = NRF_RTC2->COUNTER; |
kenjiArai | 4:36ad7c7d0400 | 30 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 31 | if ( n == NRF_RTC2->COUNTER){ |
kenjiArai | 4:36ad7c7d0400 | 32 | PRINTF("RTC2 is not running\r\n"); |
kenjiArai | 4:36ad7c7d0400 | 33 | } else { |
kenjiArai | 4:36ad7c7d0400 | 34 | PRINTF("RTC2 is running & counter = %d\r\n", n); |
kenjiArai | 4:36ad7c7d0400 | 35 | } |
kenjiArai | 4:36ad7c7d0400 | 36 | step_by_step('3'); |
kenjiArai | 4:36ad7c7d0400 | 37 | n = NRF_RTC2->COUNTER; |
kenjiArai | 4:36ad7c7d0400 | 38 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 39 | if ( n == NRF_RTC2->COUNTER){ |
kenjiArai | 4:36ad7c7d0400 | 40 | PRINTF("RTC2 is not running\r\n"); |
kenjiArai | 4:36ad7c7d0400 | 41 | } else { |
kenjiArai | 4:36ad7c7d0400 | 42 | PRINTF("RTC2 is running & counter = %d\r\n", n); |
kenjiArai | 4:36ad7c7d0400 | 43 | } |
kenjiArai | 4:36ad7c7d0400 | 44 | step_by_step('4'); |
kenjiArai | 4:36ad7c7d0400 | 45 | n = NRF_RTC0->COUNTER; |
kenjiArai | 4:36ad7c7d0400 | 46 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 47 | if ( n == NRF_RTC0->COUNTER){ |
kenjiArai | 4:36ad7c7d0400 | 48 | PRINTF("RTC0 is not running\r\n"); |
kenjiArai | 4:36ad7c7d0400 | 49 | } else { |
kenjiArai | 4:36ad7c7d0400 | 50 | PRINTF("RTC0 is running & counter = %d\r\n", n); |
kenjiArai | 4:36ad7c7d0400 | 51 | } |
kenjiArai | 4:36ad7c7d0400 | 52 | n = NRF_RTC1->COUNTER; |
kenjiArai | 4:36ad7c7d0400 | 53 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 54 | if ( n == NRF_RTC1->COUNTER){ |
kenjiArai | 4:36ad7c7d0400 | 55 | PRINTF("RTC1 is not running\r\n"); |
kenjiArai | 4:36ad7c7d0400 | 56 | NRF_RTC1->PRESCALER = 0; /* for no pre-scaling. */ |
kenjiArai | 4:36ad7c7d0400 | 57 | NRF_RTC1->TASKS_START = 1; |
kenjiArai | 4:36ad7c7d0400 | 58 | wait(0.5); |
kenjiArai | 4:36ad7c7d0400 | 59 | n = NRF_RTC1->COUNTER; |
kenjiArai | 4:36ad7c7d0400 | 60 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 61 | if ( n == NRF_RTC1->COUNTER){ |
kenjiArai | 4:36ad7c7d0400 | 62 | PRINTF("RTC1 is not running\r\n"); |
kenjiArai | 4:36ad7c7d0400 | 63 | } else { |
kenjiArai | 4:36ad7c7d0400 | 64 | PRINTF("RTC1 is running & counter = %d\r\n", n); |
kenjiArai | 4:36ad7c7d0400 | 65 | } |
kenjiArai | 4:36ad7c7d0400 | 66 | } else { |
kenjiArai | 4:36ad7c7d0400 | 67 | PRINTF("RTC1 is running & counter = %d\r\n", n); |
kenjiArai | 4:36ad7c7d0400 | 68 | } |
kenjiArai | 4:36ad7c7d0400 | 69 | step_by_step('2'); |
kenjiArai | 4:36ad7c7d0400 | 70 | NRF_POWER->SYSTEMOFF = 1; |
kenjiArai | 4:36ad7c7d0400 | 71 | #if 0 |
kenjiArai | 4:36ad7c7d0400 | 72 | NRF_CLOCK->TASKS_HFCLKSTOP = 0xffffffff; |
kenjiArai | 4:36ad7c7d0400 | 73 | NRF_CLOCK->TASKS_LFCLKSTOP = 0xffffffff; |
kenjiArai | 4:36ad7c7d0400 | 74 | step_by_step('1'); |
kenjiArai | 4:36ad7c7d0400 | 75 | sd_power_system_off(); |
kenjiArai | 4:36ad7c7d0400 | 76 | //*(uint32_t *)0x40004ffc = 0; |
kenjiArai | 4:36ad7c7d0400 | 77 | //shutdown(); |
kenjiArai | 4:36ad7c7d0400 | 78 | //softdevice_handler_sd_disable(); |
kenjiArai | 4:36ad7c7d0400 | 79 | PRINTF("POWER=0x%x",NRF_RADIO->POWER); |
kenjiArai | 4:36ad7c7d0400 | 80 | put_rn(); |
kenjiArai | 4:36ad7c7d0400 | 81 | if (NRF_RADIO->POWER){ |
kenjiArai | 4:36ad7c7d0400 | 82 | PRINTF("Radio power is still enabled"); |
kenjiArai | 4:36ad7c7d0400 | 83 | } else { |
kenjiArai | 4:36ad7c7d0400 | 84 | PRINTF("Radio power is disabled"); |
kenjiArai | 4:36ad7c7d0400 | 85 | } |
kenjiArai | 4:36ad7c7d0400 | 86 | put_rn(); |
kenjiArai | 4:36ad7c7d0400 | 87 | step_by_step('2'); |
kenjiArai | 4:36ad7c7d0400 | 88 | NRF_CLOCK->TASKS_HFCLKSTOP = 1; |
kenjiArai | 4:36ad7c7d0400 | 89 | step_by_step('1'); |
kenjiArai | 4:36ad7c7d0400 | 90 | NRF_RADIO->POWER = 0; |
kenjiArai | 4:36ad7c7d0400 | 91 | //NRF_POWER->SYSTEMOFF = 1; |
kenjiArai | 4:36ad7c7d0400 | 92 | //sd_power_system_off(); |
kenjiArai | 4:36ad7c7d0400 | 93 | NRF_SPI0->POWER =0; |
kenjiArai | 4:36ad7c7d0400 | 94 | NRF_SPI1->POWER =0; |
kenjiArai | 4:36ad7c7d0400 | 95 | NRF_TWI0->POWER =0; |
kenjiArai | 4:36ad7c7d0400 | 96 | NRF_TWI1->POWER =0; |
kenjiArai | 4:36ad7c7d0400 | 97 | step_by_step('4'); |
kenjiArai | 4:36ad7c7d0400 | 98 | NRF_GPIO->DIR = 0xffff; // all ports set output mode |
kenjiArai | 4:36ad7c7d0400 | 99 | NRF_GPIO->OUTCLR = 0; // all ports are low level |
kenjiArai | 4:36ad7c7d0400 | 100 | //step_by_step('x'); |
kenjiArai | 4:36ad7c7d0400 | 101 | //NRF_UART0->ENABLE = 0; // Disable UART |
kenjiArai | 4:36ad7c7d0400 | 102 | step_by_step('2'); |
kenjiArai | 4:36ad7c7d0400 | 103 | NRF_SPI0->ENABLE =0; |
kenjiArai | 4:36ad7c7d0400 | 104 | NRF_SPI1->ENABLE =0; |
kenjiArai | 4:36ad7c7d0400 | 105 | NRF_TWI0->ENABLE =0; |
kenjiArai | 4:36ad7c7d0400 | 106 | NRF_TWI1->ENABLE =0; |
kenjiArai | 4:36ad7c7d0400 | 107 | step_by_step('3'); |
kenjiArai | 4:36ad7c7d0400 | 108 | NRF_POWER->RAMON = 0; |
kenjiArai | 4:36ad7c7d0400 | 109 | NRF_POWER->RAMONB = 0; |
kenjiArai | 4:36ad7c7d0400 | 110 | step_by_step('5'); |
kenjiArai | 4:36ad7c7d0400 | 111 | sd_power_system_off(); |
kenjiArai | 4:36ad7c7d0400 | 112 | //step_by_step('6'); |
kenjiArai | 4:36ad7c7d0400 | 113 | NRF_POWER->SYSTEMOFF = 1; |
kenjiArai | 4:36ad7c7d0400 | 114 | NRF_POWER->INTENCLR = 0; |
kenjiArai | 4:36ad7c7d0400 | 115 | #endif |
kenjiArai | 4:36ad7c7d0400 | 116 | while(true){ |
kenjiArai | 4:36ad7c7d0400 | 117 | sleep(); |
kenjiArai | 4:36ad7c7d0400 | 118 | } |
kenjiArai | 4:36ad7c7d0400 | 119 | //break; |
kenjiArai | 4:36ad7c7d0400 | 120 | case '2' : |
kenjiArai | 4:36ad7c7d0400 | 121 | step_by_step('a'); |
kenjiArai | 4:36ad7c7d0400 | 122 | // Internal 32kHz RC |
kenjiArai | 4:36ad7c7d0400 | 123 | NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_RC << CLOCK_LFCLKSRC_SRC_Pos; |
kenjiArai | 4:36ad7c7d0400 | 124 | // Start the 32 kHz clock, and wait for the start up to complete |
kenjiArai | 4:36ad7c7d0400 | 125 | NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; |
kenjiArai | 4:36ad7c7d0400 | 126 | NRF_CLOCK->TASKS_LFCLKSTART = 1; |
kenjiArai | 4:36ad7c7d0400 | 127 | while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); |
kenjiArai | 4:36ad7c7d0400 | 128 | // Configure the RTC to run at 2 second intervals, and make sure COMPARE0 generates an interrupt (this will be the wakeup source) |
kenjiArai | 4:36ad7c7d0400 | 129 | NRF_RTC1->PRESCALER = 3277; |
kenjiArai | 4:36ad7c7d0400 | 130 | NRF_RTC1->EVTENSET = RTC_EVTEN_COMPARE0_Msk; |
kenjiArai | 4:36ad7c7d0400 | 131 | NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk; |
kenjiArai | 4:36ad7c7d0400 | 132 | NRF_RTC1->CC[0] = 2*10; |
kenjiArai | 4:36ad7c7d0400 | 133 | NRF_RTC1->TASKS_START = 1; |
kenjiArai | 4:36ad7c7d0400 | 134 | //NVIC_EnableIRQ(RTC1_IRQn); |
kenjiArai | 4:36ad7c7d0400 | 135 | // Configure the RAM retention parameters |
kenjiArai | 4:36ad7c7d0400 | 136 | NRF_POWER->RAMON = POWER_RAMON_ONRAM0_RAM0On << POWER_RAMON_ONRAM0_Pos |
kenjiArai | 4:36ad7c7d0400 | 137 | | POWER_RAMON_ONRAM1_RAM1Off << POWER_RAMON_ONRAM1_Pos |
kenjiArai | 4:36ad7c7d0400 | 138 | | POWER_RAMON_OFFRAM0_RAM0Off << POWER_RAMON_OFFRAM0_Pos |
kenjiArai | 4:36ad7c7d0400 | 139 | | POWER_RAMON_OFFRAM1_RAM1Off << POWER_RAMON_OFFRAM1_Pos; |
kenjiArai | 4:36ad7c7d0400 | 140 | while(1) { |
kenjiArai | 4:36ad7c7d0400 | 141 | __WFI(); |
kenjiArai | 4:36ad7c7d0400 | 142 | //NRF_RTC1->TASKS_STOP = 1; |
kenjiArai | 4:36ad7c7d0400 | 143 | } |
kenjiArai | 4:36ad7c7d0400 | 144 | //break; |
kenjiArai | 4:36ad7c7d0400 | 145 | #if 0 |
kenjiArai | 4:36ad7c7d0400 | 146 | case '3' : |
kenjiArai | 4:36ad7c7d0400 | 147 | step_by_step('x'); |
kenjiArai | 4:36ad7c7d0400 | 148 | p_out = 1; |
kenjiArai | 4:36ad7c7d0400 | 149 | step_by_step('y'); |
kenjiArai | 4:36ad7c7d0400 | 150 | p_out = 0; |
kenjiArai | 4:36ad7c7d0400 | 151 | step_by_step('z'); |
kenjiArai | 4:36ad7c7d0400 | 152 | for (uint8_t n =100; n > 0; n--){ |
kenjiArai | 4:36ad7c7d0400 | 153 | p_out = 1; |
kenjiArai | 4:36ad7c7d0400 | 154 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 155 | p_out = 0; |
kenjiArai | 4:36ad7c7d0400 | 156 | wait(0.1); |
kenjiArai | 4:36ad7c7d0400 | 157 | } |
kenjiArai | 4:36ad7c7d0400 | 158 | break; |
kenjiArai | 4:36ad7c7d0400 | 159 | #endif |