This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BLE stumbles without RTT Viewer.

Hello, I'm developing a BLE mouse using nRF52840.

I found something strange while testing mouse movement by connecting the BLE.

I was logging using the RTTViewer and found that the BLE only works normally when the logger is in operation.



Here is the description of the attached video.


1. I modified the firmware so that the mouse moves automatically.
2. I connected my mouse and PC with BLE and started to record this video.
3. I recorded when I connected the RTT Viewer and when I didn't. Please look at the mouse's movements.
4. The numbers 39, 40 in the logger are outputting the return value of app_sched_queue_space_get().

The following is an approximate initialization code.

//log init
NRF_LOG_INIT(NULL);
NRF_LOG_DEFAULT_BACKENDS_INIT();

//timer init
nrf_drv_clock_init();
nrf_drv_clock_lfclk_request(NULL);
app_timer_init();

//pwr mgmt init
nrf_pwr_mgmt_init()

//schedler init
APP_SCHED_INIT(sizeof(my_event_t), SCHED_QUEUE_SIZE:40);


//cli init
nrf_cli_init(const p_cli*:&m_cli_rtt, void* p_transport_config:NULL, int use_color:true, int log_backend:true, int LOG_LVL)
nrf_cli_start(&m_cli_rtt);

//twi init
nrf_twi_mngr_init(g_twi_mnger, twi_config)
twi_probe()

//usb init
app_usbd_init(&usbd_config);
app_usbd_class_append(app_usbd_hid_mouse_class_inst_get(&m_app_hid_mouse););
app_usbd_class_append(app_usbd_hid_kbd_inst_get(&m_app_hid_kbd));
app_usbd_class_append(app_usbd_hid_generic_class_inst_get(&m_app_hid_generic));

//BLE init
buffer_init();
ble_stack_init();
{
	nrf_sdh_enable_request();
	nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
	nrf_sdh_ble_enable(&ram_start);
	NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
	sd_power_dcdc_mode_set(NRF_POWER_DCC_ENABLE);
}
gap_params_init();
{
	BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
	sd_ble_gap_device_name_set(&sec_mode, device_name, device_name_len);
	sd_ble_gap_appearance_set(BLE_APPEARANCE_HID_KEYBOARD);
	sd_ble_gap_ppcp_set(&gap_conn_params)
}
nrf_ble_gatt_init(&m_gatt, gatt_evt_handler)
dis_init();
bas_init();
hids_init();
ble_conn_params_init(&cp_init);
pm_init();
pm_sec_params_set(&sec_param);
pm_register(mkb_ble_pm_evt_handler);
ble_advertising_init(&m_advertising, &init);
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);

//fds init
fds_register(fds_evt_hadler);
fds_init();
fds_wait_for_ready();

//wdt init
nrf_drv_wdt_init(&config, wdt_event_handler);
nrf_drv_wdt_channel_alloc(&m_wdt_channel_id);

//event_init
nrf_balloc_init(&s_event_pool);

//i2c handler init
drv_my_chip_init(touchpad_read_handler)

//adc init
mkb_battery_sensor_adc_init();
app_timer_create(&m_battery_timer_id, APP_TIMER_MODE_REPEATED, battery_level_mean_timeout_handler)a

//pwm init
app_timer_create(&m_led_timer, APP_TMER_MODE_REPEATED, mkb_led_timer_handler)
nrf_drv_pwm_init(&m_pwm1, &led1_cfg, NULL)
nrf_drv_pwm_init(&m_pwm2, &led2_cfg, NULL)
nrf_drv_pwm_init(&m_pwm3, &led3_cfg, NULL)
nrf_drv_pwm_init(&m_pwm4, &led4_cfg, NULL)

 

I don't know how RTT Viewer could affect BLE.

