PWM not working after upgrade to nrf Connect SDK 1.9.1

Since upgrading to nrf Connect SDK 1.9.1, I no longer have PWM output. No errors returned when calling pwm_pin_set_usec, yet no output.

I tried upgrading to the latest nrf Connect SDK (2.2.0), thinking that perhaps a bug was fixed, but the number of changes (include paths, etc) was too daunting.

  • I was able to convert my device tree and software calls to be consistent with latest best practices. I am now able to get my PWM signal out! Unfortunately, my SPI communication has now stopped as the polarity of the CS signal is inverted. I am guessing that it is a similar issue with device tree and software calls. Should I create a new ticket or address it here? My old code grabbed the device object from the device tree and then I defined a spi_config struct to pass on the spi_read/write/transceive calls. Since this seems to not be working, I updated to defining the CS parameters in the device tree itself and am using the spi_read_dt/write_dt/transceive_dt calls but it still won't change the polarity of the CS signal. I need ACTIVE_LOW. I am using spi1. Any insights?

  • csteaderman said:
    I am now able to get my PWM signal out!

    Good to hear!

    csteaderman said:
    Should I create a new ticket or address it here?

    We can continue here.

    csteaderman said:
    Any insights?

    Can you share your pinctrl configuration for SPI?

    Our central nRF pairing sample uses SPI with ACTIVE LOW cs-gpios.
    Is this what you need?

    Regards,
    Sigurd Hellesvik

  • Here are the relevant sections from the pinctrl file and device tree files.

    	spi1_default: spi1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    				<NRF_PSEL(SPIM_MISO, 0, 14)>;
    		};
    	};
    
    	spi1_sleep: spi1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 16)>,
    				<NRF_PSEL(SPIM_MOSI, 0, 15)>,
    				<NRF_PSEL(SPIM_MISO, 0, 14)>;
    			low-power-enable;
    		};
    	};

    &spi1 {
    	compatible = "nordic,nrf-spi";
    	status = "okay";
    	pinctrl-0 = <&spi1_default>;
    	pinctrl-1 = <&spi1_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
    	afe4490: afe4490@0 {
    		compatible = "vnd,spi-device";
    		reg = <0>;
    		spi-max-frequency = <4000000>;
    		label = "afe4490";
    	};
    };
    

  • Can you share your SPI code?

    Or even better, a minimal sample with only SPI communication so I can try to replicate the issue on my end?

    Regards,
    Sigurd Hellesvik

  • Here is my SPI code. I have tested both the non-dts and the dts version of the functions, both perform the same with the CS being inverted.

    /* spi.c - SPI wrapper */
    
    #include <stdint.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/spi.h>
    #include "spi.h"
    
    #include <zephyr/logging/log.h>
    LOG_MODULE_REGISTER(spi_wrapper, CONFIG_LOG_DEFAULT_LEVEL);
    
    static struct spi_buf rx;
    const static struct spi_buf_set rx_bufs = {
    	.buffers = &rx,
    	.count = 1,
    };
    
    static struct spi_buf tx;
    const static struct spi_buf_set tx_bufs = {
    	.buffers = &tx,
    	.count = 1,
    };
    
    static const struct spi_config spi_cfg = {
    	.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
    	.frequency = 4000000,
    	.slave = 0,
        .cs = &(struct spi_cs_control) {
            .delay = 1,
            .gpio.pin = 18,
            .gpio.dt_flags = GPIO_ACTIVE_LOW,
            .gpio.port = DEVICE_DT_GET(DT_NODELABEL(gpio0)),
        },
    };
    
    int spi_send(const struct device *spi,
            const uint8_t *data, size_t len)
    {
        tx.buf = (void*)data;
        tx.len = len;
    
    	return spi_write(spi, &spi_cfg, &tx_bufs);
    }
    
    int spi_send_dt(const struct spi_dt_spec *spi_dt,
        const uint8_t *data, size_t len)
    {
        tx.buf = (void*)data;
        tx.len = len;
    
    	return spi_write_dt(spi_dt, &tx_bufs);
    }
    
    int spi_recv(const struct device *spi,
        uint8_t *data, size_t len)
    {
        rx.buf = data;
        rx.len = len;
    
    	return spi_read(spi, &spi_cfg, &rx_bufs);
    }
    
    int spi_sendrecv(const struct device *spi,
        const uint8_t *writedata, uint8_t *readdata,
        size_t len)
    {
        tx.buf = (void*)writedata;
        tx.len = len;
        rx.buf = readdata;
        rx.len = len;
    
    	return spi_transceive(spi, &spi_cfg, &tx_bufs, &rx_bufs);
    }
    
    int spi_sendrecv_dt(const struct spi_dt_spec *spi_dt,
        const uint8_t *writedata, uint8_t *readdata,
        size_t len)
    {
        tx.buf = (void*)writedata;
        tx.len = len;
        rx.buf = readdata;
        rx.len = len;
    
    	return spi_transceive_dt(spi_dt, &tx_bufs, &rx_bufs);
    }
    

Related