From b283f9e12bba26d1d02ad611598cf036ae720c2e Mon Sep 17 00:00:00 2001 From: rbaron Date: Thu, 11 Mar 2021 22:28:49 +0100 Subject: [PATCH] ble-rtc-low-power-advertiser works with an external XTAL --- .../ble_app_beacon_gcc_nrf52.ld | 2 +- .../config/sdk_config.h | 46 +++++++++---------- .../ble-rtc-low-power-advertiser/src/main.c | 27 +++++++++-- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/ble_app_beacon_gcc_nrf52.ld b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/ble_app_beacon_gcc_nrf52.ld index fc70071..c6e70fb 100644 --- a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/ble_app_beacon_gcc_nrf52.ld +++ b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/ble_app_beacon_gcc_nrf52.ld @@ -6,7 +6,7 @@ GROUP(-lgcc -lc -lnosys) MEMORY { FLASH (rx) : ORIGIN = 0x27000, LENGTH = 0xd9000 - RAM (rwx) : ORIGIN = 0x200018d8, LENGTH = 0x3e728 + RAM (rwx) : ORIGIN = 0x20002300, LENGTH = 0x3dd00 } SECTIONS diff --git a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/config/sdk_config.h b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/config/sdk_config.h index 9e07094..0f2fcb6 100644 --- a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/config/sdk_config.h +++ b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/config/sdk_config.h @@ -1730,7 +1730,7 @@ // <196609=> External Full Swing #ifndef NRFX_CLOCK_CONFIG_LF_SRC -#define NRFX_CLOCK_CONFIG_LF_SRC 0 +#define NRFX_CLOCK_CONFIG_LF_SRC 1 #endif // NRFX_CLOCK_CONFIG_IRQ_PRIORITY - Interrupt priority @@ -3248,7 +3248,7 @@ // NRFX_RTC_ENABLED - nrfx_rtc - RTC peripheral driver //========================================================== #ifndef NRFX_RTC_ENABLED -#define NRFX_RTC_ENABLED 1 +#define NRFX_RTC_ENABLED 0 #endif // NRFX_RTC0_ENABLED - Enable RTC0 instance @@ -3308,7 +3308,7 @@ // NRFX_RTC_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef NRFX_RTC_CONFIG_LOG_ENABLED -#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#define NRFX_RTC_CONFIG_LOG_ENABLED 1 #endif // NRFX_RTC_CONFIG_LOG_LEVEL - Default Severity level @@ -4823,7 +4823,7 @@ #ifndef CLOCK_CONFIG_LF_CAL_ENABLED -#define CLOCK_CONFIG_LF_CAL_ENABLED 1 +#define CLOCK_CONFIG_LF_CAL_ENABLED 0 #endif // CLOCK_CONFIG_IRQ_PRIORITY - Interrupt priority @@ -5384,7 +5384,7 @@ #ifndef RTC0_ENABLED -#define RTC0_ENABLED 1 +#define RTC0_ENABLED 0 #endif // RTC1_ENABLED - Enable RTC1 instance @@ -7625,7 +7625,7 @@ // NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend //========================================================== #ifndef NRF_LOG_BACKEND_RTT_ENABLED -#define NRF_LOG_BACKEND_RTT_ENABLED 0 +#define NRF_LOG_BACKEND_RTT_ENABLED 1 #endif // NRF_LOG_BACKEND_RTT_TEMP_BUFFER_SIZE - Size of buffer for partially processed strings. // Size of the buffer is a trade-off between RAM usage and processing. @@ -7703,7 +7703,7 @@ // NRF_LOG_ENABLED - nrf_log - Logger //========================================================== #ifndef NRF_LOG_ENABLED -#define NRF_LOG_ENABLED 0 +#define NRF_LOG_ENABLED 1 #endif // Log message pool - Configuration of log message pool @@ -8070,7 +8070,7 @@ // CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef CLOCK_CONFIG_LOG_ENABLED -#define CLOCK_CONFIG_LOG_ENABLED 0 +#define CLOCK_CONFIG_LOG_ENABLED 1 #endif // CLOCK_CONFIG_LOG_LEVEL - Default Severity level @@ -8638,7 +8638,7 @@ // RTC_CONFIG_LOG_ENABLED - Enables logging in the module. //========================================================== #ifndef RTC_CONFIG_LOG_ENABLED -#define RTC_CONFIG_LOG_ENABLED 0 +#define RTC_CONFIG_LOG_ENABLED 1 #endif // RTC_CONFIG_LOG_LEVEL - Default Severity level @@ -8649,7 +8649,7 @@ // <4=> Debug #ifndef RTC_CONFIG_LOG_LEVEL -#define RTC_CONFIG_LOG_LEVEL 3 +#define RTC_CONFIG_LOG_LEVEL 4 #endif // RTC_CONFIG_INFO_COLOR - ANSI escape code prefix. @@ -10282,7 +10282,7 @@ // NRF_SDH_BLE_LOG_ENABLED - Enable logging in SoftDevice handler (BLE) module. //========================================================== #ifndef NRF_SDH_BLE_LOG_ENABLED -#define NRF_SDH_BLE_LOG_ENABLED 0 +#define NRF_SDH_BLE_LOG_ENABLED 1 #endif // NRF_SDH_BLE_LOG_LEVEL - Default Severity level @@ -10333,7 +10333,7 @@ // NRF_SDH_LOG_ENABLED - Enable logging in SoftDevice handler module. //========================================================== #ifndef NRF_SDH_LOG_ENABLED -#define NRF_SDH_LOG_ENABLED 0 +#define NRF_SDH_LOG_ENABLED 1 #endif // NRF_SDH_LOG_LEVEL - Default Severity level @@ -11374,7 +11374,7 @@ // NRF_SDH_BLE_PERIPHERAL_LINK_COUNT - Maximum number of peripheral links. #ifndef NRF_SDH_BLE_PERIPHERAL_LINK_COUNT -#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 0 +#define NRF_SDH_BLE_PERIPHERAL_LINK_COUNT 1 #endif // NRF_SDH_BLE_CENTRAL_LINK_COUNT - Maximum number of central links. @@ -11403,12 +11403,13 @@ // NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE - Attribute Table size in bytes. The size must be a multiple of 4. #ifndef NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE -#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 248 +// #define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 248 +#define NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408 #endif // NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs. #ifndef NRF_SDH_BLE_VS_UUID_COUNT -#define NRF_SDH_BLE_VS_UUID_COUNT 0 +#define NRF_SDH_BLE_VS_UUID_COUNT 10 #endif // NRF_SDH_BLE_SERVICE_CHANGED - Include the Service Changed characteristic in the Attribute Table. @@ -11870,14 +11871,13 @@ // <2=> NRF_CLOCK_LF_SRC_SYNTH #ifndef NRF_SDH_CLOCK_LF_SRC -#define NRF_SDH_CLOCK_LF_SRC 0 -// #define NRF_SDH_CLOCK_LF_SRC 1 +#define NRF_SDH_CLOCK_LF_SRC 1 #endif // NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval. #ifndef NRF_SDH_CLOCK_LF_RC_CTIV -// #define NRF_SDH_CLOCK_LF_RC_CTIV 1 -#define NRF_SDH_CLOCK_LF_RC_CTIV 16 +#define NRF_SDH_CLOCK_LF_RC_CTIV 0 +// #define NRF_SDH_CLOCK_LF_RC_CTIV 16 #endif // NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature. @@ -11885,8 +11885,8 @@ // if the temperature has not changed. #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV -// #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 -#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 8 +#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0 +// #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 8 #endif // NRF_SDH_CLOCK_LF_ACCURACY - External clock accuracy used in the LL to compute timing. @@ -11905,8 +11905,8 @@ // <11=> NRF_CLOCK_LF_ACCURACY_1_PPM #ifndef NRF_SDH_CLOCK_LF_ACCURACY -// #define NRF_SDH_CLOCK_LF_ACCURACY 7 -#define NRF_SDH_CLOCK_LF_ACCURACY 1 +#define NRF_SDH_CLOCK_LF_ACCURACY 7 +// #define NRF_SDH_CLOCK_LF_ACCURACY 1 #endif // diff --git a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/src/main.c b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/src/main.c index d509492..6e949e6 100644 --- a/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/src/main.c +++ b/code/playground/nrf_sdk/ble-rtc-low-power-advertiser/src/main.c @@ -17,7 +17,8 @@ #include "nrf_soc.h" // P0.03 -#define LED_PIN 3 +// #define LED_PIN 3 +#define LED_PIN NRF_GPIO_PIN_MAP(1, 11) // Environmental sensing #define SERVICE_UUID 0x181a @@ -33,7 +34,7 @@ static uint8_t service_data[SERVICE_DATA_LEN]; #define APP_BLE_CONN_CFG_TAG 1 // Seconds between RTC 2 events. -#define COMPARE_COUNTERTIME (6UL) +#define COMPARE_COUNTERTIME (2UL) // RTC0 is used by softdevice! We need to pick another instance. const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2); @@ -105,6 +106,7 @@ static void advertising_start(void) { err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG); APP_ERROR_CHECK(err_code); + NRF_LOG_INFO("Advertising started\n.") } static void advertising_stop(void) { @@ -165,11 +167,14 @@ static void idle_state_handle(void) { } static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { + NRF_LOG_INFO("CALLBACK!\n"); + NRF_LOG_FLUSH(); if (int_type == NRF_DRV_RTC_INT_COMPARE2) { - // nrf_gpio_pin_toggle(LED_PIN); + nrf_gpio_pin_set(LED_PIN); advertising_start(); nrf_delay_ms(1000); advertising_stop(); + nrf_gpio_pin_clear(LED_PIN); nrf_drv_rtc_counter_clear(&rtc); // We need to re-enable the RTC2 interrupt. nrf_drv_rtc_int_enable(&rtc, NRF_RTC_INT_COMPARE2_MASK); @@ -182,21 +187,25 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { static void rtc_config(void) { uint32_t err_code; + NRF_LOG_INFO("1!\n"); NRF_LOG_FLUSH(); // Initialize RTC instance. nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG; config.prescaler = 4095; err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler); APP_ERROR_CHECK(err_code); + NRF_LOG_INFO("2!\n"); NRF_LOG_FLUSH(); nrf_drv_rtc_tick_disable(&rtc); nrf_drv_rtc_overflow_disable(&rtc); nrf_drv_rtc_counter_clear(&rtc); + NRF_LOG_INFO("3!\n"); NRF_LOG_FLUSH(); // Set compare channel to trigger interrupt after COMPARE_COUNTERTIME // seconds. err_code = nrf_drv_rtc_cc_set(&rtc, 2, COMPARE_COUNTERTIME * 8, true); APP_ERROR_CHECK(err_code); + NRF_LOG_INFO("4!\n"); NRF_LOG_FLUSH(); // Power on RTC instance. nrf_drv_rtc_enable(&rtc); } @@ -212,15 +221,25 @@ static void power_manage(void) { int main(void) { // Initialize. - // leds_init(); + log_init(); + leds_init(); power_management_init(); + NRF_LOG_INFO("Power inited\n"); NRF_LOG_FLUSH(); ble_stack_init(); + NRF_LOG_INFO("BLE stack inited\n"); NRF_LOG_FLUSH(); advertising_init(); + NRF_LOG_INFO("Adv inited\n"); NRF_LOG_FLUSH(); rtc_config(); + // advertising_start(); + + NRF_LOG_FLUSH(); // Enter main loop. for (;;) { // sd_power_system_off(); power_manage(); + // NRF_LOG_INFO("Hello, RTT!\n"); + // NRF_LOG_FLUSH(); + // nrf_delay_ms(500); } } \ No newline at end of file