I'm attempting to build a project to use easyDMA with PWM, but as there are no applicable examples in SDK 15, I am working on it myself. I originally asked for help here: https://devzone.nordicsemi.com/f/nordic-q-a/33473/using-sdk-15-0-and-pca10040-would-like-to-create-a-repeating-sawtooth-waveform-using-pwm-and-easydma
but didn't get any responses so I am converting a code example that I referenced in my previous post to be compatible with SDK 15.
I've currently got one build error caused by NRFX_PWM0_INST_IDX being undefined.
It's used in line 78 of nrfx_pwm.h (see line 21 below)
/** * @brief PWM driver instance data structure. */ typedef struct { NRF_PWM_Type * p_registers; ///< Pointer to the structure with PWM peripheral instance registers. uint8_t drv_inst_idx; ///< Driver instance index. } nrfx_pwm_t; /** * @brief Macro for creating a PWM driver instance. */ #define NRFX_PWM_INSTANCE(id) \ { \ .p_registers = NRFX_CONCAT_2(NRF_PWM, id), \ .drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \ } enum { #if NRFX_CHECK(NRFX_PWM0_ENABLED) NRFX_PWM0_INST_IDX, #endif #if NRFX_CHECK(NRFX_PWM1_ENABLED) NRFX_PWM1_INST_IDX, #endif #if NRFX_CHECK(NRFX_PWM2_ENABLED) NRFX_PWM2_INST_IDX, #endif #if NRFX_CHECK(NRFX_PWM3_ENABLED) NRFX_PWM3_INST_IDX, #endif NRFX_PWM_ENABLED_COUNT };
I don't think I'm missing any include files, does anyone have some hints? You won't find anything mentioning this value anywhere!
Here is my current code, which is an example I found which I converted to be compatible with SDK 15:
// for PWM #include <stdio.h> #include "nrfx_pwm.h" #include "app_util_platform.h" #include "app_error.h" #include "boards.h" #include "bsp.h" #include "app_timer.h" #include "nrf_drv_clock.h" #include "nrf_delay.h" // other items for PWM #define OUTPUT_PIN 26 #define DUTY_A 50 #define DUTY_B 80 #define NRFX_PWM0_INST_IDX 0 // <<-- just added this as it was undefined static nrfx_pwm_t m_pwm0 = NRFX_PWM_INSTANCE(0); static nrf_pwm_values_common_t /*const*/ seq0_values[] = { DUTY_A,DUTY_A,DUTY_A }; nrf_pwm_sequence_t const seq0 = { .values.p_common = seq0_values, .length = NRF_PWM_VALUES_LENGTH(seq0_values), .repeats = 0, .end_delay = 0 }; static nrf_pwm_values_common_t /*const*/ seq1_values[] = { DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B }; nrf_pwm_sequence_t const seq1 = { .values.p_common = seq1_values, .length = NRF_PWM_VALUES_LENGTH(seq1_values), .repeats = 36, .end_delay = 0 }; static void pwm_init(void) { nrfx_pwm_config_t const config0 = { .output_pins = { OUTPUT_PIN, // channel 0 NRFX_PWM_PIN_NOT_USED, // channel 1 NRFX_PWM_PIN_NOT_USED, // channel 2 NRFX_PWM_PIN_NOT_USED, // channel 3 }, .irq_priority = APP_IRQ_PRIORITY_LOWEST, .base_clock = NRF_PWM_CLK_1MHz, .count_mode = NRF_PWM_MODE_UP, .top_value = 100, .load_mode = NRF_PWM_LOAD_COMMON, .step_mode = NRF_PWM_STEP_AUTO }; // Init PWM without error handler APP_ERROR_CHECK(nrfx_pwm_init(&m_pwm0, &config0, NULL)); } // end PWM // and here is main() /**@brief Function for application main entry. */ int main(void) { bool erase_bonds; // Initialize modules. log_init(); clock_init(); #ifdef TRC_USE_TRACEALYZER_RECORDER #if (TRC_CFG_RECORDER_MODE == TRC_RECORDER_MODE_STREAMING) vTraceEnable(TRC_INIT); #else vTraceEnable(TRC_START); #endif #endif // Do not start any interrupt that uses system functions before system initialisation. // The best solution is to start the OS before any other initalisation. #if NRF_LOG_ENABLED // Start execution. if (pdPASS != xTaskCreate(logger_thread, "LOGGER", 256, NULL, 1, &m_logger_thread)) { APP_ERROR_HANDLER(NRF_ERROR_NO_MEM); } #endif // Activate deep sleep mode. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Configure and initialize the BLE stack. ble_stack_init(); // Initialize modules. timers_init(); buttons_leds_init(&erase_bonds); gap_params_init(); gatt_init(); advertising_init(); services_init(); sensor_simulator_init(); conn_params_init(); peer_manager_init(); application_timers_start(); BattChn=xTraceRegisterString("Battery Level"); RateChn=xTraceRegisterString("Heart Rate"); // PWM // Start clock for accurate frequencies NRF_CLOCK->TASKS_HFCLKSTART = 1; // Wait for clock to start while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0); pwm_init(); APP_ERROR_CHECK(nrfx_pwm_complex_playback(&m_pwm0, &seq0, &seq1, 1, NRFX_PWM_FLAG_LOOP )); // end PWM // Create a FreeRTOS task for the BLE stack. // The task will run advertising_start() before entering its loop. nrf_sdh_freertos_init(advertising_start, &erase_bonds); NRF_LOG_INFO("HRS FreeRTOS example started."); // Start FreeRTOS scheduler. vTaskStartScheduler(); for (;;) { APP_ERROR_HANDLER(NRF_ERROR_FORBIDDEN); } }
Currently, the linker is giving these two errors:
Any ideas?