adding BLE to a system without softdevice, using the 17.1 sdk (can't change) freetos no ble events

the existing code is using freetos, 
and main.c finally ends at 

vTaskStartScheduler();
 
which never returns as expected... but my ble scan and advertise do not appear to work, no events are recevied... and nrf_connect app doesn't see my device advertising
I had a previous topic open on adding the ble code, which fixed a couple build setup issues. 
debugging with OZONE
have stops on the event handlers.. 
scanning I am not filtering UUIDs in the scan,, give me everything
 
advertise start 
 
err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG);
 
scanner start 
bool ble_stack_manager_scan_start(ble_mgr_adv_report_handler_t scan_handler)
{
ret_code_t err_code;

m_scan_handler = scan_handler;

err_code = nrf_ble_scan_start(&m_scan);
everything returns rc=0
I don't think I have to  create freetos tasks explicitly and run them 
we did have to move the existing timer 0 code to 1 so SD timer would work. 
Parents
  • here is the scan setup code 

    #define SCAN_INTERVAL 0x00A0 // Scan interval (100 ms)
    #define SCAN_WINDOW 0x0050 // Scan window (50 ms)
    #define SCAN_TIMEOUT 0 // Scan timeout (0 = no timeout)
    // Initialize central mode
    // QLOGD("Initializing BLE in central mode");
    
    // Initialize scanner
    nrf_ble_scan_init_t scan_init_params;
    memset(&scan_init_params, 0, sizeof(scan_init_params));
    
    // Set scan parameters
    scan_init_params.p_scan_param = &(ble_gap_scan_params_t){
    .active = 1,
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .scan_phys = BLE_GAP_PHY_1MBPS,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    };
    
    
    err_code = nrf_ble_scan_init(&m_scan, &scan_init_params, NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize scanner: %ld", err_code);
    return false;
    }
    
    // Initialize database discovery
    err_code = ble_db_discovery_init(NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize database discovery: %ld", err_code);
    return false;
    }
    // Initialize central mode
    // QLOGD("Initializing BLE in central mode");
    
    // Initialize scanner
    nrf_ble_scan_init_t scan_init_params;
    memset(&scan_init_params, 0, sizeof(scan_init_params));
    
    // Set scan parameters
    scan_init_params.p_scan_param = &(ble_gap_scan_params_t){
    .active = 1,
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .scan_phys = BLE_GAP_PHY_1MBPS,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    };
    
    
    err_code = nrf_ble_scan_init(&m_scan, &scan_init_params, NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize scanner: %ld", err_code);
    return false;
    }
    
    // Initialize database discovery
    err_code = ble_db_discovery_init(NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize database discovery: %ld", err_code);
    return false;
    }
Reply
  • here is the scan setup code 

    #define SCAN_INTERVAL 0x00A0 // Scan interval (100 ms)
    #define SCAN_WINDOW 0x0050 // Scan window (50 ms)
    #define SCAN_TIMEOUT 0 // Scan timeout (0 = no timeout)
    // Initialize central mode
    // QLOGD("Initializing BLE in central mode");
    
    // Initialize scanner
    nrf_ble_scan_init_t scan_init_params;
    memset(&scan_init_params, 0, sizeof(scan_init_params));
    
    // Set scan parameters
    scan_init_params.p_scan_param = &(ble_gap_scan_params_t){
    .active = 1,
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .scan_phys = BLE_GAP_PHY_1MBPS,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    };
    
    
    err_code = nrf_ble_scan_init(&m_scan, &scan_init_params, NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize scanner: %ld", err_code);
    return false;
    }
    
    // Initialize database discovery
    err_code = ble_db_discovery_init(NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize database discovery: %ld", err_code);
    return false;
    }
    // Initialize central mode
    // QLOGD("Initializing BLE in central mode");
    
    // Initialize scanner
    nrf_ble_scan_init_t scan_init_params;
    memset(&scan_init_params, 0, sizeof(scan_init_params));
    
    // Set scan parameters
    scan_init_params.p_scan_param = &(ble_gap_scan_params_t){
    .active = 1,
    .interval = SCAN_INTERVAL,
    .window = SCAN_WINDOW,
    .timeout = SCAN_TIMEOUT,
    .scan_phys = BLE_GAP_PHY_1MBPS,
    .filter_policy = BLE_GAP_SCAN_FP_ACCEPT_ALL,
    };
    
    
    err_code = nrf_ble_scan_init(&m_scan, &scan_init_params, NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize scanner: %ld", err_code);
    return false;
    }
    
    // Initialize database discovery
    err_code = ble_db_discovery_init(NULL);
    if (err_code != NRF_SUCCESS)
    {
    QLOGE("Failed to initialize database discovery: %ld", err_code);
    return false;
    }
Children
  • add rtt for debugging
    in Controller mode, this will scan for Controllee mode endpoints, AND advertise to pair with phone 

    neither appear to actually work, altho rc=0 

    about 20 seconds in get hardfault,  stack return address out of range, pc A60, which shouldn't be.. like branch to 0 

    00> Calling ble_stack_manager_init...
    00> ble_stack_manager_init returned: TRUE
    00> BLE init SUCCESS - starting advertising
    00> advertising_start called
    00> === BLE Init Complete ===

    freetos scheduler started here

    00> log_processing_task: Started
    00> [00:00:03.275,078] <info> app: ble_stack_manager_init: 1-nrf_sdh_enable_request
    00>
    00> [00:00:03.275,274] <info> app: ble_stack_manager_init: 2-nrf_sdh_ble_default_cfg_set
    00>
    00> [00:00:03.275,325] <info> app: ble_stack_manager_init: 3-nrf_sdh_ble_enable
    00>
    00> [00:00:03.275,977] <info> app: ble_stack_manager_init: 4-nrf_sdh_freertos_init
    00>
    00> [00:00:03.276,419] <info> app: ble_stack_manager_init: 5-gap_params_init
    00>
    00> [00:00:03.276,484] <info> app: ble_stack_manager_init: 6-gap_conn_params_init
    00>
    00> [00:00:03.276,505] <info> app: ble_stack_manager_init: 7-gatt_init
    00>
    00> [00:00:03.276,523] <info> app: Registered UCI UUID with type: 2
    00>
    00> [00:00:03.276,767] <info> app: ble_stack_manager_init: 8-advertising_init
    00>
    00> [00:00:03.276,799] <info> app: Advertising will include UCI service UUID: 0x0001 (type 2)
    00>
    00> [00:00:03.276,923] <info> app: ble_stack_manager_init: 9-scan_init
    00>
    00> [00:00:03.276,927] <info> app: Initializing BLE scanning module
    00>
    00> [00:00:03.276,933] <info> app: ble_stack_manager_init: 10-COMPLETE
    00>
    00> [00:00:03.276,937] <info> app: BLE stack initialized successfully
    00>
    00> [00:00:03.276,972] <info> app: About to call ble_advertising_start...
    00>
    00> [00:00:03.283,869] <info> app: ble_advertising_start returned: 0

    this was an app that used USB only. nothing connected to USB uart port on Murata 2AB 
    debugger connect via pin header, and USB port socket

  • I’ve made progress. Lots of setup problems, but finally working

    one outstanding issue, set number of peripherals 16 with larger buffer size, get ram_size 12400

    set in ld file, linker shows 12400

    sdh_ble_enable fails rc=4

    but it reports 12400 is needed

    is there a 64k limit?  Size under 64k works

    but I might have 30 or more of our devices to scan and talk to

  • Hi!

    rexxdad said:
    I’ve made progress. Lots of setup problems, but finally working

    Great to hear!

    rexxdad said:

    one outstanding issue, set number of peripherals 16 with larger buffer size, get ram_size 12400

    set in ld file, linker shows 12400

    sdh_ble_enable fails rc=4

    but it reports 12400 is needed

    is there a 64k limit?  Size under 64k works

    but I might have 30 or more of our devices to scan and talk to

    Yes, there is a limit, the dynamic part of the SoftDevice RAM region can be max 64 kB 

    https://docs.nordicsemi.com/bundle/s140_v7.2.0_api/page/group_b_l_e_c_o_m_m_o_n_f_u_n_c_t_i_o_n_s.html#ga8a92420df90945526d4c89d09486508d

  • Ok, almost there

    using the S140 softdevice works, debug works in Ozone
    now another device, using the 52833

    I have adjusted the LD file to reserve space for SD per the release notes.

    in Ozone project script I load the elf (which does NOT have SD included, but does have the debugger symbols) 

    then load the SD file(incl the MBR) at position 0 (as the elf positons the app isr vectors after the SD size)

    then the setupTarget function (in the ozone project)  gets the sp value from data at 0

    and the pc value from position 4

    but I get immediate hardfault. 

    the process should be the same for 52833 vs 52840, right?  Boot Record is the same

    log from the Ozone startup 

    Downloading Program.
    Exec.Download ("$(ProjectDir)/Downloads/DW3_QM33_SDK_1.0.2.new/SDK/Firmware/BuildOutput/DW3_QM33_SDK_UCI/FreeRTOS/DWM3001CDK/DWM3001CDK-DW3_QM33_SDK_UCI-FreeRTOS.elf");
    J-Link: Flash download: Bank 0 @ 0x00000000: 10 ranges affected (266240 bytes)
    J-Link: Flash download: Total: 8.561s (Prepare: 0.114s, Compare: 0.222s, Erase: 5.663s, Program & Verify: 2.471s, Restore: 0.089s)
    J-Link: Flash download: Program & Verify speed: 104 KB/s
    Loading softdevice
    Target.LoadMemory ("/home/sam/Downloads/DW3_QM33_SDK_1.0.2.new/SDK/Firmware/SDK_BSP/Nordic/NORDIC_SDK_17_1_0/components/softdevice/s113/hex/s113_nrf52_7.2.0_softdevice.hex", 0x00000000);
    J-Link: Flash download: Bank 0 @ 0x00000000: Skipped. Contents already match
    Target.ReadU32 (0x00000000); // returns 0x4, data is 0x20000400
    Target.SetReg ("SP", 0x20000400);
    Target.ReadU32 (0x00000004); // returns 0x4, data is 0xA81
    Target.SetReg ("PC", 0xA81);

    the LD file for app before SD is 

    MEMORY
    {
    RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 128K
    FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 512K - 4K - 4K /* 1M minus calib_sha/calib sections. */
    CALIB_SHA (rw) : ORIGIN = 0x0007E000, LENGTH = 4K
    CALIB (rw) : ORIGIN = 0x0007F000, LENGTH = 4K
    }

    SECTIONS
    {
    .application (0x00000000) :
    {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */

    and after 

    MEMORY
    {
    RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 128K - 8k
    FLASH (rx) : ORIGIN = 0x0001E000, LENGTH = 512K - 112K - 4K - 4K /* 512 minus calib_sha/calib sections. */
    CALIB_SHA (rw) : ORIGIN = 0x0007E000, LENGTH = 4K
    CALIB (rw) : ORIGIN = 0x0007F000, LENGTH = 4K
    }

    SECTIONS
    {
    /* start with interrupt vectors */
    isr_vectors (ORIGIN(FLASH)) :

    I know the ram value isn't correct, I need to see the output of the ble_enable. 

    the map shows the app start address at 3D990
    and the app vector table loaded at 1E000 shows (flash origin)
    00 00 02 20
    91 D9 03 00  (03D991)

    --------
    hardfault info 
    @ 0000 0000

    top of stack out of range
    pc=1AE44

    That would be in the SD code space.. top/ending at 1E000 (-8k)= 1C000 (documented size for SD S113)
    ozone setup link 
    devzone.nordicsemi.com/.../segger-ozone-causes-a-soft-device-error-when-trying-to-debug-or-reset-during-debugging

  • I changed flash to 
    FLASH (rx) : ORIGIN = 0x0001C000,

    and now my code is entered.

    but 
    nrf_sdh_enable_request();  returns 0x1001 (already enabled?)

    skip that then 
    nrf_sdh_ble_default_cfg_set
    returns rc=0, ram_start= 0x2002000, matching LD

    then 
    nrf_sdh_ble_enable(&ram_start);

    returns rc=2

    confused

Related