mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
boards/arm/stm32/stm32f4discovery: Add Ethernet SPI ENC28J60 board support to STM32F4Discovery.
This commit is contained in:
committed by
Gregory Nutt
parent
f4d8c184b0
commit
69a9f3b8ec
@@ -42,6 +42,7 @@ Contents
|
||||
- SSD1289
|
||||
- UG-2864AMBAG01 / UG-2864HSWEG01
|
||||
- NiceRF LoRa (2AD66-LoRa V2)
|
||||
- Ethernet SPI Module ENC28J60
|
||||
- HCI UART
|
||||
- STM32F4Discovery-specific Configuration Options
|
||||
- BASIC
|
||||
@@ -652,6 +653,23 @@ First connect the GND and VCC (to 3.3V) and then connect the SCK label to PA5,
|
||||
connnect the MISO to PA6, connect the MOSI to PA7, connect the NSS to PD8,
|
||||
connect DIO0 to PD0 and finally connect NRESET to PD4.
|
||||
|
||||
Ethernet SPI Module ENC28J60
|
||||
============================
|
||||
|
||||
You can use an external Ethernet SPI Module ENC28J60 with STM32F4Discovery board.
|
||||
|
||||
First connect the GND and VCC (to 3.3V). Note: according with ENC28J60 datasheet
|
||||
the Operating Voltage should be between 3.1V to 3.6V, but STM32F4Discover only
|
||||
supply 3.0V. You can modify your board to supply 3.3V: just remove the D3 diode
|
||||
and short-circuit the board pads where it was soldered).
|
||||
|
||||
Connect the SCK label to PA5, connnect the SO to PA6, connect the SI to PA7,
|
||||
connect the CS to PA4, connect RST to PE1 and finally connect INT to PE4.
|
||||
|
||||
The next step is to enable the ENC28J60 in the menuconfig ("make menuconfig")
|
||||
and the necessary Network configuration, you can use the
|
||||
boards/arm/stm32/fire-stm32v2/configs/nsh/defconfig as reference.
|
||||
|
||||
HCI UART
|
||||
========
|
||||
|
||||
|
||||
@@ -81,6 +81,10 @@ ifeq ($(CONFIG_LCD_ST7567),y)
|
||||
CSRCS += stm32_st7567.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENC28J60),y)
|
||||
CSRCS += stm32_enc28j60.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LPWAN_SX127X),y)
|
||||
CSRCS += stm32_sx127x.c
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/fire-stm32v2/src/stm32_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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* 2MBit SPI FLASH OR ENC28J60
|
||||
*
|
||||
* --- ------ -------------- -----------------------------------------------------
|
||||
* PIN NAME SIGNAL NOTES
|
||||
* --- ------ -------------- -----------------------------------------------------
|
||||
*
|
||||
* 29 PA4 PA4-SPI1-NSS 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 30 PA5 PA5-SPI1-SCK 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 31 PA6 PA6-SPI1-MISO 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 32 PA7 PA7-SPI1-MOSI 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/spi/spi.h>
|
||||
#include <nuttx/net/enc28j60.h>
|
||||
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "chip.h"
|
||||
#include "up_arch.h"
|
||||
#include "up_internal.h"
|
||||
#include "stm32_spi.h"
|
||||
|
||||
#include "stm32f4discovery.h"
|
||||
|
||||
#ifdef CONFIG_ENC28J60
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* ENC28J60
|
||||
*
|
||||
* --- ------ -------------- -----------------------------------------------------
|
||||
* PIN NAME SIGNAL NOTES
|
||||
* --- ------ -------------- -----------------------------------------------------
|
||||
*
|
||||
* 29 PA4 PA4-SPI1-NSS 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 30 PA5 PA5-SPI1-SCK 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 31 PA6 PA6-SPI1-MISO 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 32 PA7 PA7-SPI1-MOSI 2.4" TFT + Touchscreen, 10Mbit ENC28J60, SPI 2M FLASH
|
||||
* 98 PE1 PE1-FSMC_NBL1 2.4" TFT + Touchscreen, 10Mbit EN28J60 Reset
|
||||
* 4 PE5 (no name) 10Mbps ENC28J60 Interrupt
|
||||
*/
|
||||
|
||||
/* ENC28J60 is on SPI1 */
|
||||
|
||||
#ifndef CONFIG_STM32_SPI1
|
||||
# error "Need CONFIG_STM32_SPI1 in the configuration"
|
||||
#endif
|
||||
|
||||
/* SPI Assumptions **********************************************************/
|
||||
|
||||
#define ENC28J60_SPI_PORTNO 1 /* On SPI1 */
|
||||
#define ENC28J60_DEVNO 0 /* Only one ENC28J60 */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct stm32_lower_s
|
||||
{
|
||||
const struct enc_lower_s lower; /* Low-level MCU interface */
|
||||
xcpt_t handler; /* ENC28J60 interrupt handler */
|
||||
FAR void *arg; /* Argument that accompanies the interrupt */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* 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 mechanixm for controlling
|
||||
* the ENC28J60 GPIO interrupt.
|
||||
*/
|
||||
|
||||
static struct stm32_lower_s g_enclower =
|
||||
{
|
||||
.lower =
|
||||
{
|
||||
.attach = up_attach,
|
||||
.enable = up_enable,
|
||||
.disable = up_disable
|
||||
},
|
||||
.handler = NULL,
|
||||
.arg = NULL
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* 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)
|
||||
{
|
||||
FAR struct stm32_lower_s *priv = (FAR struct stm32_lower_s *)lower;
|
||||
|
||||
/* Just save the handler for use when the interrupt is enabled */
|
||||
|
||||
priv->handler = handler;
|
||||
priv->arg = arg;
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void up_enable(FAR const struct enc_lower_s *lower)
|
||||
{
|
||||
FAR struct stm32_lower_s *priv = (FAR struct stm32_lower_s *)lower;
|
||||
|
||||
DEBUGASSERT(priv->handler);
|
||||
stm32_gpiosetevent(GPIO_ENC28J60_INTR, false, true, true,
|
||||
priv->handler, priv->arg);
|
||||
}
|
||||
|
||||
/* REVISIT: Since the interrupt is completely torn down, not just disabled,
|
||||
* in interrupt requests that occurs while the interrupt is disabled will be
|
||||
* lost.
|
||||
*/
|
||||
|
||||
static void up_disable(FAR const struct enc_lower_s *lower)
|
||||
{
|
||||
stm32_gpiosetevent(GPIO_ENC28J60_INTR, false, true, true,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_netinitialize
|
||||
****************************************************************************/
|
||||
|
||||
void up_netinitialize(void)
|
||||
{
|
||||
FAR struct spi_dev_s *spi;
|
||||
int ret;
|
||||
|
||||
/* Assumptions:
|
||||
* 1) ENC28J60 pins were configured in up_spi.c early in the boot-up phase.
|
||||
* 2) Clocking for the SPI1 peripheral was also provided earlier in boot-up.
|
||||
*/
|
||||
|
||||
spi = stm32_spibus_initialize(ENC28J60_SPI_PORTNO);
|
||||
if (!spi)
|
||||
{
|
||||
nerr("ERROR: Failed to initialize SPI port %d\n", ENC28J60_SPI_PORTNO);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Take ENC28J60 out of reset (active low)*/
|
||||
|
||||
stm32_gpiowrite(GPIO_ENC28J60_RESET, true);
|
||||
|
||||
/* 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",
|
||||
ENC28J60_SPI_PORTNO, ENC28J60_DEVNO, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
ninfo("Bound SPI port %d to ENC28J60 device %d\n",
|
||||
ENC28J60_SPI_PORTNO, ENC28J60_DEVNO);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ENC28J60 */
|
||||
@@ -69,6 +69,12 @@
|
||||
|
||||
void weak_function stm32_spidev_initialize(void)
|
||||
{
|
||||
#ifdef CONFIG_ENC28J60
|
||||
stm32_configgpio(GPIO_ENC28J60_CS);
|
||||
stm32_configgpio(GPIO_ENC28J60_RESET);
|
||||
stm32_configgpio(GPIO_ENC28J60_INTR);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_SPI1
|
||||
stm32_configgpio(GPIO_CS_MEMS); /* MEMS chip select */
|
||||
#endif
|
||||
@@ -104,22 +110,23 @@ void weak_function stm32_spidev_initialize(void)
|
||||
* Name: stm32_spi1/2/3select and stm32_spi1/2/3status
|
||||
*
|
||||
* Description:
|
||||
* The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status must be
|
||||
* provided by board-specific logic. They are implementations of the select
|
||||
* and status methods of the SPI interface defined by struct spi_ops_s (see
|
||||
* include/nuttx/spi/spi.h). All other methods (including stm32_spibus_initialize())
|
||||
* are provided by common STM32 logic. To use this common SPI logic on your
|
||||
* board:
|
||||
* The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status
|
||||
* must be provided by board-specific logic. They are implementations of
|
||||
* the select and status methods of the SPI interface defined by struct
|
||||
* spi_ops_s (see include/nuttx/spi/spi.h). All other methods (including
|
||||
* stm32_spibus_initialize()) are provided by common STM32 logic. To use
|
||||
* this common SPI logic on your board:
|
||||
*
|
||||
* 1. Provide logic in stm32_boardinitialize() to configure SPI chip select
|
||||
* pins.
|
||||
* 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions in your
|
||||
* board-specific logic. These functions will perform chip selection and
|
||||
* status operations using GPIOs in the way your board is configured.
|
||||
* 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions
|
||||
* in your board-specific logic. These functions will perform chip
|
||||
* selection and status operations using GPIOs in the way your board
|
||||
* is configured.
|
||||
* 3. Add a calls to stm32_spibus_initialize() in your low level application
|
||||
* initialization logic
|
||||
* 4. The handle returned by stm32_spibus_initialize() may then be used to bind the
|
||||
* SPI driver to higher level logic (e.g., calling
|
||||
* 4. The handle returned by stm32_spibus_initialize() may then be used to
|
||||
* bind the SPI driver to higher level logic (e.g., calling
|
||||
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
|
||||
* the SPI MMC/SD driver).
|
||||
*
|
||||
@@ -130,24 +137,36 @@ void stm32_spi1select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
|
||||
{
|
||||
spiinfo("devid: %d CS: %s\n", (int)devid, selected ? "assert" : "de-assert");
|
||||
|
||||
#ifdef CONFIG_ENC28J60
|
||||
if (devid == SPIDEV_ETHERNET(0))
|
||||
{
|
||||
/* Set the GPIO low to select and high to de-select */
|
||||
|
||||
stm32_gpiowrite(GPIO_ENC28J60_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LPWAN_SX127X
|
||||
if (devid == SPIDEV_LPWAN(0))
|
||||
{
|
||||
stm32_gpiowrite(GPIO_SX127X_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_LCD_ST7567
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
{
|
||||
stm32_gpiowrite(STM32_LCD_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LCD_MAX7219) || defined(CONFIG_LEDS_MAX7219)
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
{
|
||||
stm32_gpiowrite(GPIO_MAX7219_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
@@ -187,6 +206,7 @@ void stm32_spi2select(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
|
||||
stm32_gpiowrite(GPIO_MAX31855_CS, !selected);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SENSORS_MAX6675)
|
||||
if (devid == SPIDEV_TEMPERATURE(0))
|
||||
{
|
||||
@@ -213,6 +233,7 @@ uint8_t stm32_spi2status(FAR struct spi_dev_s *dev, uint32_t devid)
|
||||
ret = stm32_gpioread(GPIO_MMCSD_NCD) ? 0 : 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@@ -275,6 +296,7 @@ int stm32_spi1cmddata(FAR struct spi_dev_s *dev, uint32_t devid, bool cmd)
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
|
||||
defined(CONFIG_LCD_SSD1351)
|
||||
if (devid == SPIDEV_DISPLAY(0))
|
||||
|
||||
@@ -247,7 +247,7 @@
|
||||
#define GPIO_SX127X_DIO0 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0)
|
||||
|
||||
#define GPIO_SX127X_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_OUTPUT_CLEAR|\
|
||||
GPIO_SPEED_50MHz|GPIO_PORTD|GPIO_PIN4)
|
||||
GPIO_SPEED_50MHz|GPIO_PORTD|GPIO_PIN4)
|
||||
|
||||
/* PWM
|
||||
*
|
||||
@@ -286,6 +286,15 @@
|
||||
#define GPIO_CS_XEN1210 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)
|
||||
|
||||
#define GPIO_ENC28J60_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)
|
||||
|
||||
#define GPIO_ENC28J60_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
|
||||
GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN1)
|
||||
|
||||
#define GPIO_ENC28J60_INTR (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|\
|
||||
GPIO_OPENDRAIN|GPIO_PORTE|GPIO_PIN4)
|
||||
|
||||
/* USB OTG FS
|
||||
*
|
||||
* PA9 OTG_FS_VBUS VBUS sensing (also connected to the green LED)
|
||||
@@ -407,7 +416,7 @@
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
@@ -487,7 +496,7 @@ int stm32_bmp180initialize(FAR const char *devpath);
|
||||
int stm32_lis3dshinitialize(FAR const char *devpath);
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: stm32_lpwaninitialize
|
||||
*
|
||||
* Description:
|
||||
|
||||
Reference in New Issue
Block a user