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

nRF51-ble-bcast-mesh with freertos

I want make OpenMesh stack running as a task with freertos(8.2.1).

first,I got two LEDs tasks running on nrf51822 very well,That's the base.

Then I set mesh stack as a task "ble_stack_thread",and three tasks like this:

UNUSED_VARIABLE(xTaskCreate(ble_stack_thread, "BLE", configMINIMAL_STACK_SIZE + 256, NULL, 1, &m_ble_stack_thread));
	
UNUSED_VARIABLE(xTaskCreate( vLed0Function, "L0", configMINIMAL_STACK_SIZE, NULL, 2, &xLed0Handle ));    // LED0 task creation
xLed1Handle = xTimerCreate( "L1", TIMER_PERIOD, pdTRUE, NULL, vLed1Callback );                                 // LED1 timer creation
UNUSED_VARIABLE(xTimerStart( xLed1Handle, 0 ));                                                                // LED1 timer start

/* Activate deep sleep mode */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;

// Start FreeRTOS scheduler.
vTaskStartScheduler();

while (true)
{
    // FreeRTOS should not be here...
		
}

The source code of task ble_stack_thread like below:

static void ble_stack_thread(void * arg){

UNUSED_PARAMETER(arg);

/* Enable Softdevice (including sd_ble before framework */
SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SOURCE, NULL);
softdevice_ble_evt_handler_set(sd_ble_evt_handler); /* app-defined event handler, as we need to send it to the nrf_adv_conn module and the rbc_mesh */
softdevice_sys_evt_handler_set(rbc_mesh_sd_evt_handler);

rbc_mesh_init_params_t init_params;

init_params.access_addr = MESH_ACCESS_ADDR;
init_params.interval_min_ms = MESH_INTERVAL_MIN_MS;
init_params.channel = MESH_CHANNEL;
init_params.lfclksrc = MESH_CLOCK_SOURCE;
init_params.tx_power = RBC_MESH_TXPOWER_0dBm;

uint32_t error_code = rbc_mesh_init(init_params);
APP_ERROR_CHECK(error_code);

/* request values for both LEDs on the mesh */
for (uint32_t i = 0; i < 2; ++i)
{
    error_code = rbc_mesh_value_enable(i);
    APP_ERROR_CHECK(error_code);
}

/* init BLE gateway softdevice application: */
nrf_adv_conn_init();

rbc_mesh_event_t evt;

while (1)
{		
    for (uint32_t pin = BUTTON_START; pin <= BUTTON_STOP; ++pin)
    {
        if(nrf_gpio_pin_read(pin) == 0)
        {
            while(nrf_gpio_pin_read(pin) == 0);
            uint8_t mesh_data[1];
            uint32_t led_status = !!((pin - BUTTON_START) & 0x01); /* even buttons are OFF, odd buttons are ON */
            uint32_t led_offset = !!((pin - BUTTON_START) & 0x02); /* two buttons per led */

            mesh_data[0] = led_status;
            if (rbc_mesh_value_set(led_offset, mesh_data, 1) == NRF_SUCCESS)
            {
                //led_config(led_offset, led_status);
									nrf_gpio_pin_toggle(BSP_LED_0);
            }
        }
    }
    if (rbc_mesh_event_get(&evt) == NRF_SUCCESS)
    {
        rbc_mesh_event_handler(&evt);
        rbc_mesh_event_release(&evt);
    }			
}

}

Question is, it stuck in function "SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SOURCE, NULL);"

What I think It's a clock problem maybe, freertos initialize clock first then softdevice initialize again cause it.But I'm not sure.

Does anyone have an idea about this? And any idea about OpenMesh stack using on freertos need to pay attention to. Thanks in advance!

Related