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

PWM conflict with FreeRTOS Thread example

Hi,

I've created 3 PWM pulses via:

APP_PWM_INSTANCE(PWM1,2);                   // Create the instance "PWM1" using TIMER1.
APP_PWM_INSTANCE(PWM2,3);
APP_PWM_INSTANCE(PWM3,4);


    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, LED_R);
    app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, LED_G);
    app_pwm_config_t pwm3_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, LED_B);

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    err_code = app_pwm_init(&PWM2, &pwm2_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    err_code = app_pwm_init(&PWM3, &pwm3_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);

    app_pwm_enable(&PWM1);
    app_pwm_enable(&PWM2);
    app_pwm_enable(&PWM3);

    
    while (app_pwm_channel_duty_set(&PWM1, 0, 0) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM2, 0, 0) == NRF_ERROR_BUSY);
    while (app_pwm_channel_duty_set(&PWM3, 0, 100) == NRF_ERROR_BUSY);

Which works when I'm not starting Thread (from the examples/thread/freertos_coap_server example)

But when I start Thread (via the commands below), the last configured PWM is not working

    thread_coap_utils_led_timer_init();
    thread_coap_utils_provisioning_timer_init();
    thread_instance_init();
    thread_coap_init();
    thread_bsp_init();
    thread_coap_utils_light_changed_callback_set(light_changed);
    thread_initialized = true;

In this example, the BLUE led is configured last, which means I cannot change this PWM after calling thread_instance_init()

I've boiled the bug down to this function (in thread_utils.c):

error = otIp6SetEnabled(mp_ot_instance, true);

After executing this function, I see that the BLUE led disappears. Unfortunately, I cannot debug in further down due to this function being in a library.

Any advice/help?

Thanks,

Jonathan

Related