diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-dimensions-side.jpg b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-dimensions-side.jpg new file mode 100644 index 00000000000..282c3d457fe Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-dimensions-side.jpg differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-functional-block-diagram.png b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-functional-block-diagram.png new file mode 100644 index 00000000000..0369b176066 Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-functional-block-diagram.png differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-pinout.png b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-pinout.png new file mode 100644 index 00000000000..810c08ea9e2 Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4-pinout.png differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-dimensions-back.jpg b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-dimensions-back.jpg new file mode 100644 index 00000000000..805ff59f7ba Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-dimensions-back.jpg differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-f-layout.jpeg b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-f-layout.jpeg new file mode 100644 index 00000000000..89098c82c69 Binary files /dev/null and b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/esp32-pico-kit-v4.1-f-layout.jpeg differ diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/index.rst b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/index.rst new file mode 100644 index 00000000000..1bee4f97fd5 --- /dev/null +++ b/Documentation/platforms/xtensa/esp32/boards/esp32-pico-kit/index.rst @@ -0,0 +1,240 @@ +ESP32-PICO-KIT V4 +================= + +This guide shows how to get started with the ESP32-PICO-KIT V4/V4.1 mini development board. + +This particular description covers ESP32-PICO-KIT V4 and V4.1. The difference is the upgraded USB-UART bridge from CP2102 in V4 with up to 1 Mbps transfer rates to CP2102N in V4.1 with up to 3 Mbps transfer rates. + +What You Need +------------- + +* :ref:`ESP32-PICO-KIT mini development board ` +* USB 2.0 A to Micro B cable +* Computer running Windows, Linux, or macOS + +Overview +-------- + +ESP32-PICO-KIT is an ESP32-based mini development board produced by `Espressif `_. + +The core of this board is ESP32-PICO-D4 - a System-in-Package (SiP) module with complete Wi-Fi and Bluetooth functionalities. Compared to other ESP32 modules, ESP32-PICO-D4 integrates the following peripheral components in one single package, which otherwise would need to be installed separately: + +- 40 MHz crystal oscillator +- 4 MB flash +- Filter capacitors +- RF matching links + +This setup reduces the costs of additional external components as well as the cost of assembly and testing and also increases the overall usability of the product. + +The development board features a USB-UART Bridge circuit which allows developers to connect the board to a computer's USB port for flashing and debugging. + +All the IO signals and system power on ESP32-PICO-D4 are led out to two rows of 20 x 0.1" header pads on both sides of the development board for easy access. For compatibility with Dupont wires, 2 x 17 header pads are populated with two rows of male pin headers. The remaining 2 x 3 header pads beside the antenna are not populated. These pads may be populated later by the user if required. + +.. note:: + + 1. There are two versions of ESP32-PICO-KIT boards, respectively with male headers and female headers. In this guide, the male header version is taken as an example. + 2. The 2 x 3 pads not populated with pin headers are connected to the flash memory embedded in the ESP32-PICO-D4 SiP module. For more details, see module's datasheet in `Related Documents`_. + +Functionality Overview +---------------------- + +The block diagram below shows the main components of ESP32-PICO-KIT and their interconnections. + +.. figure:: esp32-pico-kit-v4-functional-block-diagram.png + :align: center + :alt: ESP32-PICO-KIT functional block diagram + :figclass: align-center + + ESP32-PICO-KIT block diagram + + +Functional Description +---------------------- + +The following figure and the table below describe the key components, interfaces, and controls of the ESP32-PICO-KIT board. + +.. _get-started-pico-kit-v4-board-front: + +.. figure:: esp32-pico-kit-v4.1-f-layout.jpeg + :align: center + :alt: ESP32-PICO-KIT board layout (with female headers) + :figclass: align-center + + ESP32-PICO-KIT board layout (with female headers) + +Below is the description of the items identified in the figure starting from the top left corner and going clockwise. + +.. list-table:: + :widths: 25 75 + :header-rows: 1 + + * - Key Component + - Description + * - ESP32-PICO-D4 + - Standard ESP32-PICO-D4 module soldered to the ESP32-PICO-KIT board. The complete ESP32 system on a chip (ESP32 SoC) has been integrated into the SiP module, requiring only an external antenna with LC matching network, decoupling capacitors, and a pull-up resistor for EN signals to function properly. + * - LDO + - 5V-to-3.3V Low dropout voltage regulator (LDO). + * - USB-UART bridge + - Single-chip USB-UART bridge: CP2102 in V4 provides up to 1 Mbps transfer rates and CP2102N in V4.1 offers up to 3 Mbps transfers rates. + * - Micro USB Port + - USB interface. Power supply for the board as well as the communication interface between a computer and the board. + * - 5V Power On LED + - This red LED turns on when power is supplied to the board. For details, see the schematics in `Related Documents`_. + * - I/O + - All the pins on ESP32-PICO-D4 are broken out to pin headers. You can program ESP32 to enable multiple functions, such as PWM, ADC, DAC, I2C, I2S, SPI, etc. For details, please see Section `Pin Descriptions`_. + * - BOOT Button + - Download button. Holding down **Boot** and then pressing **EN** initiates Firmware Download mode for downloading firmware through the serial port. + * - EN Button + - Reset button. + + +Power Supply Options +-------------------- + +There are three mutually exclusive ways to provide power to the board: + +* Micro USB port, default power supply +* 5V / GND header pins +* 3V3 / GND header pins + +.. warning:: + + The power supply must be provided using **one and only one of the options above**, otherwise the board and/or the power supply source can be damaged. + + +Pin Descriptions +---------------- + +The two tables below provide the **Name** and **Function** of I/O header pins on both sides of the board, see :ref:`get-started-pico-kit-v4-board-front`. The pin numbering and header names are the same as in the schematic given in `Related Documents`_. + + +Header J2 +""""""""" + +====== ================= ====== ====================================================== +No. Name Type Function +====== ================= ====== ====================================================== +1 FLASH_SD1 (FSD1) I/O | GPIO8, SD_DATA1, SPID, HS1_DATA1 :ref:`(See 1) ` , U2CTS +2 FLASH_SD3 (FSD3) I/O | GPIO7, SD_DATA0, SPIQ, HS1_DATA0 :ref:`(See 1) ` , U2RTS +3 FLASH_CLK (FCLK) I/O | GPIO6, SD_CLK, SPICLK, HS1_CLK :ref:`(See 1) ` , U1CTS +4 IO21 I/O | GPIO21, VSPIHD, EMAC_TX_EN +5 IO22 I/O | GPIO22, VSPIWP, U0RTS, EMAC_TXD1 +6 IO19 I/O | GPIO19, VSPIQ, U0CTS, EMAC_TXD0 +7 IO23 I/O | GPIO23, VSPID, HS1_STROBE +8 IO18 I/O | GPIO18, VSPICLK, HS1_DATA7 +9 IO5 I/O | GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK +10 IO10 I/O | GPIO10, SD_DATA3, SPIWP, HS1_DATA3, U1TXD +11 IO9 I/O | GPIO9, SD_DATA2, SPIHD, HS1_DATA2, U1RXD +12 RXD0 I/O | GPIO3, U0RXD :ref:`(See 3) ` , CLK_OUT2 +13 TXD0 I/O | GPIO1, U0TXD :ref:`(See 3) ` , CLK_OUT3, EMAC_RXD2 +14 IO35 I | ADC1_CH7, RTC_GPIO5 +15 IO34 I | ADC1_CH6, RTC_GPIO4 +16 IO38 I | GPIO38, ADC1_CH2, RTC_GPIO2 +17 IO37 I | GPIO37, ADC1_CH1, RTC_GPIO1 +18 EN I | CHIP_PU +19 GND P | Ground +20 VDD33 (3V3) P | 3.3V power supply +====== ================= ====== ====================================================== + + +Header J3 +""""""""" + +====== ================= ====== ====================================================== +No. Name Type Function +====== ================= ====== ====================================================== +1 FLASH_CS (FCS) I/O | GPIO16, HS1_DATA4 :ref:`(See 1) ` , U2RXD, EMAC_CLK_OUT +2 FLASH_SD0 (FSD0) I/O | GPIO17, HS1_DATA5 :ref:`(See 1) ` , U2TXD, EMAC_CLK_OUT_180 +3 FLASH_SD2 (FSD2) I/O | GPIO11, SD_CMD, SPICS0, HS1_CMD :ref:`(See 1) ` , U1RTS +4 SENSOR_VP (FSVP) I | GPIO36, ADC1_CH0, RTC_GPIO0 +5 SENSOR_VN (FSVN) I | GPIO39, ADC1_CH3, RTC_GPIO3 +6 IO25 I/O | GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0 +7 IO26 I/O | GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1 +8 IO32 I/O | 32K_XP :ref:`(See 2a) ` , ADC1_CH4, TOUCH9, RTC_GPIO9 +9 IO33 I/O | 32K_XN :ref:`(See 2b) ` , ADC1_CH5, TOUCH8, RTC_GPIO8 +10 IO27 I/O | GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17 + | EMAC_RX_DV +11 IO14 I/O | ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, + | HS2_CLK, SD_CLK, EMAC_TXD2 +12 IO12 I/O | ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI :ref:`(See 4) ` , HSPIQ, + | HS2_DATA2, SD_DATA2, EMAC_TXD3 +13 IO13 I/O | ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, + | HS2_DATA3, SD_DATA3, EMAC_RX_ER +14 IO15 I/O | ADC2_CH3, TOUCH3, RTC_GPIO13, MTDO, HSPICS0 + | HS2_CMD, SD_CMD, EMAC_RXD3 +15 IO2 I/O | ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, + | HS2_DATA0, SD_DATA0 +16 IO4 I/O | ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, + | HS2_DATA1, SD_DATA1, EMAC_TX_ER +17 IO0 I/O | ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1 + | EMAC_TX_CLK +18 VDD33 (3V3) P | 3.3V power supply +19 GND P | Ground +20 EXT_5V (5V) P | 5V power supply +====== ================= ====== ====================================================== + + +.. _get-started-pico-kit-v4-pin-notes: + +.. note:: + + 1. This pin is connected to the flash pin of ESP32-PICO-D4. + 2. 32.768 kHz crystal oscillator: a) input, b) output. + 3. This pin is connected to the pin of the USB bridge chip on the board. + 4. The operating voltage of ESP32-PICO-KIT’s embedded SPI flash is 3.3 V. Therefore, the strapping pin MTDI should hold bit zero during the module power-on reset. If connected, please make sure that this pin is not held up on reset. + +Pin Layout +^^^^^^^^^^^ +.. figure:: esp32-pico-kit-v4-pinout.png + :align: center + :scale: 43% + :alt: ESP32-PICO-KIT (click to enlarge) + + ESP32-PICO-KIT Pin Layout (click to enlarge) + +Board Dimensions +---------------- + +The dimensions are 52 x 20.3 x 10 mm (2.1" x 0.8" x 0.4"). + +.. figure:: esp32-pico-kit-v4.1-dimensions-back.jpg + :align: center + :alt: ESP32-PICO-KIT dimensions - back (with male headers) + :figclass: align-center + + ESP32-PICO-KIT dimensions - back (with male headers) + +.. figure:: esp32-pico-kit-v4-dimensions-side.jpg + :align: center + :alt: ESP32-PICO-KIT V4 dimensions - side (with male headers) + :figclass: align-center + + ESP32-PICO-KIT dimensions - side (with male headers) + +For the board physical construction details, please refer to its Reference Design listed below. + + +Related Documents +----------------- + +* `ESP32-PICO-KIT V4 schematic `_ (PDF) +* `ESP32-PICO-KIT V4.1 schematic `_ (PDF) +* `ESP32-PICO-KIT Reference Design `_ containing OrCAD schematic, PCB layout, gerbers and BOM +* `ESP32-PICO-D4 Datasheet `_ (PDF) + +Configurations +-------------- + +All of the configurations presented below can be tested by running the following commands:: + + $ ./tools/configure.sh esp32-pico-kit: + $ make flash ESPTOOL_PORT=/dev/ttyUSB0 -j + +Where is the name of board configuration you want to use, i.e.: nsh, buttons, wifi... +Then use a serial console terminal like ``picocom`` configured to 115200 8N1. + +nsh +""" + +Basic NuttShell configuration (console enabled in UART0, exposed via +USB connection by means of CP2102 converter, at 115200 bps). diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig index 7693919e5d9..1647a0aa31e 100644 --- a/arch/xtensa/src/esp32/Kconfig +++ b/arch/xtensa/src/esp32/Kconfig @@ -90,6 +90,13 @@ config ARCH_CHIP_ESP32_A1S Ai-Thinker ESP32-A1S module with an embedded ESP32-D0WD chip, 16 MB of Flash memory, 8 MB of PSRAM +config ARCH_CHIP_ESP32PICOD4 + bool "ESP32-PICO-D4" + select ESP32_ESP32DXWDXX + select ESP32_FLASH_4M + ---help--- + ESP32 chip with a dual Xtensa LX6 core, 4 MB of in-package Flash memory + endchoice # ESP32 Chip Selection config ESP32_SINGLE_CPU diff --git a/boards/Kconfig b/boards/Kconfig index cb14dac00d4..408d6192be2 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -265,6 +265,20 @@ config ARCH_BOARD_ESP32_LYRAT Development Framework (ADF). It is designed for smart speakers and smart-home applications. This port is for board version 4.3. +config ARCH_BOARD_ESP32_PICO_KIT + bool "Espressif ESP32-PICO-KIT V4" + depends on ARCH_CHIP_ESP32PICOD4 + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS if ESP32_GPIO_IRQ + ---help--- + ESP32-PICO-KIT is an ESP32-based mini development board produced by Espressif. + The core of this board is ESP32-PICO-D4, a System-in-Package module with complete + Wi-Fi and Bluetooth functionalities. Compared to other ESP32 modules, ESP32-PICO-D4 + integrates the following peripheral components in one single package, which otherwise + would need to be installed separately: Crystal Oscillator, Flash Memory, Filter Capacitors + and RF matching links. + + config ARCH_BOARD_ESP32_SPARROWKIT bool "Espressif ESP-SPARROW-KIT" depends on ARCH_CHIP_ESP32WROVER @@ -2819,6 +2833,7 @@ config ARCH_BOARD default "ttgo_eink5_v2" if ARCH_BOARD_TTGO_T5V2_ESP32 default "esp32-ethernet-kit" if ARCH_BOARD_ESP32_ETHERNETKIT default "esp32-lyrat" if ARCH_BOARD_ESP32_LYRAT + default "esp32-pico-kit" if ARCH_BOARD_ESP32_PICO_KIT default "esp32-sparrow-kit" if ARCH_BOARD_ESP32_SPARROWKIT default "esp32-wrover-kit" if ARCH_BOARD_ESP32_WROVERKIT default "esp32c3-devkit" if ARCH_BOARD_ESP32C3_DEVKIT @@ -3871,6 +3886,9 @@ endif if ARCH_BOARD_ESP32_ETHERNETKIT source "boards/xtensa/esp32/esp32-ethernet-kit/Kconfig" endif +if ARCH_BOARD_ESP32_PICO_KIT +source "boards/xtensa/esp32/esp32-pico-kit/Kconfig" +endif if ARCH_BOARD_ESP32_LYRAT source "boards/xtensa/esp32/esp32-lyrat/Kconfig" endif diff --git a/boards/xtensa/esp32/esp32-pico-kit/Kconfig b/boards/xtensa/esp32/esp32-pico-kit/Kconfig new file mode 100644 index 00000000000..95b24e60058 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/Kconfig @@ -0,0 +1,118 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_BOARD_ESP32_PICO_KIT + +if PM + +config PM_ALARM_SEC + int "PM_STANDBY delay (seconds)" + default 15 + depends on PM + ---help--- + Number of seconds to wait in PM_STANDBY before going to PM_STANDBY mode. + +config PM_ALARM_NSEC + int "PM_STANDBY delay (nanoseconds)" + default 0 + depends on PM + ---help--- + Number of additional nanoseconds to wait in PM_STANDBY before going to PM_STANDBY mode. + +config PM_SLEEP_WAKEUP_SEC + int "PM_SLEEP delay (seconds)" + default 20 + depends on PM + ---help--- + Number of seconds to wait in PM_SLEEP. + +config PM_SLEEP_WAKEUP_NSEC + int "PM_SLEEP delay (nanoseconds)" + default 0 + depends on PM + ---help--- + Number of additional nanoseconds to wait in PM_SLEEP. + +endif # PM + +if ESP32_SPIRAM + +menu "PSRAM clock and cs IO for ESP32-DOWD" +config D0WD_PSRAM_CLK_IO + int "PSRAM CLK IO number" + range 0 33 + default 17 + ---help--- + The PSRAM CLOCK IO can be any unused GPIO, user can config it + based on hardware design. If user use 1.8V flash and 1.8V psram, + this value can only be one of 6, 7, 8, 9, 10, 11, 16, 17. + +config D0WD_PSRAM_CS_IO + int "PSRAM CS IO number" + range 0 33 + default 16 + ---help--- + The PSRAM CS IO can be any unused GPIO, user can config it based + on hardware design. If user use 1.8V flash and 1.8V psram, this + value can only be one of 6, 7, 8, 9, 10, 11, 16, 17. +endmenu + +menu "PSRAM clock and cs IO for ESP32-D2WD" +config D2WD_PSRAM_CLK_IO + int "PSRAM CLK IO number" + range 0 33 + default 9 + ---help--- + User can config it based on hardware design. For ESP32-D2WD chip, + the psram can only be 1.8V psram, so this value can only be one + of 6, 7, 8, 9, 10, 11, 16, 17. + +config D2WD_PSRAM_CS_IO + int "PSRAM CS IO number" + range 0 33 + default 10 + ---help--- + User can config it based on hardware design. For ESP32-D2WD chip, + the psram can only be 1.8V psram, so this value can only be one + of 6, 7, 8, 9, 10, 11, 16, 17. +endmenu + +menu "PSRAM clock and cs IO for ESP32-PICO" +config PICO_PSRAM_CS_IO + int "PSRAM CS IO number" + range 0 33 + default 10 + ---help--- + The PSRAM CS IO can be any unused GPIO, user can config it based on + hardware design. + For ESP32-PICO chip, the psram share clock with flash, so user do + not need to configure the clock IO. + For the reference hardware design, please refer to + https://www.espressif.com/sites/default/files/documentation/esp32-pico-d4_datasheet_en.pdf +endmenu + +config ESP32_SPIRAM_SPIWP_SD3_PIN + int "SPI PSRAM WP(SD3) Pin when customising pins via eFuse (read help)" + range 0 33 + default 7 + ---help--- + This value is ignored unless flash mode is set to DIO or DOUT and + the SPI flash pins have been overridden by setting the eFuses + SPI_PAD_CONFIG_xxx. + + When this is the case, the eFuse config only defines 3 of the 4 + Quad I/O data pins. The WP pin (aka ESP32 pin "SD_DATA_3" or SPI + flash pin "IO2") is not specified in eFuse. And the psram only + has QPI mode, the WP pin is necessary, so we need to configure + this value here. + + When flash mode is set to QIO or QOUT, the PSRAM WP pin will be + set as the value configured in bootloader. + + For ESP32-PICO chip, the default value of this config should be 7. + +endif # ESP32_PSRAM + +endif # ARCH_BOARD_ESP32_PICO_KIT diff --git a/boards/xtensa/esp32/esp32-pico-kit/configs/nsh/defconfig b/boards/xtensa/esp32/esp32-pico-kit/configs/nsh/defconfig new file mode 100644 index 00000000000..d0e2d698d79 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/configs/nsh/defconfig @@ -0,0 +1,43 @@ +# +# 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_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32-pico-kit" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32_PICO_KIT=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_CHIP_ESP32PICOD4=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=3 +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32/esp32-pico-kit/include/board.h b/boards/xtensa/esp32/esp32-pico-kit/include/board.h new file mode 100644 index 00000000000..dd9c5a8411a --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/include/board.h @@ -0,0 +1,52 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/include/board.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_H +#define __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Clocking *****************************************************************/ + +/* The ESP32-Pico-Kit board is fitted with a 40MHz crystal */ + +# define BOARD_XTAL_FREQUENCY 40000000 + +#ifdef CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ +# define BOARD_CLOCK_FREQUENCY (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000) +#else +# define BOARD_CLOCK_FREQUENCY 80000000 +#endif + +/* LED definitions **********************************************************/ + +/* Define how many LEDs this board has (needed by userleds) */ + +#define BOARD_NLEDS 1 + +/* GPIO pins used by the GPIO Subsystem */ + +#define BOARD_NGPIOOUT 1 /* Amount of GPIO Output pins */ +#define BOARD_NGPIOIN 1 /* Amount of GPIO Input without Interruption */ +#define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_H */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/include/board_memorymap.h b/boards/xtensa/esp32/esp32-pico-kit/include/board_memorymap.h new file mode 100644 index 00000000000..ede920b4261 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/include/board_memorymap.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)__kirom_start +#define KIROM_SIZE (uintptr_t)__kirom_size +#define KDROM_START (uintptr_t)__kdrom_start +#define KDROM_SIZE (uintptr_t)__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)__kiram_0_size +#define KIRAM_0_END (uintptr_t)__kiram_0_end +#define KIRAM_1_START (uintptr_t)__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)__kiram_1_size +#define KIRAM_1_END (uintptr_t)__kiram_1_end +#define KDRAM_0_START (uintptr_t)__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)__kdram_0_size +#define KDRAM_0_END (uintptr_t)__kdram_0_end +#define KDRAM_1_START (uintptr_t)__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)__kdram_1_size +#define KDRAM_1_END (uintptr_t)__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)__vectors_start +#define VECTORS_END (uintptr_t)__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)__uirom_start +#define UIROM_SIZE (uintptr_t)__uirom_size +#define UIROM_END (uintptr_t)__uirom_end +#define UDROM_START (uintptr_t)__udrom_start +#define UDROM_SIZE (uintptr_t)__udrom_size +#define UDROM_END (uintptr_t)__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)__uiram_start +#define UIRAM_SIZE (uintptr_t)__uiram_size +#define UIRAM_END (uintptr_t)__uiram_end +#define UDRAM_START (uintptr_t)__udram_start +#define UDRAM_SIZE (uintptr_t)__udram_size +#define UDRAM_END (uintptr_t)__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uint8_t __kirom_start[]; +extern uint8_t __kirom_size[]; +extern uint8_t __kdrom_start[]; +extern uint8_t __kdrom_size[]; + +/* Kernel RAM (RW) */ + +extern uint8_t __kiram_0_start[]; +extern uint8_t __kiram_0_size[]; +extern uint8_t __kiram_0_end[]; +extern uint8_t __kiram_1_start[]; +extern uint8_t __kiram_1_size[]; +extern uint8_t __kiram_1_end[]; +extern uint8_t __kdram_0_start[]; +extern uint8_t __kdram_0_size[]; +extern uint8_t __kdram_0_end[]; +extern uint8_t __kdram_1_start[]; +extern uint8_t __kdram_1_size[]; +extern uint8_t __kdram_1_end[]; + +/* Exception vectors */ + +extern uint8_t __vectors_start[]; +extern uint8_t __vectors_end[]; + +/* User ROM (RX) */ + +extern uint8_t __uirom_start[]; +extern uint8_t __uirom_size[]; +extern uint8_t __uirom_end[]; +extern uint8_t __udrom_start[]; +extern uint8_t __udrom_size[]; +extern uint8_t __udrom_end[]; + +/* User RAM (RW) */ + +extern uint8_t __uiram_start[]; +extern uint8_t __uiram_size[]; +extern uint8_t __uiram_end[]; +extern uint8_t __udram_start[]; +extern uint8_t __udram_size[]; +extern uint8_t __udram_end[]; + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs new file mode 100644 index 00000000000..93783a01cc8 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs @@ -0,0 +1,72 @@ +############################################################################ +# boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs +# +# 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. +# +############################################################################ + +include $(TOPDIR)/.config +include $(TOPDIR)/tools/Config.mk +include $(TOPDIR)/tools/esp32/Config.mk +include $(TOPDIR)/arch/xtensa/src/lx6/Toolchain.defs + +ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_rom.ld + +# Pick the linker scripts from the board level if they exist, if not +# pick the common linker scripts. + +ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(call FINDSCRIPT,protected_memory.ld) + ARCHSCRIPT += $(call FINDSCRIPT,kernel-space.ld) +else + ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld) + + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(call FINDSCRIPT,mcuboot_sections.ld) + else + ARCHSCRIPT += $(call FINDSCRIPT,legacy_sections.ld) + endif +endif + +ARCHPICFLAGS = -fpic + +# if SPIRAM/PSRAM is used then we need to include a workaround + +ifeq ($(CONFIG_ESP32_SPIRAM),y) + ARCHCFLAGS += -mfix-esp32-psram-cache-issue +endif + +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) +AFLAGS := $(CFLAGS) -D__ASSEMBLY__ + +# Loadable module definitions + +CMODULEFLAGS = $(CFLAGS) -mtext-section-literals + +LDMODULEFLAGS = -r -e module_initialize +LDMODULEFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld) + +# ELF module definitions + +CELFFLAGS = $(CFLAGS) -mtext-section-literals +CXXELFFLAGS = $(CXXFLAGS) -mtext-section-literals + +LDELFFLAGS = -r -e main +LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libelf$(DELIM)gnu-elf.ld) diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/Make.defs b/boards/xtensa/esp32/esp32-pico-kit/src/Make.defs new file mode 100644 index 00000000000..b772705dbc2 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/Make.defs @@ -0,0 +1,51 @@ +############################################################################ +# boards/xtensa/esp32/esp32-pico-kit/src/Make.defs +# +# 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. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +CSRCS = esp32_boot.c esp32_bringup.c + +ifeq ($(CONFIG_BOARDCTL),y) +CSRCS += esp32_appinit.c +ifeq ($(CONFIG_BOARDCTL_RESET),y) +CSRCS += esp32_reset.c +endif +endif + +ifeq ($(CONFIG_DEV_GPIO),y) +CSRCS += esp32_gpio.c +endif + +ifeq ($(CONFIG_PWM),y) +CSRCS += esp32_ledc.c +endif + +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += esp32_buttons.c +endif + +ifeq ($(CONFIG_ESP32_TWAI),y) +CSRCS += esp32_twai.c +endif + +DEPPATH += --dep-path board +VPATH += :board +CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board) + diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32-pico-kit.h b/boards/xtensa/esp32/esp32-pico-kit/src/esp32-pico-kit.h new file mode 100644 index 00000000000..566f1b03cef --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32-pico-kit.h @@ -0,0 +1,174 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32-pico-kit.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_SRC_ESP32_PICO_KIT_H +#define __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_SRC_ESP32_PICO_KIT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* ESP32-Pico-KitC GPIOs ****************************************************/ + +/* BOOT Button */ + +#define BUTTON_BOOT 0 + +/* LED + * + * This is an externally connected LED used for testing. + */ + +#define GPIO_LED1 2 + +/* PCNT Quadrature Encoder IDs */ + +#define PCNT_QE0_ID 0 + +/* MCP2515 Interrupt pin */ + +#define GPIO_MCP2515_IRQ 22 + +/* TIMERS */ + +#define TIMER0 0 +#define TIMER1 1 +#define TIMER2 2 +#define TIMER3 3 + +/* ONESHOT */ + +#define ONESHOT_TIMER 1 +#define ONESHOT_RESOLUTION_US 1 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y : + * Called from the NSH library via board_app_initialize() + * + ****************************************************************************/ + +int esp32_bringup(void); + +/**************************************************************************** + * Name: esp32_gpio_init + ****************************************************************************/ + +#ifdef CONFIG_DEV_GPIO +int esp32_gpio_init(void); +#endif + +/**************************************************************************** + * Name: esp32_ledc_setup + * + * Description: + * Initialize LEDC PWM and register the PWM device. + * + ****************************************************************************/ + +#ifdef CONFIG_ESP32_LEDC +int esp32_pwm_setup(void); +#endif + +/**************************************************************************** + * Name: board_spidev_initialize + * + * Description: + * Initialize SPI driver and register the /dev/spi device. + * + * Input Parameters: + * bus - The SPI bus number, used to build the device path as /dev/spiN + * + * Returned Value: + * Zero (OK) is returned on success; A negated errno value is returned + * to indicate the nature of any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_SPI_DRIVER +int board_spidev_initialize(int bus); +#endif + +/**************************************************************************** + * Name: esp32_twai_setup + * + * Description: + * Initialize TWAI and register the TWAI device + * + ****************************************************************************/ +#ifdef CONFIG_ESP32_TWAI +int esp32_twai_setup(void); +#endif + +/**************************************************************************** + * Name: board_i2sdev_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the generic I2S audio driver. This function will register + * the driver as /dev/audio/pcm[x] where x is determined by the I2S port + * number. + * + * Input Parameters: + * port - The I2S port used for the device + * enable_tx - Register device as TX if true + * enable_rx - Register device as RX if true + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#if defined(CONFIG_ESP32_I2S0) || defined(CONFIG_ESP32_I2S1) +int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx); +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARDS_XTENSA_ESP32_ESP32_PICO_KIT_SRC_ESP32_PICO_KIT_H */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_appinit.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_appinit.c new file mode 100644 index 00000000000..63da8e5969a --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_appinit.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_appinit.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 "esp32-pico-kit.h" + +#ifdef CONFIG_BOARDCTL + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_app_initialize + * + * Description: + * Perform application specific initialization. This function is never + * called directly from application code, but only indirectly via the + * (non-standard) boardctl() interface using the command BOARDIOC_INIT. + * + * Input Parameters: + * arg - The boardctl() argument is passed to the board_app_initialize() + * implementation without modification. The argument has no + * meaning to NuttX; the meaning of the argument is a contract + * between the board-specific initialization logic and the + * matching application logic. The value could be such things as a + * mode enumeration value, a set of DIP switch settings, a + * pointer to configuration data read from a file or serial FLASH, + * or whatever you would like to do with it. Every implementation + * should accept zero/NULL as a default configuration. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure to indicate the nature of the failure. + * + ****************************************************************************/ + +int board_app_initialize(uintptr_t arg) +{ +#ifdef CONFIG_BOARD_LATE_INITIALIZE + /* Board initialization already performed by board_late_initialize() */ + + return OK; +#else + /* Perform board-specific initialization */ + + return esp32_bringup(); +#endif +} + +#endif /* CONFIG_BOARDCTL */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_boot.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_boot.c new file mode 100644 index 00000000000..6d1ae79200a --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_boot.c @@ -0,0 +1,96 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_boot.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 "esp32-pico-kit.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_board_initialize + * + * Description: + * All ESP32 architectures must provide the following entry point. + * This entry point is called early in the initialization -- after all + * memory has been configured and mapped but before any devices have been + * initialized. + * + ****************************************************************************/ + +void esp32_board_initialize(void) +{ +} + +/**************************************************************************** + * Name: board_late_initialize + * + * Description: + * If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional + * initialization call will be performed in the boot-up sequence to a + * function called board_late_initialize(). board_late_initialize() will + * be called immediately after up_initialize() is called and just before + * the initial application is started. This additional initialization + * phase may be used, for example, to initialize board-specific device + * drivers. + * + ****************************************************************************/ + +#ifdef CONFIG_BOARD_LATE_INITIALIZE +void board_late_initialize(void) +{ + /* Perform board-specific initialization */ + + esp32_bringup(); + +#ifdef CONFIG_SMP + /* To avoid corrupting the heap, this region of memory (~3KB) is not + * included until the APP CPU has started. + * So we can't add it with the rest of the regions at xtensa_add_region(), + * that function is called early from up_initialize(). We wait until the + * SMP bringup is complete. + */ + + umm_addregion((void *)HEAP_REGION_ROMAPP_START, + (size_t)(HEAP_REGION_ROMAPP_END - HEAP_REGION_ROMAPP_START)); +#endif +} +#endif diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_bringup.c new file mode 100644 index 00000000000..9e72264bfb5 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_bringup.c @@ -0,0 +1,459 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_bringup.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 +#include +#include +#include + +#include +#if defined(CONFIG_ESP32_EFUSE) +#include +#endif +#include +#include + +#if defined(CONFIG_ESP32_EFUSE) +#include "esp32_efuse.h" +#endif +#include "esp32_partition.h" + +#ifdef CONFIG_TIMER +#include +#endif + +#ifdef CONFIG_ONESHOT +# include "esp32_board_oneshot.h" +#endif + +#ifdef CONFIG_WATCHDOG +# include "esp32_board_wdt.h" +#endif + +#ifdef CONFIG_ESP32_SPIFLASH +# include "esp32_board_spiflash.h" +#endif + +#ifdef CONFIG_ESP32_BLE +# include "esp32_ble.h" +#endif + +#ifdef CONFIG_ESP32_WIFI +# include "esp32_board_wlan.h" +#endif + +#ifdef CONFIG_ESP32_WIFI_BT_COEXIST +# include "esp32_wifi_adapter.h" +#endif + +#ifdef CONFIG_ESP32_I2C +# include "esp32_board_i2c.h" +#endif + +#ifdef CONFIG_ESP32_I2S +# include "esp32_i2s.h" +#endif + +#ifdef CONFIG_ESP32_AES_ACCELERATOR +# include "esp32_aes.h" +#endif + +#ifdef CONFIG_ESP32_RT_TIMER +# include "esp32_rt_timer.h" +#endif + +#ifdef CONFIG_INPUT_BUTTONS +# include +#endif + +#ifdef CONFIG_RTC_DRIVER +# include "esp32_rtc_lowerhalf.h" +#endif + +#ifdef CONFIG_SPI_DRIVER +# include "esp32_spi.h" +#endif + +#include "esp32-pico-kit.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_bringup + * + * Description: + * Perform architecture-specific initialization + * + * CONFIG_BOARD_LATE_INITIALIZE=y : + * Called from board_late_initialize(). + * + * CONFIG_BOARD_LATE_INITIALIZE=n && CONFIG_BOARDCTL=y : + * Called from the NSH library + * + ****************************************************************************/ + +int esp32_bringup(void) +{ + int ret; + +#ifdef CONFIG_ESP32_AES_ACCELERATOR + ret = esp32_aes_init(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize AES: %d\n", ret); + } +#endif + +#if defined(CONFIG_ESP32_SPIRAM) && \ + defined(CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE) + ret = esp_himem_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to init HIMEM: %d\n", ret); + } +#endif + +#if defined(CONFIG_ESP32_EFUSE) + ret = esp32_efuse_initialize("/dev/efuse"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to init EFUSE: %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_PROCFS + /* Mount the procfs file system */ + + ret = nx_mount(NULL, "/proc", "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount procfs at /proc: %d\n", ret); + } +#endif + +#ifdef CONFIG_LCD_BACKPACK + /* slcd:0, i2c:0, rows=2, cols=16 */ + + ret = board_lcd_backpack_init(0, 0, 2, 16); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize PCF8574 LCD, error %d\n", ret); + } +#endif + +#ifdef CONFIG_FS_TMPFS + /* Mount the tmpfs file system */ + + ret = nx_mount(NULL, CONFIG_LIBC_TMPDIR, "tmpfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount tmpfs at %s: %d\n", + CONFIG_LIBC_TMPDIR, ret); + } +#endif + +#ifdef CONFIG_ESP32_SPIFLASH + ret = esp32_spiflash_init(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize SPI Flash\n"); + } +#endif + +#ifdef CONFIG_ESP32_PARTITION_TABLE + ret = esp32_partition_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize partition error=%d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_LEDC + ret = esp32_pwm_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: esp32_pwm_setup() failed: %d\n", ret); + } +#endif /* CONFIG_ESP32_LEDC */ + +#ifdef CONFIG_ESP32_TWAI + + /* Initialize TWAI and register the TWAI driver. */ + + ret = esp32_twai_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: esp32_twai_setup failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_RT_TIMER + ret = esp32_rt_timer_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize RT timer: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_WIFI_BT_COEXIST + ret = esp32_wifi_bt_coexist_init(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize Wi-Fi and BT " + "coexistence support\n"); + } +#endif + +#ifdef CONFIG_ESP32_BLE + ret = esp32_ble_initialize(); + if (ret) + { + syslog(LOG_ERR, "ERROR: Failed to initialize BLE: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_WIFI + ret = board_wlan_init(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to initialize wireless subsystem=%d\n", + ret); + } +#endif + +/* First, register the timer drivers and let timer 1 for oneshot + * if it is enabled. + */ + +#ifdef CONFIG_TIMER + +#if defined(CONFIG_ESP32_TIMER0) && !defined(CONFIG_ESP32_RT_TIMER) + ret = esp32_timer_initialize("/dev/timer0", TIMER0); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT) + ret = esp32_timer_initialize("/dev/timer1", TIMER1); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_TIMER2 + ret = esp32_timer_initialize("/dev/timer2", TIMER2); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#ifdef CONFIG_ESP32_TIMER3 + ret = esp32_timer_initialize("/dev/timer3", TIMER3); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize timer driver: %d\n", + ret); + } +#endif + +#endif /* CONFIG_TIMER */ + + /* Now register one oneshot driver */ + +#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32_TIMER1) + + ret = esp32_oneshot_init(ONESHOT_TIMER, ONESHOT_RESOLUTION_US); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: esp32_oneshot_init() failed: %d\n", ret); + } + +#endif /* CONFIG_ONESHOT */ + +#ifdef CONFIG_WATCHDOG + /* Configure watchdog timer */ + + ret = board_wdt_init(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to initialize watchdog drivers: %d\n", + ret); + } +#endif + +#ifdef CONFIG_DEV_GPIO + ret = esp32_gpio_init(); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret); + } +#endif + +#ifdef CONFIG_I2C_DRIVER + +#ifdef CONFIG_ESP32_I2C0 + ret = esp32_i2c_register(0); + + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2C Driver for I2C0: %d\n", ret); + } +#endif + +#ifdef CONFIG_ESP32_I2C1 + ret = esp32_i2c_register(1); + + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2C Driver for I2C1: %d\n", ret); + } +#endif + +#endif + +#ifdef CONFIG_ESP32_I2S + +#if defined(CONFIG_ESP32_I2S0) && || defined(CONFIG_ESP32_I2S1) + bool i2s_enable_tx; + bool i2s_enable_rx; +#endif + +#ifdef CONFIG_ESP32_I2S0 + + /* Configure I2S0 */ + +#ifdef CONFIG_ESP32_I2S0_TX + i2s_enable_tx = true; +#else + i2s_enable_tx = false; +#endif /* CONFIG_ESP32_I2S0_TX */ + +#ifdef CONFIG_ESP32_I2S0_RX + i2s_enable_rx = true; +#else + i2s_enable_rx = false; +#endif /* CONFIG_ESP32_I2S0_RX */ + + /* Configure I2S generic audio on I2S0 */ + + ret = board_i2sdev_initialize(ESP32_I2S0, i2s_enable_tx, i2s_enable_rx); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2S%d driver: %d\n", + CONFIG_ESP32_I2S0, ret); + } + +#endif /* CONFIG_ESP32_I2S0 */ + +#ifdef CONFIG_ESP32_I2S1 + +#ifdef CONFIG_ESP32_I2S1_TX + i2s_enable_tx = true; +#else + i2s_enable_tx = false; +#endif /* CONFIG_ESP32_I2S1_TX */ + +#ifdef CONFIG_ESP32_I2S1_RX + i2s_enable_rx = true; +#else + i2s_enable_rx = false; +#endif /* CONFIG_ESP32_I2S1_RX */ + + /* Configure I2S generic audio on I2S1 */ + + ret = board_i2sdev_initialize(ESP32_I2S1, i2s_enable_tx, i2s_enable_rx); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize I2S%d driver: %d\n", + CONFIG_ESP32_I2S1, ret); + } + +#endif /* CONFIG_ESP32_I2S1 */ + +#endif /* CONFIG_ESP32_I2S */ + +#ifdef CONFIG_INPUT_BUTTONS + /* Register the BUTTON driver */ + + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + +#ifdef CONFIG_RTC_DRIVER + /* Instantiate the ESP32 RTC driver */ + + ret = esp32_rtc_driverinit(); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to Instantiate the RTC driver: %d\n", ret); + } +#endif + +#ifdef CONFIG_SPI_DRIVER +# ifdef CONFIG_ESP32_SPI2 + ret = board_spidev_initialize(ESP32_SPI2); + if (ret < 0) + { + syslog(LOG_ERR, "Failed to initialize SPI%d driver: %d\n", + ESP32_SPI2, ret); + } +# endif +#endif + + /* If we got here then perhaps not all initialization was successful, but + * at least enough succeeded to bring-up NSH with perhaps reduced + * capabilities. + */ + + UNUSED(ret); + return OK; +} diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_buttons.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_buttons.c new file mode 100644 index 00000000000..c96619899f7 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_buttons.c @@ -0,0 +1,166 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_buttons.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 +#include +#include + +#include "esp32_gpio.h" + +#include "esp32-pico-kit.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + esp32_configgpio(BUTTON_BOOT, INPUT_FUNCTION_3 | PULLUP); + return 1; +} + +/**************************************************************************** + * Name: board_buttons + * + * Description: + * After board_button_initialize() has been called, board_buttons() may be + * called to collect the state of all buttons. board_buttons() returns an + * 8-bit bit set with each bit associated with a button. See the + * BUTTON_*_BIT definitions in board.h for the meaning of each bit. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint8_t ret = 0; + int i = 0; + int n = 0; + + bool b0 = esp32_gpioread(BUTTON_BOOT); + + for (i = 0; i < 10; i++) + { + up_mdelay(1); /* TODO */ + + bool b1 = esp32_gpioread(BUTTON_BOOT); + + if (b0 == b1) + { + n++; + } + else + { + n = 0; + } + + if (3 == n) + { + break; + } + + b0 = b1; + } + + iinfo("b=%d n=%d\n", b0, n); + + /* Low value means that the button is pressed */ + + if (!b0) + { + ret = 0x1; + } + + return ret; +} + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * board_button_irq() may be called to register an interrupt handler that + * will be called when a button is depressed or released. The ID value is + * a button enumeration value that uniquely identifies a button resource. + * See the BUTTON_* definitions in board.h for the meaning of enumeration + * value. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + int ret; + DEBUGASSERT(id == 0); + + int irq = ESP32_PIN2IRQ(BUTTON_BOOT); + + if (NULL != irqhandler) + { + /* Make sure the interrupt is disabled */ + + esp32_gpioirqdisable(irq); + + ret = irq_attach(irq, irqhandler, arg); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: irq_attach() failed: %d\n", ret); + return ret; + } + + gpioinfo("Attach %p\n", irqhandler); + + gpioinfo("Enabling the interrupt\n"); + + /* Configure the interrupt for rising and falling edges */ + + esp32_gpioirqenable(irq, CHANGE); + } + else + { + gpioinfo("Disable the interrupt\n"); + esp32_gpioirqdisable(irq); + } + + return OK; +} +#endif diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_gpio.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_gpio.c new file mode 100644 index 00000000000..48c33a3eee0 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_gpio.c @@ -0,0 +1,391 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_gpio.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 + +#include "esp32-pico-kit.h" +#include "esp32_gpio.h" +#include "hardware/esp32_gpio_sigmap.h" + +#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if !defined(CONFIG_ESP32_GPIO_IRQ) && BOARD_NGPIOINT > 0 +# error "NGPIOINT is > 0 and GPIO interrupts aren't enabled" +#endif + +/* Output pins. GPIO15 is used as an example, any other outputs could be + * used. + */ + +#define GPIO_OUT1 15 + +/* Input pins. GPIO18 is used as an example, any other inputs could be + * used. + */ + +#define GPIO_IN1 18 + +/* Interrupt pins. GPIO22 is used as an example, any other inputs could be + * used. + */ + +#define GPIO_IRQPIN1 22 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct esp32gpio_dev_s +{ + struct gpio_dev_s gpio; + uint8_t id; +}; + +struct esp32gpint_dev_s +{ + struct esp32gpio_dev_s esp32gpio; + pin_interrupt_t callback; +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value); +static int gpout_write(struct gpio_dev_s *dev, bool value); +#endif + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value); +#endif + +#if BOARD_NGPIOINT > 0 +static int gpint_read(struct gpio_dev_s *dev, bool *value); +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback); +static int gpint_enable(struct gpio_dev_s *dev, bool enable); +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static const struct gpio_operations_s gpout_ops = +{ + .go_read = gpout_read, + .go_write = gpout_write, + .go_attach = NULL, + .go_enable = NULL, +}; + +/* This array maps the GPIO pins used as OUTPUT */ + +static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] = +{ + GPIO_OUT1 +}; + +static struct esp32gpio_dev_s g_gpout[BOARD_NGPIOOUT]; +#endif + +#if BOARD_NGPIOIN > 0 +static const struct gpio_operations_s gpin_ops = +{ + .go_read = gpin_read, + .go_write = NULL, + .go_attach = NULL, + .go_enable = NULL, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpioinputs[BOARD_NGPIOIN] = +{ + GPIO_IN1 +}; + +static struct esp32gpio_dev_s g_gpin[BOARD_NGPIOIN]; +#endif + +#if BOARD_NGPIOINT > 0 +static const struct gpio_operations_s gpint_ops = +{ + .go_read = gpint_read, + .go_write = NULL, + .go_attach = gpint_attach, + .go_enable = gpint_enable, +}; + +/* This array maps the GPIO pins used as INTERRUPT INPUTS */ + +static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] = +{ + GPIO_IRQPIN1, +}; + +static struct esp32gpint_dev_s g_gpint[BOARD_NGPIOINT]; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: gpout_read + ****************************************************************************/ + +#if BOARD_NGPIOOUT > 0 +static int gpout_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL && value != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Reading...\n"); + + *value = esp32_gpioread(g_gpiooutputs[esp32gpio->id]); + return OK; +} + +/**************************************************************************** + * Name: gpout_write + ****************************************************************************/ + +static int gpout_write(struct gpio_dev_s *dev, bool value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOOUT); + gpioinfo("Writing %d\n", (int)value); + + esp32_gpiowrite(g_gpiooutputs[esp32gpio->id], value); + return OK; +} +#endif + +/**************************************************************************** + * Name: gpin_read + ****************************************************************************/ + +#if BOARD_NGPIOIN > 0 +static int gpin_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpio_dev_s *esp32gpio = (struct esp32gpio_dev_s *)dev; + + DEBUGASSERT(esp32gpio != NULL && value != NULL); + DEBUGASSERT(esp32gpio->id < BOARD_NGPIOIN); + gpioinfo("Reading... pin %d\n", g_gpioinputs[esp32gpio->id]); + + *value = esp32_gpioread(g_gpioinputs[esp32gpio->id]); + return OK; +} +#endif + +/**************************************************************************** + * Name: esp32gpio_interrupt + ****************************************************************************/ + +#if BOARD_NGPIOINT > 0 +static int esp32gpio_interrupt(int irq, void *context, void *arg) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)arg; + + DEBUGASSERT(esp32gpint != NULL && esp32gpint->callback != NULL); + gpioinfo("Interrupt! callback=%p\n", esp32gpint->callback); + + esp32gpint->callback(&esp32gpint->esp32gpio.gpio, + esp32gpint->esp32gpio.id); + return OK; +} + +/**************************************************************************** + * Name: gpint_read + ****************************************************************************/ + +static int gpint_read(struct gpio_dev_s *dev, bool *value) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + + DEBUGASSERT(esp32gpint != NULL && value != NULL); + DEBUGASSERT(esp32gpint->esp32gpio.id < BOARD_NGPIOINT); + gpioinfo("Reading int pin...\n"); + + *value = esp32_gpioread(g_gpiointinputs[esp32gpint->esp32gpio.id]); + return OK; +} + +/**************************************************************************** + * Name: gpint_attach + ****************************************************************************/ + +static int gpint_attach(struct gpio_dev_s *dev, + pin_interrupt_t callback) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + int irq = ESP32_PIN2IRQ(g_gpiointinputs[esp32gpint->esp32gpio.id]); + int ret; + + gpioinfo("Attaching the callback\n"); + + /* Make sure the interrupt is disabled */ + + esp32_gpioirqdisable(irq); + ret = irq_attach(irq, + esp32gpio_interrupt, + &g_gpint[esp32gpint->esp32gpio.id]); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: gpint_attach() failed: %d\n", ret); + return ret; + } + + gpioinfo("Attach %p\n", callback); + esp32gpint->callback = callback; + return OK; +} + +/**************************************************************************** + * Name: gpint_enable + ****************************************************************************/ + +static int gpint_enable(struct gpio_dev_s *dev, bool enable) +{ + struct esp32gpint_dev_s *esp32gpint = + (struct esp32gpint_dev_s *)dev; + int irq = ESP32_PIN2IRQ(g_gpiointinputs[esp32gpint->esp32gpio.id]); + + if (enable) + { + if (esp32gpint->callback != NULL) + { + gpioinfo("Enabling the interrupt\n"); + + /* Configure the interrupt for rising edge */ + + esp32_gpioirqenable(irq, RISING); + } + } + else + { + gpioinfo("Disable the interrupt\n"); + esp32_gpioirqdisable(irq); + } + + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_gpio_init + ****************************************************************************/ + +int esp32_gpio_init(void) +{ + int pincount = 0; + int i; + +#if BOARD_NGPIOOUT > 0 + for (i = 0; i < BOARD_NGPIOOUT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN; + g_gpout[i].gpio.gp_ops = &gpout_ops; + g_gpout[i].id = i; + gpio_pin_register(&g_gpout[i].gpio, pincount); + + /* Configure the pins that will be used as output */ + + esp32_gpio_matrix_out(g_gpiooutputs[i], SIG_GPIO_OUT_IDX, 0, 0); + esp32_configgpio(g_gpiooutputs[i], OUTPUT_FUNCTION_3 | + INPUT_FUNCTION_3); + esp32_gpiowrite(g_gpiooutputs[i], 0); + + pincount++; + } +#endif + +#if BOARD_NGPIOIN > 0 + for (i = 0; i < BOARD_NGPIOIN; i++) + { + /* Setup and register the GPIO pin */ + + g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN; + g_gpin[i].gpio.gp_ops = &gpin_ops; + g_gpin[i].id = i; + gpio_pin_register(&g_gpin[i].gpio, pincount); + + /* Configure the pins that will be used as INPUT */ + + esp32_configgpio(g_gpioinputs[i], INPUT_FUNCTION_3); + + pincount++; + } +#endif + +#if BOARD_NGPIOINT > 0 + for (i = 0; i < BOARD_NGPIOINT; i++) + { + /* Setup and register the GPIO pin */ + + g_gpint[i].esp32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN; + g_gpint[i].esp32gpio.gpio.gp_ops = &gpint_ops; + g_gpint[i].esp32gpio.id = i; + gpio_pin_register(&g_gpint[i].esp32gpio.gpio, pincount); + + /* Configure the pins that will be used as interrupt input */ + + esp32_configgpio(g_gpiointinputs[i], INPUT_FUNCTION_3 | PULLDOWN); + + pincount++; + } +#endif + + return OK; +} +#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_ledc.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_ledc.c new file mode 100644 index 00000000000..f6f0fbc4da5 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_ledc.c @@ -0,0 +1,134 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_ledc.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 "esp32_ledc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_pwm_setup + * + * Description: + * Initialize LEDC PWM and register the PWM device. + * + ****************************************************************************/ + +int esp32_pwm_setup(void) +{ + int ret; + struct pwm_lowerhalf_s *pwm; + +#ifdef CONFIG_ESP32_LEDC_TIM0 + pwm = esp32_ledc_init(0); + if (!pwm) + { + syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 0 lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm0" */ + + ret = pwm_register("/dev/pwm0", pwm); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_ESP32_LEDC_TIM1 + pwm = esp32_ledc_init(1); + if (!pwm) + { + syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 1 lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm1" */ + + ret = pwm_register("/dev/pwm1", pwm); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_ESP32_LEDC_TIM2 + pwm = esp32_ledc_init(2); + if (!pwm) + { + syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 2 lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm2" */ + + ret = pwm_register("/dev/pwm2", pwm); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_ESP32_LEDC_TIM3 + pwm = esp32_ledc_init(3); + if (!pwm) + { + syslog(LOG_ERR, "ERROR: Failed to get the LEDC PWM 3 lower half\n"); + return -ENODEV; + } + + /* Register the PWM driver at "/dev/pwm3" */ + + ret = pwm_register("/dev/pwm3", pwm); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: pwm_register failed: %d\n", ret); + return ret; + } +#endif + + return OK; +} + diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_reset.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_reset.c new file mode 100644 index 00000000000..7c6e105c273 --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_reset.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_reset.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 "esp32_systemreset.h" + +#ifdef CONFIG_BOARDCTL_RESET + +#if CONFIG_BOARD_ASSERT_RESET_VALUE == EXIT_SUCCESS +# error "CONFIG_BOARD_ASSERT_RESET_VALUE must not be equal to EXIT_SUCCESS" +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_reset + * + * Description: + * Reset board. Support for this function is required by board-level + * logic if CONFIG_BOARDCTL_RESET is selected. + * + * Input Parameters: + * status - Status information provided with the reset event. This + * meaning of this status information is board-specific. If not + * used by a board, the value zero may be provided in calls to + * board_reset(). + * + * Returned Value: + * If this function returns, then it was not possible to power-off the + * board due to some constraints. The return value in this case is a + * board-specific reason for the failure to shutdown. + * + ****************************************************************************/ + +int board_reset(int status) +{ + syslog(LOG_INFO, "reboot status=%d\n", status); + + switch (status) + { + case EXIT_SUCCESS: + up_shutdown_handler(); + break; + + case CONFIG_BOARD_ASSERT_RESET_VALUE: + break; + + default: + break; + } + + up_systemreset(); + + return 0; +} + +#endif /* CONFIG_BOARDCTL_RESET */ diff --git a/boards/xtensa/esp32/esp32-pico-kit/src/esp32_twai.c b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_twai.c new file mode 100644 index 00000000000..4c813c5ba2a --- /dev/null +++ b/boards/xtensa/esp32/esp32-pico-kit/src/esp32_twai.c @@ -0,0 +1,92 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-pico-kit/src/esp32_twai.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 "chip.h" + +#include "esp32_twai.h" +#include "esp32-pico-kit.h" + +#ifdef CONFIG_CAN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#define TWAI_PORT0 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_twai_setup + * + * Description: + * Initialize TWAI and register the TWAI device + * + ****************************************************************************/ + +int esp32_twai_setup(void) +{ +#ifdef CONFIG_ESP32_TWAI0 + struct can_dev_s *twai; + int ret; + + /* Call esp32_twaiinitialize() to get an instance of the TWAI0 + * interface + * */ + + twai = esp32_twaiinitialize(TWAI_PORT0); + if (twai == NULL) + { + canerr("ERROR: Failed to get TWAI0 interface\n"); + return -ENODEV; + } + + /* Register the TWAI0 driver at "/dev/can0" */ + + ret = can_register("/dev/can0", twai); + if (ret < 0) + { + canerr("ERROR: TWAI1 register failed: %d\n", ret); + return ret; + } + + return OK; +#else + return -ENODEV; +#endif +} + +#endif /* CONFIG_CAN */