Please help me.

  • Hi,


    Just to be on the same page, as the Software is now it only works as expected if RTT is on?

    Regards,
    Jonathan

  • What is SEGGER_RTT_CONFIG_DEFAULT_MODE sett to ?qw

    // <i> The following modes are supported:
    // <i> - SKIP  - Do not block, output nothing.
    // <i> - TRIM  - Do not block, output as much as fits.
    // <i> - BLOCK - Wait until there is space in the buffer.
    // <0=> SKIP 
    // <1=> TRIM 
    // <2=> BLOCK_IF_FIFO_FULL  


    If it is sett to 2 then that might be the issue, otherwise see if everything is initialized correctly, clocks and timers.

    Regards,
    Jonathan

  • The SEGGER_RTT_CONFIG_DEFAULT_MODE setting you mentioned is already 0.

    Let me explain the phenomenon in more detail.

    Flashing Firmware from SES to Ctrl+T+L.
    I've set up BLE Advertising after the LED lights when Firmware runs.
    But the LED doesn't turn on.
    In other words, Firmware does not run immediately after Flash.
    Of course, I can't check BLE either.

    However, LED and BLE turn on when F2 is pressed in RTTVviewer to start logging.
    I'll call this "STATE1".

    In "STATE1", when I press F3 to disconnect the RTTVviewer, it sends data very stumbly as shown in the video.

    But in a state of "STATE1" physically disconnect the SWD and SWC, LED and BLE are still working fine.
    I'll call this "STATE2".

    When I physically disconnect power from "STATE2" and reconnect and reboot, the LED lights up, but the BLE is not responding.

    in conclusion

    SWDSWC plug-> Flashing -> LED:off , BLE:off

    SWDSWC plug-> Flashing -> SWDSWC unplug -> nRF reset -> LED:on, BLE:stumble

    SWDSWC plug-> Flashing -> connect RTT -> LED:on, BLE:on

    SWDSWC plug-> Flashing -> connect RTT -> SWDSWC unplug-> LED:on, BLE:on

    SWDSWC plug-> Flashing -> connect RTT -> disconnect RTT -> LED:on, BLE:stumble

    It seems as if the Connect, Disconnect command in RTTVviewer has some effect on Softdevice.


    Here I attach the sdk_config.h code of my clock and RTT.

    // <e> NRFX_CLOCK_ENABLED - nrfx_clock - CLOCK peripheral driver
    //==========================================================
    #ifndef NRFX_CLOCK_ENABLED
    #define NRFX_CLOCK_ENABLED 1
    #endif
    // <o> NRFX_CLOCK_CONFIG_LF_SRC  - LF Clock Source
     
    // <0=> RC 
    // <1=> XTAL 
    // <2=> Synth 
    // <131073=> External Low Swing 
    // <196609=> External Full Swing 
    
    #ifndef NRFX_CLOCK_CONFIG_LF_SRC
    #define NRFX_CLOCK_CONFIG_LF_SRC 1
    #endif
    
    // <o> NRFX_CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef NRFX_CLOCK_CONFIG_IRQ_PRIORITY
    #define NRFX_CLOCK_CONFIG_IRQ_PRIORITY 6
    #endif
    
    // <e> NRFX_CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRFX_CLOCK_CONFIG_LOG_ENABLED
    #define NRFX_CLOCK_CONFIG_LOG_ENABLED 0
    #endif
    // <o> NRFX_CLOCK_CONFIG_LOG_LEVEL  - Default Severity level
     
    // <0=> Off 
    // <1=> Error 
    // <2=> Warning 
    // <3=> Info 
    // <4=> Debug 
    
    #ifndef NRFX_CLOCK_CONFIG_LOG_LEVEL
    #define NRFX_CLOCK_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRFX_CLOCK_CONFIG_INFO_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_CLOCK_CONFIG_INFO_COLOR
    #define NRFX_CLOCK_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRFX_CLOCK_CONFIG_DEBUG_COLOR  - ANSI escape code prefix.
     
    // <0=> Default 
    // <1=> Black 
    // <2=> Red 
    // <3=> Green 
    // <4=> Yellow 
    // <5=> Blue 
    // <6=> Magenta 
    // <7=> Cyan 
    // <8=> White 
    
    #ifndef NRFX_CLOCK_CONFIG_DEBUG_COLOR
    #define NRFX_CLOCK_CONFIG_DEBUG_COLOR 0
    #endif
    
    
    // <e> NRF_CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver - legacy layer
    //==========================================================
    #ifndef NRF_CLOCK_ENABLED
    #define NRF_CLOCK_ENABLED 1
    #endif
    // <o> CLOCK_CONFIG_LF_SRC  - LF Clock Source
     
    // <0=> RC 
    // <1=> XTAL 
    // <2=> Synth 
    // <131073=> External Low Swing 
    // <196609=> External Full Swing 
    
    #ifndef CLOCK_CONFIG_LF_SRC
    #define CLOCK_CONFIG_LF_SRC 1
    #endif
    
    // <q> CLOCK_CONFIG_LF_CAL_ENABLED  - Calibration enable for LF Clock Source
     
    
    #ifndef CLOCK_CONFIG_LF_CAL_ENABLED
    #define CLOCK_CONFIG_LF_CAL_ENABLED 0
    #endif
    
    // <o> CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority
     
    
    // <i> Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
    // <0=> 0 (highest) 
    // <1=> 1 
    // <2=> 2 
    // <3=> 3 
    // <4=> 4 
    // <5=> 5 
    // <6=> 6 
    // <7=> 7 
    
    #ifndef CLOCK_CONFIG_IRQ_PRIORITY
    #define CLOCK_CONFIG_IRQ_PRIORITY 6
    #endif
    
    
    // </h> 
    //==========================================================
    
    // <h> Clock - SoftDevice clock configuration
    
    //==========================================================
    // <o> NRF_SDH_CLOCK_LF_SRC  - SoftDevice clock source.
     
    // <0=> NRF_CLOCK_LF_SRC_RC 
    // <1=> NRF_CLOCK_LF_SRC_XTAL 
    // <2=> NRF_CLOCK_LF_SRC_SYNTH 
    
    #ifndef NRF_SDH_CLOCK_LF_SRC
    #define NRF_SDH_CLOCK_LF_SRC 1
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval. 
    #ifndef NRF_SDH_CLOCK_LF_RC_CTIV
    #define NRF_SDH_CLOCK_LF_RC_CTIV 0
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature. 
    // <i> How often (in number of calibration intervals) the RC oscillator shall be calibrated
    // <i>  if the temperature has not changed.
    
    #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
    #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 0
    #endif
    
    // <o> NRF_SDH_CLOCK_LF_ACCURACY  - External clock accuracy used in the LL to compute timing.
     
    // <0=> NRF_CLOCK_LF_ACCURACY_250_PPM 
    // <1=> NRF_CLOCK_LF_ACCURACY_500_PPM 
    // <2=> NRF_CLOCK_LF_ACCURACY_150_PPM 
    // <3=> NRF_CLOCK_LF_ACCURACY_100_PPM 
    // <4=> NRF_CLOCK_LF_ACCURACY_75_PPM 
    // <5=> NRF_CLOCK_LF_ACCURACY_50_PPM 
    // <6=> NRF_CLOCK_LF_ACCURACY_30_PPM 
    // <7=> NRF_CLOCK_LF_ACCURACY_20_PPM 
    // <8=> NRF_CLOCK_LF_ACCURACY_10_PPM 
    // <9=> NRF_CLOCK_LF_ACCURACY_5_PPM 
    // <10=> NRF_CLOCK_LF_ACCURACY_2_PPM 
    // <11=> NRF_CLOCK_LF_ACCURACY_1_PPM 
    
    #ifndef NRF_SDH_CLOCK_LF_ACCURACY
    #define NRF_SDH_CLOCK_LF_ACCURACY 11
    #endif
    

    and this is my enabled modules in sdk_config.h

    #define APP_USBD_CONFIG_EVENT_QUEUE_ENABLE 1
    #define BLE_ADVERTISING_ENABLED 1
    #define NRF_BLE_CONN_PARAMS_ENABLED 1
    #define NRF_BLE_GATT_ENABLED 1
    #define NRF_BLE_QWR_ENABLED 1
    #define PEER_MANAGER_ENABLED 1
    #define PM_SERVICE_CHANGED_ENABLED 1
    #define PM_PEER_RANKS_ENABLED 1
    #define BLE_BAS_ENABLED 1
    #define BLE_DIS_ENABLED 1
    #define BLE_HIDS_ENABLED 1
    #define NRF_CRYPTO_ENABLED 1
    #define NRF_CRYPTO_BACKEND_CC310_BL_ECC_SECP256R1_ENABLED 1
    #define NRF_CRYPTO_BACKEND_CC310_BL_HASH_SHA256_ENABLED 1
    #define NRF_CRYPTO_BACKEND_CC310_BL_INTERRUPTS_ENABLED 1
    #define NRF_CRYPTO_BACKEND_CC310_AES_CBC_ENABLED 1
    //and crypto things are enabled 1....
    
    #define GPIOTE_ENABLED 1
    #define NRFX_CLOCK_ENABLED 1
    #define NRFX_POWER_ENABLED 1
    #define NRFX_PPI_ENABLED 1
    #define NRFX_PRS_ENABLED 1
    #define NRFX_PRS_BOX_4_ENABLED 1
    #define NRFX_PWM_ENABLED 1
    #define NRFX_PWM0_ENABLED 1
    #define NRFX_PWM1_ENABLED 1
    #define NRFX_PWM2_ENABLED 1
    #define NRFX_PWM3_ENABLED 1
    #define NRFX_SAADC_ENABLED 1
    #define NRFX_SYSTICK_ENABLED 1
    #define NRFX_TIMER_ENABLED 1
    #define NRFX_TIMER0_ENABLED 1
    #define NRFX_TIMER1_ENABLED 1
    #define NRFX_TIMER2_ENABLED 1
    #define NRFX_TIMER3_ENABLED 1
    #define NRFX_TIMER4_ENABLED 1
    #define NRFX_TWIM_ENABLED 1
    #define NRFX_TWI_ENABLED 1
    #define NRFX_UARTE_ENABLED 1
    #define NRFX_USBD_ENABLED 1
    #define NRF_CLOCK_ENABLED 1
    #define POWER_ENABLED 1
    #define PPI_ENABLED 1
    #define PWM_ENABLED 1
    #define PWM0_ENABLED 1
    #define PWM1_ENABLED 1
    #define PWM2_ENABLED 1
    #define PWM3_ENABLED 1
    #define SAADC_ENABLED 1
    #define TIMER_ENABLED 1
    #define TIMER0_ENABLED 1
    #define TIMER1_ENABLED 1
    #define TIMER2_ENABLED 1
    #define TIMER3_ENABLED 1
    #define TIMER4_ENABLED 1
    #define TWI_ENABLED 1
    #define TWI0_ENABLED 1
    #define UART_ENABLED 1
    #define USBD_ENABLED 1
    #define WDT_ENABLED 1
    #define APP_GPIOTE_ENABLED 1
    #define APP_SCHEDULER_ENABLED 1
    #define APP_TIMER_ENABLED 1
    #define APP_USBD_ENABLED 1
    #define APP_USBD_HID_ENABLED 1
    #define APP_USBD_HID_GENERIC_ENABLED 1
    #define APP_USBD_HID_KBD_ENABLED 1
    #define APP_USBD_HID_MOUSE_ENABLED 1
    #define CRC16_ENABLED 1
    #define FDS_ENABLED 1
    #define NRF_BALLOC_ENABLED 1
    #define NRF_CSENSE_ENABLED 1
    #define NRF_CLI_RTT_ENABLED 1
    #define NRF_FSTORAGE_ENABLED 1
    #define NRF_MEMOBJ_ENABLED 1
    #define NRF_PWR_MGMT_ENABLED 1
    #define NRF_PWR_MGMT_CONFIG_STANDBY_TIMEOUT_ENABLED 1
    #define NRF_PWR_MGMT_CONFIG_FPU_SUPPORT_ENABLED 1
    #define NRF_QUEUE_ENABLED 1
    #define NRF_SECTION_ITER_ENABLED 1
    #define NRF_SORTLIST_ENABLED 1
    #define NRF_STRERROR_ENABLED 1
    #define NRF_TWI_MNGR_ENABLED 1
    #define TASK_MANAGER_CONFIG_STACK_PROFILER_ENABLED 1
    #define BUTTON_ENABLED 1
    #define NRF_CLI_ENABLED 1
    #define NRF_CLI_BUILD_IN_CMDS_ENABLED 1
    #define NRF_CLI_HISTORY_ENABLED 1
    #define NRF_CLI_VT100_COLORS_ENABLED 1
    #define NRF_CLI_STATISTICS_ENABLED 1
    #define NRF_FPRINTF_ENABLED 1
    #define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 1
    #define NRF_LOG_BACKEND_RTT_ENABLED 1
    #define NRF_LOG_ENABLED 1
    #define NRF_SDH_BLE_LOG_ENABLED 1
    #define NRF_SDH_LOG_ENABLED 1
    #define NRF_SDH_SOC_LOG_ENABLED 1
    #define NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED 1
    #define NRF_SDH_BLE_ENABLED 1
    #define NRF_SDH_ENABLED 1
    #define NRF_SDH_SOC_ENABLED 1
    



  • Sorry for not getting back to you sooner, have you had any progress on this issue ?

Related