diff --git a/boards/arm/rp2040/common/src/Make.defs b/boards/arm/rp2040/common/src/Make.defs index 25b16cb4fd..72c2862a0a 100644 --- a/boards/arm/rp2040/common/src/Make.defs +++ b/boards/arm/rp2040/common/src/Make.defs @@ -42,6 +42,10 @@ ifeq ($(CONFIG_SENSORS_INA219),y) CSRCS += rp2040_ina219.c endif +ifeq ($(CONFIG_ENC28J60),y) + CSRCS += rp2040_enc28j60.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/boards/arm/rp2040/common/src/rp2040_enc28j60.c b/boards/arm/rp2040/common/src/rp2040_enc28j60.c new file mode 100644 index 0000000000..440593bfd9 --- /dev/null +++ b/boards/arm/rp2040/common/src/rp2040_enc28j60.c @@ -0,0 +1,164 @@ +/**************************************************************************** + * boards/arm/rp2040/common/src/rp2040_enc28j60.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include +#include + +#include + +#include "chip.h" +#include "arm_arch.h" +#include "arm_internal.h" + +#include "rp2040_spi.h" +#include "rp2040_gpio.h" + +#ifdef CONFIG_ENC28J60 + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if CONFIG_RP2040_ENC28J60_INTR_GPIO < 0 +# error "Need CONFIG_RP2040_ENC28J60_INTR_GPIO to specify the interrupt pin" +#endif + +#define ENC28J60_DEVNO 0 /* Only one ENC28J60 */ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct rp2040_lower_s +{ + const struct enc_lower_s lower; /* Low-level MCU interface */ +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg); +static void up_enable(FAR const struct enc_lower_s *lower); +static void up_disable(FAR const struct enc_lower_s *lower); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* The ENC28J60 normal provides interrupts to the MCU via a GPIO pin. The + * following structure provides an MCU-independent mechanism for controlling + * the ENC28J60 GPIO interrupt. + */ + +static struct rp2040_lower_s g_enclower = +{ + .lower = + { + .attach = up_attach, + .enable = up_enable, + .disable = up_disable + }, +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: struct enc_lower_s methods + ****************************************************************************/ + +static int up_attach(FAR const struct enc_lower_s *lower, xcpt_t handler, + FAR void *arg) +{ + rp2040_gpio_irq_attach(CONFIG_RP2040_ENC28J60_INTR_GPIO, + RP2040_GPIO_INTR_EDGE_LOW, handler, arg); + return OK; +} + +static void up_enable(FAR const struct enc_lower_s *lower) +{ + rp2040_gpio_enable_irq(CONFIG_RP2040_ENC28J60_INTR_GPIO); +} + +static void up_disable(FAR const struct enc_lower_s *lower) +{ + rp2040_gpio_disable_irq(CONFIG_RP2040_ENC28J60_INTR_GPIO); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: arm_netinitialize + ****************************************************************************/ + +void arm_netinitialize(void) +{ + FAR struct spi_dev_s *spi; + int ret; + + spi = rp2040_spibus_initialize(CONFIG_RP2040_ENC28J60_SPI_CH); + if (!spi) + { + nerr("ERROR: Failed to initialize SPI port %d\n", + CONFIG_RP2040_ENC28J60_SPI_CH); + return; + } + + /* Take ENC28J60 out of reset (active low) */ + +#if CONFIG_RP2040_ENC28J60_RESET_GPIO >= 0 + rp2040_gpio_init(CONFIG_RP2040_ENC28J60_RESET_GPIO); + rp2040_gpio_setdir(CONFIG_RP2040_ENC28J60_RESET_GPIO, true); + rp2040_gpio_put(CONFIG_RP2040_ENC28J60_RESET_GPIO, true); +#endif + + rp2040_gpio_init(CONFIG_RP2040_ENC28J60_INTR_GPIO); + rp2040_gpio_set_pulls(CONFIG_RP2040_ENC28J60_INTR_GPIO, true, false); + + /* Bind the SPI port to the ENC28J60 driver */ + + ret = enc_initialize(spi, &g_enclower.lower, ENC28J60_DEVNO); + if (ret < 0) + { + nerr("ERROR: Failed to bind SPI port %d ENC28J60 device %d: %d\n", + CONFIG_RP2040_ENC28J60_SPI_CH, ENC28J60_DEVNO, ret); + return; + } + + ninfo("Bound SPI port %d to ENC28J60 device %d\n", + CONFIG_RP2040_ENC28J60_SPI_CH, ENC28J60_DEVNO); +} + +#endif /* CONFIG_ENC28J60 */ diff --git a/boards/arm/rp2040/raspberrypi-pico/Kconfig b/boards/arm/rp2040/raspberrypi-pico/Kconfig index 7af06c3b1f..769fb26c97 100644 --- a/boards/arm/rp2040/raspberrypi-pico/Kconfig +++ b/boards/arm/rp2040/raspberrypi-pico/Kconfig @@ -63,4 +63,25 @@ config RP2040_SPI1_GPIO range -1 29 depends on RP2040_SPI1 + +config RP2040_ENC28J60_SPI_CH + int "ENC28J60 SPI channel number" + default 1 + range 0 1 + depends on ENC28J60 + ---help--- + Select SPI channel number to use ENC28J60 ethernet. + +config RP2040_ENC28J60_INTR_GPIO + int "ENC28J60 interrupt GPIO pin assign" + default -1 + range -1 29 + depends on ENC28J60 + +config RP2040_ENC28J60_RESET_GPIO + int "ENC28J60 reset GPIO pin assign (optional)" + default -1 + range -1 29 + depends on ENC28J60 + endif diff --git a/boards/arm/rp2040/raspberrypi-pico/README.txt b/boards/arm/rp2040/raspberrypi-pico/README.txt index 3869435755..37d7a743e6 100644 --- a/boards/arm/rp2040/raspberrypi-pico/README.txt +++ b/boards/arm/rp2040/raspberrypi-pico/README.txt @@ -86,6 +86,22 @@ Defconfigs DAT1 (NC) * Card hot swapping is not supported. +- enc28j60 + ENC28J60 SPI ethernet controller support + - IP address is configured by DHCP. + - DNS address is 8.8.8.8 (CONFIG_NETINIT_DNSIPADDR) + - NTP client is enabled. + Connection: + ENC28J60 Raspberry Pi Pico + GND ----- GND (Pin 3 or 38 or ...) + 3.3 ----- 3V3 OUT (Pin 36) + SI ----- GP15 (SPI1 TX) (Pin 20) + SCK ----- GP14 (SPI1 SCK) (Pin 19) + CS ----- GP13 (SPI1 CSn) (Pin 17) + SO ----- GP12 (SPI1 RX) (Pin 16) + INT ----- GP11 (Pin 15) + RESET ----- GP10 (Pin 14) + License exceptions ================== diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/enc28j60/defconfig b/boards/arm/rp2040/raspberrypi-pico/configs/enc28j60/defconfig new file mode 100644 index 0000000000..b90c2bb3a9 --- /dev/null +++ b/boards/arm/rp2040/raspberrypi-pico/configs/enc28j60/defconfig @@ -0,0 +1,87 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_FS_PROCFS_EXCLUDE_ENVIRON is not set +# CONFIG_LIBC_LONG_LONG is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_DISABLE_DATE is not set +# CONFIG_NSH_DISABLE_LOSMART is not set +# CONFIG_NSH_DISABLE_PRINTF is not set +# CONFIG_NSH_DISABLE_TRUNCATE is not set +# CONFIG_STANDARD_SERIAL is not set +CONFIG_ARCH="arm" +CONFIG_ARCH_BOARD="raspberrypi-pico" +CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y +CONFIG_ARCH_CHIP="rp2040" +CONFIG_ARCH_CHIP_RP2040=y +CONFIG_ARCH_RAMVECTORS=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_BOARDCTL_RESET=y +CONFIG_BOARD_LOOPSPERMSEC=10450 +CONFIG_BUILTIN=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEV_ZERO=y +CONFIG_DISABLE_POSIX_TIMERS=y +CONFIG_ENC28J60=y +CONFIG_EXAMPLES_HELLO=y +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y +CONFIG_MAX_TASKS=8 +CONFIG_NET=y +CONFIG_NETDB_DNSCLIENT=y +CONFIG_NETDB_DNSSERVER_NOADDR=y +CONFIG_NETDEVICES=y +CONFIG_NETDEV_PHY_IOCTL=y +CONFIG_NETINIT_DHCPC=y +CONFIG_NETINIT_DNS=y +CONFIG_NETINIT_DNSIPADDR=0x08080808 +CONFIG_NETINIT_NOMAC=y +CONFIG_NET_BROADCAST=y +CONFIG_NET_ICMP=y +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_LOOPBACK=y +CONFIG_NET_ROUTE=y +CONFIG_NET_SOCKOPTS=y +CONFIG_NET_TCP=y +CONFIG_NET_UDP=y +CONFIG_NET_UDP_CHECKSUMS=y +CONFIG_NFILE_DESCRIPTORS=6 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_READLINE=y +CONFIG_RAM_SIZE=270336 +CONFIG_RAM_START=0x20000000 +CONFIG_READLINE_CMD_HISTORY=y +CONFIG_RP2040_ENC28J60_INTR_GPIO=11 +CONFIG_RP2040_ENC28J60_RESET_GPIO=10 +CONFIG_RP2040_SPI0=y +CONFIG_RP2040_SPI0_GPIO=16 +CONFIG_RP2040_SPI1=y +CONFIG_RP2040_SPI1_GPIO=12 +CONFIG_RP2040_SPI=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_LPWORK=y +CONFIG_START_DAY=9 +CONFIG_START_MONTH=2 +CONFIG_START_YEAR=2021 +CONFIG_SYSLOG_CONSOLE=y +CONFIG_SYSTEM_DHCPC_RENEW=y +CONFIG_SYSTEM_NETDB=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NTPC=y +CONFIG_SYSTEM_PING=y +CONFIG_SYSTEM_SPITOOL=y +CONFIG_SYSTEM_SYSTEM=y +CONFIG_SYSTEM_TELNET_CLIENT=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART0_SERIAL_CONSOLE=y +CONFIG_USER_ENTRYPOINT="nsh_main" +CONFIG_WQUEUE_NOTIFIER=y