2018-09-05 02:39:50 +02:00
|
|
|
/*
|
2019-09-05 13:35:58 +02:00
|
|
|
* Copyright (C) 2019 Gunar Schorcht
|
2018-09-05 02:39:50 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu_esp8266
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief CPU specific definitions and functions for peripheral handling
|
|
|
|
*
|
|
|
|
* @author Gunar Schorcht <gunar@schorcht.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PERIPH_CPU_H
|
|
|
|
#define PERIPH_CPU_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
esp8266: Support UART1 and other UART0 pins.
The esp8266 CPU has actually two hardware UART peripherals. UART0 is
used by the boot ROM for flashing and serial output during boot,
typically at a baudrate of 74880 bps until the bootloader or application
sets the more standard 115200 baudrate. This UART0 device has two
possible pins for TXD, GPIO1 and GPIO2, which are both set to TXD by the
boot ROM. esp8266 modules will typically have GPIO1 labeled as the TX
pin, but it is possible to use GPIO2 for that purpose even while
flashing the device with esptool.py.
The second device, UART1, also has two options for TXD, GPIO2 and GPIO7,
and only one option for RXD, GPIO8. However, GPIO7 and GPIO8 are used
by the flash internally so those options are not very useful unless
maybe while running from IRAM with the flash disabled, for example for
a debugger over UART1.
This patch allows boards to override UART{0,1}_{R,T}XD in their
periph_conf.h to configure the uart selection. Defining UART1_TX will
make the UART_DEV(1) device available.
Tested with:
```CFLAGS='-DUART1_TXD=GPIO2' make -C tests/periph_uart BOARD=esp8266-esp-12x flash term```
* Connected one USB-UART to the standard GPIO1 and GPIO3 for flashing
and console. After flashing we see the manual test output at 115200
bps
* Connected a second USB-UART with RX to GPIO2 running at 74880.
Then run on the first console:
```
> init 1 74880
> send 1 hello
```
The word "hello" appears on the second UART connection.
Note that GPIO2 is used during boot for UART0's TX until the application
or bootloader set it to a regular GPIO, so some boot ROM messages at
74880 bps are visible. After running `init 1 74880` it is set to UART1's
TX.
2021-04-25 03:34:38 +02:00
|
|
|
#include <limits.h>
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
#include "eagle_soc.h"
|
2021-12-06 12:00:42 +01:00
|
|
|
#include "cpu_conf.h"
|
2024-02-21 23:15:21 +01:00
|
|
|
#include "macros/units.h"
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Length of the CPU_ID in octets
|
|
|
|
*/
|
|
|
|
#define CPUID_LEN (4U)
|
|
|
|
|
2024-01-09 23:20:35 +01:00
|
|
|
/**
|
|
|
|
* @brief CPU cycles per busy wait loop
|
|
|
|
*/
|
|
|
|
#define CPU_CYCLES_PER_LOOP (5)
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @name GPIO configuration
|
2018-09-05 02:39:50 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @brief Override the default gpio_t type definition
|
|
|
|
*
|
|
|
|
* This is required here to have gpio_t defined in this file.
|
2018-09-05 02:39:50 +02:00
|
|
|
* @{
|
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define HAVE_GPIO_T
|
|
|
|
typedef unsigned int gpio_t;
|
2018-09-05 02:39:50 +02:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Definition of a fitting UNDEF value
|
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define GPIO_UNDEF ((gpio_t)(UINT_MAX))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Define a CPU specific GPIO pin generator macro
|
|
|
|
*/
|
|
|
|
#define GPIO_PIN(x, y) ((x & 0) | y)
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @brief Available GPIO ports on ESP8266
|
2018-09-05 02:39:50 +02:00
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define PORT_GPIO (0)
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Define CPU specific number of GPIO pins
|
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define GPIO_PIN_NUMOF (17)
|
|
|
|
|
2019-11-18 11:29:38 +01:00
|
|
|
#ifndef DOXYGEN
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @brief Override flank selection values
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define HAVE_GPIO_FLANK_T
|
|
|
|
typedef enum {
|
|
|
|
GPIO_NONE = 0,
|
|
|
|
GPIO_RISING = 1, /**< emit interrupt on rising flank */
|
|
|
|
GPIO_FALLING = 2, /**< emit interrupt on falling flank */
|
|
|
|
GPIO_BOTH = 3, /**< emit interrupt on both flanks */
|
|
|
|
GPIO_LOW = 4, /**< emit interrupt on low level */
|
|
|
|
GPIO_HIGH = 5 /**< emit interrupt on low level */
|
|
|
|
} gpio_flank_t;
|
|
|
|
/** @} */
|
2019-11-18 11:29:38 +01:00
|
|
|
#endif /* ndef DOXYGEN */
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Predefined GPIO names
|
|
|
|
* @{
|
|
|
|
*/
|
2024-04-11 19:19:58 +02:00
|
|
|
#define GPIO0 (GPIO_PIN(PORT_GPIO, 0))
|
|
|
|
#define GPIO1 (GPIO_PIN(PORT_GPIO, 1))
|
|
|
|
#define GPIO2 (GPIO_PIN(PORT_GPIO, 2))
|
|
|
|
#define GPIO3 (GPIO_PIN(PORT_GPIO, 3))
|
|
|
|
#define GPIO4 (GPIO_PIN(PORT_GPIO, 4))
|
|
|
|
#define GPIO5 (GPIO_PIN(PORT_GPIO, 5))
|
|
|
|
#define GPIO6 (GPIO_PIN(PORT_GPIO, 6))
|
|
|
|
#define GPIO7 (GPIO_PIN(PORT_GPIO, 7))
|
|
|
|
#define GPIO8 (GPIO_PIN(PORT_GPIO, 8))
|
|
|
|
#define GPIO9 (GPIO_PIN(PORT_GPIO, 9))
|
|
|
|
#define GPIO10 (GPIO_PIN(PORT_GPIO, 10))
|
|
|
|
#define GPIO11 (GPIO_PIN(PORT_GPIO, 11))
|
|
|
|
#define GPIO12 (GPIO_PIN(PORT_GPIO, 12))
|
|
|
|
#define GPIO13 (GPIO_PIN(PORT_GPIO, 13))
|
|
|
|
#define GPIO14 (GPIO_PIN(PORT_GPIO, 14))
|
|
|
|
#define GPIO15 (GPIO_PIN(PORT_GPIO, 15))
|
|
|
|
#define GPIO16 (GPIO_PIN(PORT_GPIO, 16))
|
2018-09-05 02:39:50 +02:00
|
|
|
/** @} */
|
|
|
|
|
2024-04-11 19:02:40 +02:00
|
|
|
/** @} */
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @name I2C configuration
|
|
|
|
*
|
|
|
|
* ESP8266 provides up to two bit-banging I2C interfaces.
|
|
|
|
*
|
|
|
|
* The board-specific configuration of the I2C interface I2C_DEV(n) requires
|
|
|
|
* the definition of
|
|
|
|
*
|
|
|
|
* I2Cn_SPEED, the bus speed,
|
|
|
|
* I2Cn_SCL, the GPIO used as SCL signal, and
|
|
|
|
* I2Cn_SDA, the GPIO used as SDA signal,
|
|
|
|
*
|
|
|
|
* where n can be 0 or 1. If they are not defined, the I2C interface
|
|
|
|
* I2C_DEV(n) is not used.
|
|
|
|
*
|
|
|
|
* @note The configuration of the I2C interfaces I2C_DEV(n) must be in
|
|
|
|
* continuous ascending order of n.
|
|
|
|
*
|
|
|
|
* I2C_NUMOF is determined automatically from board-specific peripheral
|
|
|
|
* definitions of I2Cn_SPEED, I2Cn_SCK, and I2Cn_SDA.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
2019-11-18 11:30:29 +01:00
|
|
|
#ifndef DOXYGEN
|
2018-09-05 02:39:50 +02:00
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @brief Override I2C clock speed values
|
|
|
|
*
|
|
|
|
* This is required here to have i2c_speed_t defined in this file.
|
2018-09-05 02:39:50 +02:00
|
|
|
* @{
|
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define HAVE_I2C_SPEED_T
|
2018-09-05 02:39:50 +02:00
|
|
|
typedef enum {
|
2019-09-05 13:35:58 +02:00
|
|
|
I2C_SPEED_LOW = 0, /**< 10 kbit/s */
|
|
|
|
I2C_SPEED_NORMAL, /**< 100 kbit/s */
|
|
|
|
I2C_SPEED_FAST, /**< 400 kbit/s */
|
|
|
|
I2C_SPEED_FAST_PLUS, /**< 1 Mbit/s */
|
|
|
|
I2C_SPEED_HIGH, /**< not supported */
|
|
|
|
} i2c_speed_t;
|
2018-09-05 02:39:50 +02:00
|
|
|
/** @} */
|
2019-11-18 11:30:29 +01:00
|
|
|
#endif /* ndef DOXYGEN */
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @brief I2C configuration structure type
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
i2c_speed_t speed; /**< I2C bus speed */
|
|
|
|
gpio_t scl; /**< GPIO used as SCL pin */
|
|
|
|
gpio_t sda; /**< GPIO used as SDA pin */
|
|
|
|
} i2c_conf_t;
|
2018-09-05 02:39:50 +02:00
|
|
|
|
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @brief Maximum number of I2C interfaces that can be used by board definitions
|
2018-09-05 02:39:50 +02:00
|
|
|
*/
|
2019-09-05 13:35:58 +02:00
|
|
|
#define I2C_NUMOF_MAX (2)
|
|
|
|
|
|
|
|
#define PERIPH_I2C_NEED_READ_REG /**< i2c_read_reg required */
|
|
|
|
#define PERIPH_I2C_NEED_READ_REGS /**< i2c_read_regs required */
|
|
|
|
#define PERIPH_I2C_NEED_WRITE_REG /**< i2c_write_reg required */
|
|
|
|
#define PERIPH_I2C_NEED_WRITE_REGS /**< i2c_write_regs required */
|
2018-09-05 02:39:50 +02:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Power management configuration
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define PROVIDES_PM_SET_LOWEST
|
|
|
|
#define PROVIDES_PM_RESTART
|
|
|
|
#define PROVIDES_PM_OFF
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
2019-09-05 13:35:58 +02:00
|
|
|
* @name PWM configuration
|
|
|
|
*
|
|
|
|
* The hardware implementation of ESP8266 PWM supports only frequencies as
|
|
|
|
* power of two. Therefore a software implementation of one PWM device
|
|
|
|
* PWM_DEV(0) with up to 8 PWM channels (#PWM_CHANNEL_NUM_MAX) is used. The
|
|
|
|
* GPIOs that can be used as PWM channels are defined by #PWM0_GPIOS in board
|
|
|
|
* definition.
|
|
|
|
*
|
|
|
|
* @note The minimum PWM period that can be realized is 10 us or 100.000 PWM
|
|
|
|
* clock cycles per second. Therefore, the product of frequency and resolution
|
|
|
|
* should not be greater than 100.000. Otherwise the frequency is scaled down
|
|
|
|
* automatically.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum number of PWM devices.
|
|
|
|
*/
|
|
|
|
#define PWM_NUMOF_MAX (1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum number of channels per PWM device.
|
|
|
|
*/
|
|
|
|
#define PWM_CHANNEL_NUM_MAX (8)
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
2019-12-12 15:06:23 +01:00
|
|
|
/**
|
|
|
|
* @name RNG configuration
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The address of the register for accessing the hardware RNG.
|
|
|
|
*/
|
|
|
|
#define RNG_DATA_REG_ADDR (0x3ff20e44)
|
|
|
|
/** @} */
|
|
|
|
|
2020-03-19 13:59:45 +01:00
|
|
|
/**
|
|
|
|
* @name RTT and RTC configuration
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define RTT_FREQUENCY (312500UL)
|
|
|
|
#define RTT_MAX_VALUE (0xFFFFFFFFUL)
|
|
|
|
/** @} */
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @name SPI configuration
|
|
|
|
*
|
|
|
|
* ESP8266 has two SPI controllers:
|
|
|
|
*
|
|
|
|
* - _CSPI_ for caching and accessing the flash memory<br>
|
|
|
|
* - _HSPI_ for peripherals
|
|
|
|
*
|
|
|
|
* Thus, _HSPI_ is the only SPI interface that is available for peripherals.
|
|
|
|
* It is exposed as RIOT's SPI_DEV(0). The pin configuration of the _HSPI_
|
|
|
|
* interface is fixed as shown in following table.
|
|
|
|
*
|
|
|
|
* Signal | Pin
|
|
|
|
* -- --------|-------
|
|
|
|
* #SPI0_MISO | GPIO12
|
|
|
|
* #SPI0_MOSI | GPIO13
|
|
|
|
* #SPI0_SCK | GPIO14
|
|
|
|
* #SPI0_CS0 | GPIOn with n = 0, 2, 4, 5, 15, 16 (additionally 9, 10 in DOUT flash mode)
|
|
|
|
*
|
|
|
|
* The only pin definition that can be overridden by an application-specific
|
|
|
|
* board configuration is the CS signal defined by #SPI0_CS0.
|
|
|
|
*
|
2018-09-05 02:39:50 +02:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @brief SPI controllers that can be used for peripheral interfaces
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
HSPI = 1, /**< HSPI interface controller */
|
|
|
|
} spi_ctrl_t;
|
2018-09-05 02:39:50 +02:00
|
|
|
|
2024-02-21 23:15:21 +01:00
|
|
|
/**
|
|
|
|
* @brief Override SPI clock speed values
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define HAVE_SPI_CLK_T
|
|
|
|
typedef enum {
|
|
|
|
SPI_CLK_100KHZ = KHZ(100), /**< drive the SPI bus with 100KHz */
|
|
|
|
SPI_CLK_400KHZ = KHZ(400), /**< drive the SPI bus with 400KHz */
|
|
|
|
SPI_CLK_1MHZ = MHZ(1), /**< drive the SPI bus with 1MHz */
|
|
|
|
SPI_CLK_5MHZ = MHZ(5), /**< drive the SPI bus with 5MHz */
|
|
|
|
SPI_CLK_10MHZ = MHZ(10), /**< drive the SPI bus with 10MHz */
|
|
|
|
} spi_clk_t;
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @brief SPI configuration structure type
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
spi_ctrl_t ctrl; /**< SPI controller used for the interface */
|
|
|
|
gpio_t sck; /**< GPIO used as SCK pin */
|
|
|
|
gpio_t mosi; /**< GPIO used as MOSI pin */
|
|
|
|
gpio_t miso; /**< GPIO used as MISO pin */
|
|
|
|
gpio_t cs; /**< GPIO used as CS0 pin */
|
|
|
|
} spi_conf_t;
|
2018-09-07 22:14:32 +02:00
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @brief Maximum number of SPI interfaces
|
|
|
|
*/
|
|
|
|
#define SPI_NUMOF_MAX (1)
|
|
|
|
|
|
|
|
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE /**< requires function spi_transfer_byte */
|
|
|
|
#define PERIPH_SPI_NEEDS_TRANSFER_REG /**< requires function spi_transfer_reg */
|
|
|
|
#define PERIPH_SPI_NEEDS_TRANSFER_REGS /**< requires function spi_transfer_regs */
|
2018-09-11 09:25:27 +02:00
|
|
|
/** @} */
|
|
|
|
|
2024-04-11 19:02:40 +02:00
|
|
|
/** @} */
|
|
|
|
|
2018-09-07 22:14:32 +02:00
|
|
|
/**
|
|
|
|
* @brief Prevent shared timer functions from being used
|
|
|
|
*/
|
|
|
|
#define PERIPH_TIMER_PROVIDES_SET
|
|
|
|
|
2019-09-05 13:35:58 +02:00
|
|
|
/**
|
|
|
|
* @name UART configuration
|
|
|
|
*
|
|
|
|
* All ESP8266 boards have exactly one UART device with fixed pin mapping.
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UART configuration structure type
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
gpio_t txd; /**< GPIO used as TxD pin */
|
|
|
|
gpio_t rxd; /**< GPIO used as RxD pin */
|
|
|
|
} uart_conf_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Maximum number of UART interfaces
|
|
|
|
*/
|
esp8266: Support UART1 and other UART0 pins.
The esp8266 CPU has actually two hardware UART peripherals. UART0 is
used by the boot ROM for flashing and serial output during boot,
typically at a baudrate of 74880 bps until the bootloader or application
sets the more standard 115200 baudrate. This UART0 device has two
possible pins for TXD, GPIO1 and GPIO2, which are both set to TXD by the
boot ROM. esp8266 modules will typically have GPIO1 labeled as the TX
pin, but it is possible to use GPIO2 for that purpose even while
flashing the device with esptool.py.
The second device, UART1, also has two options for TXD, GPIO2 and GPIO7,
and only one option for RXD, GPIO8. However, GPIO7 and GPIO8 are used
by the flash internally so those options are not very useful unless
maybe while running from IRAM with the flash disabled, for example for
a debugger over UART1.
This patch allows boards to override UART{0,1}_{R,T}XD in their
periph_conf.h to configure the uart selection. Defining UART1_TX will
make the UART_DEV(1) device available.
Tested with:
```CFLAGS='-DUART1_TXD=GPIO2' make -C tests/periph_uart BOARD=esp8266-esp-12x flash term```
* Connected one USB-UART to the standard GPIO1 and GPIO3 for flashing
and console. After flashing we see the manual test output at 115200
bps
* Connected a second USB-UART with RX to GPIO2 running at 74880.
Then run on the first console:
```
> init 1 74880
> send 1 hello
```
The word "hello" appears on the second UART connection.
Note that GPIO2 is used during boot for UART0's TX until the application
or bootloader set it to a regular GPIO, so some boot ROM messages at
74880 bps are visible. After running `init 1 74880` it is set to UART1's
TX.
2021-04-25 03:34:38 +02:00
|
|
|
#define UART_NUMOF_MAX (2)
|
2019-09-05 13:35:58 +02:00
|
|
|
/** @} */
|
|
|
|
|
2018-09-05 02:39:50 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* PERIPH_CPU_H */
|
|
|
|
/** @} */
|