diff --git a/cpu/nrf52/periph/pwm.c b/cpu/nrf52/periph/pwm.c index f00bca774a..0cd46701e8 100644 --- a/cpu/nrf52/periph/pwm.c +++ b/cpu/nrf52/periph/pwm.c @@ -92,7 +92,10 @@ uint32_t pwm_init(pwm_t pwm, pwm_mode_t mode, uint32_t freq, uint16_t res) for (unsigned i = 0; i < PWM_CHANNELS; i++) { /* either left aligned pol or inverted duty cycle */ pwm_seq[pwm][i] = (POL_MASK & mode) ? POL_MASK : res; - dev(pwm)->PSEL.OUT[i] = pwm_config[pwm].pin[i]; + /* Sign-extend the undefined pin into a value that also sets the + * 'Disconnected' field, and is also that register's reset state */ + uint32_t extended_pin = (int32_t)(int8_t)pwm_config[pwm].pin[i]; + dev(pwm)->PSEL.OUT[i] = extended_pin; DEBUG("set PIN[%i] to %i with 0x%x\n", (int)i, (int)pwm_config[pwm].pin[i], pwm_seq[pwm][i]); } diff --git a/cpu/nrf5x_common/include/periph_cpu_common.h b/cpu/nrf5x_common/include/periph_cpu_common.h index a467eed50d..d305624d65 100644 --- a/cpu/nrf5x_common/include/periph_cpu_common.h +++ b/cpu/nrf5x_common/include/periph_cpu_common.h @@ -55,6 +55,8 @@ extern "C" { /** * @brief Override GPIO_UNDEF value */ +/* The precise value matters where GPIO_UNDEF is set in registers like + * PWM.PSEL.OUT where it is used in sign-extended form to get a UINT32_MAX */ #define GPIO_UNDEF (UINT8_MAX) /**