boards/stm32f411-minimum: Add optional onboard flash support

* Enable W25Q64 on SPI1 and use SMARTFS (using code from similar boards)
* Set defconfig dates to something more recent
This commit is contained in:
Denis Tolstov
2023-04-03 06:35:10 +03:00
committed by Xiang Xiao
parent f09f167592
commit da53c294b6
8 changed files with 470 additions and 4 deletions
@@ -15,4 +15,23 @@ config STM32F411MINIMUM_USBHOST_PRIO
default 100
depends on USBHOST
config STM32F411MINIMUM_FLASH
bool "MTD driver for external 8Mbyte W25Q64FV FLASH on SPI1"
default n
select MTD
select MTD_W25
select MTD_SMART
select FS_SMARTFS
select STM32_SPI1
select MTD_BYTE_WRITE
---help---
Configures an MTD device for use with the onboard flash
config STM32F411MINIMUM_FLASH_MINOR
int "Minor number for the FLASH /dev/smart entry"
default 0
depends on STM32F411MINIMUM_FLASH
---help---
Sets the minor number for the FLASH MTD /dev entry
endif
@@ -35,9 +35,9 @@ CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=14
CONFIG_START_MONTH=10
CONFIG_START_YEAR=2014
CONFIG_START_DAY=06
CONFIG_START_MONTH=06
CONFIG_START_YEAR=2020
CONFIG_STM32_FLASH_CONFIG_E=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_USART1=y
@@ -0,0 +1,50 @@
#
# 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_ARCH_FPU is not set
# CONFIG_DISABLE_OS_API is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_STM32_SYSCFG is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f411-minimum"
CONFIG_ARCH_BOARD_STM32F411_MINIMUM=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F411CE=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_HAVE_CXX=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_DISABLE_LOSMART=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=131072
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=02
CONFIG_START_MONTH=04
CONFIG_START_YEAR=2023
CONFIG_STM32F411MINIMUM_FLASH=y
CONFIG_STM32_FLASH_CONFIG_E=y
CONFIG_STM32_FLASH_PREFETCH=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_USART1=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=15
CONFIG_USART1_SERIAL_CONSOLE=y
@@ -30,6 +30,14 @@ ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
endif
ifeq ($(CONFIG_SPI),y)
CSRCS += stm32_spi.c
endif
ifeq ($(CONFIG_MTD_W25),y)
CSRCS += stm32_w25.c
endif
ifeq ($(CONFIG_STM32_OTGFS),y)
CSRCS += stm32_usb.c
endif
@@ -36,6 +36,32 @@
#include "stm32f411-minimum.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Checking needed by W25 Flash */
#define HAVE_W25 1
/* Can't support the W25 device if it SPI1 or W25 support is not enabled */
#if !defined(CONFIG_STM32_SPI1) || !defined(CONFIG_MTD_W25)
# undef HAVE_W25
#endif
/* Can't support W25 features if mountpoints are disabled */
#ifdef CONFIG_DISABLE_MOUNTPOINT
# undef HAVE_W25
#endif
/* Default W25 minor number */
#if defined(HAVE_W25) && !defined(CONFIG_NSH_W25MINOR)
# define CONFIG_NSH_W25MINOR 0
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -71,6 +97,18 @@ int stm32_bringup(void)
}
#endif
#ifdef HAVE_W25
/* Initialize and register the W25 FLASH file system. */
ret = stm32_w25initialize(CONFIG_NSH_W25MINOR);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize W25 minor %d: %d\n",
CONFIG_NSH_W25MINOR, ret);
return ret;
}
#endif
#ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */
@@ -0,0 +1,173 @@
/****************************************************************************
* boards/arm/stm32/stm32f411-minimum/src/stm32_spi.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>
#include <stdint.h>
#include <stdbool.h>
#include <debug.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
#include "arm_internal.h"
#include "chip.h"
#include "stm32.h"
#include "stm32f411-minimum.h"
#if defined(CONFIG_STM32_SPI1) || defined(CONFIG_STM32_SPI2)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_spidev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins
* for the WeAct Studio MiniF4 board.
*
****************************************************************************/
void stm32_spidev_initialize(void)
{
/* NOTE: Clocking for SPI1 and/or SPI2 was already provided in stm32_rcc.c.
* Configurations of SPI pins is performed in stm32_spi.c.
* Here, we only initialize chip select pins unique to the board
* architecture.
*/
#ifdef CONFIG_MTD_W25
stm32_configgpio(FLASH_SPI1_CS); /* FLASH chip select */
#endif
#ifdef CONFIG_MMCSD_SPI
stm32_configgpio(GPIO_SDCARD_CS); /* SD/MMC Card chip select */
#endif
}
/****************************************************************************
* Name: stm32_spi1/2select and stm32_spi1/2status
*
* Description:
* The external functions, stm32_spi1/2/3select and stm32_spi1/2/3status
* must be provided by board-specific logic. They are implementations of
* the select and status methods of the SPI interface defined by struct
* spi_ops_s (see include/nuttx/spi/spi.h). All other methods (including
* stm32_spibus_initialize()) are provided by common STM32 logic.
* To use this common SPI logic on your board:
*
* 1. Provide logic in stm32_boardinitialize() to configure SPI chip select
* pins.
* 2. Provide stm32_spi1/2/3select() and stm32_spi1/2/3status() functions
* in your board-specific logic. These functions will perform chip
* selection and status operations using GPIOs in the way your board is
* configured.
* 3. Add a calls to stm32_spibus_initialize() in your low level
* application initialization logic
* 4. The handle returned by stm32_spibus_initialize() may then be used to
* bind the SPI driver to higher level logic (e.g., calling
* mmcsd_spislotinitialize(), for example, will bind the SPI driver to
* the SPI MMC/SD driver).
*
****************************************************************************/
#ifdef CONFIG_STM32_SPI1
void stm32_spi1select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
#ifdef CONFIG_MMCSD_SPI
if (devid == SPIDEV_MMCSD(0))
{
stm32_gpiowrite(GPIO_SDCARD_CS, !selected);
}
#endif
#ifdef CONFIG_MTD_W25
stm32_gpiowrite(FLASH_SPI1_CS, !selected);
#endif
}
uint8_t stm32_spi1status(struct spi_dev_s *dev, uint32_t devid)
{
uint8_t status = 0;
#ifdef CONFIG_MMCSD_SPI
if (devid == SPIDEV_MMCSD(0))
{
status |= SPI_STATUS_PRESENT;
}
#endif
return status;
}
#endif
#ifdef CONFIG_STM32_SPI2
void stm32_spi2select(struct spi_dev_s *dev, uint32_t devid,
bool selected)
{
}
uint8_t stm32_spi2status(struct spi_dev_s *dev, uint32_t devid)
{
return 0;
}
#endif
/****************************************************************************
* Name: stm32_spi1cmddata
*
* Description:
* Set or clear the SH1101A A0 or SD1306 D/C n bit to select data (true)
* or command (false). This function must be provided by platform-specific
* logic. This is an implementation of the cmddata method of the SPI
* interface defined by struct spi_ops_s (see include/nuttx/spi/spi.h).
*
* Input Parameters:
*
* spi - SPI device that controls the bus the device that requires the CMD/
* DATA selection.
* devid - If there are multiple devices on the bus, this selects which one
* to select cmd or data. NOTE: This design restricts, for example,
* one one SPI display per SPI bus.
* cmd - true: select command; false: select data
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_SPI_CMDDATA
#ifdef CONFIG_STM32_SPI1
int stm32_spi1cmddata(struct spi_dev_s *dev, uint32_t devid,
bool cmd)
{
return -ENODEV;
}
#endif
#endif
#endif /* CONFIG_STM32_SPI1 || CONFIG_STM32_SPI2 */
@@ -0,0 +1,150 @@
/****************************************************************************
* boards/arm/stm32/stm32f411-minimum/src/stm32_w25.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>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <debug.h>
#ifdef CONFIG_STM32_SPI1
# include <nuttx/spi/spi.h>
# include <nuttx/mtd/mtd.h>
# include <nuttx/fs/smart.h>
# include <nuttx/mtd/configdata.h>
#endif
#include "stm32_spi.h"
#include "stm32f411-minimum.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Debug ********************************************************************/
/* Non-standard debug that may be enabled just for testing the watchdog
* timer
*/
#define W25_SPI_PORT 1
/* Configuration ************************************************************/
/* Can't support the W25 device if it SPI1 or W25 support is not enabled */
#define HAVE_W25 1
#if !defined(CONFIG_STM32_SPI1) || !defined(CONFIG_MTD_W25)
# undef HAVE_W25
#endif
/* Can't support W25 features if mountpoints are disabled */
#if defined(CONFIG_DISABLE_MOUNTPOINT)
# undef HAVE_W25
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_w25initialize
*
* Description:
* Initialize and register the W25 FLASH file system.
*
****************************************************************************/
int stm32_w25initialize(int minor)
{
int ret;
#ifdef HAVE_W25
struct spi_dev_s *spi;
struct mtd_dev_s *mtd;
struct mtd_geometry_s geo;
#if defined(CONFIG_MTD_PARTITION_NAMES)
const char *partname = CONFIG_STM32F411MINIMUM_FLASH_PART_NAMES;
#endif
/* Get the SPI port */
spi = stm32_spibus_initialize(W25_SPI_PORT);
if (!spi)
{
syslog(LOG_ERR, "ERROR: Failed to initialize SPI port %d\n",
W25_SPI_PORT);
return -ENODEV;
}
/* Raise SPI frequency from default 400kHz to something usable
* SPI1 uses PCLK2 of 96MHz with DIV2 = 48Mbps max
* W25Q64 requires more dummy clocks above 26MHz
*/
SPI_SETFREQUENCY(spi, 24000000);
/* Now bind the SPI interface to the W25 SPI FLASH driver */
mtd = w25_initialize(spi);
if (!mtd)
{
syslog(LOG_ERR, "ERROR: Failed to bind SPI port %d to the Winbond"
"W25 FLASH driver\n", W25_SPI_PORT);
return -ENODEV;
}
#ifndef CONFIG_FS_SMARTFS
/* And use the FTL layer to wrap the MTD driver as a block driver */
ret = ftl_initialize(minor, mtd);
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Initialize the FTL layer\n");
return ret;
}
#else
/* Initialize to provide SMARTFS on the MTD interface */
/* Get the geometry of the FLASH device */
ret = mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)((uintptr_t)&geo));
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: mtd->ioctl failed: %d\n", ret);
return ret;
}
/* Configure the device with no partition support */
smart_initialize(CONFIG_STM32F411MINIMUM_FLASH_MINOR, mtd, NULL);
#endif /* CONFIG_FS_SMARTFS */
#endif /* HAVE_W25 */
return OK;
}
@@ -60,6 +60,12 @@
#define GPIO_BTN_USER \
(GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTA | GPIO_PIN0)
/* SPI chip selects */
#define FLASH_SPI1_CS \
(GPIO_PORTA | GPIO_PIN4 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_FLOAT | \
GPIO_SPEED_50MHz)
/* procfs File System */
#ifdef CONFIG_FS_PROCFS
@@ -93,12 +99,34 @@ extern struct spi_dev_s *g_spi2;
void stm32_spidev_initialize(void);
/****************************************************************************
* Name: stm32_mmcsd_initialize
*
* Description:
* Initializes SPI-based SD card
*
****************************************************************************/
#ifdef CONFIG_MMCSD
int stm32_mmcsd_initialize(int minor);
#endif
/****************************************************************************
* Name: stm32_w25initialize
*
* Description:
* Called to initialize Winbond W25 memory
*
****************************************************************************/
int stm32_w25initialize(int minor);
/****************************************************************************
* Name: stm32_usbinitialize
*
* Description:
* Called from stm32_boardinitialize very early in initialization to setup
* USB-related GPIO pins for the STM32F4Discovery board.
* USB-related GPIO pins for the WeAct Studio MiniF4 board.
*
****************************************************************************/