Using NCS v1.4.99-dev1.
I have no problem using the PWM with a nRF5340PDK but when i tried it on a nRF5340DK, my program was not working correctly.
I have made a simple example to demonstrate this behavior, 1 LED should blink with PWM and another with the main thread:
/* Includes ------------------------------------------------------------------*/
#include <assert.h>
#include <zephyr.h>
#include <nrfx_pwm.h>
#include <hal/nrf_gpio.h>
/* Private define ------------------------------------------------------------*/
#define LED1_PIN NRF_GPIO_PIN_MAP(0,28)
#define LED2_PIN NRF_GPIO_PIN_MAP(0,29)
#define LED3_PIN NRF_GPIO_PIN_MAP(0,30)
#define LED4_PIN NRF_GPIO_PIN_MAP(0,31)
#define PERIOD 25000
#define PWM_DEFAULT_CONFIG_IRQ_PRIORITY 6
/* Private variables ---------------------------------------------------------*/
static nrfx_pwm_t pwm = NRFX_PWM_INSTANCE(1);
static nrf_pwm_values_individual_t sequenceValues[] = {
{PERIOD / 2, 0x8000 + PERIOD / 2},
};
static nrf_pwm_sequence_t sequence = {
.values.p_individual = sequenceValues,
.length = NRF_PWM_VALUES_LENGTH(sequenceValues),
.repeats = 0,
.end_delay = 0
};
/* Public functions ----------------------------------------------------------*/
void pwm_init(void)
{
nrfx_pwm_config_t config = {
.irq_priority = PWM_DEFAULT_CONFIG_IRQ_PRIORITY,
.base_clock = NRF_PWM_CLK_125kHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = PERIOD,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO,
.output_pins[0] = LED2_PIN,
};
nrfx_err_t err = nrfx_pwm_init(&pwm, &config, NULL, NULL);
assert(err == NRFX_SUCCESS);
nrfx_pwm_simple_playback(&pwm, &sequence, 1, NRFX_PWM_FLAG_LOOP);
}
void main(void)
{
pwm_init();
nrf_gpio_cfg_output(LED1_PIN);
while(1) {
nrf_gpio_pin_write(LED1_PIN, 1);
k_sleep(K_MSEC(100));
nrf_gpio_pin_write(LED1_PIN, 0);
k_sleep(K_MSEC(100));
}
}
With a nRF5340PDK, both LED blink but with a nRF5340DK, the LED1 don't blink.