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

Add PWM library to freeRTOS (ble_app_hrs_freertos) example

Hi Sir/Miss,

I use below items to develop:

HW  : PCA10040 (nRF52832)

SDK: 15.2

Softdevice : s132

IDE  : SES V3.40

After I create my task (two same priority tasks to use GPIO to show clock tick), I want to add PWM library to freeRTOS.

I add nrf_drv_ppi.c, nrfx_ppi.c, nrfx_timer.c and app_pwm.c file to project and enable APP_PWM_ENABLED, TIMER_ENABLED, TIMER0_ENABLEDTIMER1_ENABLED, NRFX_PPI_ENABLED, PPI_ENABLED in sdk_config.h. 

And setup the function like PWM library example code (just change 2 to 1 channel )

static volatile bool ready_flag;            // A flag indicating PWM status.

void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
{
    ready_flag = true;
}

//  PWM initial
void PWM_Init(void)
{
    //  for PWM initial, include "app_pwm.c", "nrfx_timer.c", "nrf_drv_ppi.c", "nrfx_ppi.c", "nrf_nvic.c", "nrf_soc.c"
    
    ret_code_t err_code;

    //  buzzer PWM initial
    APP_PWM_INSTANCE(PWM1,1);                   // Create the instance "PWM1" using TIMER1.

    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(250L, buzzer_PWM_pin);

    //  Initialize and enable PWM
    err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);
}

And compiler it, SES doesn't display any error.

But, two tasks use GPIO that voltage is not correct. It has a 1.36V offset. 

I check system on terminal. It shows fatal error and system reset, and setup breakpoint to check PWM initial err_code.

Err_code is 0x10001000.

I don't know what's meaning, and how to find error code list?

If I mistake on these step, please correct me.

Thank you.

Parents Reply
  • Sorry for the late reply, I was away travelling.

    This is strange. The PWM has its own hardware on nRF52 and FreeRTOS does not interfere in that. Not sure why using FreeRTOS affects the output.

    Probably depends on if you are doing something in the callback handler and the logic that depends on the flag in that handler. Can you make a minimalistic project for me to be able to reproduce your issue so that i can see what is the bottleneck here?

Children
Related