Hello, I need to use PWM to control GPIO and integrate it to work on simple COAP server app using nrf52840 DK.
I used "pwm_simple" example from SDK (not Thread/Zigbie SDK) and when it was working already as I wanted I tried to integrate that code in simple COAP server app. ALl the need includes are found but I get following error while trying to make it with GCC. Do you have any idea where to search for a problem?
In file included from ../../../../../../modules/nrfx/nrfx.h:45:0, from ../../../../../../modules/nrfx/hal/nrf_gpio.h:44, from ../../../../../../components/boards/boards.h:43, from ../../../../../../components/libraries/bsp/bsp.h:58, from ../../../../../../components/libraries/bsp/bsp_thread.h:54, from ../../../../app_utils/thread_coap_utils.c:10: ../../../../../../modules/nrfx/drivers/include/nrfx_pwm.h:73:35: error: 'NRFX_PWM0_INST_IDX' undeclared here (not in a function) .drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \ ^ ../../../../../../modules/nrfx/drivers/nrfx_common.h:117:37: note: in definition of macro 'NRFX_CONCAT_3_' #define NRFX_CONCAT_3_(p1, p2, p3) p1 ## p2 ## p3 ^~ ../../../../../../modules/nrfx/drivers/include/nrfx_pwm.h:73:21: note: in expansion of macro 'NRFX_CONCAT_3' .drv_inst_idx = NRFX_CONCAT_3(NRFX_PWM, id, _INST_IDX), \ ^~~~~~~~~~~~~ ../../../../../../integration/nrfx/legacy/nrf_drv_pwm.h:64:49: note: in expansion of macro 'NRFX_PWM_INSTANCE' #define NRF_DRV_PWM_INSTANCE NRFX_PWM_INSTANCE ^~~~~~~~~~~~~~~~~ ../../../../app_utils/thread_coap_utils.c:43:31: note: in expansion of macro 'NRF_DRV_PWM_INSTANCE' static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0); ^~~~~~~~~~~~~~~~~~~~ make: *** [_build/nrf52840_xxaa/thread_coap_utils.c.o] Error 1
here is fragment of my code for inserted into simple COAP server app. That code is taken mainly from pwm_simple example and is fully working while using in directory with peripheral examples in generic SDK directory, but I try to build it in my Thread SDK COAP examples directory.
#include "thread_coap_utils.h" #include "app_timer.h" #include "bsp_thread.h" #include "nrf_assert.h" #include "nrf_log.h" #include "sdk_config.h" #include "thread_utils.h" #include <openthread/ip6.h> #include <openthread/link.h> #include <openthread/thread.h> #include <openthread/platform/alarm-milli.h> // include GPIO #include "nrf_gpio.h" // includes for PWM #include <stdio.h> #include <string.h> #include "nrf_drv_pwm.h" #include "app_util_platform.h" #include "app_error.h" #include "boards.h" #include "bsp.h" #include "nrf_drv_clock.h" #include "nrf_delay.h" #define RESPONSE_POLL_PERIOD 100 #define GPIO_LED_OUT ( NRF_GPIO_PIN_MAP(0,31) ) APP_TIMER_DEF(m_provisioning_timer); APP_TIMER_DEF(m_led_timer); static uint32_t m_poll_period; static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0); // Declare variables holding PWM sequence values. In this example only one channel is used nrf_pwm_values_individual_t seq_values[] = {{ 0, 0, 0, 0}}; nrf_pwm_sequence_t const seq = { .values.p_individual = seq_values, .length = NRF_PWM_VALUES_LENGTH(seq_values), .repeats = 0, .end_delay = 0 }; void thread_coap_utils_light_blinking_is_on_set(bool value) { m_coap_status.led_blinking_is_on = value; } bool thread_coap_utils_light_blinking_is_on_get(void) { return m_coap_status.led_blinking_is_on; } // SECTION FOR PWM OPERATIONS // Set duty cycle between 0 and 100% void pwm_update_duty_cycle(uint8_t duty_cycle) { // Check if value is outside of range. If so, set to 100% if(duty_cycle >= 100) { seq_values->channel_0 = 100; } else { seq_values->channel_0 = duty_cycle; } nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP); } void pwm_init(void) { nrf_drv_pwm_config_t const config0 = { .output_pins = { GPIO_LED_OUT,// | NRF_DRV_PWM_PIN_INVERTED, // channel 0 NRF_DRV_PWM_PIN_NOT_USED, // channel 1 NRF_DRV_PWM_PIN_NOT_USED, // channel 2 NRF_DRV_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_INDIVIDUAL, .step_mode = NRF_PWM_STEP_AUTO }; nrf_drv_pwm_init(&m_pwm0, &config0, NULL); }
#include "thread_coap_utils.h" #include "app_timer.h" #include "bsp_thread.h" #include "nrf_assert.h" #include "nrf_log.h" #include "sdk_config.h" #include "thread_utils.h" #include <openthread/ip6.h> #include <openthread/link.h> #include <openthread/thread.h> #include <openthread/platform/alarm-milli.h> // include GPIO #include "nrf_gpio.h" // includes for PWM #include <stdio.h> #include <string.h> #include "nrf_drv_pwm.h" #include "app_util_platform.h" #include "app_error.h" #include "boards.h" #include "bsp.h" #include "nrf_drv_clock.h" #include "nrf_delay.h" #define RESPONSE_POLL_PERIOD 100 #define GPIO_LED_OUT ( NRF_GPIO_PIN_MAP(0,31) ) APP_TIMER_DEF(m_provisioning_timer); APP_TIMER_DEF(m_led_timer); static uint32_t m_poll_period; static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0); // Declare variables holding PWM sequence values. In this example only one channel is used nrf_pwm_values_individual_t seq_values[] = {{ 0, 0, 0, 0}}; nrf_pwm_sequence_t const seq = { .values.p_individual = seq_values, .length = NRF_PWM_VALUES_LENGTH(seq_values), .repeats = 0, .end_delay = 0 }; // SECTION FOR PWM OPERATIONS // Set duty cycle between 0 and 100% void pwm_update_duty_cycle(uint8_t duty_cycle) { // Check if value is outside of range. If so, set to 100% if(duty_cycle >= 100) { seq_values->channel_0 = 100; } else { seq_values->channel_0 = duty_cycle; } nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP); } void pwm_init(void) { nrf_drv_pwm_config_t const config0 = { .output_pins = { GPIO_LED_OUT,// | NRF_DRV_PWM_PIN_INVERTED, // channel 0 NRF_DRV_PWM_PIN_NOT_USED, // channel 1 NRF_DRV_PWM_PIN_NOT_USED, // channel 2 NRF_DRV_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_INDIVIDUAL, .step_mode = NRF_PWM_STEP_AUTO }; nrf_drv_pwm_init(&m_pwm0, &config0, NULL); }
Thanks a lot for any advice