You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/07/30 20:07:31 UTC

[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1491: xtensa/esp32: Add SPI Flash device driver

Ouss4 commented on a change in pull request #1491:
URL: https://github.com/apache/incubator-nuttx/pull/1491#discussion_r463237748



##########
File path: arch/xtensa/src/esp32/esp32_spiflash.c
##########
@@ -0,0 +1,1194 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spiflash.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 <nuttx/config.h>
+
+#ifdef CONFIG_ESP32_SPIFLASH
+
+#include <stdint.h>
+#include <debug.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/errno.h>
+
+#include <nuttx/mtd/mtd.h>
+
+#include "xtensa.h"
+#include "hardware/esp32_spi.h"
+#include "rom/esp32_spiflash.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define SPI_FLASH_WRITE_BUF_SIZE    (32)
+#define SPI_FLASH_READ_BUF_SIZE     (64)
+
+#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
+#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
+
+#define MTD2PRIV(_dev)              ((FAR struct esp32_spiflash_s *)_dev)
+#define MTD_SIZE(_priv)             ((_priv)->chip->chip_size)
+#define MTD_BLKSIZE(_priv)          ((_priv)->chip->page_size)
+#define MTD_ERASESIZE(_priv)        ((_priv)->chip->sector_size)
+#define MTD_BLK2SIZE(_priv, _b)     (MTD_BLKSIZE(_priv) * (_b))
+#define MTD_SIZE2BLK(_priv, _s)     ((_s) / MTD_BLKSIZE(_priv))
+
+#ifndef MIN
+#  define  MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Flash device hardware configuration */
+
+struct esp32_spiflash_config_s
+{
+  /* SPI register base address */
+
+  uint32_t reg_base;
+};
+
+/* SPI Flash device private data  */
+
+struct esp32_spiflash_s
+{
+  struct mtd_dev_s mtd;
+
+  /* Port configuration */
+
+  const struct esp32_spiflash_config_s *config;
+
+  /* SPI Flash data */
+
+  esp32_spiflash_chip_t *chip;
+
+  /* SPI Flash communication dummy number */
+
+  uint8_t *dummies;
+};
+
+/****************************************************************************
+ * Private Functions Prototypes
+ ****************************************************************************/
+
+static int esp32_erase(FAR struct mtd_dev_s *dev, off_t startblock,
+                       size_t nblocks);
+
+static ssize_t esp32_read(FAR struct mtd_dev_s *dev, off_t offset,
+                          size_t nbytes, FAR uint8_t *buffer);
+
+static ssize_t esp32_bread(FAR struct mtd_dev_s *dev, off_t startblock,
+                           size_t nblocks, FAR uint8_t *buffer);
+
+static ssize_t esp32_write(FAR struct mtd_dev_s *dev, off_t offset,
+                           size_t nbytes, FAR const uint8_t *buffer);
+
+static ssize_t esp32_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
+                            size_t nblocks, FAR const uint8_t *buffer);
+
+static int esp32_ioctl(FAR struct mtd_dev_s *dev, int cmd,
+                       unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct esp32_spiflash_config_s s_esp32_spiflash1_config =
+{
+  .reg_base = REG_SPI_BASE(1)
+};
+
+static struct esp32_spiflash_s s_esp32_spiflash1 =
+{
+  .mtd =
+          {
+            .erase  = esp32_erase,
+            .bread  = esp32_bread,
+            .bwrite = esp32_bwrite,
+            .read   = esp32_read,
+            .ioctl  = esp32_ioctl,
+#if defined(CONFIG_MTD_BYTE_WRITE) && !defined(CONFIG_W25_READONLY)

Review comment:
       ```suggestion
   #if defined(CONFIG_MTD_BYTE_WRITE)
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org