diff --git a/boards/arm/stm32f7/stm32f746g-disco/Kconfig b/boards/arm/stm32f7/stm32f746g-disco/Kconfig index 15c51d8a03e..3621e4f00c5 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/Kconfig +++ b/boards/arm/stm32f7/stm32f746g-disco/Kconfig @@ -16,6 +16,19 @@ config STM32F746GDISCO_FLASH select MTD_BYTE_WRITE ---help--- Configures an MTD device for use with the onboard flash + Micron N25Q. + +config STM32F746GDISCO_FLASH_WINBOND + bool "MTD driver for external 16Mbyte W25Q128JVEQ FLASH on QSPI port" + default n + select MTD + select MTD_W25QXXXJV + select FS_NXFFS + select STM32_QSPI + ---help--- + Configures an MTD device for use with the onboard flash + Winbond W25Q. Set CONFIG_W25QXXXJV_QSPI_FREQUENCY to + 100MHz for correct operation. config STM32F746GDISCO_TOUCHSCREEN_SWAPXY bool "STM32F746G DISCO Touchscreen sway X/Y" diff --git a/boards/arm/stm32f7/stm32f746g-disco/include/board.h b/boards/arm/stm32f7/stm32f746g-disco/include/board.h index f9e4afa5372..c6c51607584 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/include/board.h +++ b/boards/arm/stm32f7/stm32f746g-disco/include/board.h @@ -519,12 +519,12 @@ /* QSPI pinset */ -#define GPIO_QSPI_CS (GPIO_QUADSPI_BK1_NCS|GPIO_SPEED_100MHz) +#define GPIO_QSPI_CS (GPIO_QUADSPI_BK1_NCS_0|GPIO_SPEED_100MHz) #define GPIO_QSPI_IO0 (GPIO_QUADSPI_BK1_IO0_3|GPIO_SPEED_100MHz) #define GPIO_QSPI_IO1 (GPIO_QUADSPI_BK1_IO1_3|GPIO_SPEED_100MHz) #define GPIO_QSPI_IO2 (GPIO_QUADSPI_BK1_IO2_1|GPIO_SPEED_100MHz) #define GPIO_QSPI_IO3 (GPIO_QUADSPI_BK1_IO3_2|GPIO_SPEED_100MHz) -#define GPIO_QSPI_SCK (GPIO_QUADSPI_CLK|GPIO_SPEED_100MHz) +#define GPIO_QSPI_SCK (GPIO_QUADSPI_CLK_0|GPIO_SPEED_100MHz) /* SAI2 pinset */ diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/Make.defs b/boards/arm/stm32f7/stm32f746g-disco/src/Make.defs index bfa456fb8a5..5618415d85f 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/src/Make.defs +++ b/boards/arm/stm32f7/stm32f746g-disco/src/Make.defs @@ -58,6 +58,10 @@ ifeq ($(CONFIG_MTD_N25QXXX),y) CSRCS += stm32_n25q.c endif +ifeq ($(CONFIG_MTD_W25QXXXJV),y) +CSRCS += stm32_w25q.c +endif + ifeq ($(CONFIG_STM32_OTGFS),y) CSRCS += stm32_usb.c else ifeq ($(CONFIG_STM32_OTGFSHS),y) diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c index 3773c61a101..6b7e4767f0f 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c +++ b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_bringup.c @@ -138,6 +138,14 @@ int stm32_bringup(void) } #endif +#ifdef CONFIG_MTD_W25QXXXJV + ret = stm32_w25qxxx_setup(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: stm32_w25qxxx_setup failed: %d\n", ret); + } +#endif + #ifdef HAVE_SDIO ret = stm32_sdio_initialize(); if (ret < 0) diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/stm32_w25q.c b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_w25q.c new file mode 100644 index 00000000000..7ea9a654c0f --- /dev/null +++ b/boards/arm/stm32f7/stm32f746g-disco/src/stm32_w25q.c @@ -0,0 +1,140 @@ +/**************************************************************************** + * boards/arm/stm32f7/stm32f746g-disco/src/stm32_w25q.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 + +#include +#include +#include + +#ifdef CONFIG_FS_NXFFS +#include +#endif + +#ifdef CONFIG_FS_SMARTFS +#include +#endif + +#include "stm32f746g-disco.h" + +#include "stm32_qspi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: stm32_w25qxxx_setup + * + * Description: + * This function is called by board-bringup logic to configure the + * flash device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int stm32_w25qxxx_setup(void) +{ + struct qspi_dev_s *qspi_dev; + struct mtd_dev_s *mtd_dev; + int ret = -1; + + qspi_dev = stm32_qspi_initialize(0); + if (!qspi_dev) + { + _err("ERROR: Failed to initialize W25 minor %d: %d\n", + 0, ret); + return -1; + } + + mtd_dev = w25qxxxjv_initialize(qspi_dev, true); + if (!mtd_dev) + { + _err("ERROR: w25qxxxjv_initialize() failed!\n"); + return -1; + } + +#if defined(CONFIG_FS_NXFFS) && !defined(CONFIG_FS_LITTLEFS) + /* Initialize to provide NXFFS on the W25QXXX MTD interface */ + + ret = nxffs_initialize(mtd_dev); + if (ret < 0) + { + _err("ERROR: NXFFS initialization failed: %d\n", ret); + return ret; + } + + ret = nx_mount(NULL, "/w25", "nxffs", 0, "autoformat"); + if (ret < 0) + { + _err("ERROR: Failed to mount the NXFFS volume: %d\n", ret); + return ret; + } + +#endif + +#if !defined(CONFIG_FS_NXFFS) && defined(CONFIG_FS_LITTLEFS) + /* Register the MTD driver so that it can be accessed from the + * VFS. + */ + + ret = register_mtddriver("/dev/w25", mtd_dev, 0755, NULL); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to register MTD driver: %d\n", + ret); + } + + /* Mount the LittleFS file system */ + + ret = nx_mount("/dev/w25", "/w25", "littlefs", 0, "autoformat"); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount LittleFS at /w25: %d\n", + ret); + } +#endif + + return 0; +} diff --git a/boards/arm/stm32f7/stm32f746g-disco/src/stm32f746g-disco.h b/boards/arm/stm32f7/stm32f746g-disco/src/stm32f746g-disco.h index fec4ada12bd..423f670b08e 100644 --- a/boards/arm/stm32f7/stm32f746g-disco/src/stm32f746g-disco.h +++ b/boards/arm/stm32f7/stm32f746g-disco/src/stm32f746g-disco.h @@ -253,6 +253,18 @@ int stm32_tsc_setup(int minor); int stm32_n25qxxx_setup(void); #endif +/**************************************************************************** + * Name: stm32_w25qxxx_setup + * + * Description: + * Initialize and register the Flash for W25QXXX driver. + * + ****************************************************************************/ + +#ifdef CONFIG_MTD_W25QXXXJV +int stm32_w25qxxx_setup(void); +#endif + #ifdef HAVE_SDIO int stm32_sdio_initialize(void); #endif