This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zephyr CustomBoard with NRF52840 and MCP23S17

Hello folks

I have been struggling for some time with the driver for the MCP23S17 in Zephyr.

I have already tried this code:
https://devzone.nordicsemi.com/f/nordic-q-a/64024/sample-mcp23s17-driver

But for me its not working!

I receive the following error:

/home/trug/zephyrproject/zephyr/include/devicetree.h:158:36: error: 'DT_N_NODELABEL_spi2gpio_P_label' undeclared (first use in this function); did you mean 'DT_N_NODELABEL_gpiote'?
  158 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                                    ^~~~~~~~~~~~~~~
/home/trug/zephyrproject/zephyr/include/devicetree.h:1526:38: note: in definition of macro 'DT_CAT'
 1526 | #define DT_CAT(node_id, prop_suffix) node_id##prop_suffix
      |                                      ^~~~~~~
/home/trug/zephyrproject/zephyr/include/devicetree.h:390:27: note: in expansion of macro 'DT_PROP'
  390 | #define DT_LABEL(node_id) DT_PROP(node_id, label)
      |                           ^~~~~~~
../src/main.c:80:27: note: in expansion of macro 'DT_LABEL'
   80 | #define MCP23S17_DEV_NAME DT_LABEL(DT_NODELABEL(spi2gpio))
      |                           ^~~~~~~~
/home/trug/zephyrproject/zephyr/include/devicetree.h:158:29: note: in expansion of macro 'DT_CAT'
  158 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
../src/main.c:80:36: note: in expansion of macro 'DT_NODELABEL'
   80 | #define MCP23S17_DEV_NAME DT_LABEL(DT_NODELABEL(spi2gpio))
   
...
...
...
      |                                    ^~~~~~~~~~~~
../src/main.c:106:51: note: in expansion of macro 'MCP23S17_DEV_NAME'
  106 |  struct device *mcp23s17_dev = device_get_binding(MCP23S17_DEV_NAME);

This is my main.c

#include <zephyr.h>

#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>        
 
#include <sys/printk.h>
#include <drivers/uart.h>

#include <logging/log.h>

#include "CustomBoard.h"

LOG_MODULE_REGISTER(net_google_iot_mqtt, LOG_LEVEL_DBG);

/* This comes from newlib. */
#include <time.h>
#include <inttypes.h>



#define	MCP23S17_DEV_NAME	DT_LABEL(DT_NODELABEL(spi2gpio))

void main(void)
{
	int ret;

	LOG_INF(">>> Test: Driver MCP23S17 <<<");

	// MCP23S17
	struct device *mcp23s17_dev = device_get_binding(MCP23S17_DEV_NAME);

	if (!mcp23s17_dev) {
		LOG_INF("Cannot find mcp23s17!\n");
		return;
	}

	ret = gpio_pin_configure(mcp23s17_dev, 1, GPIO_OUTPUT_ACTIVE);
	
	...
    ...
    ...
    
	while (1) {
		gpio_pin_set(mcp23s17_dev, 1, (int)true);

		k_msleep(125);

		gpio_pin_set(mcp23s17_dev, 1, (int)false);
	}
}

I compared it to some other drivers in zephyr and also tried the following defines in the main.c (but no of them are working)

//#define    MCP23S17_DEV_NAME    DT_LABEL(DT_NODELABEL("spi2gpio"))

//#define    MCP23S17_DEV_NAME    DT_LABEL(DT_NODELABEL(mcp23s17))

//#define    MCP23S17_DEV_NAME    DT_INST(0, spi2gpio)

//#define    MCP23S17_DEV_NAME    DT_LABEL(DT_INST(0, microchip_mcp23s17)
//#define    MCP23S17_DEV_NAME    DT_LABEL(DT_INST(0, mcp23s17)

//#define    MCP23S17_DEV_NAME    "GPIO_MCP23S17"
//#define    MCP23S17_DEV_NAME    "microchip_mcp23s17"

Here is my .overlay file:

/* GPIO Expander */
&spi2 {
    label="SPI2";
    status = "okay";
    sck-pin = <22>;
    mosi-pin = <23>;
    miso-pin = <24>;
    cs-gpios = <&gpio1 1 0>;

    spi2gpio: gpio@0 {	
    	label="mcp23s17";
        compatible="microchip,mcp23s17";
        gpio-controller;
        #gpio-cells = <2>;
        spi-max-frequency = <800000>;
        reg = <0>;
	    #ngpios = <16>;
    };
};

Here are my configs from my prj.confg

# Driver: GPIO
CONFIG_GPIO=y
CONFIG_GPIO_MCP23S17=y

# SPI
CONFIG_SPI=y
CONFIG_SPI_2=y

# UART support
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=n

# Print
CONFIG_PRINTK=y

# RTT Segger Debugger
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y

 

What am I doing wrong? Can anyone help me or give me an example?

Regards
Dominique

Parents Reply Children
Related