"app_timer"
static void timers_init(void) { ret_code_t err_code; // Initialize timer module. err_code = app_timer_init(); APP_ERROR_CHECK(err_code); err_code = app_timer_create(&m_heart_rate_timer_id, APP_TIMER_MODE_REPEATED, heart_rate_meas_timeout_handler); APP_ERROR_CHECK(err_code); }
"pwm_library"
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1. void init_pwm(void) { ret_code_t err_code; app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5, PWM_DRIVER_PIN); pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH; err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); }
"nrf_drv_timer "
const nrf_drv_timer_t MYTIMER_2 = NRF_DRV_TIMER_INSTANCE(2); void init_my_timer(void) { ret_code_t err_code; uint32_t time_us = 60, time_ticks; nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG; err_code = nrf_drv_timer_init(&MYTIMER_2, &timer_cfg, mytimer_event_handler); APP_ERROR_CHECK(err_code); time_ticks = nrf_drv_timer_us_to_ticks(&MYTIMER_2, time_us); nrf_drv_timer_extended_compare( &MYTIMER_2, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); }
main
int main(void) { bool erase_bonds = false; log_init(); // Initialize. timers_init(); ble_stack_init(); gap_params_init(); gatt_init(); advertising_init(); services_init(); conn_params_init(); peer_manager_init(); // Start execution. NRF_LOG_INFO("Heart Rate Sensor example started."); application_timers_start(); advertising_start(erase_bonds); init_my_timer();//------------------1 init_pwm();//-----------------------2 // Enter main loop. for (;;) { if (NRF_LOG_PROCESS() == false) { power_manage(); } } }
nRF5_SDK_14.0.0_3bcc1f7
as above hree pieces of code, if put them together with softdevice, i can get fault when run to "main()-------init_pwm();//-----------------------2"
debug "init_pwm();" in function :
ret_code_t app_pwm_init(app_pwm_t const * const p_instance, app_pwm_config_t const * const p_config, app_pwm_callback_t p_ready_callback) { ............................ ............................ ............................ // Initialize timer: nrf_timer_frequency_t timer_freq = pwm_calculate_timer_frequency(p_config->period_us); nrf_drv_timer_config_t timer_cfg = { .frequency = timer_freq, .mode = NRF_TIMER_MODE_TIMER, .bit_width = NRF_TIMER_BIT_WIDTH_16, .interrupt_priority = APP_IRQ_PRIORITY_LOWEST, .p_context = (void *) (uint32_t) p_instance->p_timer->instance_id }; err_code = nrf_drv_timer_init(p_instance->p_timer, &timer_cfg, pwm_ready_tick);//---------------------------3 if (err_code != NRF_SUCCESS) { pwm_dealloc(p_instance); return err_code; } ............................ ............................ ............................ }
"nrf_drv_timer_init" return "NRF_ERROR_INVALID_STATE".
How do they conflict with each other?